From 20f79ee13993c8cb86c48c8ef1b4f3de1e7e5412 Mon Sep 17 00:00:00 2001 From: Mikhail Rakhmanov Date: Thu, 22 May 2025 13:28:13 +0200 Subject: [PATCH] Update request to join logic to include cases with two invite links --- commonspace/object/acl/list/aclstate.go | 7 +++++++ commonspace/object/acl/list/acltestsuite.go | 4 ++-- commonspace/object/acl/list/acltestsuite_test.go | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/commonspace/object/acl/list/aclstate.go b/commonspace/object/acl/list/aclstate.go index 61fbfeab..8e332630 100644 --- a/commonspace/object/acl/list/aclstate.go +++ b/commonspace/object/acl/list/aclstate.go @@ -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) { return st.unpackAllKeys(ch.EncryptedReadKey) } diff --git a/commonspace/object/acl/list/acltestsuite.go b/commonspace/object/acl/list/acltestsuite.go index bf61312c..a3b178c8 100644 --- a/commonspace/object/acl/list/acltestsuite.go +++ b/commonspace/object/acl/list/acltestsuite.go @@ -218,7 +218,7 @@ func (a *AclTestExecutor) buildBatchRequest(args []string, acl AclList, getPerm } } if recId == "" { - return nil, fmt.Errorf("no join records for approve") + return nil, fmt.Errorf("no join records to approve") } perms := getPerm(argParts[1]) afterAll = append(afterAll, func() { @@ -461,7 +461,7 @@ func (a *AclTestExecutor) Execute(cmd string) (err error) { } } if recId == "" { - return fmt.Errorf("no join records for approve") + return fmt.Errorf("no join records to approve") } perms := getPerm(argParts[1]) res, err := acl.RecordBuilder().BuildRequestAccept(RequestAcceptPayload{ diff --git a/commonspace/object/acl/list/acltestsuite_test.go b/commonspace/object/acl/list/acltestsuite_test.go index ec06267f..5cefe156 100644 --- a/commonspace/object/acl/list/acltestsuite_test.go +++ b/commonspace/object/acl/list/acltestsuite_test.go @@ -90,7 +90,7 @@ func TestAclExecutor(t *testing.T) { {"g.join::inv1Id", nil}, {"g.cancel::g", nil}, // 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}, {"e.decline::g", nil}, // g cannot cancel declined request @@ -144,6 +144,12 @@ func TestAclExecutor(t *testing.T) { {"new4.add::super,r,superm", nil}, // check that users can't join using request to join for anyone can join links {"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 { err := a.Execute(cmd.cmd)