diff --git a/docs/office.md b/docs/office.md index 1ca8edc0c59..c63f7219e91 100644 --- a/docs/office.md +++ b/docs/office.md @@ -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 @@ -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 ``` diff --git a/model/office/file_by_key.go b/model/office/file_by_key.go index e10801bff69..71932522924 100644 --- a/model/office/file_by_key.go +++ b/model/office/file_by_key.go @@ -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 diff --git a/web/office/office.go b/web/office/office.go index 2ae6bfba466..08081c67434 100644 --- a/web/office/office.go +++ b/web/office/office.go @@ -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) } @@ -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) } diff --git a/web/office/office_test.go b/web/office/office_test.go index 61a10143cb5..19375b3ecfa 100644 --- a/web/office/office_test.go +++ b/web/office/office_test.go @@ -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"}). @@ -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"}). @@ -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"}).