mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-10 01:51:11 +09:00
Change request join method
This commit is contained in:
parent
2c61cf1485
commit
d755864d0d
1 changed files with 31 additions and 7 deletions
|
@ -2,11 +2,15 @@ package aclclient
|
|||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"storj.io/drpc"
|
||||
|
||||
"github.com/anyproto/any-sync/accountservice"
|
||||
"github.com/anyproto/any-sync/app"
|
||||
"github.com/anyproto/any-sync/commonspace/object/accountdata"
|
||||
"github.com/anyproto/any-sync/commonspace/object/acl/list"
|
||||
"github.com/anyproto/any-sync/commonspace/object/acl/liststorage"
|
||||
"github.com/anyproto/any-sync/commonspace/spacesyncproto"
|
||||
"github.com/anyproto/any-sync/consensus/consensusproto"
|
||||
"github.com/anyproto/any-sync/net/pool"
|
||||
|
@ -18,12 +22,13 @@ const CName = "common.acl.aclclient"
|
|||
type AclInvitingClient interface {
|
||||
app.Component
|
||||
AclGetRecords(ctx context.Context, spaceId, aclHead string) ([]*consensusproto.RawRecordWithId, error)
|
||||
RequestJoin(ctx context.Context, spaceId string, acl list.AclList, payload list.RequestJoinPayload) error
|
||||
RequestJoin(ctx context.Context, spaceId string, payload list.RequestJoinPayload) error
|
||||
}
|
||||
|
||||
type aclInvitingClient struct {
|
||||
nodeConf nodeconf.Service
|
||||
pool pool.Pool
|
||||
keys *accountdata.AccountKeys
|
||||
}
|
||||
|
||||
func NewAclInvitingClient() AclInvitingClient {
|
||||
|
@ -37,6 +42,7 @@ func (c *aclInvitingClient) Name() (name string) {
|
|||
func (c *aclInvitingClient) Init(a *app.App) (err error) {
|
||||
c.pool = a.MustComponent(pool.CName).(pool.Pool)
|
||||
c.nodeConf = a.MustComponent(nodeconf.CName).(nodeconf.Service)
|
||||
c.keys = a.MustComponent(accountservice.CName).(accountservice.Service).Account()
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -64,15 +70,33 @@ func (c *aclInvitingClient) AclGetRecords(ctx context.Context, spaceId, aclHead
|
|||
return
|
||||
}
|
||||
|
||||
func (c *aclInvitingClient) RequestJoin(ctx context.Context, spaceId string, acl list.AclList, payload list.RequestJoinPayload) (err error) {
|
||||
acl.RLock()
|
||||
res, err := acl.RecordBuilder().BuildRequestJoin(payload)
|
||||
func (c *aclInvitingClient) RequestJoin(ctx context.Context, spaceId string, payload list.RequestJoinPayload) (err error) {
|
||||
res, err := c.AclGetRecords(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
|
||||
}
|
||||
pubIdentity := payload.InviteKey.GetPublic()
|
||||
for _, rec := range acl.AclState().JoinRecords() {
|
||||
if rec.RequestIdentity.Equals(pubIdentity) {
|
||||
return fmt.Errorf("request already sent")
|
||||
}
|
||||
}
|
||||
rec, err := acl.RecordBuilder().BuildRequestJoin(payload)
|
||||
if err != nil {
|
||||
acl.RUnlock()
|
||||
return
|
||||
}
|
||||
acl.RUnlock()
|
||||
data, err := res.Marshal()
|
||||
data, err := rec.Marshal()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue