From 83b6bc312c225a31d1c91a0cdd710898d3eefc39 Mon Sep 17 00:00:00 2001 From: mcrakhman Date: Tue, 27 Feb 2024 19:20:49 +0100 Subject: [PATCH] GO-2966 Add revoke invite method --- core/acl/aclservice.go | 18 ++++++++++++++++++ core/space.go | 11 +++++++++-- go.mod | 2 +- go.sum | 4 ++-- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/core/acl/aclservice.go b/core/acl/aclservice.go index eb84f37f2..82d628114 100644 --- a/core/acl/aclservice.go +++ b/core/acl/aclservice.go @@ -49,6 +49,7 @@ type AccountPermissions struct { type AclService interface { app.Component GenerateInvite(ctx context.Context, spaceId string) (*InviteInfo, error) + RevokeInvite(ctx context.Context, spaceId string) error GetCurrentInvite(spaceId string) (*InviteInfo, error) ViewInvite(ctx context.Context, inviteCid cid.Cid, inviteFileKey crypto.SymKey) (*InviteView, error) Join(ctx context.Context, spaceId string, inviteCid cid.Cid, inviteFileKey crypto.SymKey) error @@ -139,6 +140,23 @@ func (a *aclService) Decline(ctx context.Context, spaceId string, identity crypt return nil } +func (a *aclService) RevokeInvite(ctx context.Context, spaceId string) error { + sp, err := a.spaceService.Get(ctx, spaceId) + if err != nil { + return err + } + cl := sp.CommonSpace().AclClient() + err = cl.RevokeAllInvites(ctx) + if err != nil { + return fmt.Errorf("%w, %w", ErrAclRequestFailed, err) + } + spaceViewId, err := a.spaceService.SpaceViewId(spaceId) + if err != nil { + return fmt.Errorf("get space view id: %w", err) + } + return a.removeExistingInviteFileInfo(ctx, spaceViewId) +} + func (a *aclService) ChangePermissions(ctx context.Context, spaceId string, perms []AccountPermissions) error { sp, err := a.spaceService.Get(ctx, spaceId) if err != nil { diff --git a/core/space.go b/core/space.go index d03f0f0e6..678fe0aa6 100644 --- a/core/space.go +++ b/core/space.go @@ -82,10 +82,17 @@ func (mw *Middleware) SpaceInviteGetCurrent(cctx context.Context, req *pb.RpcSpa } func (mw *Middleware) SpaceInviteRevoke(cctx context.Context, req *pb.RpcSpaceInviteRevokeRequest) *pb.RpcSpaceInviteRevokeResponse { + aclService := mw.applicationService.GetApp().MustComponent(acl.CName).(acl.AclService) + err := aclService.RevokeInvite(cctx, req.SpaceId) + code := mapErrorCode(err, + errToCode(space.ErrSpaceDeleted, pb.RpcSpaceInviteRevokeResponseError_SPACE_IS_DELETED), + errToCode(space.ErrSpaceNotExists, pb.RpcSpaceInviteRevokeResponseError_NO_SUCH_SPACE), + errToCode(acl.ErrAclRequestFailed, pb.RpcSpaceInviteRevokeResponseError_REQUEST_FAILED), + ) return &pb.RpcSpaceInviteRevokeResponse{ Error: &pb.RpcSpaceInviteRevokeResponseError{ - Code: 1, - Description: getErrorDescription(fmt.Errorf("not implemented")), + Code: code, + Description: getErrorDescription(err), }, } } diff --git a/go.mod b/go.mod index c976372e5..f3a08db51 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ require ( github.com/PuerkitoBio/goquery v1.8.1 github.com/VividCortex/ewma v1.2.0 github.com/adrium/goheif v0.0.0-20230113233934-ca402e77a786 - github.com/anyproto/any-sync v0.3.26 + github.com/anyproto/any-sync v0.3.27 github.com/anyproto/go-naturaldate/v2 v2.0.2-0.20230524105841-9829cfd13438 github.com/araddon/dateparse v0.0.0-20210429162001-6b43995a97de github.com/blevesearch/bleve/v2 v2.3.10 diff --git a/go.sum b/go.sum index 3884cc1d0..8e8ff2649 100644 --- a/go.sum +++ b/go.sum @@ -108,8 +108,8 @@ github.com/andybalholm/cascadia v1.2.0/go.mod h1:YCyR8vOZT9aZ1CHEd8ap0gMVm2aFgxB github.com/andybalholm/cascadia v1.3.1/go.mod h1:R4bJ1UQfqADjvDa4P6HZHLh/3OxWWEqc0Sk8XGwHqvA= github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsViSLyss= github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU= -github.com/anyproto/any-sync v0.3.26 h1:LhLc7e4EDb02l0jNqCnbxczk2Xh8RiUtXQE2P/mHD0E= -github.com/anyproto/any-sync v0.3.26/go.mod h1:xAzQ+njdF1FM1SD5nw1aUbhLh0tiOmzY0hrFajuY6Ik= +github.com/anyproto/any-sync v0.3.27 h1:acT5oSqLXpAbEGHeAbkMDVbV8iHzLAd3Q+1ugLVlBBY= +github.com/anyproto/any-sync v0.3.27/go.mod h1:xAzQ+njdF1FM1SD5nw1aUbhLh0tiOmzY0hrFajuY6Ik= github.com/anyproto/badger/v4 v4.2.1-0.20240110160636-80743fa3d580 h1:Ba80IlCCxkZ9H1GF+7vFu/TSpPvbpDCxXJ5ogc4euYc= github.com/anyproto/badger/v4 v4.2.1-0.20240110160636-80743fa3d580/go.mod h1:T/uWAYxrXdaXw64ihI++9RMbKTCpKd/yE9+saARew7k= github.com/anyproto/go-chash v0.1.0 h1:I9meTPjXFRfXZHRJzjOHC/XF7Q5vzysKkiT/grsogXY=