Skip to content

Commit

Permalink
[1658]: Allow an admin to revoke their permission to manage permissions.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpicyLemon committed Oct 12, 2023
1 parent 09e346a commit 79641ca
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
7 changes: 0 additions & 7 deletions x/exchange/msg.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,9 +307,6 @@ func (m MsgMarketManagePermissionsRequest) ValidateBasic() error {
errs = append(errs, fmt.Errorf("invalid revoke-all address %q: %w", addrStr, err))
}
}
if ContainsString(m.RevokeAll, m.Admin) {
errs = append(errs, fmt.Errorf("message administrator %s cannot revoke all of their permissions", m.Admin))
}

if err := ValidateAccessGrantsField("to-revoke", m.ToRevoke); err != nil {
errs = append(errs, err)
Expand All @@ -320,10 +317,6 @@ func (m MsgMarketManagePermissionsRequest) ValidateBasic() error {
if ContainsString(m.RevokeAll, ag.Address) {
errs = append(errs, fmt.Errorf("address %s appears in both the revoke-all and to-revoke fields", ag.Address))
}
if ag.Address == m.Admin && ag.Contains(Permission_permissions) {
errs = append(errs, fmt.Errorf("message administrator %s cannot revoke their own ability to manage permissions",
ag.Address))
}
toRevokeByAddr[ag.Address] = ag
}

Expand Down
6 changes: 4 additions & 2 deletions x/exchange/msg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1318,13 +1318,14 @@ func TestMsgMarketManagePermissionsRequest_ValidateBasic(t *testing.T) {
},
},
{
// We allow this because it can be fixed via gov prop if no one is left that can manage permissions.
name: "admin in revoke-all",
msg: MsgMarketManagePermissionsRequest{
Admin: goodAdminAddr,
MarketId: 1,
RevokeAll: []string{goodAddr1, goodAdminAddr, goodAddr2},
},
expErr: []string{"message administrator " + goodAdminAddr + " cannot revoke all of their permissions"},
expErr: nil,
},
{
name: "admin revoking all their permissions except permissions",
Expand All @@ -1342,6 +1343,7 @@ func TestMsgMarketManagePermissionsRequest_ValidateBasic(t *testing.T) {
expErr: nil,
},
{
// We allow this because it can be fixed via gov prop if no one is left that can manage permissions.
name: "admin revoking own ability to manage permissions",
msg: MsgMarketManagePermissionsRequest{
Admin: goodAdminAddr,
Expand All @@ -1352,7 +1354,7 @@ func TestMsgMarketManagePermissionsRequest_ValidateBasic(t *testing.T) {
{Address: goodAddr2, Permissions: []Permission{Permission_permissions}},
},
},
expErr: []string{"message administrator " + goodAdminAddr + " cannot revoke their own ability to manage permissions"},
expErr: nil,
},
{
name: "multiple errs",
Expand Down

0 comments on commit 79641ca

Please sign in to comment.