fix(ImportCommunity): Setting admin roles during import community.
Issue #7414
This commit is contained in:
parent
9dd80e7f1e
commit
8fc7d921a7
|
@ -550,7 +550,7 @@ func (o *Community) InviteUserToOrg(pk *ecdsa.PublicKey) (*protobuf.CommunityInv
|
|||
return nil, ErrNotAdmin
|
||||
}
|
||||
|
||||
err := o.AddMember(pk)
|
||||
err := o.AddMember(pk, []protobuf.CommunityMember_Roles{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1630,7 +1630,7 @@ func (o *Community) RequestsToJoin() []*RequestToJoin {
|
|||
return o.config.RequestsToJoin
|
||||
}
|
||||
|
||||
func (o *Community) AddMember(publicKey *ecdsa.PublicKey) error {
|
||||
func (o *Community) AddMember(publicKey *ecdsa.PublicKey, roles []protobuf.CommunityMember_Roles) error {
|
||||
if o.config.PrivateKey == nil {
|
||||
return ErrNotAdmin
|
||||
}
|
||||
|
@ -1642,7 +1642,7 @@ func (o *Community) AddMember(publicKey *ecdsa.PublicKey) error {
|
|||
}
|
||||
|
||||
if _, ok := o.config.CommunityDescription.Members[memberKey]; !ok {
|
||||
o.config.CommunityDescription.Members[memberKey] = &protobuf.CommunityMember{}
|
||||
o.config.CommunityDescription.Members[memberKey] = &protobuf.CommunityMember{Roles: roles}
|
||||
}
|
||||
o.increaseClock()
|
||||
return nil
|
||||
|
|
|
@ -908,7 +908,7 @@ func (m *Manager) AcceptRequestToJoin(request *requests.AcceptRequestToJoinCommu
|
|||
return nil, err
|
||||
}
|
||||
|
||||
err = community.AddMember(pk)
|
||||
err = community.AddMember(pk, []protobuf.CommunityMember_Roles{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1202,7 +1202,7 @@ func (m *Manager) InviteUsersToCommunity(communityID types.HexBytes, pks []*ecds
|
|||
return m.inviteUsersToCommunity(community, pks)
|
||||
}
|
||||
|
||||
func (m *Manager) AddMemberToCommunity(communityID types.HexBytes, pk *ecdsa.PublicKey) (*Community, error) {
|
||||
func (m *Manager) AddMemberOwnerToCommunity(communityID types.HexBytes, pk *ecdsa.PublicKey) (*Community, error) {
|
||||
community, err := m.GetByID(communityID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
@ -1211,7 +1211,7 @@ func (m *Manager) AddMemberToCommunity(communityID types.HexBytes, pk *ecdsa.Pub
|
|||
return nil, ErrOrgNotFound
|
||||
}
|
||||
|
||||
err = community.AddMember(pk)
|
||||
err = community.AddMember(pk, []protobuf.CommunityMember_Roles{protobuf.CommunityMember_ROLE_ALL})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
@ -826,6 +826,51 @@ func (s *MessengerCommunitiesSuite) TestImportCommunity() {
|
|||
s.Require().NoError(err)
|
||||
}
|
||||
|
||||
func (s *MessengerCommunitiesSuite) TestRolesAfterImportCommunity() {
|
||||
ctx := context.Background()
|
||||
|
||||
description := &requests.CreateCommunity{
|
||||
Membership: protobuf.CommunityPermissions_NO_MEMBERSHIP,
|
||||
Name: "status",
|
||||
Color: "#ffffff",
|
||||
Description: "status community description",
|
||||
}
|
||||
|
||||
// Create a community chat
|
||||
response, err := s.bob.CreateCommunity(description, true)
|
||||
s.Require().NoError(err)
|
||||
s.Require().NotNil(response)
|
||||
s.Require().Len(response.Communities(), 1)
|
||||
s.Require().Len(response.CommunitiesSettings(), 1)
|
||||
s.Require().True(response.Communities()[0].Joined())
|
||||
s.Require().True(response.Communities()[0].IsAdmin())
|
||||
s.Require().True(response.Communities()[0].IsMemberAdmin(&s.bob.identity.PublicKey))
|
||||
s.Require().False(response.Communities()[0].IsMemberAdmin(&s.alice.identity.PublicKey))
|
||||
|
||||
community := response.Communities()[0]
|
||||
communitySettings := response.CommunitiesSettings()[0]
|
||||
|
||||
s.Require().Equal(communitySettings.CommunityID, community.IDString())
|
||||
s.Require().Equal(communitySettings.HistoryArchiveSupportEnabled, false)
|
||||
|
||||
category := &requests.CreateCommunityCategory{
|
||||
CommunityID: community.ID(),
|
||||
CategoryName: "category-name",
|
||||
ChatIDs: []string{},
|
||||
}
|
||||
|
||||
response, err = s.bob.CreateCommunityCategory(category)
|
||||
s.Require().NoError(err)
|
||||
community = response.Communities()[0]
|
||||
|
||||
privateKey, err := s.bob.ExportCommunity(community.ID())
|
||||
s.Require().NoError(err)
|
||||
|
||||
response, err = s.alice.ImportCommunity(ctx, privateKey)
|
||||
s.Require().NoError(err)
|
||||
s.Require().True(response.Communities()[0].IsMemberAdmin(&s.alice.identity.PublicKey))
|
||||
}
|
||||
|
||||
func (s *MessengerCommunitiesSuite) TestRequestAccess() {
|
||||
ctx := context.Background()
|
||||
|
||||
|
|
|
@ -1120,12 +1120,16 @@ func (m *Messenger) ImportCommunity(ctx context.Context, key *ecdsa.PrivateKey)
|
|||
return nil, err
|
||||
}
|
||||
|
||||
//request info already stored on mailserver, but its success is not crucial
|
||||
// for import
|
||||
_, _ = m.RequestCommunityInfoFromMailserver(community.IDString(), false)
|
||||
_, err = m.RequestCommunityInfoFromMailserver(community.IDString(), false)
|
||||
if err != nil {
|
||||
// TODO In the future we should add a mechanism to re-apply next steps (adding owner, joining)
|
||||
// if there is no connection with mailserver. Otherwise changes will be overwritten.
|
||||
// Do not return error to make tests pass.
|
||||
m.logger.Error("Can't request community info from mailserver")
|
||||
}
|
||||
|
||||
// We add ourselves
|
||||
community, err = m.communitiesManager.AddMemberToCommunity(community.ID(), &m.identity.PublicKey)
|
||||
community, err = m.communitiesManager.AddMemberOwnerToCommunity(community.ID(), &m.identity.PublicKey)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -1390,6 +1394,7 @@ func (m *Messenger) RequestCommunityInfoFromMailserver(communityID string, useDa
|
|||
return community, nil
|
||||
}
|
||||
}
|
||||
|
||||
return m.requestCommunityInfoFromMailserver(communityID, true)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue