refactor: remove community invitation only access

This commit is contained in:
Patryk Osmaczko 2023-10-25 15:22:12 +02:00 committed by osmaczko
parent b262d7e88c
commit 3452eb72a8
4 changed files with 5 additions and 102 deletions

View File

@ -1229,10 +1229,6 @@ func (o *Community) ManualAccept() bool {
return o.config.CommunityDescription.Permissions.Access == protobuf.CommunityPermissions_MANUAL_ACCEPT return o.config.CommunityDescription.Permissions.Access == protobuf.CommunityPermissions_MANUAL_ACCEPT
} }
func (o *Community) InvitationOnly() bool {
return o.config.CommunityDescription.Permissions.Access == protobuf.CommunityPermissions_INVITATION_ONLY
}
func (o *Community) AutoAccept() bool { func (o *Community) AutoAccept() bool {
// We no longer have the notion of "no membership", but for historical reasons // We no longer have the notion of "no membership", but for historical reasons
// we use `NO_MEMBERSHIP` to determine wether requests to join should be automatically // we use `NO_MEMBERSHIP` to determine wether requests to join should be automatically

View File

@ -391,13 +391,6 @@ func (s *CommunitySuite) TestValidateRequestToJoin() {
request: request, request: request,
err: ErrNotAdmin, err: ErrNotAdmin,
}, },
{
name: "invitation-only",
config: s.configInvitationOnly(),
signer: signer,
request: request,
err: ErrCantRequestAccess,
},
{ {
name: "ens-only org and missing ens", name: "ens-only org and missing ens",
config: s.configENSOnly(), config: s.configENSOnly(),
@ -429,14 +422,6 @@ func (s *CommunitySuite) TestValidateRequestToJoin() {
request: requestWithChatID, request: requestWithChatID,
err: ErrCantRequestAccess, err: ErrCantRequestAccess,
}, },
// NO_MEMBERSHIP-INVITATION_ONLY = error as it's invitation only
{
name: "no-membership org with no-membeship chat",
config: s.configNoMembershipOrgInvitationOnlyChat(),
signer: signer,
request: requestWithChatID,
err: ErrCantRequestAccess,
},
// NO_MEMBERSHIP-ON_REQUEST = this is a valid case // NO_MEMBERSHIP-ON_REQUEST = this is a valid case
{ {
name: "no-membership org with on-request chat", name: "no-membership org with on-request chat",
@ -444,30 +429,6 @@ func (s *CommunitySuite) TestValidateRequestToJoin() {
signer: signer, signer: signer,
request: requestWithChatID, request: requestWithChatID,
}, },
// INVITATION_ONLY-INVITATION_ONLY error as it's invitation only
{
name: "invitation-only org with invitation-only chat",
config: s.configInvitationOnlyOrgInvitationOnlyChat(),
signer: signer,
request: requestWithChatID,
err: ErrCantRequestAccess,
},
// ON_REQUEST-INVITATION_ONLY error as it's invitation only
{
name: "on-request org with invitation-only chat",
config: s.configOnRequestOrgInvitationOnlyChat(),
signer: signer,
request: requestWithChatID,
err: ErrCantRequestAccess,
},
// ON_REQUEST-INVITATION_ONLY error as it's invitation only
{
name: "on-request org with invitation-only chat",
config: s.configOnRequestOrgInvitationOnlyChat(),
signer: signer,
request: requestWithChatID,
err: ErrCantRequestAccess,
},
// ON_REQUEST-ON_REQUEST success // ON_REQUEST-ON_REQUEST success
{ {
name: "on-request org with on-request chat", name: "on-request org with on-request chat",
@ -513,32 +474,6 @@ func (s *CommunitySuite) TestCanPost() {
member: notMember, member: notMember,
canPost: false, canPost: false,
}, },
{
name: "no-membership org with invitation only chat-not-a-member",
config: s.configNoMembershipOrgInvitationOnlyChat(),
member: notMember,
canPost: false,
},
{
name: "no-membership org with invitation only chat member",
config: s.configNoMembershipOrgInvitationOnlyChat(),
member: member,
canPost: true,
},
{
name: "no-membership org with invitation only chat-not-a-member valid grant",
config: s.configNoMembershipOrgInvitationOnlyChat(),
member: notMember,
canPost: false,
grant: validGrant,
},
{
name: "no-membership org with invitation only chat-not-a-member invalid grant",
config: s.configNoMembershipOrgInvitationOnlyChat(),
member: notMember,
canPost: false,
grant: invalidGrant,
},
{ {
name: "membership org with no-membership chat-not-a-member", name: "membership org with no-membership chat-not-a-member",
config: s.configOnRequestOrgNoMembershipChat(), config: s.configOnRequestOrgNoMembershipChat(),
@ -671,7 +606,7 @@ func (s *CommunitySuite) TestHandleCommunityDescription() {
changes.MembersAdded[s.member3Key] = &protobuf.CommunityMember{} changes.MembersAdded[s.member3Key] = &protobuf.CommunityMember{}
changes.ChatsAdded[testChatID2] = &protobuf.CommunityChat{ changes.ChatsAdded[testChatID2] = &protobuf.CommunityChat{
Identity: &protobuf.ChatIdentity{DisplayName: "added-chat", Description: "description"}, Identity: &protobuf.ChatIdentity{DisplayName: "added-chat", Description: "description"},
Permissions: &protobuf.CommunityPermissions{Access: protobuf.CommunityPermissions_INVITATION_ONLY}, Permissions: &protobuf.CommunityPermissions{Access: protobuf.CommunityPermissions_MANUAL_ACCEPT},
Members: make(map[string]*protobuf.CommunityMember)} Members: make(map[string]*protobuf.CommunityMember)}
changes.ChatsAdded[testChatID2].Members[s.member3Key] = &protobuf.CommunityMember{} changes.ChatsAdded[testChatID2].Members[s.member3Key] = &protobuf.CommunityMember{}
@ -848,12 +783,6 @@ func (s *CommunitySuite) configOnRequest() Config {
return s.newConfig(s.identity, description) return s.newConfig(s.identity, description)
} }
func (s *CommunitySuite) configInvitationOnly() Config {
description := s.emptyCommunityDescription()
description.Permissions.Access = protobuf.CommunityPermissions_INVITATION_ONLY
return s.newConfig(s.identity, description)
}
func (s *CommunitySuite) configNoMembershipOrgNoMembershipChat() Config { func (s *CommunitySuite) configNoMembershipOrgNoMembershipChat() Config {
description := s.emptyCommunityDescriptionWithChat() description := s.emptyCommunityDescriptionWithChat()
description.Permissions.Access = protobuf.CommunityPermissions_AUTO_ACCEPT description.Permissions.Access = protobuf.CommunityPermissions_AUTO_ACCEPT
@ -861,20 +790,6 @@ func (s *CommunitySuite) configNoMembershipOrgNoMembershipChat() Config {
return s.newConfig(s.identity, description) return s.newConfig(s.identity, description)
} }
func (s *CommunitySuite) configNoMembershipOrgInvitationOnlyChat() Config {
description := s.emptyCommunityDescriptionWithChat()
description.Permissions.Access = protobuf.CommunityPermissions_AUTO_ACCEPT
description.Chats[testChatID1].Permissions.Access = protobuf.CommunityPermissions_INVITATION_ONLY
return s.newConfig(s.identity, description)
}
func (s *CommunitySuite) configInvitationOnlyOrgInvitationOnlyChat() Config {
description := s.emptyCommunityDescriptionWithChat()
description.Permissions.Access = protobuf.CommunityPermissions_INVITATION_ONLY
description.Chats[testChatID1].Permissions.Access = protobuf.CommunityPermissions_INVITATION_ONLY
return s.newConfig(s.identity, description)
}
func (s *CommunitySuite) configNoMembershipOrgOnRequestChat() Config { func (s *CommunitySuite) configNoMembershipOrgOnRequestChat() Config {
description := s.emptyCommunityDescriptionWithChat() description := s.emptyCommunityDescriptionWithChat()
description.Permissions.Access = protobuf.CommunityPermissions_AUTO_ACCEPT description.Permissions.Access = protobuf.CommunityPermissions_AUTO_ACCEPT
@ -889,13 +804,6 @@ func (s *CommunitySuite) configOnRequestOrgOnRequestChat() Config {
return s.newConfig(s.identity, description) return s.newConfig(s.identity, description)
} }
func (s *CommunitySuite) configOnRequestOrgInvitationOnlyChat() Config {
description := s.emptyCommunityDescriptionWithChat()
description.Permissions.Access = protobuf.CommunityPermissions_MANUAL_ACCEPT
description.Chats[testChatID1].Permissions.Access = protobuf.CommunityPermissions_INVITATION_ONLY
return s.newConfig(s.identity, description)
}
func (s *CommunitySuite) configOnRequestOrgNoMembershipChat() Config { func (s *CommunitySuite) configOnRequestOrgNoMembershipChat() Config {
description := s.emptyCommunityDescriptionWithChat() description := s.emptyCommunityDescriptionWithChat()
description.Permissions.Access = protobuf.CommunityPermissions_MANUAL_ACCEPT description.Permissions.Access = protobuf.CommunityPermissions_MANUAL_ACCEPT
@ -919,12 +827,12 @@ func (s *CommunitySuite) configENSOnly() Config {
} }
func (s *CommunitySuite) config() Config { func (s *CommunitySuite) config() Config {
config := s.configOnRequestOrgInvitationOnlyChat() config := s.configOnRequestOrgOnRequestChat()
return config return config
} }
func (s *CommunitySuite) buildCommunityDescription() *protobuf.CommunityDescription { func (s *CommunitySuite) buildCommunityDescription() *protobuf.CommunityDescription {
config := s.configOnRequestOrgInvitationOnlyChat() config := s.configOnRequestOrgOnRequestChat()
desc := config.CommunityDescription desc := config.CommunityDescription
desc.Clock = 1 desc.Clock = 1
desc.Members = make(map[string]*protobuf.CommunityMember) desc.Members = make(map[string]*protobuf.CommunityMember)
@ -1016,7 +924,7 @@ func (s *CommunitySuite) addedChatCommunityDescription(org *Community) *protobuf
description.Members[s.member3Key] = &protobuf.CommunityMember{} description.Members[s.member3Key] = &protobuf.CommunityMember{}
description.Chats[testChatID2] = &protobuf.CommunityChat{ description.Chats[testChatID2] = &protobuf.CommunityChat{
Identity: &protobuf.ChatIdentity{DisplayName: "added-chat", Description: "description"}, Identity: &protobuf.ChatIdentity{DisplayName: "added-chat", Description: "description"},
Permissions: &protobuf.CommunityPermissions{Access: protobuf.CommunityPermissions_INVITATION_ONLY}, Permissions: &protobuf.CommunityPermissions{Access: protobuf.CommunityPermissions_MANUAL_ACCEPT},
Members: make(map[string]*protobuf.CommunityMember)} Members: make(map[string]*protobuf.CommunityMember)}
description.Chats[testChatID2].Members[s.member3Key] = &protobuf.CommunityMember{} description.Chats[testChatID2].Members[s.member3Key] = &protobuf.CommunityMember{}

View File

@ -1672,7 +1672,7 @@ func (m *Manager) handleCommunityDescriptionMessageCommon(community *Community,
} }
// If the community require membership, we set whether we should leave/join the community after a state change // If the community require membership, we set whether we should leave/join the community after a state change
if community.InvitationOnly() || community.ManualAccept() || community.AutoAccept() { if community.ManualAccept() || community.AutoAccept() {
if changes.HasNewMember(pkString) { if changes.HasNewMember(pkString) {
hasPendingRequest, err := m.persistence.HasPendingRequestsToJoinForUserAndCommunity(pkString, changes.Community.ID()) hasPendingRequest, err := m.persistence.HasPendingRequestsToJoinForUserAndCommunity(pkString, changes.Community.ID())
if err != nil { if err != nil {

View File

@ -2450,7 +2450,6 @@ func (s *MessengerCommunitiesSuite) TestSyncCommunity() {
s.Equal(newCommunity.Muted(), tnc.Muted()) s.Equal(newCommunity.Muted(), tnc.Muted())
s.Equal(newCommunity.Joined(), tnc.Joined()) s.Equal(newCommunity.Joined(), tnc.Joined())
s.Equal(newCommunity.Spectated(), tnc.Spectated()) s.Equal(newCommunity.Spectated(), tnc.Spectated())
s.Equal(newCommunity.InvitationOnly(), tnc.InvitationOnly())
s.True(newCommunity.IsControlNode()) s.True(newCommunity.IsControlNode())
s.True(newCommunity.IsOwner()) s.True(newCommunity.IsOwner())