mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-12-05 05:43:36 -05:00
Merge pull request #4137 from opencloud-eu/fix/mention-share-jail-id
fix(graph): resolve share jail ids in activity notifications
This commit is contained in:
2 files changed
+129
-1
No files matched your search
@@ -9,6 +9,7 @@ import (
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
|
||||
storageprovider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/go-chi/chi/v5"
|
||||
revactx "github.com/opencloud-eu/reva/v3/pkg/ctx"
|
||||
@@ -104,7 +105,12 @@ func (g Graph) SendActivityNotification(w http.ResponseWriter, r *http.Request)
|
||||
return
|
||||
}
|
||||
|
||||
ref := &storageprovider.Reference{ResourceId: &itemID}
|
||||
resourceID, ok := g.resolveShareJailID(w, r, gatewayClient, &itemID)
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
ref := &storageprovider.Reference{ResourceId: resourceID}
|
||||
|
||||
statResponse, err := gatewayClient.Stat(ctx, &storageprovider.StatRequest{Ref: ref})
|
||||
switch {
|
||||
@@ -195,3 +201,39 @@ func (g Graph) SendActivityNotification(w http.ResponseWriter, r *http.Request)
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
}
|
||||
|
||||
// resolveShareJailID maps a share jail id to the shared resource. Its opaque id is the
|
||||
// caller's own received share id, which no other user can resolve.
|
||||
func (g Graph) resolveShareJailID(w http.ResponseWriter, r *http.Request, gatewayClient gateway.GatewayAPIClient, id *storageprovider.ResourceId) (*storageprovider.ResourceId, bool) {
|
||||
if !IsShareJail(id) {
|
||||
return id, true
|
||||
}
|
||||
|
||||
res, err := gatewayClient.GetReceivedShare(r.Context(), &collaboration.GetReceivedShareRequest{
|
||||
Ref: &collaboration.ShareReference{
|
||||
Spec: &collaboration.ShareReference_Id{
|
||||
Id: ExtractShareIdFromResourceId(id),
|
||||
},
|
||||
},
|
||||
})
|
||||
switch {
|
||||
case err != nil:
|
||||
g.logger.Error().Err(err).Msg("could not get the received share")
|
||||
errorcode.GeneralException.Render(w, r, http.StatusInternalServerError, "could not get the received share")
|
||||
return nil, false
|
||||
case res.GetStatus().GetCode() == rpc.Code_CODE_NOT_FOUND,
|
||||
res.GetStatus().GetCode() == rpc.Code_CODE_PERMISSION_DENIED,
|
||||
res.GetStatus().GetCode() == rpc.Code_CODE_OK && res.GetShare().GetShare().GetResourceId() == nil:
|
||||
errorcode.ItemNotFound.Render(w, r, http.StatusNotFound, "item not found")
|
||||
return nil, false
|
||||
case res.GetStatus().GetCode() != rpc.Code_CODE_OK:
|
||||
g.logger.Error().
|
||||
Str("code", res.GetStatus().GetCode().String()).
|
||||
Str("message", res.GetStatus().GetMessage()).
|
||||
Msg("could not get the received share")
|
||||
errorcode.RenderError(w, r, errorcode.FromCS3Status(res.GetStatus(), nil))
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return res.GetShare().GetShare().GetResourceId(), true
|
||||
}
|
||||
@@ -10,6 +10,7 @@ import (
|
||||
gateway "github.com/cs3org/go-cs3apis/cs3/gateway/v1beta1"
|
||||
userpb "github.com/cs3org/go-cs3apis/cs3/identity/user/v1beta1"
|
||||
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
|
||||
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
|
||||
provider "github.com/cs3org/go-cs3apis/cs3/storage/provider/v1beta1"
|
||||
"github.com/go-chi/chi/v5"
|
||||
. "github.com/onsi/ginkgo/v2"
|
||||
@@ -17,6 +18,7 @@ import (
|
||||
revactx "github.com/opencloud-eu/reva/v3/pkg/ctx"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/rgrpc/status"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/rgrpc/todo/pool"
|
||||
"github.com/opencloud-eu/reva/v3/pkg/utils"
|
||||
cs3mocks "github.com/opencloud-eu/reva/v3/tests/cs3mocks/mocks"
|
||||
"github.com/stretchr/testify/mock"
|
||||
"google.golang.org/grpc"
|
||||
@@ -307,6 +309,90 @@ var _ = Describe("SendActivityNotification", func() {
|
||||
Expect(mentions()).To(BeEmpty())
|
||||
})
|
||||
|
||||
Describe("with a share jail id", func() {
|
||||
shareJailMention := `{"topic":{"source":"text","value":"` +
|
||||
utils.ShareStorageProviderID + `$` + utils.ShareStorageSpaceID + `!share"},` +
|
||||
`"activityType":"mentioned","teamsAppId":"` + service.WebOfficeAppID + `"}`
|
||||
|
||||
receivedShare := func(st *rpc.Status) {
|
||||
gatewayClient.On("GetReceivedShare", mock.Anything, mock.MatchedBy(
|
||||
func(req *collaboration.GetReceivedShareRequest) bool {
|
||||
return req.GetRef().GetId().GetOpaqueId() == "share"
|
||||
},
|
||||
)).Return(&collaboration.GetReceivedShareResponse{
|
||||
Status: st,
|
||||
Share: &collaboration.ReceivedShare{Share: &collaboration.Share{
|
||||
ResourceId: &provider.ResourceId{StorageId: "storage", SpaceId: "space", OpaqueId: "item"},
|
||||
}},
|
||||
}, nil)
|
||||
}
|
||||
|
||||
statRefs := func() []*provider.ResourceId {
|
||||
var refs []*provider.ResourceId
|
||||
for _, call := range gatewayClient.Calls {
|
||||
if req, ok := call.Arguments[1].(*provider.StatRequest); ok {
|
||||
refs = append(refs, req.GetRef().GetResourceId())
|
||||
}
|
||||
}
|
||||
|
||||
return refs
|
||||
}
|
||||
|
||||
// the jail id carries the caller's share, the recipient only knows the shared item
|
||||
It("notifies about the shared item", func() {
|
||||
receivedShare(status.NewOK(context.Background()))
|
||||
statAs("", "alice-token")
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
svc.SendActivityNotification(rr, request("alice", shareJailMention))
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusAccepted))
|
||||
Expect(statRefs()).To(HaveLen(2))
|
||||
for _, ref := range statRefs() {
|
||||
Expect(ref.GetStorageId()).To(Equal("storage"))
|
||||
Expect(ref.GetSpaceId()).To(Equal("space"))
|
||||
Expect(ref.GetOpaqueId()).To(Equal("item"))
|
||||
}
|
||||
Expect(mentions()).To(HaveLen(1))
|
||||
Expect(mentions()[0].Ref.GetResourceId().GetOpaqueId()).To(Equal("item"))
|
||||
})
|
||||
|
||||
It("hides a share the caller did not receive", func() {
|
||||
receivedShare(status.NewNotFound(context.Background(), "not found"))
|
||||
statAs("", "alice-token")
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
svc.SendActivityNotification(rr, request("alice", shareJailMention))
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusNotFound))
|
||||
Expect(statRefs()).To(BeEmpty())
|
||||
Expect(mentions()).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("fails when the received share cannot be looked up", func() {
|
||||
gatewayClient.On("GetReceivedShare", mock.Anything, mock.Anything).
|
||||
Return(nil, errors.New("connection refused"))
|
||||
statAs("", "alice-token")
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
svc.SendActivityNotification(rr, request("alice", shareJailMention))
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusInternalServerError))
|
||||
Expect(mentions()).To(BeEmpty())
|
||||
})
|
||||
|
||||
It("carries the cs3 status of a failed share lookup", func() {
|
||||
receivedShare(status.NewInvalidArg(context.Background(), "invalid share id"))
|
||||
statAs("", "alice-token")
|
||||
|
||||
rr := httptest.NewRecorder()
|
||||
svc.SendActivityNotification(rr, request("alice", shareJailMention))
|
||||
|
||||
Expect(rr.Code).To(Equal(http.StatusBadRequest))
|
||||
Expect(mentions()).To(BeEmpty())
|
||||
})
|
||||
})
|
||||
|
||||
// a user id is no secret, other endpoints look users up as well
|
||||
It("refuses a recipient that does not exist", func() {
|
||||
statAs("", "alice-token")
|
||||
|
||||
Reference in new issue
Block a user