Skip to content

Commit

Permalink
Fix OO code from code review feedbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
nono committed Oct 5, 2023
1 parent 38ca4aa commit 2368a15
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 9 deletions.
4 changes: 2 additions & 2 deletions docs/office.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ Content-Type: application/vnd.api+json
}
```

### GET /office/keys/:key
### POST /office/keys/:key

If a document is being edited while a new version is uploaded (via the desktop
for example), the OO webapp should call this endpoint if the user chooses to
Expand All @@ -131,7 +131,7 @@ created, so that no work is lost.
#### Request

```http
GET /office/keys/7c7ccc2e7137ba774b7e44de HTTP/1.1
POST /office/keys/7c7ccc2e7137ba774b7e44de HTTP/1.1
Host: bob.cozy.example
```

Expand Down
7 changes: 6 additions & 1 deletion model/office/file_by_key.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import (
"github.com/cozy/cozy-stack/model/vfs"
)

func GetFileByKey(inst *instance.Instance, key string) (*vfs.FileDoc, error) {
// EnsureFileForKey returns the file that will be written when OnlyOffice will
// save a document with the given key. The general case is that is the file
// that has been opened. But, it can also be a new file if a conflict has
// happened because a new version has been uploaded for this file (by the
// desktop client for example).
func EnsureFileForKey(inst *instance.Instance, key string) (*vfs.FileDoc, error) {
detector, err := GetStore().GetDoc(inst, key)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions web/office/office.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ func Open(c echo.Context) error {
return jsonapi.Data(c, http.StatusOK, doc, nil)
}

func GetFileByKey(c echo.Context) error {
func FileByKey(c echo.Context) error {
inst := middlewares.GetInstance(c)
file, err := office.GetFileByKey(inst, c.Param("key"))
file, err := office.EnsureFileForKey(inst, c.Param("key"))
if err != nil {
return wrapError(err)
}
Expand Down Expand Up @@ -102,7 +102,7 @@ func Callback(c echo.Context) error {
// Routes sets the routing for the collaborative edition of office documents.
func Routes(router *echo.Group) {
router.GET("/:id/open", Open)
router.GET("/keys/:key", GetFileByKey)
router.POST("/keys/:key", FileByKey)
router.POST("/callback", Callback)
}

Expand Down
6 changes: 3 additions & 3 deletions web/office/office_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ func TestOffice(t *testing.T) {
key = document.Value("key").String().NotEmpty().Raw()

// the key is associated to this file
obj = e.GET("/office/keys/"+key).
obj = e.POST("/office/keys/"+key).
WithHeader("Authorization", "Bearer "+token).
Expect().Status(200).
JSON(httpexpect.ContentOpts{MediaType: "application/vnd.api+json"}).
Expand All @@ -160,7 +160,7 @@ func TestOffice(t *testing.T) {
// When an upload is made that changes the content of this document,
// the key will now be associated to a conflict file
updateFile(t, inst, fileID)
obj = e.GET("/office/keys/"+key).
obj = e.POST("/office/keys/"+key).
WithHeader("Authorization", "Bearer "+token).
Expect().Status(200).
JSON(httpexpect.ContentOpts{MediaType: "application/vnd.api+json"}).
Expand All @@ -175,7 +175,7 @@ func TestOffice(t *testing.T) {
assert.Equal(t, "letter (2).docx", conflictName)

// When another user uses the same key, they obtains the same file
obj = e.GET("/office/keys/"+key).
obj = e.POST("/office/keys/"+key).
WithHeader("Authorization", "Bearer "+token).
Expect().Status(200).
JSON(httpexpect.ContentOpts{MediaType: "application/vnd.api+json"}).
Expand Down

0 comments on commit 2368a15

Please sign in to comment.