fix: do not ignore banned list if EventsData is nil (#4473)

This commit is contained in:
Mykhailo Prakhov 2023-12-19 12:00:29 +01:00 committed by GitHub
parent b1e000ed59
commit 45bd8c16da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 11 deletions

View File

@ -1555,15 +1555,14 @@ func (o *Community) tokenPermissions() map[string]*CommunityTokenPermission {
func (o *Community) PendingAndBannedMembers() map[string]CommunityMemberState { func (o *Community) PendingAndBannedMembers() map[string]CommunityMemberState {
result := make(map[string]CommunityMemberState) result := make(map[string]CommunityMemberState)
// Non-privileged members should not see pending and banned members
if o.config.EventsData == nil || !o.IsPrivilegedMember(o.MemberIdentity()) {
return result
}
for _, bannedMemberID := range o.config.CommunityDescription.BanList { for _, bannedMemberID := range o.config.CommunityDescription.BanList {
result[bannedMemberID] = CommunityMemberBanned result[bannedMemberID] = CommunityMemberBanned
} }
if o.config.EventsData == nil {
return result
}
processedEvents := make(map[string]bool) processedEvents := make(map[string]bool)
for _, event := range o.config.EventsData.Events { for _, event := range o.config.EventsData.Events {
if processedEvents[event.MemberToAction] { if processedEvents[event.MemberToAction] {

View File

@ -668,8 +668,8 @@ func kickMember(base CommunityEventsTestsInterface, communityID types.HexBytes,
return errors.New("alice should not be not kicked (yet)") return errors.New("alice should not be not kicked (yet)")
} }
if len(modifiedCommmunity.PendingAndBannedMembers()) > 0 { if len(modifiedCommmunity.PendingAndBannedMembers()) == 0 {
return errors.New("alice should not know about banned and pending members") return errors.New("alice should know about banned and pending members")
} }
return nil return nil
@ -749,8 +749,8 @@ func banMember(base CommunityEventsTestsInterface, banRequest *requests.BanUserF
return errors.New("alice should not be not banned (yet)") return errors.New("alice should not be not banned (yet)")
} }
if len(modifiedCommmunity.PendingAndBannedMembers()) > 0 { if len(modifiedCommmunity.PendingAndBannedMembers()) == 0 {
return errors.New("alice should not know about banned and pending members") return errors.New("alice should know about banned and pending members")
} }
return nil return nil
@ -817,8 +817,8 @@ func unbanMember(base CommunityEventsTestsInterface, unbanRequest *requests.Unba
return err return err
} }
if len(modifiedCommmunity.PendingAndBannedMembers()) > 0 { if len(modifiedCommmunity.PendingAndBannedMembers()) == 0 {
return errors.New("alice should not know about banned and pending members") return errors.New("alice should know about banned and pending members")
} }
return nil return nil

View File

@ -2336,6 +2336,7 @@ func (s *MessengerCommunitiesSuite) TestBanUser() {
community = response.Communities()[0] community = response.Communities()[0]
s.Require().False(community.HasMember(&s.alice.identity.PublicKey)) s.Require().False(community.HasMember(&s.alice.identity.PublicKey))
s.Require().True(community.IsBanned(&s.alice.identity.PublicKey)) s.Require().True(community.IsBanned(&s.alice.identity.PublicKey))
s.Require().Len(community.PendingAndBannedMembers(), 1)
response, err = s.owner.UnbanUserFromCommunity( response, err = s.owner.UnbanUserFromCommunity(
&requests.UnbanUserFromCommunity{ &requests.UnbanUserFromCommunity{