mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Add helper methods
This commit is contained in:
parent
8c4467f091
commit
671be22a98
3 changed files with 33 additions and 2 deletions
|
@ -21,6 +21,7 @@ type AclJoiningClient interface {
|
||||||
AclGetRecords(ctx context.Context, spaceId, aclHead string) ([]*consensusproto.RawRecordWithId, error)
|
AclGetRecords(ctx context.Context, spaceId, aclHead string) ([]*consensusproto.RawRecordWithId, error)
|
||||||
RequestJoin(ctx context.Context, spaceId string, payload list.RequestJoinPayload) (aclHeadId string, err error)
|
RequestJoin(ctx context.Context, spaceId string, payload list.RequestJoinPayload) (aclHeadId string, err error)
|
||||||
CancelJoin(ctx context.Context, spaceId string) (err error)
|
CancelJoin(ctx context.Context, spaceId string) (err error)
|
||||||
|
InviteJoin(ctx context.Context, spaceId string, payload list.InviteJoinPayload) (aclHeadId string, err error)
|
||||||
CancelRemoveSelf(ctx context.Context, spaceId string) (err error)
|
CancelRemoveSelf(ctx context.Context, spaceId string) (err error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -107,6 +108,23 @@ func (c *aclJoiningClient) RequestJoin(ctx context.Context, spaceId string, payl
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *aclJoiningClient) InviteJoin(ctx context.Context, spaceId string, payload list.InviteJoinPayload) (aclHeadId string, err error) {
|
||||||
|
acl, err := c.getAcl(ctx, spaceId)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
rec, err := acl.RecordBuilder().BuildInviteJoin(payload)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
recWithId, err := c.nodeClient.AclAddRecord(ctx, spaceId, rec)
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
aclHeadId = recWithId.Id
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func (c *aclJoiningClient) CancelRemoveSelf(ctx context.Context, spaceId string) (err error) {
|
func (c *aclJoiningClient) CancelRemoveSelf(ctx context.Context, spaceId string) (err error) {
|
||||||
acl, err := c.getAcl(ctx, spaceId)
|
acl, err := c.getAcl(ctx, spaceId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"errors"
|
"errors"
|
||||||
|
|
||||||
"github.com/anyproto/any-sync/app"
|
"github.com/anyproto/any-sync/app"
|
||||||
|
"github.com/anyproto/any-sync/commonspace/object/acl/aclrecordproto"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/list"
|
"github.com/anyproto/any-sync/commonspace/object/acl/list"
|
||||||
"github.com/anyproto/any-sync/commonspace/object/acl/syncacl"
|
"github.com/anyproto/any-sync/commonspace/object/acl/syncacl"
|
||||||
"github.com/anyproto/any-sync/commonspace/spacestate"
|
"github.com/anyproto/any-sync/commonspace/spacestate"
|
||||||
|
@ -27,6 +28,7 @@ type InviteSaveFunc func()
|
||||||
type AclSpaceClient interface {
|
type AclSpaceClient interface {
|
||||||
app.Component
|
app.Component
|
||||||
GenerateInvite() (list.InviteResult, error)
|
GenerateInvite() (list.InviteResult, error)
|
||||||
|
GenerateAnyoneCanJoinInvite(permissions list.AclPermissions) (list.InviteResult, error)
|
||||||
StopSharing(ctx context.Context, readKeyChange list.ReadKeyChangePayload) (err error)
|
StopSharing(ctx context.Context, readKeyChange list.ReadKeyChangePayload) (err error)
|
||||||
AddRecord(ctx context.Context, consRec *consensusproto.RawRecord) error
|
AddRecord(ctx context.Context, consRec *consensusproto.RawRecord) error
|
||||||
RemoveAccounts(ctx context.Context, payload list.AccountRemovePayload) error
|
RemoveAccounts(ctx context.Context, payload list.AccountRemovePayload) error
|
||||||
|
@ -211,11 +213,21 @@ func (c *aclSpaceClient) AcceptRequest(ctx context.Context, payload list.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *aclSpaceClient) GenerateInvite() (resp list.InviteResult, err error) {
|
func (c *aclSpaceClient) GenerateInvite() (resp list.InviteResult, err error) {
|
||||||
c.acl.RLock()
|
c.acl.Lock()
|
||||||
defer c.acl.RUnlock()
|
defer c.acl.Unlock()
|
||||||
return c.acl.RecordBuilder().BuildInvite()
|
return c.acl.RecordBuilder().BuildInvite()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *aclSpaceClient) GenerateAnyoneCanJoinInvite(permissions list.AclPermissions) (resp list.InviteResult, err error) {
|
||||||
|
c.acl.Lock()
|
||||||
|
defer c.acl.Unlock()
|
||||||
|
anyoneInvites := c.acl.AclState().Invites(aclrecordproto.AclInviteType_AnyoneCanJoin)
|
||||||
|
if len(anyoneInvites) > 0 {
|
||||||
|
return list.InviteResult{}, list.ErrDuplicateInvites
|
||||||
|
}
|
||||||
|
return c.acl.RecordBuilder().BuildInviteAnyone(permissions)
|
||||||
|
}
|
||||||
|
|
||||||
func (c *aclSpaceClient) AddRecord(ctx context.Context, consRec *consensusproto.RawRecord) (err error) {
|
func (c *aclSpaceClient) AddRecord(ctx context.Context, consRec *consensusproto.RawRecord) (err error) {
|
||||||
return c.sendRecordAndUpdate(ctx, c.spaceId, consRec)
|
return c.sendRecordAndUpdate(ctx, c.spaceId, consRec)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ var (
|
||||||
ErrNoSuchRequest = errors.New("no such request")
|
ErrNoSuchRequest = errors.New("no such request")
|
||||||
ErrNoSuchInvite = errors.New("no such invite")
|
ErrNoSuchInvite = errors.New("no such invite")
|
||||||
ErrInsufficientPermissions = errors.New("insufficient permissions")
|
ErrInsufficientPermissions = errors.New("insufficient permissions")
|
||||||
|
ErrDuplicateInvites = errors.New("duplicate invites")
|
||||||
ErrIsOwner = errors.New("can't be made by owner")
|
ErrIsOwner = errors.New("can't be made by owner")
|
||||||
ErrIncorrectNumberOfAccounts = errors.New("incorrect number of accounts")
|
ErrIncorrectNumberOfAccounts = errors.New("incorrect number of accounts")
|
||||||
ErrDuplicateAccounts = errors.New("duplicate accounts")
|
ErrDuplicateAccounts = errors.New("duplicate accounts")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue