diff --git a/services/collaboration/pkg/connector/fileconnector.go b/services/collaboration/pkg/connector/fileconnector.go index ce623dd339..2ea1c9bf8c 100644 --- a/services/collaboration/pkg/connector/fileconnector.go +++ b/services/collaboration/pkg/connector/fileconnector.go @@ -222,6 +222,14 @@ func (f *FileConnector) Lock(ctx context.Context, lockID, oldLockID string) (*Co return NewResponse(400), nil } + // OnlyOffice locks on every open, a SetLock with a read-only token fails and the 500 becomes an error dialog + // in OnlyOffice, so read-only and view-only sessions get their 200 without a lock + if wopiContext.ViewMode == appproviderv1beta1.ViewMode_VIEW_MODE_READ_ONLY || + wopiContext.ViewMode == appproviderv1beta1.ViewMode_VIEW_MODE_VIEW_ONLY { + logger.Debug().Msg("Lock: read-only session, skipping the lock") + return NewResponseWithVersion(nil), nil + } + var setOrRefreshStatus *rpcv1beta1.Status if oldLockID == "" { // If the oldLockID is empty, this is a "LOCK" request diff --git a/services/collaboration/pkg/connector/fileconnector_test.go b/services/collaboration/pkg/connector/fileconnector_test.go index f5bdca4f76..8fccfe4164 100644 --- a/services/collaboration/pkg/connector/fileconnector_test.go +++ b/services/collaboration/pkg/connector/fileconnector_test.go @@ -171,6 +171,26 @@ var _ = Describe("FileConnector", func() { Expect(response.Headers).To(BeNil()) }) + It("Read-only session gets 200 without a lock", func() { + gatewaySelector.EXPECT().Next().Unset() + wopiCtx.ViewMode = appproviderv1beta1.ViewMode_VIEW_MODE_READ_ONLY + ctx := middleware.WopiContextToCtx(context.Background(), wopiCtx) + + response, err := fc.Lock(ctx, "abcdef123", "") + Expect(err).ToNot(HaveOccurred()) + Expect(response.Status).To(Equal(200)) + }) + + It("View-only session gets 200 without a lock", func() { + gatewaySelector.EXPECT().Next().Unset() + wopiCtx.ViewMode = appproviderv1beta1.ViewMode_VIEW_MODE_VIEW_ONLY + ctx := middleware.WopiContextToCtx(context.Background(), wopiCtx) + + response, err := fc.Lock(ctx, "abcdef123", "") + Expect(err).ToNot(HaveOccurred()) + Expect(response.Status).To(Equal(200)) + }) + It("Set lock failed", func() { ctx := middleware.WopiContextToCtx(context.Background(), wopiCtx)