fix: promote self to community control node event if we are not a community member (#4270)

This commit is contained in:
Mykhailo Prakhov 2023-11-07 14:18:59 +01:00 committed by GitHub
parent 1d08b403e6
commit b15fa6d2c8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 31 additions and 17 deletions

View File

@ -4879,12 +4879,7 @@ func (m *Manager) createCommunityTokenPermission(request *requests.CreateCommuni
}
func (m *Manager) PromoteSelfToControlNode(communityID types.HexBytes, clock uint64) (*CommunityChanges, error) {
community, err := m.GetByID(communityID)
if err != nil {
return nil, err
}
func (m *Manager) PromoteSelfToControlNode(community *Community, clock uint64) (*CommunityChanges, error) {
if community == nil {
return nil, ErrOrgNotFound
}
@ -4921,7 +4916,23 @@ func (m *Manager) promoteSelfToControlNode(community *Community, clock uint64) (
}
community.config.ControlDevice = true
_, err = community.AddRoleToMember(&m.identity.PublicKey, protobuf.CommunityMember_ROLE_OWNER)
if exists := community.HasMember(&m.identity.PublicKey); !exists {
ownerRole := []protobuf.CommunityMember_Roles{protobuf.CommunityMember_ROLE_OWNER}
_, err = community.AddMember(&m.identity.PublicKey, ownerRole)
if err != nil {
return false, err
}
for channelID := range community.Chats() {
_, err = community.AddMemberToChat(channelID, &m.identity.PublicKey, ownerRole)
if err != nil {
return false, err
}
}
} else {
_, err = community.AddRoleToMember(&m.identity.PublicKey, protobuf.CommunityMember_ROLE_OWNER)
}
if err != nil {
return false, err
}

View File

@ -44,7 +44,6 @@ import (
localnotifications "github.com/status-im/status-go/services/local-notifications"
"github.com/status-im/status-go/services/wallet/bigint"
"github.com/status-im/status-go/signal"
"github.com/status-im/status-go/transactions"
)
// 7 days interval
@ -6053,17 +6052,21 @@ func (m *Messenger) processCommunityChanges(messageState *ReceivedMessageState)
messageState.Response.CommunityChanges = nil
}
func (m *Messenger) SetCommunitySignerPubKey(ctx context.Context, communityID []byte, chainID uint64, contractAddress string, txArgs transactions.SendTxArgs, password string, newSignerPubKey string) (string, error) {
if m.communityTokensService == nil {
return "", errors.New("tokens service not initialized")
}
return m.communityTokensService.SetSignerPubKey(ctx, chainID, contractAddress, txArgs, password, newSignerPubKey)
}
func (m *Messenger) PromoteSelfToControlNode(communityID types.HexBytes) (*MessengerResponse, error) {
clock, _ := m.getLastClockWithRelatedChat()
changes, err := m.communitiesManager.PromoteSelfToControlNode(communityID, clock)
community, err := m.FetchCommunity(&FetchCommunityRequest{
CommunityKey: types.EncodeHex(communityID),
Shard: nil,
TryDatabase: true,
WaitForResponse: true,
})
if err != nil {
return nil, err
}
changes, err := m.communitiesManager.PromoteSelfToControlNode(community, clock)
if err != nil {
return nil, err
}