diff --git a/VERSION b/VERSION index 22e1f1fc0..65138dac8 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.149.0 +0.149.1 diff --git a/protocol/communities/manager.go b/protocol/communities/manager.go index 5584b0c6f..81f0b42cc 100644 --- a/protocol/communities/manager.go +++ b/protocol/communities/manager.go @@ -1388,6 +1388,11 @@ func (m *Manager) HandleCommunityRequestToJoin(signer *ecdsa.PublicKey, request return nil, ErrCommunityRequestAlreadyRejected } + // Banned member can't request to join community + if community.isBanned(signer) { + return nil, ErrCantRequestAccess + } + if err := community.ValidateRequestToJoin(signer, request); err != nil { return nil, err } diff --git a/protocol/communities_messenger_test.go b/protocol/communities_messenger_test.go index f87525203..9d1642730 100644 --- a/protocol/communities_messenger_test.go +++ b/protocol/communities_messenger_test.go @@ -3242,3 +3242,81 @@ func (s *MessengerCommunitiesSuite) TestCommunityTokensMetadata() { s.Require().Equal(tokensMetadata[0].Symbol, newToken.Symbol) s.Require().Equal(tokensMetadata[0].Name, newToken.Name) } + +func (s *MessengerCommunitiesSuite) TestCommunityBanUserRequesToJoin() { + description := &requests.CreateCommunity{ + Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP, + Name: "status", + Color: "#ffffff", + Description: "status community description", + } + + // Create an community chat + response, err := s.bob.CreateCommunity(description, true) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Communities(), 1) + + community := response.Communities()[0] + + response, err = s.bob.InviteUsersToCommunity( + &requests.InviteUsersToCommunity{ + CommunityID: community.ID(), + Users: []types.HexBytes{common.PubkeyToHexBytes(&s.alice.identity.PublicKey)}, + }, + ) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Communities(), 1) + + community = response.Communities()[0] + s.Require().True(community.HasMember(&s.alice.identity.PublicKey)) + + response, err = s.bob.BanUserFromCommunity( + &requests.BanUserFromCommunity{ + CommunityID: community.ID(), + User: common.PubkeyToHexBytes(&s.alice.identity.PublicKey), + }, + ) + s.Require().NoError(err) + s.Require().NotNil(response) + s.Require().Len(response.Communities(), 1) + + community = response.Communities()[0] + s.Require().False(community.HasMember(&s.alice.identity.PublicKey)) + s.Require().True(community.IsBanned(&s.alice.identity.PublicKey)) + + response, err = WaitOnMessengerResponse( + s.alice, + func(r *MessengerResponse) bool { return len(r.communities) > 0 }, + "no communities", + ) + + s.Require().NoError(err) + s.Require().Len(response.Communities(), 1) + + request := &requests.RequestToJoinCommunity{CommunityID: community.ID()} + // We try to join the org + _, rtj, err := s.alice.communitiesManager.RequestToJoin(&s.alice.identity.PublicKey, request) + + s.Require().NoError(err) + + displayName, err := s.alice.settings.DisplayName() + s.Require().NoError(err) + + requestToJoinProto := &protobuf.CommunityRequestToJoin{ + Clock: rtj.Clock, + EnsName: rtj.ENSName, + DisplayName: displayName, + CommunityId: community.ID(), + RevealedAddresses: make(map[string][]byte), + } + + s.Require().NoError(err) + + messageState := s.bob.buildMessageState() + + err = s.bob.HandleCommunityRequestToJoin(messageState, &s.alice.identity.PublicKey, *requestToJoinProto) + + s.Require().ErrorContains(err, "can't request access") +}