From 925a6434edf86269161b4c72f36e6c58a8c1fe6e Mon Sep 17 00:00:00 2001 From: Christian Richter Date: Fri, 6 Sep 2024 07:04:25 +0200 Subject: [PATCH] allow updateing of ocm shares MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Christian Richter add changelog Signed-off-by: Christian Richter Signed-off-by: Jörn Friedrich Dreyer --- .../unreleased/allow-update-ocm-shares.md | 6 ++ pkg/ocm/share/repository/json/json.go | 93 ++++++++++++++++++- 2 files changed, 97 insertions(+), 2 deletions(-) create mode 100644 changelog/unreleased/allow-update-ocm-shares.md diff --git a/changelog/unreleased/allow-update-ocm-shares.md b/changelog/unreleased/allow-update-ocm-shares.md new file mode 100644 index 0000000000..9b11235199 --- /dev/null +++ b/changelog/unreleased/allow-update-ocm-shares.md @@ -0,0 +1,6 @@ +Bugfix: Allow update of ocm shares + +We fixed a bug that prevented ocm shares to be updated or removed. + +https://github.com/cs3org/reva/pull/4840/ +https://github.com/owncloud/ocis/issues/9926 \ No newline at end of file diff --git a/pkg/ocm/share/repository/json/json.go b/pkg/ocm/share/repository/json/json.go index 139a320b4e..234b76553a 100644 --- a/pkg/ocm/share/repository/json/json.go +++ b/pkg/ocm/share/repository/json/json.go @@ -381,8 +381,97 @@ func receivedShareEqual(ref *ocm.ShareReference, s *ocm.ReceivedShare) bool { return false } -func (m *mgr) UpdateShare(ctx context.Context, user *userpb.User, ref *ocm.ShareReference, f ...*ocm.UpdateOCMShareRequest_UpdateField) (*ocm.Share, error) { - return nil, errtypes.NotSupported("not yet implemented") +// UpdateShare updates the share with the given fields. +func (m *mgr) UpdateShare(ctx context.Context, user *userpb.User, ref *ocm.ShareReference, fields ...*ocm.UpdateOCMShareRequest_UpdateField) (*ocm.Share, error) { + m.Lock() + defer m.Unlock() + if err := m.load(); err != nil { + return nil, err + } + for _, s := range m.model.Shares { + if sharesEqual(ref, s) { + if utils.UserEqual(user.Id, s.Owner) || utils.UserEqual(user.Id, s.Creator) { + + for _, f := range fields { + if exp := f.GetExpiration(); exp != nil { + s.Expiration = exp + } + if am := f.GetAccessMethods(); am != nil { + var ( + webdavOptions *ocm.WebDAVAccessMethod + webappOptions *ocm.WebappAccessMethod + transferOptions *ocm.TransferAccessMethod + // TODO: *AccessMethod_GenericOptions + + newWebdavOptions *ocm.WebDAVAccessMethod + newWebappOptions *ocm.WebappAccessMethod + newTransferOptions *ocm.TransferAccessMethod + // TODO: *AccessMethod_GenericOptions + ) + + for _, sm := range s.GetAccessMethods() { + webdavOptions = sm.GetWebdavOptions() + webappOptions = sm.GetWebappOptions() + transferOptions = sm.GetTransferOptions() + } + + newWebdavOptions = am.GetWebdavOptions() + newWebappOptions = am.GetWebappOptions() + newTransferOptions = am.GetTransferOptions() + + newAccesMethods := []*ocm.AccessMethod{} + + if newWebdavOptions != nil { + newAccesMethods = append(newAccesMethods, &ocm.AccessMethod{ + Term: &ocm.AccessMethod_WebdavOptions{ + WebdavOptions: newWebdavOptions, + }, + }) + } else if webdavOptions != nil { + newAccesMethods = append(newAccesMethods, &ocm.AccessMethod{ + Term: &ocm.AccessMethod_WebdavOptions{ + WebdavOptions: webdavOptions, + }, + }) + } + + if newWebappOptions != nil { + newAccesMethods = append(newAccesMethods, &ocm.AccessMethod{ + Term: &ocm.AccessMethod_WebappOptions{ + WebappOptions: newWebappOptions, + }, + }) + } else if webappOptions != nil { + newAccesMethods = append(newAccesMethods, &ocm.AccessMethod{ + Term: &ocm.AccessMethod_WebappOptions{ + WebappOptions: webappOptions, + }, + }) + } + + if newTransferOptions != nil { + newAccesMethods = append(newAccesMethods, &ocm.AccessMethod{ + Term: &ocm.AccessMethod_TransferOptions{ + TransferOptions: newTransferOptions, + }, + }) + } else if transferOptions != nil { + newAccesMethods = append(newAccesMethods, &ocm.AccessMethod{ + Term: &ocm.AccessMethod_TransferOptions{ + TransferOptions: transferOptions, + }, + }) + } + s.AccessMethods = newAccesMethods + } + } + + return s, nil + } + } + } + + return nil, errtypes.NotFound(ref.String()) } func (m *mgr) ListShares(ctx context.Context, user *userpb.User, filters []*ocm.ListOCMSharesRequest_Filter) ([]*ocm.Share, error) {