Add the ocm notification ShareChangePermission

This commit is contained in:
Roman Perekhod committed 2025-02-24 10:40:31 +01:00
1 parent 9b2b7e968f
commit 0de97ddee0
11 files changed
+336 -208

No files matched your search

@@ -0,0 +1,5 @@
Enhancement: Add the ocm notification ShareChangePermission
Added the ocm notification ShareChangePermission that allows to synchronize the permissions of a share between the federated instances.
https://github.com/owncloud/ocis/pull/11041
+1 -1
View File
@@ -17,7 +17,7 @@ require (
github.com/cenkalti/backoff v2.2.1+incompatible
github.com/coreos/go-oidc/v3 v3.11.0
github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1
github.com/cs3org/reva/v2 v2.27.5-0.20250217133727-8aefc9e791f7
github.com/cs3org/reva/v2 v2.27.5-0.20250221083634-a04df6f633fe
github.com/davidbyttow/govips/v2 v2.16.0
github.com/dhowden/tag v0.0.0-20240417053706-3d75831295e8
github.com/dutchcoders/go-clamd v0.0.0-20170520113014-b970184f4d9e
+2 -2
View File
@@ -249,8 +249,8 @@ github.com/crewjam/saml v0.4.14 h1:g9FBNx62osKusnFzs3QTN5L9CVA/Egfgm+stJShzw/c=
github.com/crewjam/saml v0.4.14/go.mod h1:UVSZCf18jJkk6GpWNVqcyQJMD5HsRugBPf4I1nl2mME=
github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1 h1:RU6LT6mkD16xZs011+8foU7T3LrPvTTSWeTQ9OgfhkA=
github.com/cs3org/go-cs3apis v0.0.0-20241105092511-3ad35d174fc1/go.mod h1:DedpcqXl193qF/08Y04IO0PpxyyMu8+GrkD6kWK2MEQ=
github.com/cs3org/reva/v2 v2.27.5-0.20250217133727-8aefc9e791f7 h1:slkg8L8rG4ei0OKwEMDZ7EY88d3cduzO53rWMY6lX+A=
github.com/cs3org/reva/v2 v2.27.5-0.20250217133727-8aefc9e791f7/go.mod h1:1H26PMXoa1rDrIoZ7lGOerq1Bg07/5srYfRaKfxBSsc=
github.com/cs3org/reva/v2 v2.27.5-0.20250221083634-a04df6f633fe h1:q6M8ZBu5/NbvA8fw5c+ELyKeoeb7g2Ea1B0jH9XBaos=
github.com/cs3org/reva/v2 v2.27.5-0.20250221083634-a04df6f633fe/go.mod h1:1H26PMXoa1rDrIoZ7lGOerq1Bg07/5srYfRaKfxBSsc=
github.com/cyberdelia/templates v0.0.0-20141128023046-ca7fffd4298c/go.mod h1:GyV+0YP4qX0UQ7r2MoYZ+AvYDp12OF5yg4q8rGnyNh4=
github.com/cyphar/filepath-securejoin v0.2.5 h1:6iR5tXJ/e6tJZzzdMc1km3Sa7RRIVBKAK32O2s7AYfo=
github.com/cyphar/filepath-securejoin v0.2.5/go.mod h1:aPGpWjXOXUn2NCNjFvBE6aRxGGx79pTxQpKOJNYHHl4=
+29 -1
View File
@@ -39,6 +39,7 @@ import (
"github.com/cs3org/reva/v2/pkg/utils/cfg"
"github.com/rs/zerolog"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/fieldmaskpb"
)
func init() {
@@ -148,7 +149,34 @@ func (s *service) CreateOCMCoreShare(ctx context.Context, req *ocmcore.CreateOCM
}
func (s *service) UpdateOCMCoreShare(ctx context.Context, req *ocmcore.UpdateOCMCoreShareRequest) (*ocmcore.UpdateOCMCoreShareResponse, error) {
return nil, errtypes.NotSupported("not implemented")
grantee := utils.ReadPlainFromOpaque(req.GetOpaque(), "grantee")
if grantee == "" {
return nil, errtypes.UserRequired("missing remote user id in a metadata")
}
if req == nil || len(req.Protocols) == 0 {
return nil, errtypes.PreconditionFailed("missing protocols in a request")
}
fileMask := &fieldmaskpb.FieldMask{Paths: []string{"protocols"}}
user := &userpb.User{Id: ocmuser.RemoteID(&userpb.UserId{OpaqueId: grantee})}
_, err := s.repo.UpdateReceivedShare(ctx, user, &ocm.ReceivedShare{
Id: &ocm.ShareId{
OpaqueId: req.GetOcmShareId(),
},
Protocols: req.Protocols,
}, fileMask)
res := &ocmcore.UpdateOCMCoreShareResponse{}
if err == nil {
res.Status = status.NewOK(ctx)
} else {
var notFound errtypes.NotFound
if errors.As(err, &notFound) {
res.Status = status.NewNotFound(ctx, "remote ocm share not found")
} else {
res.Status = status.NewInternal(ctx, "error deleting remote ocm share")
}
}
return res, nil
}
func (s *service) DeleteOCMCoreShare(ctx context.Context, req *ocmcore.DeleteOCMCoreShareRequest) (*ocmcore.DeleteOCMCoreShareResponse, error) {
@@ -20,6 +20,7 @@ package ocmshareprovider
import (
"context"
"fmt"
"net/url"
"path/filepath"
"strings"
@@ -38,7 +39,6 @@ import (
ctxpkg "github.com/cs3org/reva/v2/pkg/ctx"
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/cs3org/reva/v2/pkg/ocm/client"
"github.com/cs3org/reva/v2/pkg/ocm/payload"
"github.com/cs3org/reva/v2/pkg/ocm/share"
"github.com/cs3org/reva/v2/pkg/ocm/share/repository/registry"
ocmuser "github.com/cs3org/reva/v2/pkg/ocm/user"
@@ -381,19 +381,16 @@ func (s *service) CreateOCMShare(ctx context.Context, req *ocm.CreateOCMShareReq
func (s *service) RemoveOCMShare(ctx context.Context, req *ocm.RemoveOCMShareRequest) (*ocm.RemoveOCMShareResponse, error) {
user := ctxpkg.ContextMustGetUser(ctx)
getShareRes, err := s.GetOCMShare(ctx, &ocm.GetOCMShareRequest{
Ref: req.Ref,
})
getShareRes, err := s.GetOCMShare(ctx, &ocm.GetOCMShareRequest{Ref: req.Ref})
if err != nil {
return &ocm.RemoveOCMShareResponse{
Status: status.NewInternal(ctx, "error getting ocm share"),
}, nil
}
if getShareRes.Status.Code != rpc.Code_CODE_OK {
res := &ocm.RemoveOCMShareResponse{
return &ocm.RemoveOCMShareResponse{
Status: getShareRes.GetStatus(),
}
return res, nil
}, nil
}
if err := s.repo.DeleteShare(ctx, user, req.Ref); err != nil {
@@ -407,47 +404,9 @@ func (s *service) RemoveOCMShare(ctx context.Context, req *ocm.RemoveOCMShareReq
}, nil
}
// TODO: We should not fail the whole operation if the notification fails
gatewayClient, err := s.gatewaySelector.Next()
err = s.notify(ctx, client.SHARE_UNSHARED, getShareRes.GetShare())
if err != nil {
return &ocm.RemoveOCMShareResponse{
Status: status.NewInternal(ctx, "error getting gateway client"),
}, nil
}
providerInfoResp, err := gatewayClient.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{
Domain: getShareRes.GetShare().GetGrantee().GetUserId().GetIdp(),
})
if err != nil {
return &ocm.RemoveOCMShareResponse{
Status: status.NewInternal(ctx, "error getting provider info"),
}, nil
}
if providerInfoResp.Status.Code != rpc.Code_CODE_OK {
return &ocm.RemoveOCMShareResponse{
Status: providerInfoResp.Status,
}, nil
}
ocmEndpoint, err := getOCMEndpoint(providerInfoResp.GetProviderInfo())
if err != nil {
return &ocm.RemoveOCMShareResponse{
Status: status.NewInternal(ctx, "the selected provider does not have an OCM endpoint"),
}, nil
}
newShareReq := &payload.NotificationRequest{
NotificationType: payload.SHARE_UNSHARED,
ResourceType: "file", // use type "file" for shared files or folders
ProviderId: getShareRes.GetShare().GetId().GetOpaqueId(),
Notification: &payload.Notification{
Grantee: getShareRes.GetShare().GetGrantee().GetUserId().GetOpaqueId(),
},
}
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
err = s.client.NotifyRemote(ctx, ocmEndpoint, newShareReq)
if err != nil {
// Continue even if the notification fails
// Continue even if the notification fails. The share has been removed locally.
appctx.GetLogger(ctx).Err(err).Msg("error notifying ocm remote provider")
}
@@ -526,7 +485,20 @@ func (s *service) UpdateOCMShare(ctx context.Context, req *ocm.UpdateOCMShareReq
Status: status.NewOK(ctx),
}, nil
}
_, err := s.repo.UpdateShare(ctx, user, req.Ref, req.Field...)
getShareRes, err := s.GetOCMShare(ctx, &ocm.GetOCMShareRequest{Ref: req.Ref})
if err != nil {
return &ocm.UpdateOCMShareResponse{
Status: status.NewInternal(ctx, "error getting ocm share"),
}, nil
}
if getShareRes.Status.Code != rpc.Code_CODE_OK {
return &ocm.UpdateOCMShareResponse{
Status: getShareRes.GetStatus(),
}, nil
}
uShare, err := s.repo.UpdateShare(ctx, user, req.Ref, req.Field...)
if err != nil {
if errors.Is(err, share.ErrShareNotFound) {
return &ocm.UpdateOCMShareResponse{
@@ -538,10 +510,25 @@ func (s *service) UpdateOCMShare(ctx context.Context, req *ocm.UpdateOCMShareReq
}, nil
}
res := &ocm.UpdateOCMShareResponse{
Status: status.NewOK(ctx),
err = s.notify(ctx, client.SHARE_CHANGE_PERMISSION, uShare)
if err != nil {
// Disallow update if the remoter provider could not be notified to avoid inconsistencies
// between the local and remote shares. User still can delete the share.
err = fmt.Errorf("error notifying ocm remote provider: %w", err)
appctx.GetLogger(ctx).Err(err).Send()
// Revert the share changes.
if _, err := s.repo.StoreShare(ctx, getShareRes.GetShare()); err != nil {
appctx.GetLogger(ctx).Err(err).Msg("error reverting ocm share changes")
}
return &ocm.UpdateOCMShareResponse{
Status: status.NewInternal(ctx, err.Error()),
}, nil
}
return res, nil
return &ocm.UpdateOCMShareResponse{
Status: status.NewOK(ctx),
}, nil
}
func (s *service) ListReceivedOCMShares(ctx context.Context, req *ocm.ListReceivedOCMSharesRequest) (*ocm.ListReceivedOCMSharesResponse, error) {
@@ -608,3 +595,48 @@ func (s *service) GetReceivedOCMShare(ctx context.Context, req *ocm.GetReceivedO
}
return res, nil
}
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
func (s *service) notify(ctx context.Context, notificationType string, share *ocm.Share) error {
gatewayClient, err := s.gatewaySelector.Next()
if err != nil {
return err
}
providerInfoResp, err := gatewayClient.GetInfoByDomain(ctx, &ocmprovider.GetInfoByDomainRequest{
Domain: share.GetGrantee().GetUserId().GetIdp(),
})
if err != nil {
return err
}
if providerInfoResp.Status.Code != rpc.Code_CODE_OK {
return fmt.Errorf("error getting provider info: %s", providerInfoResp.Status.Message)
}
ocmEndpoint, err := getOCMEndpoint(providerInfoResp.GetProviderInfo())
if err != nil {
return err
}
notification := &client.Notification{}
switch notificationType {
case client.SHARE_UNSHARED:
notification.Grantee = share.GetGrantee().GetUserId().GetOpaqueId()
case client.SHARE_CHANGE_PERMISSION:
notification.Grantee = share.GetGrantee().GetUserId().GetOpaqueId()
notification.Protocols = s.getProtocols(ctx, share)
default:
return fmt.Errorf("unknown notification type: %s", notificationType)
}
newShareReq := &client.NotificationRequest{
NotificationType: notificationType,
ResourceType: "file", // use type "file" for shared files or folders
ProviderId: share.GetId().GetOpaqueId(),
Notification: notification,
}
err = s.client.NotifyRemote(ctx, ocmEndpoint, newShareReq)
if err != nil {
appctx.GetLogger(ctx).Err(err).Msg("error notifying ocm remote provider")
return err
}
return nil
}
@@ -30,12 +30,16 @@ import (
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
typesv1beta1 "github.com/cs3org/go-cs3apis/cs3/types/v1beta1"
"github.com/cs3org/reva/v2/pkg/appctx"
"github.com/cs3org/reva/v2/pkg/ocm/payload"
"github.com/cs3org/reva/v2/pkg/rgrpc/todo/pool"
"github.com/cs3org/reva/v2/pkg/utils"
"github.com/go-chi/render"
)
const (
SHARE_UNSHARED = "SHARE_UNSHARED"
SHARE_CHANGE_PERMISSION = "SHARE_CHANGE_PERMISSION"
)
// var validate = validator.New()
type notifHandler struct {
@@ -52,13 +56,44 @@ func (h *notifHandler) init(c *config) error {
return nil
}
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
type notificationRequest struct {
NotificationType string `json:"notificationType" validate:"required"`
ResourceType string `json:"resourceType" validate:"required"`
// Identifier to identify the shared resource at the provider side. This is unique per provider such that if the same resource is shared twice, this providerId will not be repeated.
ProviderId string `json:"providerId" validate:"required"`
// Optional additional parameters, depending on the notification and the resource type.
Notification *notification `json:"notification,omitempty"`
}
type notification struct {
Owner string `json:"owner,omitempty"`
Grantee string `json:"grantee,omitempty"`
SharedSecret string `json:"sharedSecret,omitempty"`
Expiration uint64 `json:"expiration,omitempty"`
Protocols Protocols `json:"protocol,omitempty" validate:"required"`
}
// ErrorMessageResponse is the response returned by the OCM API in case of an error.
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
type ErrorMessageResponse struct {
Message string `json:"message"`
ValidationErrors []*ValidationError `json:"validationErrors,omitempty"`
}
// ValidationError is the payload for the validationErrors field in the ErrorMessageResponse.
type ValidationError struct {
Name string `json:"name"`
Message string `json:"message"`
}
// Notifications dispatches any notifications received from remote OCM sites
// according to the specifications at:
// https://cs3org.github.io/OCM-API/docs.html?branch=v1.1.0&repo=OCM-API&user=cs3org#/paths/~1notifications/post
func (h *notifHandler) Notifications(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
log := appctx.GetLogger(ctx)
req, err := getNotification(w, r)
req, err := getNotification(r)
if err != nil {
renderErrorBadRequest(w, r, http.StatusBadRequest, err.Error())
return
@@ -68,20 +103,22 @@ func (h *notifHandler) Notifications(w http.ResponseWriter, r *http.Request) {
log.Debug().Msgf("Received OCM notification: %+v", req)
var status *rpc.Status
if req.Notification.Grantee == "" {
renderErrorBadRequest(w, r, http.StatusBadRequest, "grantee is required")
}
switch req.NotificationType {
case payload.SHARE_UNSHARED:
if req.Notification.Grantee == "" {
renderErrorBadRequest(w, r, http.StatusBadRequest, "grantee is required")
}
case SHARE_UNSHARED:
status, err = h.handleShareUnshared(ctx, req)
if err != nil {
log.Err(err).Any("NotificationRequest", req).Msg("error getting gateway client")
log.Err(err).Any("notificationRequest", req).Msg("error getting gateway client")
renderErrorBadRequest(w, r, http.StatusInternalServerError, status.GetMessage())
}
case SHARE_CHANGE_PERMISSION:
status, err = h.handleShareChangePermission(ctx, req)
if err != nil {
log.Err(err).Any("notificationRequest", req).Msg("error getting gateway client")
renderErrorBadRequest(w, r, http.StatusInternalServerError, status.GetMessage())
}
case payload.SHARE_CHANGE_PERMISSION:
// TODO implement the SHARE_CHANGE_PERMISSION
w.WriteHeader(http.StatusNotImplemented)
return
default:
renderErrorBadRequest(w, r, http.StatusBadRequest, "NotificationType "+req.NotificationType+" is not supported")
return
@@ -106,7 +143,7 @@ func (h *notifHandler) Notifications(w http.ResponseWriter, r *http.Request) {
}
}
func (h *notifHandler) handleShareUnshared(ctx context.Context, req *payload.NotificationRequest) (*rpc.Status, error) {
func (h *notifHandler) handleShareUnshared(ctx context.Context, req *notificationRequest) (*rpc.Status, error) {
gatewayClient, err := h.gatewaySelector.Next()
if err != nil {
return nil, fmt.Errorf("error getting gateway client: %w", err)
@@ -125,10 +162,34 @@ func (h *notifHandler) handleShareUnshared(ctx context.Context, req *payload.Not
return res.GetStatus(), nil
}
func getNotification(w http.ResponseWriter, r *http.Request) (*payload.NotificationRequest, error) {
func (h *notifHandler) handleShareChangePermission(ctx context.Context, req *notificationRequest) (*rpc.Status, error) {
gatewayClient, err := h.gatewaySelector.Next()
if err != nil {
return nil, fmt.Errorf("error getting gateway client: %w", err)
}
if req.Notification == nil || req.Notification.Protocols == nil {
return nil, fmt.Errorf("error getting protocols from notification")
}
o := &typesv1beta1.Opaque{}
utils.AppendPlainToOpaque(o, "grantee", req.Notification.Grantee)
res, err := gatewayClient.UpdateOCMCoreShare(ctx, &ocmcore.UpdateOCMCoreShareRequest{
OcmShareId: req.ProviderId,
Protocols: getProtocols(req.Notification.Protocols),
Opaque: o,
})
if err != nil {
return nil, fmt.Errorf("error calling DeleteOCMCoreShare: %w", err)
}
return res.GetStatus(), nil
}
func getNotification(r *http.Request) (*notificationRequest, error) {
contentType, _, err := mime.ParseMediaType(r.Header.Get("Content-Type"))
if err == nil && contentType == "application/json" {
n := &payload.NotificationRequest{}
n := &notificationRequest{}
err := json.NewDecoder(r.Body).Decode(&n)
if err != nil {
return nil, err
@@ -144,11 +205,11 @@ func renderJSON(w http.ResponseWriter, r *http.Request, statusCode int, resp any
}
func renderErrorBadRequest(w http.ResponseWriter, r *http.Request, statusCode int, message string) {
resp := &payload.ErrorMessageResponse{
resp := &ErrorMessageResponse{
Message: "BAD_REQUEST",
ValidationErrors: []*payload.ValidationError{
ValidationErrors: []*ValidationError{
{
Name: "Notification",
Name: "notification",
Message: message,
},
},
+2 -79
View File
@@ -19,7 +19,6 @@
package client
import (
"bytes"
"context"
"encoding/json"
"fmt"
@@ -29,10 +28,8 @@ import (
"strconv"
"time"
"github.com/cs3org/reva/v2/internal/http/services/ocmd"
"github.com/cs3org/reva/v2/pkg/appctx"
"github.com/cs3org/reva/v2/pkg/errtypes"
"github.com/cs3org/reva/v2/pkg/ocm/payload"
"github.com/cs3org/reva/v2/pkg/rhttp"
"github.com/pkg/errors"
)
@@ -78,32 +75,6 @@ func New(c *Config) *OCMClient {
}
}
// InviteAcceptedRequest contains the parameters for accepting
// an invitation.
type InviteAcceptedRequest struct {
UserID string `json:"userID"`
Email string `json:"email"`
Name string `json:"name"`
RecipientProvider string `json:"recipientProvider"`
Token string `json:"token"`
}
// User contains the remote user's information when accepting
// an invitation.
type User struct {
UserID string `json:"userID"`
Email string `json:"email"`
Name string `json:"name"`
}
func (r *InviteAcceptedRequest) toJSON() (io.Reader, error) {
var b bytes.Buffer
if err := json.NewEncoder(&b).Encode(r); err != nil {
return nil, err
}
return &b, nil
}
// InviteAccepted informs the sender that the invitation was accepted to start sharing
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1invite-accepted/post
func (c *OCMClient) InviteAccepted(ctx context.Context, endpoint string, r *InviteAcceptedRequest) (*User, error) {
@@ -157,35 +128,6 @@ func (c *OCMClient) parseInviteAcceptedResponse(r *http.Response) (*User, error)
return nil, errtypes.InternalError(string(body))
}
// NewShareRequest contains the parameters for creating a new OCM share.
type NewShareRequest struct {
ShareWith string `json:"shareWith"`
Name string `json:"name"`
Description string `json:"description"`
ProviderID string `json:"providerId"`
Owner string `json:"owner"`
Sender string `json:"sender"`
OwnerDisplayName string `json:"ownerDisplayName"`
SenderDisplayName string `json:"senderDisplayName"`
ShareType string `json:"shareType"`
Expiration uint64 `json:"expiration"`
ResourceType string `json:"resourceType"`
Protocols ocmd.Protocols `json:"protocol"`
}
func (r *NewShareRequest) toJSON() (io.Reader, error) {
var b bytes.Buffer
if err := json.NewEncoder(&b).Encode(r); err != nil {
return nil, err
}
return &b, nil
}
// NewShareResponse is the response returned when creating a new share.
type NewShareResponse struct {
RecipientDisplayName string `json:"recipientDisplayName"`
}
// NewShare creates a new share.
// https://github.com/cs3org/OCM-API/blob/develop/spec.yaml
func (c *OCMClient) NewShare(ctx context.Context, endpoint string, r *NewShareRequest) (*NewShareResponse, error) {
@@ -235,25 +177,6 @@ func (c *OCMClient) parseNewShareResponse(r *http.Response) (*NewShareResponse,
return nil, errtypes.InternalError(string(body))
}
// Capabilities contains a set of properties exposed by
// a remote cloud storage.
type Capabilities struct {
Enabled bool `json:"enabled"`
APIVersion string `json:"apiVersion"`
EndPoint string `json:"endPoint"`
Provider string `json:"provider"`
ResourceTypes []struct {
Name string `json:"name"`
ShareTypes []string `json:"shareTypes"`
Protocols struct {
Webdav *string `json:"webdav"`
Webapp *string `json:"webapp"`
Datatx *string `json:"datatx"`
} `json:"protocols"`
} `json:"resourceTypes"`
Capabilities []string `json:"capabilities"`
}
// Discovery returns a number of properties used to discover the capabilities offered by a remote cloud storage.
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1ocm-provider/get
func (c *OCMClient) Discovery(ctx context.Context, endpoint string) (*Capabilities, error) {
@@ -291,7 +214,7 @@ func (c *OCMClient) Discovery(ctx context.Context, endpoint string) (*Capabiliti
// A notification MAY also be sent to let a recipient know that the provider removed that recipient from the list of trusted users, along with any related share.
// The recipient MAY reciprocally remove that provider from the list of trusted users, along with any related share.
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
func (c *OCMClient) NotifyRemote(ctx context.Context, endpoint string, r *payload.NotificationRequest) error {
func (c *OCMClient) NotifyRemote(ctx context.Context, endpoint string, r *NotificationRequest) error {
url, err := url.JoinPath(endpoint, "notifications")
if err != nil {
return err
@@ -327,7 +250,7 @@ func (c *OCMClient) parseNotifyRemoteResponse(r *http.Response, resp any) error
if resp == nil {
return nil
}
err := json.NewDecoder(r.Body).Decode(&resp)
err := json.NewDecoder(r.Body).Decode(resp)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("http status code: %v, error decoding response body", r.StatusCode))
}
+131
View File
@@ -0,0 +1,131 @@
package client
import (
"bytes"
"encoding/json"
"io"
"github.com/cs3org/reva/v2/internal/http/services/ocmd"
)
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
// NotificationType one of "SHARE_ACCEPTED", "SHARE_DECLINED", "SHARE_CHANGE_PERMISSION", "SHARE_UNSHARED", "USER_REMOVED"
const (
SHARE_UNSHARED = "SHARE_UNSHARED"
SHARE_CHANGE_PERMISSION = "SHARE_CHANGE_PERMISSION"
)
// InviteAcceptedRequest contains the parameters for accepting
// an invitation.
type InviteAcceptedRequest struct {
UserID string `json:"userID"`
Email string `json:"email"`
Name string `json:"name"`
RecipientProvider string `json:"recipientProvider"`
Token string `json:"token"`
}
// User contains the remote user's information when accepting
// an invitation.
type User struct {
UserID string `json:"userID"`
Email string `json:"email"`
Name string `json:"name"`
}
func (r *InviteAcceptedRequest) toJSON() (io.Reader, error) {
var b bytes.Buffer
if err := json.NewEncoder(&b).Encode(r); err != nil {
return nil, err
}
return &b, nil
}
// NewShareRequest contains the parameters for creating a new OCM share.
type NewShareRequest struct {
ShareWith string `json:"shareWith"`
Name string `json:"name"`
Description string `json:"description"`
ProviderID string `json:"providerId"`
Owner string `json:"owner"`
Sender string `json:"sender"`
OwnerDisplayName string `json:"ownerDisplayName"`
SenderDisplayName string `json:"senderDisplayName"`
ShareType string `json:"shareType"`
Expiration uint64 `json:"expiration"`
ResourceType string `json:"resourceType"`
Protocols ocmd.Protocols `json:"protocol"`
}
func (r *NewShareRequest) toJSON() (io.Reader, error) {
var b bytes.Buffer
if err := json.NewEncoder(&b).Encode(r); err != nil {
return nil, err
}
return &b, nil
}
// Capabilities contains a set of properties exposed by
// a remote cloud storage.
type Capabilities struct {
Enabled bool `json:"enabled"`
APIVersion string `json:"apiVersion"`
EndPoint string `json:"endPoint"`
Provider string `json:"provider"`
ResourceTypes []struct {
Name string `json:"name"`
ShareTypes []string `json:"shareTypes"`
Protocols struct {
Webdav *string `json:"webdav"`
Webapp *string `json:"webapp"`
Datatx *string `json:"datatx"`
} `json:"protocols"`
} `json:"resourceTypes"`
Capabilities []string `json:"capabilities"`
}
// NotificationRequest is the request payload for the OCM API notifications endpoint.
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
type NotificationRequest struct {
NotificationType string `json:"notificationType" validate:"required"`
ResourceType string `json:"resourceType" validate:"required"`
// Identifier to identify the shared resource at the provider side. This is unique per provider such that if the same resource is shared twice, this providerId will not be repeated.
ProviderId string `json:"providerId" validate:"required"`
// Optional additional parameters, depending on the notification and the resource type.
Notification *Notification `json:"notification,omitempty"`
}
// Notification is the payload for the notification field in the NotificationRequest.
type Notification struct {
// Owner string `json:"owner,omitempty"`
Grantee string `json:"grantee,omitempty"`
SharedSecret string `json:"sharedSecret,omitempty"`
Protocols ocmd.Protocols `json:"protocol,omitempty"`
}
// ToJSON returns the JSON io.Reader of the NotificationRequest.
func (r *NotificationRequest) ToJSON() (io.Reader, error) {
var b bytes.Buffer
if err := json.NewEncoder(&b).Encode(r); err != nil {
return nil, err
}
return &b, nil
}
// NewShareResponse is the response returned when creating a new share.
type NewShareResponse struct {
RecipientDisplayName string `json:"recipientDisplayName"`
}
// ErrorMessageResponse is the response returned by the OCM API in case of an error.
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
type ErrorMessageResponse struct {
Message string `json:"message"`
ValidationErrors []*ValidationError `json:"validationErrors,omitempty"`
}
// ValidationError is the payload for the validationErrors field in the ErrorMessageResponse.
type ValidationError struct {
Name string `json:"name"`
Message string `json:"message"`
}
-54
View File
@@ -1,54 +0,0 @@
package payload
import (
"bytes"
"encoding/json"
"io"
)
const (
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
// NotificationType one of "SHARE_ACCEPTED", "SHARE_DECLINED", "SHARE_CHANGE_PERMISSION", "SHARE_UNSHARED", "USER_REMOVED"
SHARE_UNSHARED = "SHARE_UNSHARED"
SHARE_CHANGE_PERMISSION = "SHARE_CHANGE_PERMISSION"
)
// NotificationRequest is the request payload for the OCM API notifications endpoint.
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
type NotificationRequest struct {
NotificationType string `json:"notificationType" validate:"required"`
ResourceType string `json:"resourceType" validate:"required"`
// Identifier to identify the shared resource at the provider side. This is unique per provider such that if the same resource is shared twice, this providerId will not be repeated.
ProviderId string `json:"providerId" validate:"required"`
// Optional additional parameters, depending on the notification and the resource type.
Notification *Notification `json:"notification,omitempty"`
}
// Notification is the payload for the notification field in the NotificationRequest.
type Notification struct {
// Owner string `json:"owner,omitempty"`
Grantee string `json:"grantee,omitempty"`
SharedSecret string `json:"sharedSecret,omitempty"`
}
// ToJSON returns the JSON io.Reader of the NotificationRequest.
func (r *NotificationRequest) ToJSON() (io.Reader, error) {
var b bytes.Buffer
if err := json.NewEncoder(&b).Encode(r); err != nil {
return nil, err
}
return &b, nil
}
// ErrorMessageResponse is the response returned by the OCM API in case of an error.
// https://cs3org.github.io/OCM-API/docs.html?branch=develop&repo=OCM-API&user=cs3org#/paths/~1notifications/post
type ErrorMessageResponse struct {
Message string `json:"message"`
ValidationErrors []*ValidationError `json:"validationErrors,omitempty"`
}
// ValidationError is the payload for the validationErrors field in the ErrorMessageResponse.
type ValidationError struct {
Name string `json:"name"`
Message string `json:"message"`
}
+4 -1
View File
@@ -629,12 +629,15 @@ func (m *mgr) UpdateReceivedShare(ctx context.Context, user *userpb.User, share
switch mask {
case "state":
rs.State = share.State
m.model.ReceivedShares[share.Id.OpaqueId].State = share.State
m.model.ReceivedShares[rs.Id.OpaqueId].State = share.State
case "protocols":
m.model.ReceivedShares[rs.Id.OpaqueId].Protocols = share.Protocols
// TODO case "mount_point":
default:
return nil, errtypes.NotSupported("updating " + mask + " is not supported")
}
}
m.model.ReceivedShares[rs.Id.OpaqueId].Mtime = &typespb.Timestamp{Seconds: uint64(time.Now().Second())}
if err := m.save(); err != nil {
return nil, errors.Wrap(err, "error saving model")
+1 -2
View File
@@ -371,7 +371,7 @@ github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1
github.com/cs3org/go-cs3apis/cs3/storage/registry/v1beta1
github.com/cs3org/go-cs3apis/cs3/tx/v1beta1
github.com/cs3org/go-cs3apis/cs3/types/v1beta1
# github.com/cs3org/reva/v2 v2.27.5-0.20250217133727-8aefc9e791f7
# github.com/cs3org/reva/v2 v2.27.5-0.20250221083634-a04df6f633fe
## explicit; go 1.22.7
github.com/cs3org/reva/v2/cmd/revad/internal/grace
github.com/cs3org/reva/v2/cmd/revad/runtime
@@ -562,7 +562,6 @@ github.com/cs3org/reva/v2/pkg/ocm/invite/repository/loader
github.com/cs3org/reva/v2/pkg/ocm/invite/repository/memory
github.com/cs3org/reva/v2/pkg/ocm/invite/repository/registry
github.com/cs3org/reva/v2/pkg/ocm/invite/repository/sql
github.com/cs3org/reva/v2/pkg/ocm/payload
github.com/cs3org/reva/v2/pkg/ocm/provider
github.com/cs3org/reva/v2/pkg/ocm/provider/authorizer/json
github.com/cs3org/reva/v2/pkg/ocm/provider/authorizer/loader