mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Cancel join fix
This commit is contained in:
parent
a3f8fe1b2b
commit
cbd44561be
1 changed files with 26 additions and 15 deletions
|
@ -19,6 +19,7 @@ type AclJoiningClient interface {
|
|||
app.Component
|
||||
AclGetRecords(ctx context.Context, spaceId, aclHead string) ([]*consensusproto.RawRecordWithId, error)
|
||||
RequestJoin(ctx context.Context, spaceId string, payload list.RequestJoinPayload) (aclHeadId string, err error)
|
||||
CancelJoin(ctx context.Context, spaceId string) (err error)
|
||||
CancelRemoveSelf(ctx context.Context, spaceId string) (err error)
|
||||
}
|
||||
|
||||
|
@ -45,7 +46,7 @@ func (c *aclJoiningClient) AclGetRecords(ctx context.Context, spaceId, aclHead s
|
|||
return c.coordinatorClient.AclGetRecords(ctx, spaceId, aclHead)
|
||||
}
|
||||
|
||||
func (c *aclJoiningClient) RequestJoin(ctx context.Context, spaceId string, payload list.RequestJoinPayload) (aclHeadId string, err error) {
|
||||
func (c *aclJoiningClient) getAcl(ctx context.Context, spaceId string) (l list.AclList, err error) {
|
||||
res, err := c.AclGetRecords(ctx, spaceId, "")
|
||||
if err != nil {
|
||||
return
|
||||
|
@ -58,7 +59,28 @@ func (c *aclJoiningClient) RequestJoin(ctx context.Context, spaceId string, payl
|
|||
if err != nil {
|
||||
return
|
||||
}
|
||||
acl, err := list.BuildAclListWithIdentity(c.keys, storage, list.NoOpAcceptorVerifier{})
|
||||
return list.BuildAclListWithIdentity(c.keys, storage, list.NoOpAcceptorVerifier{})
|
||||
}
|
||||
|
||||
func (c *aclJoiningClient) CancelJoin(ctx context.Context, spaceId string) (err error) {
|
||||
acl, err := c.getAcl(ctx, spaceId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
pendingReq, err := acl.AclState().JoinRecord(acl.AclState().Identity(), false)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
res, err := acl.RecordBuilder().BuildRequestCancel(pendingReq.RecordId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
_, err = c.coordinatorClient.AclAddRecord(ctx, spaceId, res)
|
||||
return
|
||||
}
|
||||
|
||||
func (c *aclJoiningClient) RequestJoin(ctx context.Context, spaceId string, payload list.RequestJoinPayload) (aclHeadId string, err error) {
|
||||
acl, err := c.getAcl(ctx, spaceId)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -85,20 +107,9 @@ func (c *aclJoiningClient) RequestJoin(ctx context.Context, spaceId string, payl
|
|||
}
|
||||
|
||||
func (c *aclJoiningClient) CancelRemoveSelf(ctx context.Context, spaceId string) (err error) {
|
||||
res, err := c.AclGetRecords(ctx, spaceId, "")
|
||||
acl, err := c.getAcl(ctx, spaceId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(res) == 0 {
|
||||
return fmt.Errorf("acl not found")
|
||||
}
|
||||
storage, err := liststorage.NewInMemoryAclListStorage(res[0].Id, res)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
acl, err := list.BuildAclListWithIdentity(c.keys, storage, list.NoOpAcceptorVerifier{})
|
||||
if err != nil {
|
||||
return err
|
||||
return
|
||||
}
|
||||
pendingReq, err := acl.AclState().Record(acl.AclState().Identity())
|
||||
if err != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue