mirror of
https://github.com/anyproto/any-sync.git
synced 2025-06-08 05:57:03 +09:00
Merge pull request #457 from anyproto/GO-5682-request-to-join-invite-links
GO-5682: request to join invite links
This commit is contained in:
commit
6ff6aee8b9
6 changed files with 27 additions and 4 deletions
|
@ -681,6 +681,13 @@ func (st *AclState) applyInviteJoin(ch *aclrecordproto.AclAccountInviteJoin, rec
|
||||||
}),
|
}),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, rec := range st.requestRecords {
|
||||||
|
if rec.RequestIdentity.Equals(identity) {
|
||||||
|
delete(st.pendingRequests, mapKeyFromPubKey(rec.RequestIdentity))
|
||||||
|
delete(st.requestRecords, rec.RecordId)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
if st.pubKey.Equals(identity) {
|
if st.pubKey.Equals(identity) {
|
||||||
return st.unpackAllKeys(ch.EncryptedReadKey)
|
return st.unpackAllKeys(ch.EncryptedReadKey)
|
||||||
}
|
}
|
||||||
|
|
|
@ -218,7 +218,7 @@ func (a *AclTestExecutor) buildBatchRequest(args []string, acl AclList, getPerm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if recId == "" {
|
if recId == "" {
|
||||||
return nil, fmt.Errorf("no join records for approve")
|
return nil, fmt.Errorf("no join records to approve")
|
||||||
}
|
}
|
||||||
perms := getPerm(argParts[1])
|
perms := getPerm(argParts[1])
|
||||||
afterAll = append(afterAll, func() {
|
afterAll = append(afterAll, func() {
|
||||||
|
@ -461,7 +461,7 @@ func (a *AclTestExecutor) Execute(cmd string) (err error) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if recId == "" {
|
if recId == "" {
|
||||||
return fmt.Errorf("no join records for approve")
|
return fmt.Errorf("no join records to approve")
|
||||||
}
|
}
|
||||||
perms := getPerm(argParts[1])
|
perms := getPerm(argParts[1])
|
||||||
res, err := acl.RecordBuilder().BuildRequestAccept(RequestAcceptPayload{
|
res, err := acl.RecordBuilder().BuildRequestAccept(RequestAcceptPayload{
|
||||||
|
|
|
@ -90,7 +90,7 @@ func TestAclExecutor(t *testing.T) {
|
||||||
{"g.join::inv1Id", nil},
|
{"g.join::inv1Id", nil},
|
||||||
{"g.cancel::g", nil},
|
{"g.cancel::g", nil},
|
||||||
// e cannot approve cancelled request
|
// e cannot approve cancelled request
|
||||||
{"e.approve::g,rw", fmt.Errorf("no join records for approve")},
|
{"e.approve::g,rw", fmt.Errorf("no join records to approve")},
|
||||||
{"g.join::inv1Id", nil},
|
{"g.join::inv1Id", nil},
|
||||||
{"e.decline::g", nil},
|
{"e.decline::g", nil},
|
||||||
// g cannot cancel declined request
|
// g cannot cancel declined request
|
||||||
|
@ -144,6 +144,12 @@ func TestAclExecutor(t *testing.T) {
|
||||||
{"new4.add::super,r,superm", nil},
|
{"new4.add::super,r,superm", nil},
|
||||||
// check that users can't join using request to join for anyone can join links
|
// check that users can't join using request to join for anyone can join links
|
||||||
{"new5.join::someId", ErrNoSuchInvite},
|
{"new5.join::someId", ErrNoSuchInvite},
|
||||||
|
{"a.invite::requestJoinId", nil},
|
||||||
|
{"joiner.join::requestJoinId", nil},
|
||||||
|
// check that users can join under a different link even after they created a request to join
|
||||||
|
{"joiner.invite_join::someId", nil},
|
||||||
|
// check that they can't be approved after they joined under a different link
|
||||||
|
{"a.approve::joiner,rw", fmt.Errorf("no join records to approve")},
|
||||||
}
|
}
|
||||||
for _, cmd := range cmds {
|
for _, cmd := range cmds {
|
||||||
err := a.Execute(cmd.cmd)
|
err := a.Execute(cmd.cmd)
|
||||||
|
|
|
@ -53,6 +53,9 @@ func (t *Tree) Root() *Change {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tree) AddFast(changes ...*Change) []*Change {
|
func (t *Tree) AddFast(changes ...*Change) []*Change {
|
||||||
|
if len(changes) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
defer t.clearUnattached()
|
defer t.clearUnattached()
|
||||||
t.addedBuf = t.addedBuf[:0]
|
t.addedBuf = t.addedBuf[:0]
|
||||||
for _, c := range changes {
|
for _, c := range changes {
|
||||||
|
|
|
@ -49,6 +49,10 @@ func TestTree_Add(t *testing.T) {
|
||||||
assert.Equal(t, tr.root.Id, "root")
|
assert.Equal(t, tr.root.Id, "root")
|
||||||
assert.Equal(t, []string{"root"}, tr.Heads())
|
assert.Equal(t, []string{"root"}, tr.Heads())
|
||||||
})
|
})
|
||||||
|
t.Run("empty tree add should not panic", func(t *testing.T) {
|
||||||
|
tr := &Tree{}
|
||||||
|
tr.AddFast()
|
||||||
|
})
|
||||||
t.Run("linear add", func(t *testing.T) {
|
t.Run("linear add", func(t *testing.T) {
|
||||||
tr := new(Tree)
|
tr := new(Tree)
|
||||||
res, _ := tr.Add(
|
res, _ := tr.Add(
|
||||||
|
|
|
@ -17,7 +17,7 @@ import (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
log = logger.NewNamedSugared("common.commonspace.objecttree")
|
log = logger.NewNamedSugared("common.commonspace.objecttree")
|
||||||
ErrEmpty = errors.New("logs empty")
|
ErrEmpty = errors.New("database is empty")
|
||||||
)
|
)
|
||||||
|
|
||||||
type treeBuilder struct {
|
type treeBuilder struct {
|
||||||
|
@ -146,6 +146,9 @@ func (tb *treeBuilder) build(opts treeBuilderOpts) (tr *Tree, err error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("failed to get changes after order: %w", err)
|
return nil, fmt.Errorf("failed to get changes after order: %w", err)
|
||||||
}
|
}
|
||||||
|
if len(changes) == 0 {
|
||||||
|
return nil, ErrEmpty
|
||||||
|
}
|
||||||
tr = &Tree{}
|
tr = &Tree{}
|
||||||
changes = append(changes, opts.newChanges...)
|
changes = append(changes, opts.newChanges...)
|
||||||
tr.AddFast(changes...)
|
tr.AddFast(changes...)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue