Skip to content

Commit

Permalink
fix(manager)_: make sure to re-add revealed accounts in the response (#…
Browse files Browse the repository at this point in the history
…5867)

We remove the shared accounts to send normal admins to not leak the addresses, however, that was a destructive action that also removed them from the `requestToJoin` param, which is reused later in the code, so it created an unwanted side effect. The side effect is now erased.
  • Loading branch information
jrainville authored Oct 1, 2024
1 parent 107e2cb commit 1460589
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
14 changes: 9 additions & 5 deletions protocol/communities/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4897,18 +4897,22 @@ func (m *Manager) ShareRequestsToJoinWithPrivilegedMembers(community *Community,
return nil
}

func (m *Manager) shareAcceptedRequestToJoinWithPrivilegedMembers(community *Community, requestsToJoin *RequestToJoin) error {
pk, err := common.HexToPubkey(requestsToJoin.PublicKey)
func (m *Manager) shareAcceptedRequestToJoinWithPrivilegedMembers(community *Community, requestToJoin *RequestToJoin) error {
pk, err := common.HexToPubkey(requestToJoin.PublicKey)
if err != nil {
return err
}

acceptedRequestsToJoinWithoutRevealedAccounts := make(map[string]*protobuf.CommunityRequestToJoin)
acceptedRequestsToJoinWithRevealedAccounts := make(map[string]*protobuf.CommunityRequestToJoin)

acceptedRequestsToJoinWithRevealedAccounts[requestsToJoin.PublicKey] = requestsToJoin.ToCommunityRequestToJoinProtobuf()
requestsToJoin.RevealedAccounts = make([]*protobuf.RevealedAccount, 0)
acceptedRequestsToJoinWithoutRevealedAccounts[requestsToJoin.PublicKey] = requestsToJoin.ToCommunityRequestToJoinProtobuf()
acceptedRequestsToJoinWithRevealedAccounts[requestToJoin.PublicKey] = requestToJoin.ToCommunityRequestToJoinProtobuf()

revealedAccounts := requestToJoin.RevealedAccounts
requestToJoin.RevealedAccounts = make([]*protobuf.RevealedAccount, 0)
acceptedRequestsToJoinWithoutRevealedAccounts[requestToJoin.PublicKey] = requestToJoin.ToCommunityRequestToJoinProtobuf()
// Set back the revealed accounts
requestToJoin.RevealedAccounts = revealedAccounts

msgWithRevealedAccounts := &protobuf.CommunityPrivilegedUserSyncMessage{
Type: protobuf.CommunityPrivilegedUserSyncMessage_CONTROL_NODE_ACCEPT_REQUEST_TO_JOIN,
Expand Down
2 changes: 2 additions & 0 deletions protocol/communities_messenger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,8 @@ func (s *MessengerCommunitiesSuite) TestRequestAccess() {
response, err = s.bob.AcceptRequestToJoinCommunity(acceptRequestToJoin)
s.Require().NoError(err)
s.Require().NotNil(response)
s.Require().NotEmpty(response.RequestsToJoinCommunity())
s.Require().Len(response.RequestsToJoinCommunity()[0].RevealedAccounts, 1)

s.Require().Len(response.Communities(), 1)

Expand Down

0 comments on commit 1460589

Please sign in to comment.