diff --git a/.changeset/entries/4f5fc33e12f7e7c70e86f7673610e57cf287522455e702b5855dfbddc5789b7c.yaml b/.changeset/entries/4f5fc33e12f7e7c70e86f7673610e57cf287522455e702b5855dfbddc5789b7c.yaml new file mode 100644 index 0000000000..02764c4283 --- /dev/null +++ b/.changeset/entries/4f5fc33e12f7e7c70e86f7673610e57cf287522455e702b5855dfbddc5789b7c.yaml @@ -0,0 +1,6 @@ +type: feat +module: x/subspaces +pull_request: 886 +description: Improved how permissions are managed +backward_compatible: false +date: 2022-06-07T10:03:15.871498535Z diff --git a/client/docs/swagger-ui/swagger.yaml b/client/docs/swagger-ui/swagger.yaml index 02d8709cca..95614580c3 100644 --- a/client/docs/swagger-ui/swagger.yaml +++ b/client/docs/swagger-ui/swagger.yaml @@ -4044,7 +4044,7 @@ paths: format: boolean tags: - Query - /desmos/subspaces/v1/subspaces: + /desmos/subspaces/v2/subspaces: get: summary: Subspaces queries all the subspaces inside Desmos operationId: Subspaces @@ -4203,7 +4203,7 @@ paths: format: boolean tags: - Query - '/desmos/subspaces/v1/subspaces/{subspace_id}': + '/desmos/subspaces/v2/subspaces/{subspace_id}': get: summary: >- Subspace queries all the information about the subspace with the given @@ -4280,7 +4280,7 @@ paths: format: uint64 tags: - Query - '/desmos/subspaces/v1/subspaces/{subspace_id}/groups': + '/desmos/subspaces/v2/subspaces/{subspace_id}/groups': get: summary: >- UserGroups queries all the groups that are present inside the subspace @@ -4320,8 +4320,9 @@ paths: type: string title: Optional description of this group permissions: - type: integer - format: int64 + type: array + items: + type: string title: >- Permissions that will be granted to all the users part of this group @@ -4453,7 +4454,7 @@ paths: format: boolean tags: - Query - '/desmos/subspaces/v1/subspaces/{subspace_id}/groups/{group_id}': + '/desmos/subspaces/v2/subspaces/{subspace_id}/groups/{group_id}': get: summary: |- UserGroup queries the user group having the given id inside the specific @@ -4489,8 +4490,9 @@ paths: type: string title: Optional description of this group permissions: - type: integer - format: int64 + type: array + items: + type: string title: >- Permissions that will be granted to all the users part of this group @@ -4535,7 +4537,7 @@ paths: format: int64 tags: - Query - '/desmos/subspaces/v1/subspaces/{subspace_id}/groups/{group_id}/members': + '/desmos/subspaces/v2/subspaces/{subspace_id}/groups/{group_id}/members': get: summary: UserGroupMembers queries all the members of a given user group operationId: UserGroupMembers @@ -4672,7 +4674,7 @@ paths: format: boolean tags: - Query - '/desmos/subspaces/v1/subspaces/{subspace_id}/permissions/{user}': + '/desmos/subspaces/v2/subspaces/{subspace_id}/permissions/{user}': get: summary: UserPermissions queries the permissions for the given user operationId: UserPermissions @@ -4683,8 +4685,9 @@ paths: type: object properties: permissions: - type: integer - format: int64 + type: array + items: + type: string details: type: array items: @@ -4706,9 +4709,10 @@ paths: type: string title: User for which the permission was set permission: - type: integer - format: int64 - title: Permission set to the user + type: array + items: + type: string + title: Permissions set to the user group: title: Group represents a group permission type: object @@ -4718,9 +4722,10 @@ paths: format: int64 title: Unique id of the group permission: - type: integer - format: int64 - title: Permission set to the group + type: array + items: + type: string + title: Permissions set to the group title: PermissionDetail contains the details data of a permission title: |- QueryUserPermissionsRequest is the response type for the @@ -12232,9 +12237,10 @@ definitions: type: string title: User for which the permission was set permission: - type: integer - format: int64 - title: Permission set to the user + type: array + items: + type: string + title: Permissions set to the user group: title: Group represents a group permission type: object @@ -12244,9 +12250,10 @@ definitions: format: int64 title: Unique id of the group permission: - type: integer - format: int64 - title: Permission set to the group + type: array + items: + type: string + title: Permissions set to the group title: PermissionDetail contains the details data of a permission desmos.subspaces.v2.PermissionDetail.Group: type: object @@ -12256,9 +12263,10 @@ definitions: format: int64 title: Unique id of the group permission: - type: integer - format: int64 - title: Permission set to the group + type: array + items: + type: string + title: Permissions set to the group title: Group is a permission that has been set to a user group desmos.subspaces.v2.PermissionDetail.User: type: object @@ -12267,9 +12275,10 @@ definitions: type: string title: User for which the permission was set permission: - type: integer - format: int64 - title: Permission set to the user + type: array + items: + type: string + title: Permissions set to the user title: User is a permission that has been set to a specific user desmos.subspaces.v2.QuerySectionResponse: type: object @@ -12509,8 +12518,9 @@ definitions: type: string title: Optional description of this group permissions: - type: integer - format: int64 + type: array + items: + type: string title: >- Permissions that will be granted to all the users part of this group @@ -12545,8 +12555,9 @@ definitions: type: string title: Optional description of this group permissions: - type: integer - format: int64 + type: array + items: + type: string title: >- Permissions that will be granted to all the users part of this group @@ -12583,8 +12594,9 @@ definitions: type: object properties: permissions: - type: integer - format: int64 + type: array + items: + type: string details: type: array items: @@ -12606,9 +12618,10 @@ definitions: type: string title: User for which the permission was set permission: - type: integer - format: int64 - title: Permission set to the user + type: array + items: + type: string + title: Permissions set to the user group: title: Group represents a group permission type: object @@ -12618,9 +12631,10 @@ definitions: format: int64 title: Unique id of the group permission: - type: integer - format: int64 - title: Permission set to the group + type: array + items: + type: string + title: Permissions set to the group title: PermissionDetail contains the details data of a permission title: |- QueryUserPermissionsRequest is the response type for the @@ -12700,8 +12714,9 @@ definitions: type: string title: Optional description of this group permissions: - type: integer - format: int64 + type: array + items: + type: string title: Permissions that will be granted to all the users part of this group title: UserGroup represents a group of users desmos.posts.v1.Attachment: diff --git a/proto/desmos/subspaces/v2/genesis.proto b/proto/desmos/subspaces/v2/genesis.proto index 54c1607cc5..93c3cd00df 100644 --- a/proto/desmos/subspaces/v2/genesis.proto +++ b/proto/desmos/subspaces/v2/genesis.proto @@ -38,17 +38,6 @@ message SubspaceData { uint32 next_section_id = 3 [ (gogoproto.customname) = "NextSectionID" ]; } -// UserPermission represents a single Access Control List entry -message UserPermission { - option (gogoproto.equal) = true; - option (gogoproto.goproto_stringer) = true; - - uint64 subspace_id = 1 [ (gogoproto.customname) = "SubspaceID" ]; - uint32 section_id = 2 [ (gogoproto.customname) = "SectionID" ]; - string user = 3; - uint32 permissions = 4; -} - // UserGroupMemberEntry contains the details of a user group member message UserGroupMemberEntry { option (gogoproto.equal) = true; diff --git a/proto/desmos/subspaces/v2/models.proto b/proto/desmos/subspaces/v2/models.proto index 9ff5a5dade..58680be129 100644 --- a/proto/desmos/subspaces/v2/models.proto +++ b/proto/desmos/subspaces/v2/models.proto @@ -95,5 +95,19 @@ message UserGroup { string description = 5 [ (gogoproto.moretags) = "yaml:\"description\"" ]; // Permissions that will be granted to all the users part of this group - uint32 permissions = 6 [ (gogoproto.moretags) = "yaml:\"permissions\"" ]; + repeated string permissions = 6 [ + (gogoproto.castrepeated) = "Permissions", + (gogoproto.moretags) = "yaml:\"permissions\"" + ]; } + +// UserPermission represents a single Access Control List entry +message UserPermission { + option (gogoproto.equal) = true; + option (gogoproto.goproto_stringer) = true; + + uint64 subspace_id = 1 [ (gogoproto.customname) = "SubspaceID" ]; + uint32 section_id = 2 [ (gogoproto.customname) = "SectionID" ]; + string user = 3; + repeated string permissions = 4 [ (gogoproto.castrepeated) = "Permissions" ]; +} \ No newline at end of file diff --git a/proto/desmos/subspaces/v2/msgs.proto b/proto/desmos/subspaces/v2/msgs.proto index ce5633c52b..cd39ab2f41 100644 --- a/proto/desmos/subspaces/v2/msgs.proto +++ b/proto/desmos/subspaces/v2/msgs.proto @@ -253,7 +253,7 @@ message MsgCreateUserGroup { string description = 4 [ (gogoproto.moretags) = "yaml:\"description\"" ]; // Default permissions to be applied to the group - uint32 default_permissions = 5 + repeated string default_permissions = 5 [ (gogoproto.moretags) = "yaml:\"default_permissions\"" ]; // Creator of the group @@ -339,7 +339,8 @@ message MsgSetUserGroupPermissions { ]; // New permissions to be set to the group - uint32 permissions = 3 [ (gogoproto.moretags) = "yaml:\"permissions\"" ]; + repeated string permissions = 3 + [ (gogoproto.moretags) = "yaml:\"permissions\"" ]; // User setting the new permissions string signer = 4 [ (gogoproto.moretags) = "yaml:\"signer\"" ]; @@ -445,7 +446,8 @@ message MsgSetUserPermissions { string user = 3 [ (gogoproto.moretags) = "yaml:\"user\"" ]; // Permissions to be set to the user - uint32 permissions = 4 [ (gogoproto.moretags) = "yaml:\"permissions\"" ]; + repeated string permissions = 4 + [ (gogoproto.moretags) = "yaml:\"permissions\"" ]; // User signing the message string signer = 5 [ (gogoproto.moretags) = "yaml:\"signer\"" ]; diff --git a/proto/desmos/subspaces/v2/query.proto b/proto/desmos/subspaces/v2/query.proto index a8afade7b2..eb6ea47c89 100644 --- a/proto/desmos/subspaces/v2/query.proto +++ b/proto/desmos/subspaces/v2/query.proto @@ -14,13 +14,13 @@ service Query { // Subspaces queries all the subspaces inside Desmos rpc Subspaces(QuerySubspacesRequest) returns (QuerySubspacesResponse) { - option (google.api.http).get = "/desmos/subspaces/v1/subspaces"; + option (google.api.http).get = "/desmos/subspaces/v2/subspaces"; } // Subspace queries all the information about the subspace with the given id rpc Subspace(QuerySubspaceRequest) returns (QuerySubspaceResponse) { option (google.api.http).get = - "/desmos/subspaces/v1/subspaces/{subspace_id}"; + "/desmos/subspaces/v2/subspaces/{subspace_id}"; } // Sections allows to query for the sections of a specific subspace @@ -39,20 +39,20 @@ service Query { // the given id rpc UserGroups(QueryUserGroupsRequest) returns (QueryUserGroupsResponse) { option (google.api.http).get = - "/desmos/subspaces/v1/subspaces/{subspace_id}/groups"; + "/desmos/subspaces/v2/subspaces/{subspace_id}/groups"; } // UserGroup queries the user group having the given id inside the specific // subspace rpc UserGroup(QueryUserGroupRequest) returns (QueryUserGroupResponse) { option (google.api.http).get = - "/desmos/subspaces/v1/subspaces/{subspace_id}/groups/{group_id}"; + "/desmos/subspaces/v2/subspaces/{subspace_id}/groups/{group_id}"; } // UserGroupMembers queries all the members of a given user group rpc UserGroupMembers(QueryUserGroupMembersRequest) returns (QueryUserGroupMembersResponse) { - option (google.api.http).get = "/desmos/subspaces/v1/subspaces/" + option (google.api.http).get = "/desmos/subspaces/v2/subspaces/" "{subspace_id}/groups/{group_id}/members"; } @@ -60,7 +60,7 @@ service Query { rpc UserPermissions(QueryUserPermissionsRequest) returns (QueryUserPermissionsResponse) { option (google.api.http).get = - "/desmos/subspaces/v1/subspaces/{subspace_id}/permissions/{user}"; + "/desmos/subspaces/v2/subspaces/{subspace_id}/permissions/{user}"; } } @@ -192,7 +192,8 @@ message QueryUserPermissionsRequest { // QueryUserPermissionsRequest is the response type for the // Query/UserPermissions method message QueryUserPermissionsResponse { - uint32 permissions = 1 [ (gogoproto.moretags) = "yaml:\"permissions\"" ]; + repeated string permissions = 1 + [ (gogoproto.moretags) = "yaml:\"permissions\"" ]; repeated PermissionDetail details = 2 [ (gogoproto.nullable) = false, (gogoproto.moretags) = "yaml:\"details\"" @@ -228,8 +229,9 @@ message PermissionDetail { // User for which the permission was set string user = 1 [ (gogoproto.moretags) = "yaml:\"user\"" ]; - // Permission set to the user - uint32 permission = 2 [ (gogoproto.moretags) = "yaml:\"permission\"" ]; + // Permissions set to the user + repeated string permission = 2 + [ (gogoproto.moretags) = "yaml:\"permission\"" ]; } // Group is a permission that has been set to a user group @@ -243,7 +245,7 @@ message PermissionDetail { (gogoproto.moretags) = "yaml:\"group_id\"" ]; - // Permission set to the group - uint32 permission = 2; + // Permissions set to the group + repeated string permission = 2; } } \ No newline at end of file diff --git a/x/posts/keeper/external_hooks.go b/x/posts/keeper/external_hooks.go index 7bfda06e3f..b39f701a52 100644 --- a/x/posts/keeper/external_hooks.go +++ b/x/posts/keeper/external_hooks.go @@ -63,7 +63,7 @@ func (h Hooks) AfterSubspaceGroupMemberRemoved(sdk.Context, uint64, uint32, stri func (h Hooks) AfterSubspaceGroupDeleted(sdk.Context, uint64, uint32) {} // AfterUserPermissionSet implements subspacestypes.Hooks -func (h Hooks) AfterUserPermissionSet(sdk.Context, uint64, uint32, string, subspacestypes.Permission) { +func (h Hooks) AfterUserPermissionSet(sdk.Context, uint64, uint32, string, subspacestypes.Permissions) { } // AfterUserPermissionRemoved implements subspacestypes.Hooks diff --git a/x/posts/keeper/msg_server.go b/x/posts/keeper/msg_server.go index 1ab2d079c1..a0fa4291ff 100644 --- a/x/posts/keeper/msg_server.go +++ b/x/posts/keeper/msg_server.go @@ -45,7 +45,7 @@ func (k msgServer) CreatePost(goCtx context.Context, msg *types.MsgCreatePost) ( } // Check the permission to create content - if !k.HasPermission(ctx, msg.SubspaceID, msg.SectionID, author.String(), subspacestypes.PermissionWrite) { + if !k.HasPermission(ctx, msg.SubspaceID, msg.SectionID, author.String(), types.PermissionWrite) { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot create content inside this subspace") } @@ -144,7 +144,7 @@ func (k msgServer) EditPost(goCtx context.Context, msg *types.MsgEditPost) (*typ } // Check the permission to create content - if !k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), subspacestypes.PermissionEditOwnContent) { + if !k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), types.PermissionEditOwnContent) { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot edit content inside this subspace") } @@ -201,8 +201,8 @@ func (k msgServer) DeletePost(goCtx context.Context, msg *types.MsgDeletePost) ( } // Check the permission to remove the post - isModerator := k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), subspacestypes.PermissionModerateContent) - canEdit := post.Author == msg.Signer && k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), subspacestypes.PermissionEditOwnContent) + isModerator := k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), types.PermissionModerateContent) + canEdit := post.Author == msg.Signer && k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), types.PermissionEditOwnContent) if !isModerator && !canEdit { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot edit content inside this subspace") } @@ -295,7 +295,7 @@ func (k msgServer) AddPostAttachment(goCtx context.Context, msg *types.MsgAddPos } // Check the permission to edit content - if !k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), subspacestypes.PermissionEditOwnContent) { + if !k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), types.PermissionEditOwnContent) { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot edit content inside this subspace") } @@ -364,8 +364,8 @@ func (k msgServer) RemovePostAttachment(goCtx context.Context, msg *types.MsgRem } // Check the permission to remove the attachment - isModerator := k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), subspacestypes.PermissionModerateContent) - canEdit := post.Author == msg.Editor && k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), subspacestypes.PermissionEditOwnContent) + isModerator := k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), types.PermissionModerateContent) + canEdit := post.Author == msg.Editor && k.HasPermission(ctx, msg.SubspaceID, post.SectionID, editor.String(), types.PermissionEditOwnContent) if !isModerator && !canEdit { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot edit content inside this subspace") } @@ -429,7 +429,7 @@ func (k msgServer) AnswerPoll(goCtx context.Context, msg *types.MsgAnswerPoll) ( } // Check the permission to interact with content - if !k.HasPermission(ctx, msg.SubspaceID, post.SectionID, signer.String(), subspacestypes.PermissionInteractWithContent) { + if !k.HasPermission(ctx, msg.SubspaceID, post.SectionID, signer.String(), types.PermissionInteractWithContent) { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot interact with content inside this subspace") } diff --git a/x/posts/keeper/msg_server_test.go b/x/posts/keeper/msg_server_test.go index 980155e49f..7a1ce964fc 100644 --- a/x/posts/keeper/msg_server_test.go +++ b/x/posts/keeper/msg_server_test.go @@ -108,7 +108,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreatePost() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionWrite, + subspacestypes.NewPermissions(types.PermissionWrite), ) suite.k.SetParams(ctx, types.DefaultParams()) @@ -144,7 +144,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreatePost() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionWrite, + subspacestypes.NewPermissions(types.PermissionWrite), ) suite.k.SetParams(ctx, types.DefaultParams()) @@ -184,7 +184,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreatePost() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionWrite, + subspacestypes.NewPermissions(types.PermissionWrite), ) }, msg: types.NewMsgCreatePost( @@ -221,7 +221,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreatePost() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionWrite, + subspacestypes.NewPermissions(types.PermissionWrite), ) suite.k.SetNextPostID(ctx, 1, 1) @@ -263,7 +263,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreatePost() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionWrite, + subspacestypes.NewPermissions(types.PermissionWrite), ) suite.k.SetNextPostID(ctx, 1, 1) @@ -306,7 +306,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreatePost() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionWrite, + subspacestypes.NewPermissions(types.PermissionWrite), ) suite.k.SetNextPostID(ctx, 1, 1) @@ -547,7 +547,7 @@ func (suite *KeeperTestsuite) TestMsgServer_EditPost() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionEditOwnContent, + subspacestypes.NewPermissions(types.PermissionEditOwnContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -597,7 +597,7 @@ func (suite *KeeperTestsuite) TestMsgServer_EditPost() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionEditOwnContent, + subspacestypes.NewPermissions(types.PermissionEditOwnContent), ) suite.k.SetParams(ctx, types.DefaultParams()) @@ -726,7 +726,7 @@ func (suite *KeeperTestsuite) TestMsgServer_DeletePost() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionEditOwnContent, + subspacestypes.NewPermissions(types.PermissionEditOwnContent), ) }, msg: types.NewMsgDeletePost(1, 1, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd"), @@ -780,7 +780,7 @@ func (suite *KeeperTestsuite) TestMsgServer_DeletePost() { 1, 0, "cosmos1r9jamre0x0qqy562rhhckt6sryztwhnvhafyz4", - subspacestypes.PermissionEditOwnContent, + subspacestypes.NewPermissions(types.PermissionEditOwnContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -818,7 +818,7 @@ func (suite *KeeperTestsuite) TestMsgServer_DeletePost() { 1, 0, "cosmos1r9jamre0x0qqy562rhhckt6sryztwhnvhafyz4", - subspacestypes.PermissionModerateContent, + subspacestypes.NewPermissions(types.PermissionModerateContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -872,7 +872,7 @@ func (suite *KeeperTestsuite) TestMsgServer_DeletePost() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionEditOwnContent, + subspacestypes.NewPermissions(types.PermissionEditOwnContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -1087,7 +1087,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AddPostAttachment() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionEditOwnContent, + subspacestypes.NewPermissions(types.PermissionEditOwnContent), ) }, msg: types.NewMsgAddPostAttachment( @@ -1135,7 +1135,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AddPostAttachment() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionEditOwnContent, + subspacestypes.NewPermissions(types.PermissionEditOwnContent), ) }, msg: types.NewMsgAddPostAttachment( @@ -1308,7 +1308,7 @@ func (suite *KeeperTestsuite) TestMsgServer_RemovePostAttachment() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionEditOwnContent, + subspacestypes.NewPermissions(types.PermissionEditOwnContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -1351,7 +1351,7 @@ func (suite *KeeperTestsuite) TestMsgServer_RemovePostAttachment() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionEditOwnContent, + subspacestypes.NewPermissions(types.PermissionEditOwnContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -1397,7 +1397,7 @@ func (suite *KeeperTestsuite) TestMsgServer_RemovePostAttachment() { 1, 0, "cosmos1r9jamre0x0qqy562rhhckt6sryztwhnvhafyz4", - subspacestypes.PermissionModerateContent, + subspacestypes.NewPermissions(types.PermissionModerateContent), ) suite.k.SetParams(ctx, types.DefaultParams()) @@ -1481,7 +1481,7 @@ func (suite *KeeperTestsuite) TestMsgServer_RemovePostAttachment() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionEditOwnContent, + subspacestypes.NewPermissions(types.PermissionEditOwnContent), ) suite.k.SetParams(ctx, types.DefaultParams()) @@ -1635,7 +1635,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AnswerPoll() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionInteractWithContent, + subspacestypes.NewPermissions(types.PermissionInteractWithContent), ) }, msg: types.NewMsgAnswerPoll( @@ -1664,7 +1664,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AnswerPoll() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionInteractWithContent, + subspacestypes.NewPermissions(types.PermissionInteractWithContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -1708,7 +1708,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AnswerPoll() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionInteractWithContent, + subspacestypes.NewPermissions(types.PermissionInteractWithContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -1777,7 +1777,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AnswerPoll() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionInteractWithContent, + subspacestypes.NewPermissions(types.PermissionInteractWithContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -1838,7 +1838,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AnswerPoll() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionInteractWithContent, + subspacestypes.NewPermissions(types.PermissionInteractWithContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -1899,7 +1899,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AnswerPoll() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionInteractWithContent, + subspacestypes.NewPermissions(types.PermissionInteractWithContent), ) suite.k.SavePost(ctx, types.NewPost( @@ -1994,7 +1994,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AnswerPoll() { 1, 0, "cosmos13t6y2nnugtshwuy0zkrq287a95lyy8vzleaxmd", - subspacestypes.PermissionInteractWithContent, + subspacestypes.NewPermissions(types.PermissionInteractWithContent), ) suite.k.SavePost(ctx, types.NewPost( diff --git a/x/posts/simulation/operations_attachments.go b/x/posts/simulation/operations_attachments.go index e900909540..2bcac1b28f 100644 --- a/x/posts/simulation/operations_attachments.go +++ b/x/posts/simulation/operations_attachments.go @@ -134,9 +134,9 @@ func randomRemovePostAttachmentFields( editorAddr := post.Author if r.Intn(101) < 50 { // 50% of a moderator removing an attachment - moderators, _ := sk.GetUsersWithRootPermission(ctx, subspaceID, subspacestypes.PermissionModerateContent) + moderators := sk.GetUsersWithRootPermissions(ctx, subspaceID, subspacestypes.NewPermissions(types.PermissionModerateContent)) editorAddr = subspacessim.RandomAddress(r, moderators) - } else if !sk.HasPermission(ctx, subspaceID, sectionID, editorAddr, subspacestypes.PermissionEditOwnContent) { + } else if !sk.HasPermission(ctx, subspaceID, sectionID, editorAddr, types.PermissionEditOwnContent) { // Skip because the user has not the permission to edit their own content skip = true return diff --git a/x/posts/simulation/operations_polls.go b/x/posts/simulation/operations_polls.go index c0056cc0e3..044cc60bed 100644 --- a/x/posts/simulation/operations_polls.go +++ b/x/posts/simulation/operations_polls.go @@ -72,7 +72,7 @@ func randomAnswerPollFields( poll := RandomAttachment(r, polls) // Get a user - users, _ := sk.GetUsersWithRootPermission(ctx, poll.SubspaceID, subspacestypes.PermissionInteractWithContent) + users := sk.GetUsersWithRootPermissions(ctx, poll.SubspaceID, subspacestypes.NewPermissions(types.PermissionInteractWithContent)) acc := subspacessim.GetAccount(subspacessim.RandomAddress(r, users), accs) if acc == nil { // Skip the operation withofut error as the account is not valid diff --git a/x/posts/simulation/operations_posts.go b/x/posts/simulation/operations_posts.go index 6bae1fb914..b1a4d3c688 100644 --- a/x/posts/simulation/operations_posts.go +++ b/x/posts/simulation/operations_posts.go @@ -77,7 +77,7 @@ func randomPostCreateFields( section := subspacessim.RandomSection(r, sections) // Get an author - users, _ := sk.GetUsersWithRootPermission(ctx, section.SubspaceID, subspacestypes.PermissionWrite) + users := sk.GetUsersWithRootPermissions(ctx, section.SubspaceID, subspacestypes.NewPermissions(types.PermissionWrite)) acc := subspacessim.GetAccount(subspacessim.RandomAddress(r, users), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -160,7 +160,7 @@ func randomPostEditFields( editor = *authorAcc // Check the permissions - if !sk.HasPermission(ctx, subspaceID, sectionID, post.Author, subspacestypes.PermissionEditOwnContent) { + if !sk.HasPermission(ctx, subspaceID, sectionID, post.Author, types.PermissionEditOwnContent) { // Skip because the user has not the permissions skip = true return @@ -227,9 +227,9 @@ func randomPostDeleteFields( authorAddr := post.Author if r.Intn(101) < 50 { // 50% of a moderator deleting the post - moderators, _ := sk.GetUsersWithRootPermission(ctx, subspaceID, subspacestypes.PermissionModerateContent) + moderators := sk.GetUsersWithRootPermissions(ctx, subspaceID, subspacestypes.NewPermissions(types.PermissionModerateContent)) authorAddr = subspacessim.RandomAddress(r, moderators) - } else if !sk.HasPermission(ctx, subspaceID, sectionID, authorAddr, subspacestypes.PermissionEditOwnContent) { + } else if !sk.HasPermission(ctx, subspaceID, sectionID, authorAddr, types.PermissionEditOwnContent) { // Skip because the user has not the permissions skip = true return diff --git a/x/posts/types/permissions.go b/x/posts/types/permissions.go new file mode 100644 index 0000000000..804467d658 --- /dev/null +++ b/x/posts/types/permissions.go @@ -0,0 +1,21 @@ +package types + +// DONTCOVER + +import ( + subspacestypes "github.com/desmos-labs/desmos/v3/x/subspaces/types" +) + +var ( + // PermissionWrite identifies users that can create content inside the subspace + PermissionWrite = subspacestypes.RegisterPermission("write content") + + // PermissionInteractWithContent allows users to interact with content inside the subspace (eg. polls) + PermissionInteractWithContent = subspacestypes.RegisterPermission("interact with content") + + // PermissionEditOwnContent allows users to edit their own content inside the subspace + PermissionEditOwnContent = subspacestypes.RegisterPermission("edit own content") + + // PermissionModerateContent allows users to moderate other user's content + PermissionModerateContent = subspacestypes.RegisterPermission("moderate content") +) diff --git a/x/relationships/keeper/hooks.go b/x/relationships/keeper/hooks.go index 93409628c8..b5f971005a 100644 --- a/x/relationships/keeper/hooks.go +++ b/x/relationships/keeper/hooks.go @@ -47,6 +47,6 @@ func (h Hooks) AfterSubspaceGroupSaved(sdk.Context, uint64, uint32) func (h Hooks) AfterSubspaceGroupMemberAdded(sdk.Context, uint64, uint32, string) {} func (h Hooks) AfterSubspaceGroupMemberRemoved(sdk.Context, uint64, uint32, string) {} func (h Hooks) AfterSubspaceGroupDeleted(sdk.Context, uint64, uint32) {} -func (h Hooks) AfterUserPermissionSet(sdk.Context, uint64, uint32, string, subspacestypes.Permission) { +func (h Hooks) AfterUserPermissionSet(sdk.Context, uint64, uint32, string, subspacestypes.Permissions) { } func (h Hooks) AfterUserPermissionRemoved(sdk.Context, uint64, uint32, string) {} diff --git a/x/reports/keeper/external_hooks.go b/x/reports/keeper/external_hooks.go index ba664adf0b..764ce3ab9b 100644 --- a/x/reports/keeper/external_hooks.go +++ b/x/reports/keeper/external_hooks.go @@ -74,7 +74,7 @@ func (h Hooks) AfterSubspaceGroupMemberRemoved(sdk.Context, uint64, uint32, stri } // AfterUserPermissionSet implements subspacestypes.Hooks -func (h Hooks) AfterUserPermissionSet(sdk.Context, uint64, uint32, string, subspacestypes.Permission) { +func (h Hooks) AfterUserPermissionSet(sdk.Context, uint64, uint32, string, subspacestypes.Permissions) { } // AfterUserPermissionRemoved implements subspacestypes.Hooks diff --git a/x/reports/keeper/msg_server.go b/x/reports/keeper/msg_server.go index cef96dde46..9ae892ebfe 100644 --- a/x/reports/keeper/msg_server.go +++ b/x/reports/keeper/msg_server.go @@ -40,7 +40,7 @@ func (k msgServer) CreateReport(goCtx context.Context, msg *types.MsgCreateRepor } // Check the permission to report - if !k.HasPermission(ctx, msg.SubspaceID, msg.Reporter, subspacestypes.PermissionReportContent) { + if !k.HasPermission(ctx, msg.SubspaceID, msg.Reporter, types.PermissionReportContent) { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot report content inside this subspace") } @@ -141,8 +141,8 @@ func (k msgServer) DeleteReport(goCtx context.Context, msg *types.MsgDeleteRepor } // Check the permission to delete reports - isModerator := k.HasPermission(ctx, msg.SubspaceID, msg.Signer, subspacestypes.PermissionManageReports) - canDelete := report.Reporter == msg.Signer && k.HasPermission(ctx, msg.SubspaceID, msg.Signer, subspacestypes.PermissionDeleteOwnReports) + isModerator := k.HasPermission(ctx, msg.SubspaceID, msg.Signer, types.PermissionManageReports) + canDelete := report.Reporter == msg.Signer && k.HasPermission(ctx, msg.SubspaceID, msg.Signer, types.PermissionDeleteOwnReports) if !isModerator && !canDelete { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot delete reports inside this subspace") } @@ -183,7 +183,7 @@ func (k msgServer) SupportStandardReason(goCtx context.Context, msg *types.MsgSu } // Check the permission to manage reasons - if !k.HasPermission(ctx, msg.SubspaceID, msg.Signer, subspacestypes.PermissionManageReasons) { + if !k.HasPermission(ctx, msg.SubspaceID, msg.Signer, types.PermissionManageReasons) { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot manage reasons inside this subspace") } @@ -236,7 +236,7 @@ func (k msgServer) AddReason(goCtx context.Context, msg *types.MsgAddReason) (*t } // Check the permission to manage reasons - if !k.HasPermission(ctx, msg.SubspaceID, msg.Signer, subspacestypes.PermissionManageReasons) { + if !k.HasPermission(ctx, msg.SubspaceID, msg.Signer, types.PermissionManageReasons) { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot manage reasons inside this subspace") } @@ -293,7 +293,7 @@ func (k msgServer) RemoveReason(goCtx context.Context, msg *types.MsgRemoveReaso } // Check the permission to manage reasons - if !k.HasPermission(ctx, msg.SubspaceID, msg.Signer, subspacestypes.PermissionManageReasons) { + if !k.HasPermission(ctx, msg.SubspaceID, msg.Signer, types.PermissionManageReasons) { return nil, sdkerrors.Wrap(subspacestypes.ErrPermissionDenied, "you cannot manage reasons inside this subspace") } diff --git a/x/reports/keeper/msg_server_test.go b/x/reports/keeper/msg_server_test.go index 9592634627..8f0f9562a2 100644 --- a/x/reports/keeper/msg_server_test.go +++ b/x/reports/keeper/msg_server_test.go @@ -108,7 +108,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateReport() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionReportContent, + subspacestypes.NewPermissions(types.PermissionReportContent), ) suite.k.SaveReason(ctx, types.NewReason( @@ -148,7 +148,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateReport() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionReportContent, + subspacestypes.NewPermissions(types.PermissionReportContent), ) suite.k.SaveReason(ctx, types.NewReason( @@ -198,7 +198,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateReport() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionReportContent, + subspacestypes.NewPermissions(types.PermissionReportContent), ) suite.k.SaveReason(ctx, types.NewReason( @@ -268,7 +268,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateReport() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionReportContent, + subspacestypes.NewPermissions(types.PermissionReportContent), ) suite.k.SaveReason(ctx, types.NewReason( @@ -476,7 +476,7 @@ func (suite *KeeperTestsuite) TestMsgServer_DeleteReport() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionDeleteOwnReports, + subspacestypes.NewPermissions(types.PermissionDeleteOwnReports), ) suite.k.SaveReport(ctx, types.NewReport( @@ -526,7 +526,7 @@ func (suite *KeeperTestsuite) TestMsgServer_DeleteReport() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionManageReports, + subspacestypes.NewPermissions(types.PermissionManageReports), ) suite.k.SaveReport(ctx, types.NewReport( @@ -662,7 +662,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SupportStandardReason() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionManageReasons, + subspacestypes.NewPermissions(types.PermissionManageReasons), ) suite.k.SetParams(ctx, types.NewParams([]types.StandardReason{ @@ -694,7 +694,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SupportStandardReason() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionManageReasons, + subspacestypes.NewPermissions(types.PermissionManageReasons), ) suite.k.SetParams(ctx, types.NewParams([]types.StandardReason{ @@ -815,7 +815,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AddReason() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionManageReasons, + subspacestypes.NewPermissions(types.PermissionManageReasons), ) }, msg: types.NewMsgAddReason( @@ -844,7 +844,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AddReason() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionManageReasons, + subspacestypes.NewPermissions(types.PermissionManageReasons), ) }, msg: types.NewMsgAddReason( @@ -873,7 +873,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AddReason() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionManageReasons, + subspacestypes.NewPermissions(types.PermissionManageReasons), ) }, msg: types.NewMsgAddReason( @@ -1016,7 +1016,7 @@ func (suite *KeeperTestsuite) TestMsgServer_RemoveReason() { 1, 0, "cosmos1qycmg40ju50fx2mcc82qtkzuswjs3mj3mqekeh", - subspacestypes.PermissionManageReasons, + subspacestypes.NewPermissions(types.PermissionManageReasons), ) }, msg: types.NewMsgRemoveReason( diff --git a/x/reports/simulation/operations_reasons.go b/x/reports/simulation/operations_reasons.go index 478854d9c0..60e626d06c 100644 --- a/x/reports/simulation/operations_reasons.go +++ b/x/reports/simulation/operations_reasons.go @@ -85,7 +85,7 @@ func randomSupportStandardReasonFields( standardReasonID = reason.ID // Get a user - users, _ := sk.GetUsersWithRootPermission(ctx, subspace.ID, subspacestypes.PermissionManageReasons) + users := sk.GetUsersWithRootPermissions(ctx, subspace.ID, subspacestypes.NewPermissions(types.PermissionManageReasons)) acc := subspacessim.GetAccount(subspacessim.RandomAddress(r, users), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -158,7 +158,7 @@ func randomAddReasonFields( ) // Get a user - users, _ := sk.GetUsersWithRootPermission(ctx, subspace.ID, subspacestypes.PermissionManageReasons) + users := sk.GetUsersWithRootPermissions(ctx, subspace.ID, subspacestypes.NewPermissions(types.PermissionManageReasons)) acc := subspacessim.GetAccount(subspacessim.RandomAddress(r, users), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -234,7 +234,7 @@ func randomRemoveReason( reasonID = reason.ID // Get a user - users, _ := sk.GetUsersWithRootPermission(ctx, subspace.ID, subspacestypes.PermissionManageReasons) + users := sk.GetUsersWithRootPermissions(ctx, subspace.ID, subspacestypes.NewPermissions(types.PermissionManageReasons)) acc := subspacessim.GetAccount(subspacessim.RandomAddress(r, users), accs) if acc == nil { // Skip the operation without error as the account is not valid diff --git a/x/reports/simulation/operations_reports.go b/x/reports/simulation/operations_reports.go index 464d9a0fd3..3af3e610d4 100644 --- a/x/reports/simulation/operations_reports.go +++ b/x/reports/simulation/operations_reports.go @@ -111,7 +111,7 @@ func randomCreateReportFields( } // Get a reporter - reporters, _ := sk.GetUsersWithRootPermission(ctx, subspace.ID, subspacestypes.PermissionReportContent) + reporters := sk.GetUsersWithRootPermissions(ctx, subspace.ID, subspacestypes.NewPermissions(types.PermissionReportContent)) acc := subspacessim.GetAccount(subspacessim.RandomAddress(r, reporters), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -190,7 +190,7 @@ func randomDeleteReportFields( reportID = report.ID // Get an editor - editors, _ := sk.GetUsersWithRootPermission(ctx, subspace.ID, subspacestypes.PermissionManageReports) + editors := sk.GetUsersWithRootPermissions(ctx, subspace.ID, subspacestypes.NewPermissions(types.PermissionManageReports)) acc := subspacessim.GetAccount(subspacessim.RandomAddress(r, editors), accs) if acc == nil { // Skip the operation without error as the account is not valid diff --git a/x/reports/types/permissions.go b/x/reports/types/permissions.go new file mode 100644 index 0000000000..9bb215b229 --- /dev/null +++ b/x/reports/types/permissions.go @@ -0,0 +1,21 @@ +package types + +// DONTCOVER + +import ( + subspacestypes "github.com/desmos-labs/desmos/v3/x/subspaces/types" +) + +var ( + // PermissionReportContent allows users to report contents + PermissionReportContent = subspacestypes.RegisterPermission("report content") + + // PermissionDeleteOwnReports allows users to delete existing reports made by their own + PermissionDeleteOwnReports = subspacestypes.RegisterPermission("delete own reports") + + // PermissionManageReports allows users to manage other users reports + PermissionManageReports = subspacestypes.RegisterPermission("manage reports") + + // PermissionManageReasons allows users to manage a subspace reasons for reporting + PermissionManageReasons = subspacestypes.RegisterPermission("manage reasons") +) diff --git a/x/subspaces/client/cli/cli_test.go b/x/subspaces/client/cli/cli_test.go index 9141846121..45eac22ee9 100644 --- a/x/subspaces/client/cli/cli_test.go +++ b/x/subspaces/client/cli/cli_test.go @@ -5,6 +5,8 @@ import ( "testing" "time" + poststypes "github.com/desmos-labs/desmos/v3/x/posts/types" + "github.com/cosmos/cosmos-sdk/client/flags" "github.com/gogo/protobuf/proto" @@ -93,13 +95,13 @@ func (s *IntegrationTestSuite) SetupSuite() { ), }, []types.UserPermission{ - types.NewUserPermission(1, 0, "cosmos1xw69y2z3yf00rgfnly99628gn5c0x7fryyfv5e", types.PermissionWrite), - types.NewUserPermission(2, 0, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.PermissionManageGroups), + types.NewUserPermission(1, 0, "cosmos1xw69y2z3yf00rgfnly99628gn5c0x7fryyfv5e", types.NewPermissions(poststypes.PermissionWrite)), + types.NewUserPermission(2, 0, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.NewPermissions(types.PermissionManageGroups)), }, []types.UserGroup{ - types.NewUserGroup(1, 0, 1, "Test group", "", types.PermissionWrite), - types.NewUserGroup(2, 0, 1, "Another test group", "", types.PermissionManageGroups), - types.NewUserGroup(2, 0, 2, "Third group", "", types.PermissionWrite), + types.NewUserGroup(1, 0, 1, "Test group", "", types.NewPermissions(poststypes.PermissionWrite)), + types.NewUserGroup(2, 0, 1, "Another test group", "", types.NewPermissions(types.PermissionManageGroups)), + types.NewUserGroup(2, 0, 2, "Third group", "", types.NewPermissions(poststypes.PermissionWrite)), }, []types.UserGroupMemberEntry{ types.NewUserGroupMemberEntry(1, 1, "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm"), @@ -365,8 +367,8 @@ func (s *IntegrationTestSuite) TestCmdQueryUserGroups() { expResponse: types.QueryUserGroupsResponse{ Groups: []types.UserGroup{ types.DefaultUserGroup(2), - types.NewUserGroup(2, 0, 1, "Another test group", "", types.PermissionManageGroups), - types.NewUserGroup(2, 0, 2, "Third group", "", types.PermissionWrite), + types.NewUserGroup(2, 0, 1, "Another test group", "", types.NewPermissions(types.PermissionManageGroups)), + types.NewUserGroup(2, 0, 2, "Third group", "", types.NewPermissions(poststypes.PermissionWrite)), }, }, }, @@ -387,7 +389,10 @@ func (s *IntegrationTestSuite) TestCmdQueryUserGroups() { var response types.QueryUserGroupsResponse s.Require().NoError(clientCtx.JSONCodec.UnmarshalJSON(out.Bytes(), &response), out.String()) - s.Require().Equal(tc.expResponse.Groups, response.Groups) + s.Require().Equal(len(tc.expResponse.Groups), len(response.Groups)) + for i, group := range tc.expResponse.Groups { + s.Require().True(group.Equal(response.Groups[i])) + } } }) } @@ -430,7 +435,7 @@ func (s *IntegrationTestSuite) TestCmdQueryUserGroup() { var response types.QueryUserGroupResponse s.Require().NoError(clientCtx.JSONCodec.UnmarshalJSON(out.Bytes(), &response), out.String()) - s.Require().Equal(tc.expResponse.Group, response.Group) + s.Require().True(tc.expResponse.Group.Equal(response.Group)) } }) } @@ -516,10 +521,10 @@ func (s *IntegrationTestSuite) TestCmdQueryUserPermissions() { }, shouldErr: false, expResponse: types.QueryUserPermissionsResponse{ - Permissions: types.PermissionManageGroups, + Permissions: types.NewPermissions(types.PermissionManageGroups), Details: []types.PermissionDetail{ - types.NewPermissionDetailGroup(2, 0, 0, types.PermissionNothing), - types.NewPermissionDetailGroup(2, 0, 1, types.PermissionManageGroups), + types.NewPermissionDetailGroup(2, 0, 0, nil), + types.NewPermissionDetailGroup(2, 0, 1, types.NewPermissions(types.PermissionManageGroups)), }, }, }, @@ -541,7 +546,9 @@ func (s *IntegrationTestSuite) TestCmdQueryUserPermissions() { var response types.QueryUserPermissionsResponse s.Require().NoError(clientCtx.JSONCodec.UnmarshalJSON(out.Bytes(), &response), out.String()) s.Require().Equal(tc.expResponse.Permissions, response.Permissions) - s.Require().Equal(tc.expResponse.Details, response.Details) + for i, detail := range tc.expResponse.Details { + s.Require().True(detail.Equal(response.Details[i])) + } } }) } @@ -1109,7 +1116,7 @@ func (s *IntegrationTestSuite) TestCmdSetUserGroupPermissions() { { name: "valid data returns no error - group id = 0", args: []string{ - "1", "0", types.SerializePermission(types.PermissionWrite), + "1", "0", types.SerializePermission(poststypes.PermissionWrite), fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), @@ -1121,7 +1128,7 @@ func (s *IntegrationTestSuite) TestCmdSetUserGroupPermissions() { { name: "valid data returns no error - group id > 0", args: []string{ - "1", "1", types.SerializePermission(types.PermissionWrite), + "1", "1", types.SerializePermission(poststypes.PermissionWrite), fmt.Sprintf("--%s=%s", flags.FlagFrom, val.Address.String()), fmt.Sprintf("--%s=true", flags.FlagSkipConfirmation), fmt.Sprintf("--%s=%s", flags.FlagBroadcastMode, flags.BroadcastBlock), diff --git a/x/subspaces/client/cli/tx.go b/x/subspaces/client/cli/tx.go index cfb3b1f3d7..fe1701cf47 100644 --- a/x/subspaces/client/cli/tx.go +++ b/x/subspaces/client/cli/tx.go @@ -450,7 +450,7 @@ Multiple permissions must be specified separating them with a comma (,).`, FlagD Example: fmt.Sprintf(` %s tx subspaces groups create 1 "Admins" \ --description "Group of the subspace admins" \ - --permissions "Write,ModerateContent,SetUserPermissions" \ + --permissions "WRITE,MODERATE_CONTENT,SET_USER_PERMISSIONS" \ --from alice `, version.AppName), RunE: func(cmd *cobra.Command, args []string) error { @@ -476,21 +476,17 @@ Multiple permissions must be specified separating them with a comma (,).`, FlagD return err } - permissions, err := cmd.Flags().GetStringSlice(FlagPermissions) + flagPermissions, err := cmd.Flags().GetStringSlice(FlagPermissions) if err != nil { return err } - permission := types.PermissionNothing - for _, permArg := range permissions { - perm, err := types.ParsePermission(permArg) - if err != nil { - return err - } - permission = types.CombinePermissions(permission, perm) + var permissions types.Permissions + for _, arg := range flagPermissions { + permissions = types.CombinePermissions(append(permissions, arg)...) } - msg := types.NewMsgCreateUserGroup(subspaceID, sectionID, name, description, permission, clientCtx.FromAddress.String()) + msg := types.NewMsgCreateUserGroup(subspaceID, sectionID, name, description, permissions, clientCtx.FromAddress.String()) if err = msg.ValidateBasic(); err != nil { return fmt.Errorf("message validation failed: %w", err) } @@ -501,7 +497,7 @@ Multiple permissions must be specified separating them with a comma (,).`, FlagD cmd.Flags().Uint32(FlagSection, 0, "Id of the section inside which to create the group") cmd.Flags().String(FlagDescription, "", "Description of the group") - cmd.Flags().StringSlice(FlagPermissions, []string{types.SerializePermission(types.PermissionNothing)}, "Permissions of the group") + cmd.Flags().StringSlice(FlagPermissions, nil, "Permissions of the group") flags.AddTxFlagsToCmd(cmd) return cmd @@ -614,7 +610,7 @@ func GetCmdSetUserGroupPermissions() *cobra.Command { It is mandatory to specify at least one permission to be set. When specifying multiple permissions, they must be separated by a comma (,).`, Example: fmt.Sprintf(` -%s tx subspaces groups set-permissions 1 1 "Write,ModerateContent,SetUserPermissions" \ +%s tx subspaces groups set-permissions 1 1 "WRITE,MODERATE_CONTENT,SET_USER_PERMISSIONS" \ --from alice `, version.AppName), RunE: func(cmd *cobra.Command, args []string) error { @@ -633,16 +629,12 @@ When specifying multiple permissions, they must be separated by a comma (,).`, return err } - permission := types.PermissionNothing + var permissions types.Permissions for _, arg := range strings.Split(args[2], ",") { - perm, err := types.ParsePermission(arg) - if err != nil { - return err - } - permission = types.CombinePermissions(permission, perm) + permissions = types.CombinePermissions(append(permissions, arg)...) } - msg := types.NewMsgSetUserGroupPermissions(subspaceID, groupID, permission, clientCtx.FromAddress.String()) + msg := types.NewMsgSetUserGroupPermissions(subspaceID, groupID, permissions, clientCtx.FromAddress.String()) if err = msg.ValidateBasic(); err != nil { return fmt.Errorf("message validation failed: %w", err) } @@ -791,7 +783,9 @@ func GetCmdSetUserPermissions() *cobra.Command { It is mandatory to specify at least one permission to be set. When specifying multiple permissions, they must be separated by a comma (,).`, Example: fmt.Sprintf(` -%s tx subspaces set-user-permissions 1 desmos1463vltcqk6ql6zpk0g6s595jjcrzk4804hyqw7 "Write,ModerateContent,SetUserPermissions" \ +%s tx subspaces set-user-permissions 1 \ + desmos1463vltcqk6ql6zpk0g6s595jjcrzk4804hyqw7 \ + "WRITE,MODERATE_CONTENT,SET_USER_PERMISSIONS" \ --from alice `, version.AppName), RunE: func(cmd *cobra.Command, args []string) error { @@ -812,16 +806,12 @@ When specifying multiple permissions, they must be separated by a comma (,).`, user := args[1] - permission := types.PermissionNothing + var permissions types.Permissions for _, arg := range strings.Split(args[2], ",") { - perm, err := types.ParsePermission(arg) - if err != nil { - return err - } - permission = types.CombinePermissions(permission, perm) + permissions = types.CombinePermissions(append(permissions, arg)...) } - msg := types.NewMsgSetUserPermissions(subspaceID, sectionID, user, permission, clientCtx.FromAddress.String()) + msg := types.NewMsgSetUserPermissions(subspaceID, sectionID, user, permissions, clientCtx.FromAddress.String()) if err = msg.ValidateBasic(); err != nil { return fmt.Errorf("message validation failed: %w", err) } diff --git a/x/subspaces/keeper/alias_functions.go b/x/subspaces/keeper/alias_functions.go index c8155a1f71..56cbc811de 100644 --- a/x/subspaces/keeper/alias_functions.go +++ b/x/subspaces/keeper/alias_functions.go @@ -259,10 +259,10 @@ func (k Keeper) IterateUserPermissions(ctx sdk.Context, fn func(entry types.User defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - subspaceID, sectionID, user := types.SplitUserAddressPermissionKey(iterator.Key()) - permission := types.UnmarshalPermission(iterator.Value()) + var permission types.UserPermission + k.cdc.MustUnmarshal(iterator.Value(), &permission) - stop := fn(types.NewUserPermission(subspaceID, sectionID, user, permission)) + stop := fn(permission) if stop { break } @@ -278,10 +278,10 @@ func (k Keeper) IterateSubspaceUserPermissions(ctx sdk.Context, subspaceID uint6 defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - subspaceID, sectionID, user := types.SplitUserAddressPermissionKey(iterator.Key()) - permission := types.UnmarshalPermission(iterator.Value()) + var permission types.UserPermission + k.cdc.MustUnmarshal(iterator.Value(), &permission) - stop := fn(types.NewUserPermission(subspaceID, sectionID, user, permission)) + stop := fn(permission) if stop { break } @@ -307,10 +307,10 @@ func (k Keeper) IterateSectionUserPermissions(ctx sdk.Context, subspaceID uint64 defer iterator.Close() for ; iterator.Valid(); iterator.Next() { - subspaceID, sectionID, user := types.SplitUserAddressPermissionKey(iterator.Key()) - permission := types.UnmarshalPermission(iterator.Value()) + var permission types.UserPermission + k.cdc.MustUnmarshal(iterator.Value(), &permission) - stop := fn(types.NewUserPermission(subspaceID, sectionID, user, permission)) + stop := fn(permission) if stop { break } diff --git a/x/subspaces/keeper/genesis.go b/x/subspaces/keeper/genesis.go index 4c6fa9116d..b10cc1822d 100644 --- a/x/subspaces/keeper/genesis.go +++ b/x/subspaces/keeper/genesis.go @@ -18,7 +18,7 @@ func (k Keeper) ExportGenesis(ctx sdk.Context) *types.GenesisState { k.getSubspacesData(ctx), k.GetAllSubspaces(ctx), k.GetAllSections(ctx), - k.getAllUserPermissions(ctx), + k.GetAllPermissions(ctx), k.GetAllUserGroups(ctx), k.getAllUserGroupsMembers(ctx), ) @@ -45,11 +45,14 @@ func (k Keeper) getSubspacesData(ctx sdk.Context) []types.SubspaceData { return data } -// getAllUserPermissions returns all the stored user permissions for all subspaces -func (k Keeper) getAllUserPermissions(ctx sdk.Context) []types.UserPermission { +// GetAllPermissions returns all the stored permissions for all subspaces +func (k Keeper) GetAllPermissions(ctx sdk.Context) []types.UserPermission { var entries []types.UserPermission - k.IterateUserPermissions(ctx, func(entry types.UserPermission) (stop bool) { - entries = append(entries, entry) + k.IterateSubspaces(ctx, func(subspace types.Subspace) (stop bool) { + k.IterateSubspaceUserPermissions(ctx, subspace.ID, func(entry types.UserPermission) (stop bool) { + entries = append(entries, entry) + return false + }) return false }) return entries diff --git a/x/subspaces/keeper/genesis_test.go b/x/subspaces/keeper/genesis_test.go index b7a19b3460..8c3cc501ee 100644 --- a/x/subspaces/keeper/genesis_test.go +++ b/x/subspaces/keeper/genesis_test.go @@ -139,7 +139,12 @@ func (suite *KeeperTestsuite) TestKeeper_ExportGenesis() { time.Date(2020, 1, 2, 12, 00, 00, 000, time.UTC), )) - suite.k.SetUserPermissions(ctx, 2, 0, "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm", types.PermissionSetPermissions) + suite.k.SetUserPermissions(ctx, + 2, + 0, + "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm", + types.NewPermissions(types.PermissionSetPermissions), + ) }, expGenesis: types.NewGenesisState( 3, @@ -161,7 +166,12 @@ func (suite *KeeperTestsuite) TestKeeper_ExportGenesis() { types.DefaultSection(2), }, []types.UserPermission{ - types.NewUserPermission(2, 0, "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm", types.PermissionSetPermissions), + types.NewUserPermission( + 2, + 0, + "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm", + types.NewPermissions(types.PermissionSetPermissions), + ), }, []types.UserGroup{ types.DefaultUserGroup(2), @@ -189,7 +199,7 @@ func (suite *KeeperTestsuite) TestKeeper_ExportGenesis() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm") @@ -210,7 +220,7 @@ func (suite *KeeperTestsuite) TestKeeper_ExportGenesis() { 1, "Another test group", "This is another test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 2, 1, "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5") @@ -255,7 +265,7 @@ func (suite *KeeperTestsuite) TestKeeper_ExportGenesis() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), types.DefaultUserGroup(2), types.NewUserGroup( @@ -264,7 +274,7 @@ func (suite *KeeperTestsuite) TestKeeper_ExportGenesis() { 1, "Another test group", "This is another test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, []types.UserGroupMemberEntry{ @@ -388,7 +398,7 @@ func (suite *KeeperTestsuite) TestKeeper_InitGenesis() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, }, @@ -401,7 +411,7 @@ func (suite *KeeperTestsuite) TestKeeper_InitGenesis() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), stored) }, }, @@ -422,12 +432,17 @@ func (suite *KeeperTestsuite) TestKeeper_InitGenesis() { name: "user permissions are imported properly", genesis: types.GenesisState{ UserPermissions: []types.UserPermission{ - types.NewUserPermission(2, 0, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", types.PermissionSetPermissions), + types.NewUserPermission( + 2, + 0, + "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", + types.NewPermissions(types.PermissionSetPermissions), + ), }, }, check: func(ctx sdk.Context) { storedUserPermissions := suite.k.GetUserPermissions(ctx, 2, 0, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e") - suite.Require().Equal(types.PermissionSetPermissions, storedUserPermissions) + suite.Require().Equal(types.NewPermissions(types.PermissionSetPermissions), storedUserPermissions) }, }, } diff --git a/x/subspaces/keeper/groups_test.go b/x/subspaces/keeper/groups_test.go index 84172d001f..caf4c1ccf8 100644 --- a/x/subspaces/keeper/groups_test.go +++ b/x/subspaces/keeper/groups_test.go @@ -174,11 +174,10 @@ func (suite *KeeperTestsuite) TestKeeper_DeleteNextGroupID() { func (suite *KeeperTestsuite) TestKeeper_SaveUserGroup() { testCases := []struct { - name string - store func(ctx sdk.Context) - group types.UserGroup - permissions types.Permission - check func(ctx sdk.Context) + name string + store func(ctx sdk.Context) + group types.UserGroup + check func(ctx sdk.Context) }{ { name: "non existing group is stored properly", @@ -188,9 +187,8 @@ func (suite *KeeperTestsuite) TestKeeper_SaveUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), - permissions: types.PermissionWrite, check: func(ctx sdk.Context) { group, found := suite.k.GetUserGroup(ctx, 1, 1) suite.Require().True(found) @@ -200,7 +198,7 @@ func (suite *KeeperTestsuite) TestKeeper_SaveUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), group) }, }, @@ -213,7 +211,7 @@ func (suite *KeeperTestsuite) TestKeeper_SaveUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, group: types.NewUserGroup( @@ -222,9 +220,8 @@ func (suite *KeeperTestsuite) TestKeeper_SaveUserGroup() { 1, "Edited test group", "This is an edited test group", - types.PermissionChangeInfo, + types.NewPermissions(types.PermissionEverything), ), - permissions: types.PermissionManageGroups, check: func(ctx sdk.Context) { group, found := suite.k.GetUserGroup(ctx, 1, 1) suite.Require().True(found) @@ -234,7 +231,7 @@ func (suite *KeeperTestsuite) TestKeeper_SaveUserGroup() { 1, "Edited test group", "This is an edited test group", - types.PermissionChangeInfo, + types.NewPermissions(types.PermissionEverything), ), group) }, }, @@ -279,7 +276,7 @@ func (suite *KeeperTestsuite) TestKeeper_HasUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, subspaceID: 1, @@ -326,7 +323,7 @@ func (suite *KeeperTestsuite) TestKeeper_GetUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, subspaceID: 1, @@ -338,7 +335,7 @@ func (suite *KeeperTestsuite) TestKeeper_GetUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, } @@ -386,7 +383,7 @@ func (suite *KeeperTestsuite) TestKeeper_DeleteUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm") @@ -440,7 +437,7 @@ func (suite *KeeperTestsuite) TestKeeper_AddUserToGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, subspaceID: 1, @@ -503,7 +500,7 @@ func (suite *KeeperTestsuite) TestKeeper_IsMemberOfGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm") @@ -557,7 +554,7 @@ func (suite *KeeperTestsuite) TestKeeper_RemoveUserFromGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm") diff --git a/x/subspaces/keeper/grpc_query.go b/x/subspaces/keeper/grpc_query.go index fa3ea88068..21a0e1cccd 100644 --- a/x/subspaces/keeper/grpc_query.go +++ b/x/subspaces/keeper/grpc_query.go @@ -196,14 +196,14 @@ func (k Keeper) UserPermissions(ctx context.Context, request *types.QueryUserPer } // Get the user specific permissions - userPermission := k.GetUserPermissions(sdkCtx, request.SubspaceId, request.SectionId, request.User) + userPermissions := k.GetUserPermissions(sdkCtx, request.SubspaceId, request.SectionId, request.User) groupPermissions := k.GetGroupsInheritedPermissions(sdkCtx, request.SubspaceId, request.SectionId, request.User) - permissionResult := types.CombinePermissions(userPermission, groupPermissions) + permissionResult := types.CombinePermissions(append(userPermissions, groupPermissions...)...) // Get the details of all the permissions var details []types.PermissionDetail - if userPermission != types.PermissionNothing { - details = append(details, types.NewPermissionDetailUser(request.SubspaceId, request.SectionId, request.User, userPermission)) + if userPermissions != nil { + details = append(details, types.NewPermissionDetailUser(request.SubspaceId, request.SectionId, request.User, userPermissions)) } k.IterateSubspaceUserGroups(sdkCtx, request.SubspaceId, func(group types.UserGroup) (stop bool) { diff --git a/x/subspaces/keeper/grpc_query_test.go b/x/subspaces/keeper/grpc_query_test.go index fc33f8750c..ba7a702680 100644 --- a/x/subspaces/keeper/grpc_query_test.go +++ b/x/subspaces/keeper/grpc_query_test.go @@ -384,7 +384,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroups() { 1, "First test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.SaveUserGroup(ctx, types.NewUserGroup( 1, @@ -392,7 +392,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroups() { 2, "Second test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.SaveUserGroup(ctx, types.NewUserGroup( 1, @@ -400,7 +400,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroups() { 3, "Third test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, req: types.NewQueryUserGroupsRequest(1, 1, nil), @@ -412,7 +412,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroups() { 2, "Second test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, }, @@ -435,7 +435,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroups() { 1, "First test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.SaveUserGroup(ctx, types.NewUserGroup( 1, @@ -443,7 +443,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroups() { 2, "Second test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.SaveUserGroup(ctx, types.NewUserGroup( 1, @@ -451,7 +451,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroups() { 3, "Third test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, req: types.NewQueryUserGroupsRequest(1, 0, &query.PageRequest{ @@ -466,7 +466,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroups() { 3, "Third test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), types.NewUserGroup( 1, @@ -474,7 +474,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroups() { 2, "Second test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, }, @@ -531,7 +531,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, req: types.NewQueryUserGroupRequest(1, 1), @@ -542,7 +542,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, } @@ -614,7 +614,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserGroupMembers() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm") @@ -684,9 +684,9 @@ func (suite *KeeperTestsuite) TestQueryServer_UserPermissions() { ), shouldErr: false, expResponse: types.QueryUserPermissionsResponse{ - Permissions: types.PermissionNothing, + Permissions: nil, Details: []types.PermissionDetail{ - types.NewPermissionDetailGroup(1, 0, 0, types.PermissionNothing), + types.NewPermissionDetailGroup(1, 0, 0, nil), }, }, }, @@ -709,7 +709,7 @@ func (suite *KeeperTestsuite) TestQueryServer_UserPermissions() { 1, "Test group", "This is a test group", - types.PermissionChangeInfo, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e") @@ -719,11 +719,20 @@ func (suite *KeeperTestsuite) TestQueryServer_UserPermissions() { 2, "Another test group", "This is another test group", - types.PermissionSetPermissions, + types.NewPermissions(types.PermissionSetPermissions), )) - suite.k.AddUserToGroup(ctx, 1, 2, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e") + suite.k.AddUserToGroup(ctx, + 1, + 2, + "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", + ) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", types.PermissionWrite) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", + types.NewPermissions(types.PermissionDeleteSubspace), + ) }, req: types.NewQueryUserPermissionsRequest( 1, @@ -731,12 +740,12 @@ func (suite *KeeperTestsuite) TestQueryServer_UserPermissions() { ), shouldErr: false, expResponse: types.QueryUserPermissionsResponse{ - Permissions: types.PermissionWrite | types.PermissionChangeInfo | types.PermissionSetPermissions, + Permissions: types.CombinePermissions(types.PermissionDeleteSubspace, types.PermissionEditSubspace, types.PermissionSetPermissions), Details: []types.PermissionDetail{ - types.NewPermissionDetailUser(1, 0, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", types.PermissionWrite), - types.NewPermissionDetailGroup(1, 0, 0, types.PermissionNothing), - types.NewPermissionDetailGroup(1, 0, 1, types.PermissionChangeInfo), - types.NewPermissionDetailGroup(1, 0, 2, types.PermissionSetPermissions), + types.NewPermissionDetailUser(1, 0, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", types.NewPermissions(types.PermissionDeleteSubspace)), + types.NewPermissionDetailGroup(1, 0, 0, nil), + types.NewPermissionDetailGroup(1, 0, 1, types.NewPermissions(types.PermissionEditSubspace)), + types.NewPermissionDetailGroup(1, 0, 2, types.NewPermissions(types.PermissionSetPermissions)), }, }, }, diff --git a/x/subspaces/keeper/hooks.go b/x/subspaces/keeper/hooks.go index f36705775b..02ad25c6e3 100644 --- a/x/subspaces/keeper/hooks.go +++ b/x/subspaces/keeper/hooks.go @@ -68,7 +68,7 @@ func (k Keeper) AfterSubspaceGroupDeleted(ctx sdk.Context, subspaceID uint64, gr } // AfterUserPermissionSet - call if hook is registered -func (k Keeper) AfterUserPermissionSet(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string, permissions types.Permission) { +func (k Keeper) AfterUserPermissionSet(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string, permissions types.Permissions) { if k.hooks != nil { k.hooks.AfterUserPermissionSet(ctx, subspaceID, sectionID, user, permissions) } diff --git a/x/subspaces/keeper/invariants.go b/x/subspaces/keeper/invariants.go index 0c8ef6ada2..ed305dddb0 100644 --- a/x/subspaces/keeper/invariants.go +++ b/x/subspaces/keeper/invariants.go @@ -278,7 +278,7 @@ func ValidUserPermissionsInvariant(k Keeper) sdk.Invariant { // formatOutputUserPermissions concatenates the given permission entries into a string func formatOutputUserPermissions(entries []types.UserPermission) (output string) { for _, entry := range entries { - output += fmt.Sprintf("SubspaceID: %d, SectionID: %d, User: %s, Permission: %d\n", entry.SubspaceID, entry.SectionID, entry.User, entry.Permissions) + output += fmt.Sprintf("SubspaceID: %d, SectionID: %d, User: %s, Permissions: %s\n", entry.SubspaceID, entry.SectionID, entry.User, entry.Permissions) } return output } diff --git a/x/subspaces/keeper/invariants_test.go b/x/subspaces/keeper/invariants_test.go index 4cbddf5cf4..c555cd794d 100644 --- a/x/subspaces/keeper/invariants_test.go +++ b/x/subspaces/keeper/invariants_test.go @@ -301,7 +301,7 @@ func (suite *KeeperTestsuite) TestValidUserGroupsInvariant() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, expBroken: true, @@ -325,7 +325,7 @@ func (suite *KeeperTestsuite) TestValidUserGroupsInvariant() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, expBroken: true, @@ -357,7 +357,7 @@ func (suite *KeeperTestsuite) TestValidUserGroupsInvariant() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, expBroken: true, @@ -390,7 +390,7 @@ func (suite *KeeperTestsuite) TestValidUserGroupsInvariant() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, expBroken: true, @@ -423,7 +423,7 @@ func (suite *KeeperTestsuite) TestValidUserGroupsInvariant() { 1, "", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, expBroken: true, @@ -456,7 +456,7 @@ func (suite *KeeperTestsuite) TestValidUserGroupsInvariant() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, expBroken: false, @@ -543,7 +543,7 @@ func (suite *KeeperTestsuite) TestValidUserGroupMembersInvariant() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4") @@ -575,7 +575,12 @@ func (suite *KeeperTestsuite) TestValidUserPermissionsInvariant() { { name: "non existing subspace breaks invariant", store: func(ctx sdk.Context) { - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionWrite) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionEditSubspace), + ) }, expBroken: true, }, @@ -592,7 +597,12 @@ func (suite *KeeperTestsuite) TestValidUserPermissionsInvariant() { time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC), )) - suite.k.SetUserPermissions(ctx, 1, 1, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionWrite) + suite.k.SetUserPermissions(ctx, + 1, + 1, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionEditSubspace), + ) }, expBroken: true, }, @@ -617,7 +627,7 @@ func (suite *KeeperTestsuite) TestValidUserPermissionsInvariant() { "Test section", )) - suite.k.SetUserPermissions(ctx, 1, 1, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", 0b11111111111111111) + suite.k.SetUserPermissions(ctx, 1, 1, "", types.NewPermissions()) }, expBroken: true, }, @@ -642,7 +652,12 @@ func (suite *KeeperTestsuite) TestValidUserPermissionsInvariant() { "Test section", )) - suite.k.SetUserPermissions(ctx, 1, 1, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionWrite) + suite.k.SetUserPermissions(ctx, + 1, + 1, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionEditSubspace), + ) }, expBroken: false, }, diff --git a/x/subspaces/keeper/msg_server.go b/x/subspaces/keeper/msg_server.go index 3947b310b6..8e95609912 100644 --- a/x/subspaces/keeper/msg_server.go +++ b/x/subspaces/keeper/msg_server.go @@ -82,7 +82,7 @@ func (k msgServer) EditSubspace(goCtx context.Context, msg *types.MsgEditSubspac } // Check the permission to edit - if !k.HasPermission(ctx, msg.SubspaceID, types.RootSectionID, signer.String(), types.PermissionChangeInfo) { + if !k.HasPermission(ctx, msg.SubspaceID, types.RootSectionID, signer.String(), types.PermissionEditSubspace) { return nil, sdkerrors.Wrap(types.ErrPermissionDenied, "you cannot manage this subspace") } @@ -394,7 +394,7 @@ func (k msgServer) CreateUserGroup(goCtx context.Context, msg *types.MsgCreateUs } // Make sure the default permissions are valid - if !types.IsPermissionValid(msg.DefaultPermissions) { + if !types.ArePermissionsValid(msg.DefaultPermissions) { return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid permission value") } @@ -573,7 +573,7 @@ func (k msgServer) SetUserGroupPermissions(goCtx context.Context, msg *types.Msg } // Make sure the permission is valid - if !types.IsPermissionValid(msg.Permissions) { + if !types.ArePermissionsValid(msg.Permissions) { return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid permission value") } @@ -775,13 +775,13 @@ func (k msgServer) SetUserPermissions(goCtx context.Context, msg *types.MsgSetUs } // Make sure the permission is valid - if !types.IsPermissionValid(msg.Permissions) { + if !types.ArePermissionsValid(msg.Permissions) { return nil, sdkerrors.Wrap(sdkerrors.ErrInvalidRequest, "invalid permission value") } // Set the permissions - if msg.Permissions == types.PermissionNothing { - // Remove the permission to clear the store if PermissionNothing is used + if msg.Permissions == nil { + // Remove the permission to clear the store if empty permissions are provided k.RemoveUserPermissions(ctx, msg.SubspaceID, msg.SectionID, msg.User) } else { k.Keeper.SetUserPermissions(ctx, msg.SubspaceID, msg.SectionID, msg.User, msg.Permissions) diff --git a/x/subspaces/keeper/msg_server_test.go b/x/subspaces/keeper/msg_server_test.go index b39219324e..f78a710bd5 100644 --- a/x/subspaces/keeper/msg_server_test.go +++ b/x/subspaces/keeper/msg_server_test.go @@ -357,7 +357,12 @@ func (suite *KeeperTestsuite) TestMsgServer_EditSubspace() { blockTime, )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", types.PermissionChangeInfo) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", + types.NewPermissions(types.PermissionEditSubspace), + ) }, msg: types.NewMsgEditSubspace( 1, @@ -484,7 +489,12 @@ func (suite *KeeperTestsuite) TestMsgServer_DeleteSubspace() { time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", types.PermissionDeleteSubspace) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", + types.NewPermissions(types.PermissionDeleteSubspace), + ) }, msg: types.NewMsgDeleteSubspace(1, "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5"), shouldErr: false, @@ -628,7 +638,12 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateSection() { "", )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionManageSections) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionManageSections), + ) }, msg: types.NewMsgCreateSection( 1, @@ -661,7 +676,12 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateSection() { "", )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionManageSections) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionManageSections), + ) }, msg: types.NewMsgCreateSection( 1, @@ -694,7 +714,12 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateSection() { "", )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionManageSections) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionManageSections), + ) }, msg: types.NewMsgCreateSection( 1, @@ -855,7 +880,12 @@ func (suite *KeeperTestsuite) TestMsgServer_EditSection() { "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionManageSections) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionManageSections), + ) }, msg: types.NewMsgEditSection( 1, @@ -887,7 +917,12 @@ func (suite *KeeperTestsuite) TestMsgServer_EditSection() { "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionManageSections) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionManageSections), + ) }, msg: types.NewMsgEditSection( 1, @@ -1101,7 +1136,12 @@ func (suite *KeeperTestsuite) TestMsgServer_MoveSection() { suite.k.SaveSection(ctx, types.NewSection(1, 2, 1, "B", "")) suite.k.SaveSection(ctx, types.NewSection(1, 3, 2, "C", "")) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionManageSections) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionManageSections), + ) }, msg: types.NewMsgMoveSection( 1, @@ -1133,7 +1173,12 @@ func (suite *KeeperTestsuite) TestMsgServer_MoveSection() { "This is child section", )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionManageSections) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionManageSections), + ) }, msg: types.NewMsgMoveSection( 1, @@ -1279,7 +1324,12 @@ func (suite *KeeperTestsuite) TestMsgServer_DeleteSection() { "This is a test section", )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", types.PermissionManageSections) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1wq7mruftxd03qrrf9f7xnnzyqda9rkq5sshnr4", + types.NewPermissions(types.PermissionManageSections), + ) }, msg: types.NewMsgDeleteSection( 1, @@ -1348,7 +1398,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateUserGroup() { 0, "group", "description", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ), shouldErr: true, @@ -1371,7 +1421,7 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateUserGroup() { 0, "group", "description", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1y4emx0mm4ncva9mnv9yvjrm7nrq3psvmwhk9ll", ), shouldErr: true, @@ -1389,14 +1439,19 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateUserGroup() { time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1y4emx0mm4ncva9mnv9yvjrm7nrq3psvmwhk9ll", types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1y4emx0mm4ncva9mnv9yvjrm7nrq3psvmwhk9ll", + types.NewPermissions(types.PermissionManageGroups), + ) }, msg: types.NewMsgCreateUserGroup( 1, 0, "group", "description", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1y4emx0mm4ncva9mnv9yvjrm7nrq3psvmwhk9ll", ), shouldErr: true, @@ -1420,18 +1475,23 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.SetNextGroupID(ctx, 1, 2) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.CombinePermissions(types.PermissionManageGroups, types.PermissionSetPermissions)) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.CombinePermissions(types.PermissionManageGroups, types.PermissionSetPermissions), + ) }, msg: types.NewMsgCreateUserGroup( 1, 0, "another group", "another description", - 9999999, + types.NewPermissions("invalid"), "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", ), shouldErr: true, @@ -1455,18 +1515,23 @@ func (suite *KeeperTestsuite) TestMsgServer_CreateUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.SetNextGroupID(ctx, 1, 2) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.CombinePermissions(types.PermissionManageGroups, types.PermissionSetPermissions)) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.CombinePermissions(types.PermissionManageGroups, types.PermissionSetPermissions), + ) }, msg: types.NewMsgCreateUserGroup( 1, 0, "another group", "another description", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", ), shouldErr: false, @@ -1578,7 +1643,7 @@ func (suite *KeeperTestsuite) TestMsgServer_EditUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, msg: types.NewMsgEditUserGroup( @@ -1608,10 +1673,15 @@ func (suite *KeeperTestsuite) TestMsgServer_EditUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionManageGroups), + ) }, msg: types.NewMsgEditUserGroup( 1, @@ -1640,10 +1710,15 @@ func (suite *KeeperTestsuite) TestMsgServer_EditUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionManageGroups), + ) }, msg: types.NewMsgEditUserGroup( 1, @@ -1676,7 +1751,7 @@ func (suite *KeeperTestsuite) TestMsgServer_EditUserGroup() { 1, "Admins", "Group of the admins of th subspace", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), group) }, }, @@ -1766,7 +1841,7 @@ func (suite *KeeperTestsuite) TestMsgServer_MoveUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, msg: types.NewMsgMoveUserGroup( @@ -1802,7 +1877,7 @@ func (suite *KeeperTestsuite) TestMsgServer_MoveUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, msg: types.NewMsgMoveUserGroup( @@ -1838,10 +1913,15 @@ func (suite *KeeperTestsuite) TestMsgServer_MoveUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionManageGroups), + ) }, msg: types.NewMsgMoveUserGroup( 1, @@ -1876,11 +1956,22 @@ func (suite *KeeperTestsuite) TestMsgServer_MoveUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionManageGroups) - suite.k.SetUserPermissions(ctx, 1, 1, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionManageGroups), + ) + + suite.k.SetUserPermissions(ctx, + 1, + 1, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionManageGroups), + ) }, msg: types.NewMsgMoveUserGroup( 1, @@ -1915,12 +2006,27 @@ func (suite *KeeperTestsuite) TestMsgServer_MoveUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionManageGroups) - suite.k.SetUserPermissions(ctx, 1, 1, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionManageGroups) - suite.k.SetUserPermissions(ctx, 1, 1, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionSetPermissions) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionManageGroups), + ) + suite.k.SetUserPermissions(ctx, + 1, + 1, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionManageGroups), + ) + suite.k.SetUserPermissions(ctx, + 1, + 1, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionSetPermissions), + ) }, msg: types.NewMsgMoveUserGroup( 1, @@ -1952,7 +2058,7 @@ func (suite *KeeperTestsuite) TestMsgServer_MoveUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), group) }, }, @@ -1998,7 +2104,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { msg: types.NewMsgSetUserGroupPermissions( 1, 1, - types.PermissionSetPermissions, + types.NewPermissions(types.PermissionSetPermissions), "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", ), shouldErr: true, @@ -2019,7 +2125,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { msg: types.NewMsgSetUserGroupPermissions( 1, 1, - types.PermissionSetPermissions, + types.NewPermissions(types.PermissionSetPermissions), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ), shouldErr: true, @@ -2042,13 +2148,13 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, msg: types.NewMsgSetUserGroupPermissions( 1, 1, - types.PermissionSetPermissions, + types.NewPermissions(types.PermissionSetPermissions), "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", ), shouldErr: true, @@ -2071,15 +2177,20 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionSetPermissions) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionSetPermissions), + ) }, msg: types.NewMsgSetUserGroupPermissions( 1, 1, - 9999999, + types.NewPermissions("invalid"), "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", ), shouldErr: true, @@ -2102,7 +2213,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { 1, "Test group", "This is a test group", - types.PermissionSetPermissions, + types.NewPermissions(types.PermissionSetPermissions), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53") @@ -2110,7 +2221,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { msg: types.NewMsgSetUserGroupPermissions( 1, 1, - types.PermissionEverything, + types.NewPermissions(types.PermissionEverything), "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", ), shouldErr: true, @@ -2133,7 +2244,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { 1, "Test group", "This is a test group", - types.PermissionSetPermissions, + types.NewPermissions(types.PermissionSetPermissions), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53") @@ -2141,7 +2252,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { msg: types.NewMsgSetUserGroupPermissions( 1, 1, - types.PermissionEverything, + types.NewPermissions(types.PermissionEverything), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ), shouldErr: false, @@ -2162,7 +2273,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { group, found := suite.k.GetUserGroup(ctx, 1, 1) suite.Require().True(found) - suite.Require().Equal(types.PermissionEverything, group.Permissions) + suite.Require().Equal(types.NewPermissions(types.PermissionEverything), group.Permissions) }, }, { @@ -2183,15 +2294,20 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionSetPermissions) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionSetPermissions), + ) }, msg: types.NewMsgSetUserGroupPermissions( 1, 1, - types.PermissionSetPermissions, + types.NewPermissions(types.PermissionSetPermissions), "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", ), shouldErr: false, @@ -2212,7 +2328,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserGroupPermissions() { group, found := suite.k.GetUserGroup(ctx, 1, 1) suite.Require().True(found) - suite.Require().Equal(types.PermissionSetPermissions, group.Permissions) + suite.Require().Equal(types.NewPermissions(types.PermissionSetPermissions), group.Permissions) }, }, } @@ -2299,7 +2415,7 @@ func (suite *KeeperTestsuite) TestMsgServer_DeleteUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, msg: types.NewMsgDeleteUserGroup( @@ -2327,10 +2443,15 @@ func (suite *KeeperTestsuite) TestMsgServer_DeleteUserGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionManageGroups), + ) }, msg: types.NewMsgDeleteUserGroup( 1, @@ -2442,7 +2563,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AddUserToGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, msg: types.NewMsgAddUserToUserGroup( @@ -2471,7 +2592,7 @@ func (suite *KeeperTestsuite) TestMsgServer_AddUserToGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53") @@ -2502,10 +2623,15 @@ func (suite *KeeperTestsuite) TestMsgServer_AddUserToGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionSetPermissions) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionSetPermissions), + ) }, msg: types.NewMsgAddUserToUserGroup( 1, @@ -2619,7 +2745,7 @@ func (suite *KeeperTestsuite) TestMsgServer_RemoveUserFromGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, msg: types.NewMsgRemoveUserFromUserGroup( @@ -2648,7 +2774,7 @@ func (suite *KeeperTestsuite) TestMsgServer_RemoveUserFromGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) }, msg: types.NewMsgRemoveUserFromUserGroup( @@ -2677,10 +2803,15 @@ func (suite *KeeperTestsuite) TestMsgServer_RemoveUserFromGroup() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionSetPermissions) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionSetPermissions), + ) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm") }, msg: types.NewMsgRemoveUserFromUserGroup( @@ -2752,7 +2883,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserPermissions() { 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ), shouldErr: true, @@ -2774,7 +2905,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserPermissions() { 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1a0cj0j6ujn2xap8p40y6648d0w2npytw3xvenm", ), shouldErr: true, @@ -2792,13 +2923,18 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserPermissions() { time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", types.PermissionSetPermissions) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", + types.NewPermissions(types.PermissionSetPermissions), + ) }, msg: types.NewMsgSetUserPermissions( 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", - 9999999, + types.NewPermissions("invalid"), "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", ), shouldErr: true, @@ -2816,13 +2952,18 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserPermissions() { time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos17ua98rre5j9ce7hfude0y5y3rh4gtqkygm8hru", types.PermissionSetPermissions) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos17ua98rre5j9ce7hfude0y5y3rh4gtqkygm8hru", + types.NewPermissions(types.PermissionSetPermissions), + ) }, msg: types.NewMsgSetUserPermissions( 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos17ua98rre5j9ce7hfude0y5y3rh4gtqkygm8hru", ), shouldErr: false, @@ -2841,7 +2982,7 @@ func (suite *KeeperTestsuite) TestMsgServer_SetUserPermissions() { }, check: func(ctx sdk.Context) { permissions := suite.k.GetUserPermissions(ctx, 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53") - suite.Require().Equal(types.PermissionWrite, permissions) + suite.Require().Equal(types.NewPermissions(types.PermissionEditSubspace), permissions) }, }, } diff --git a/x/subspaces/keeper/permissions.go b/x/subspaces/keeper/permissions.go index 55612f6077..b4489fa397 100644 --- a/x/subspaces/keeper/permissions.go +++ b/x/subspaces/keeper/permissions.go @@ -7,9 +7,10 @@ import ( ) // SetUserPermissions sets the given permission for the specific user inside a single subspace -func (k Keeper) SetUserPermissions(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string, permissions types.Permission) { +func (k Keeper) SetUserPermissions(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string, permissions types.Permissions) { store := ctx.KVStore(k.storeKey) - store.Set(types.UserPermissionStoreKey(subspaceID, sectionID, user), types.MarshalPermission(permissions)) + permission := types.NewUserPermission(subspaceID, sectionID, user, permissions) + store.Set(types.UserPermissionStoreKey(subspaceID, sectionID, user), k.cdc.MustMarshal(&permission)) k.AfterUserPermissionSet(ctx, subspaceID, sectionID, user, permissions) } @@ -34,18 +35,21 @@ func (k Keeper) HasPermission(ctx sdk.Context, subspaceID uint64, sectionID uint groupPermissions := k.GetGroupsInheritedPermissions(ctx, subspaceID, sectionID, user) // Check the combination of the permissions - return types.CheckPermission(types.CombinePermissions(specificPermissions, groupPermissions), permission) + permissions := append(specificPermissions, groupPermissions...) + return types.CheckPermission(types.CombinePermissions(permissions...), permission) } // getSectionPermissions gets the permissions for the given user set inside the specified section only -func (k Keeper) getSectionPermissions(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string) types.Permission { +func (k Keeper) getSectionPermissions(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string) types.Permissions { store := ctx.KVStore(k.storeKey) - return types.UnmarshalPermission(store.Get(types.UserPermissionStoreKey(subspaceID, sectionID, user))) + var permissions types.UserPermission + k.cdc.MustUnmarshal(store.Get(types.UserPermissionStoreKey(subspaceID, sectionID, user)), &permissions) + return permissions.Permissions } // GetUserPermissions returns the permissions that are currently set inside // the subspace with the given id for the given user -func (k Keeper) GetUserPermissions(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string) types.Permission { +func (k Keeper) GetUserPermissions(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string) types.Permissions { if sectionID == types.RootSectionID { return k.getSectionPermissions(ctx, subspaceID, sectionID, user) } @@ -53,18 +57,18 @@ func (k Keeper) GetUserPermissions(ctx sdk.Context, subspaceID uint64, sectionID sectionPermissions := k.getSectionPermissions(ctx, subspaceID, sectionID, user) // Get the parent permissions - parentPermissions := types.PermissionNothing + var parentPermissions types.Permissions section, found := k.GetSection(ctx, subspaceID, sectionID) if found { parentPermissions = k.GetUserPermissions(ctx, subspaceID, section.ParentID, user) } - return types.CombinePermissions(parentPermissions, sectionPermissions) + return types.CombinePermissions(append(parentPermissions, sectionPermissions...)...) } // GetGroupsInheritedPermissions returns the permissions that the specified user // has inherited from all the groups that they are part of. -func (k Keeper) GetGroupsInheritedPermissions(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string) types.Permission { +func (k Keeper) GetGroupsInheritedPermissions(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string) types.Permissions { var permissions []types.Permission // Iterate over the section ancestors and get all the user groups for each ancestor @@ -72,7 +76,7 @@ func (k Keeper) GetGroupsInheritedPermissions(ctx sdk.Context, subspaceID uint64 k.IterateSectionPath(ctx, subspaceID, sectionID, func(section types.Section) (stop bool) { k.IterateSectionUserGroups(ctx, section.SubspaceID, section.ID, func(group types.UserGroup) (stop bool) { if k.IsMemberOfGroup(ctx, subspaceID, group.ID, user) { - permissions = append(permissions, group.Permissions) + permissions = append(permissions, group.Permissions...) } return false }) @@ -82,11 +86,11 @@ func (k Keeper) GetGroupsInheritedPermissions(ctx sdk.Context, subspaceID uint64 return types.CombinePermissions(permissions...) } -// GetUsersWithRootPermission returns all the users that have a given permission inside the specified subspace -func (k Keeper) GetUsersWithRootPermission(ctx sdk.Context, subspaceID uint64, permission types.Permission) ([]string, error) { +// GetUsersWithRootPermissions returns all the users that have a given permission inside the specified subspace +func (k Keeper) GetUsersWithRootPermissions(ctx sdk.Context, subspaceID uint64, permission types.Permissions) []string { subspace, found := k.GetSubspace(ctx, subspaceID) if !found { - return nil, nil + return nil } // The owner must always be included as they have all the permissions @@ -94,7 +98,7 @@ func (k Keeper) GetUsersWithRootPermission(ctx sdk.Context, subspaceID uint64, p // Iterate over the various groups k.IterateSectionUserGroups(ctx, subspaceID, types.RootSectionID, func(group types.UserGroup) (stop bool) { - if !types.CheckPermission(group.Permissions, permission) { + if !types.CheckPermissions(group.Permissions, permission) { // Return early if the group does not have the permission. We will check other groups anyway return false } @@ -106,14 +110,14 @@ func (k Keeper) GetUsersWithRootPermission(ctx sdk.Context, subspaceID uint64, p // Iterate over the various individually-set permissions k.IterateSectionUserPermissions(ctx, subspaceID, types.RootSectionID, func(entry types.UserPermission) (stop bool) { - if types.CheckPermission(entry.Permissions, permission) { + if types.CheckPermissions(entry.Permissions, permission) { users = append(users, entry.User) } return false }) - return users, nil + return users } // RemoveUserPermissions removes the permission for the given user inside the provided subspace diff --git a/x/subspaces/keeper/permissions_test.go b/x/subspaces/keeper/permissions_test.go index 760bce27c6..50881a993c 100644 --- a/x/subspaces/keeper/permissions_test.go +++ b/x/subspaces/keeper/permissions_test.go @@ -10,37 +10,42 @@ import ( func (suite *KeeperTestsuite) TestKeeper_SetUserPermissions() { testCases := []struct { - name string - store func(ctx sdk.Context) - subspaceID uint64 - sectionID uint32 - user string - permission types.Permission - check func(ctx sdk.Context) + name string + store func(ctx sdk.Context) + subspaceID uint64 + sectionID uint32 + user string + permissions types.Permissions + check func(ctx sdk.Context) }{ { - name: "permission is set properly for user", - subspaceID: 1, - sectionID: 1, - user: "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", - permission: types.PermissionChangeInfo, + name: "permissions are set properly for user", + subspaceID: 1, + sectionID: 1, + user: "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", + permissions: types.NewPermissions(types.PermissionEditSubspace), check: func(ctx sdk.Context) { permission := suite.k.GetUserPermissions(ctx, 1, 1, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn") - suite.Require().Equal(types.PermissionChangeInfo, permission) + suite.Require().Equal(types.NewPermissions(types.PermissionEditSubspace), permission) }, }, { - name: "existing permission is overridden", + name: "existing permissions are overridden", store: func(ctx sdk.Context) { - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", + types.NewPermissions(types.PermissionManageGroups), + ) }, - subspaceID: 1, - sectionID: 0, - user: "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", - permission: types.PermissionWrite, + subspaceID: 1, + sectionID: 0, + user: "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", + permissions: types.NewPermissions(types.PermissionDeleteSubspace), check: func(ctx sdk.Context) { permission := suite.k.GetUserPermissions(ctx, 1, 0, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn") - suite.Require().Equal(types.PermissionWrite, permission) + suite.Require().Equal(types.NewPermissions(types.PermissionDeleteSubspace), permission) }, }, } @@ -53,7 +58,7 @@ func (suite *KeeperTestsuite) TestKeeper_SetUserPermissions() { tc.store(ctx) } - suite.k.SetUserPermissions(ctx, tc.subspaceID, tc.sectionID, tc.user, tc.permission) + suite.k.SetUserPermissions(ctx, tc.subspaceID, tc.sectionID, tc.user, tc.permissions) if tc.check != nil { tc.check(ctx) @@ -117,10 +122,15 @@ func (suite *KeeperTestsuite) TestKeeper_HasPermission() { 1, "Test group", "This is a test group", - types.PermissionWrite|types.PermissionChangeInfo, + types.CombinePermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn") - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", + types.NewPermissions(types.PermissionManageGroups), + ) }, subspaceID: 1, sectionID: 0, @@ -147,7 +157,7 @@ func (suite *KeeperTestsuite) TestKeeper_HasPermission() { 1, "Test group", "This is a test group", - types.PermissionWrite|types.PermissionChangeInfo, + types.CombinePermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn") @@ -155,7 +165,7 @@ func (suite *KeeperTestsuite) TestKeeper_HasPermission() { subspaceID: 1, sectionID: 0, user: "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", - permission: types.PermissionWrite, + permission: types.PermissionEditSubspace, expResult: true, }, } @@ -181,24 +191,29 @@ func (suite *KeeperTestsuite) TestKeeper_GetUserPermissions() { subspaceID uint64 sectionID uint32 user string - expPermissions types.Permission + expPermissions types.Permissions }{ { name: "not found user returns PermissionNothing", subspaceID: 1, sectionID: 0, user: "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", - expPermissions: types.PermissionNothing, + expPermissions: nil, }, { name: "found user returns the correct permission", store: func(ctx sdk.Context) { - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", types.PermissionWrite|types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", + types.CombinePermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace), + ) }, subspaceID: 1, sectionID: 0, user: "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", - expPermissions: types.PermissionWrite | types.PermissionManageGroups, + expPermissions: types.CombinePermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace), }, { name: "found user inside parent section returns correct permission", @@ -215,12 +230,17 @@ func (suite *KeeperTestsuite) TestKeeper_GetUserPermissions() { suite.k.SaveSection(ctx, types.NewSection(1, 3, 1, "C", "")) // Set the permission inside root - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm", types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm", + types.NewPermissions(types.PermissionManageGroups), + ) }, subspaceID: 1, sectionID: 3, user: "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm", - expPermissions: types.PermissionManageGroups, + expPermissions: types.NewPermissions(types.PermissionManageGroups), }, } @@ -245,14 +265,14 @@ func (suite *KeeperTestsuite) TestKeeper_GetGroupsInheritedPermissions() { subspaceID uint64 sectionID uint32 user string - expPermissions types.Permission + expPermissions types.Permissions }{ { name: "user in no group returns PermissionNothing", subspaceID: 1, sectionID: 0, user: "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm", - expPermissions: types.PermissionNothing, + expPermissions: nil, }, { name: "user inside one group returns that group's permission", @@ -264,7 +284,7 @@ func (suite *KeeperTestsuite) TestKeeper_GetGroupsInheritedPermissions() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm") @@ -272,7 +292,7 @@ func (suite *KeeperTestsuite) TestKeeper_GetGroupsInheritedPermissions() { subspaceID: 1, sectionID: 0, user: "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm", - expPermissions: types.PermissionWrite, + expPermissions: types.NewPermissions(types.PermissionEditSubspace), }, { name: "user inside multiple groups returns the combination of the various permissions", @@ -284,7 +304,7 @@ func (suite *KeeperTestsuite) TestKeeper_GetGroupsInheritedPermissions() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.SaveUserGroup(ctx, types.NewUserGroup( 1, @@ -292,7 +312,7 @@ func (suite *KeeperTestsuite) TestKeeper_GetGroupsInheritedPermissions() { 2, "Permission group", "This is a permissions group", - types.PermissionSetPermissions|types.PermissionChangeInfo, + types.NewPermissions(types.PermissionDeleteSubspace, types.PermissionSetPermissions), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm") @@ -301,7 +321,7 @@ func (suite *KeeperTestsuite) TestKeeper_GetGroupsInheritedPermissions() { subspaceID: 1, sectionID: 0, user: "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm", - expPermissions: types.PermissionWrite | types.PermissionChangeInfo | types.PermissionSetPermissions, + expPermissions: types.CombinePermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace, types.PermissionSetPermissions), }, { name: "user inside group of ancestor section returns correct permissions", @@ -317,8 +337,22 @@ func (suite *KeeperTestsuite) TestKeeper_GetGroupsInheritedPermissions() { suite.k.SaveSection(ctx, types.NewSection(1, 2, 0, "B", "")) suite.k.SaveSection(ctx, types.NewSection(1, 3, 1, "C", "")) - suite.k.SaveUserGroup(ctx, types.NewUserGroup(1, 0, 1, "G1", "", types.PermissionWrite)) - suite.k.SaveUserGroup(ctx, types.NewUserGroup(1, 1, 2, "G2", "", types.PermissionSetPermissions|types.PermissionChangeInfo)) + suite.k.SaveUserGroup(ctx, types.NewUserGroup( + 1, + 0, + 1, + "G1", + "", + types.NewPermissions(types.PermissionEditSubspace), + )) + suite.k.SaveUserGroup(ctx, types.NewUserGroup( + 1, + 1, + 2, + "G2", + "", + types.NewPermissions(types.PermissionDeleteSubspace, types.PermissionSetPermissions), + )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm") suite.k.AddUserToGroup(ctx, 1, 2, "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm") @@ -326,7 +360,7 @@ func (suite *KeeperTestsuite) TestKeeper_GetGroupsInheritedPermissions() { subspaceID: 1, sectionID: 3, user: "cosmos1fgppppwfjszpts4shpsfv7n2xtchcdwhycuvvm", - expPermissions: types.PermissionWrite | types.PermissionChangeInfo | types.PermissionSetPermissions, + expPermissions: types.CombinePermissions(types.PermissionDeleteSubspace, types.PermissionSetPermissions, types.PermissionEditSubspace), }, } @@ -349,15 +383,13 @@ func (suite *KeeperTestsuite) TestKeeper_GetUsersWithRootPermissions() { name string store func(ctx sdk.Context) subspaceID uint64 - permissions types.Permission - shouldErr bool + permissions types.Permissions expUsers []string }{ { name: "subspace not found returns empty slice", subspaceID: 1, - permissions: types.PermissionWrite, - shouldErr: false, + permissions: types.NewPermissions(types.PermissionEditSubspace), expUsers: nil, }, { @@ -366,8 +398,7 @@ func (suite *KeeperTestsuite) TestKeeper_GetUsersWithRootPermissions() { }, subspaceID: 1, - permissions: types.PermissionWrite, - shouldErr: false, + permissions: types.NewPermissions(types.PermissionEditSubspace), expUsers: nil, }, { @@ -389,13 +420,12 @@ func (suite *KeeperTestsuite) TestKeeper_GetUsersWithRootPermissions() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd") }, subspaceID: 1, - permissions: types.PermissionWrite, - shouldErr: false, + permissions: types.NewPermissions(types.PermissionEditSubspace), expUsers: []string{ "cosmos1s0he0z3g92zwsxdj83h0ky9w463sx7gq9mqtgn", // Owner is always included "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", @@ -414,11 +444,15 @@ func (suite *KeeperTestsuite) TestKeeper_GetUsersWithRootPermissions() { time.Date(2020, 1, 1, 12, 00, 00, 000, time.UTC), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.PermissionWrite) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", + types.NewPermissions(types.PermissionEditSubspace), + ) }, subspaceID: 1, - permissions: types.PermissionWrite, - shouldErr: false, + permissions: types.NewPermissions(types.PermissionEditSubspace), expUsers: []string{ "cosmos1s0he0z3g92zwsxdj83h0ky9w463sx7gq9mqtgn", // Owner is always included "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", @@ -443,7 +477,7 @@ func (suite *KeeperTestsuite) TestKeeper_GetUsersWithRootPermissions() { 1, "Test group", "This is a test group", - types.PermissionWrite|types.PermissionSetPermissions, + types.NewPermissions(types.PermissionEditSubspace, types.PermissionSetPermissions), )) suite.k.AddUserToGroup(ctx, 1, 1, "cosmos1xw69y2z3yf00rgfnly99628gn5c0x7fryyfv5e") @@ -453,16 +487,25 @@ func (suite *KeeperTestsuite) TestKeeper_GetUsersWithRootPermissions() { 2, "Another test group", "This is a second test group", - types.PermissionSetPermissions, + types.NewPermissions(types.PermissionSetPermissions), )) suite.k.AddUserToGroup(ctx, 1, 2, "cosmos1e32dfqu7k9e5wj85cjtalqdd2zs6z7adgswnrn") - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.PermissionWrite|types.PermissionChangeInfo) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1f3e5dhpg3afanddld0kp6lkayz2qvuetf6hmv3", types.PermissionChangeInfo) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", + types.CombinePermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace), + ) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1f3e5dhpg3afanddld0kp6lkayz2qvuetf6hmv3", + types.NewPermissions(types.PermissionSetPermissions), + ) }, subspaceID: 1, - permissions: types.PermissionWrite, - shouldErr: false, + permissions: types.NewPermissions(types.PermissionEditSubspace), expUsers: []string{ "cosmos1s0he0z3g92zwsxdj83h0ky9w463sx7gq9mqtgn", // Owner is always included "cosmos1xw69y2z3yf00rgfnly99628gn5c0x7fryyfv5e", @@ -479,13 +522,8 @@ func (suite *KeeperTestsuite) TestKeeper_GetUsersWithRootPermissions() { tc.store(ctx) } - users, err := suite.k.GetUsersWithRootPermission(ctx, tc.subspaceID, tc.permissions) - if tc.shouldErr { - suite.Require().Error(err) - } else { - suite.Require().NoError(err) - suite.Require().Equal(tc.expUsers, users) - } + users := suite.k.GetUsersWithRootPermissions(ctx, tc.subspaceID, tc.permissions) + suite.Require().Equal(tc.expUsers, users) }) } } @@ -500,26 +538,31 @@ func (suite *KeeperTestsuite) TestKeeper_RemoveUserPermissions() { check func(ctx sdk.Context) }{ { - name: "permission is deleted for non existing user", + name: "permissions are deleted for non existing user", subspaceID: 1, sectionID: 0, user: "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", check: func(ctx sdk.Context) { - permission := suite.k.GetUserPermissions(ctx, 1, 0, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn") - suite.Require().Equal(types.PermissionNothing, permission) + permissions := suite.k.GetUserPermissions(ctx, 1, 0, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn") + suite.Require().Empty(permissions) }, }, { - name: "permission is deleted for existing user", + name: "permissionss are deleted for existing user", store: func(ctx sdk.Context) { - suite.k.SetUserPermissions(ctx, 1, 1, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", types.PermissionManageGroups) + suite.k.SetUserPermissions(ctx, + 1, + 1, + "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", + types.NewPermissions(types.PermissionManageGroups), + ) }, subspaceID: 1, sectionID: 1, user: "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn", check: func(ctx sdk.Context) { - permission := suite.k.GetUserPermissions(ctx, 1, 1, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn") - suite.Require().Equal(types.PermissionNothing, permission) + permissions := suite.k.GetUserPermissions(ctx, 1, 1, "cosmos1fz49f2njk28ue8geqm63g4zzsm97lahqa9vmwn") + suite.Require().Empty(permissions) }, }, } diff --git a/x/subspaces/keeper/sections_test.go b/x/subspaces/keeper/sections_test.go index 57afa7f341..33b2a38c01 100644 --- a/x/subspaces/keeper/sections_test.go +++ b/x/subspaces/keeper/sections_test.go @@ -497,11 +497,16 @@ func (suite *KeeperTestsuite) TestKeeper_DeleteSection() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) // Permissions - suite.k.SetUserPermissions(ctx, 1, 1, "cosmos1p7vudy57pw08w6plujlpqpuqea2hkqusfq5zjc", types.PermissionManageSections) + suite.k.SetUserPermissions(ctx, + 1, + 1, + "cosmos1p7vudy57pw08w6plujlpqpuqea2hkqusfq5zjc", + types.NewPermissions(types.PermissionManageSections), + ) // Children section suite.k.SaveSection(ctx, types.NewSection( diff --git a/x/subspaces/keeper/subspaces_test.go b/x/subspaces/keeper/subspaces_test.go index d7007d7891..0649e3e913 100644 --- a/x/subspaces/keeper/subspaces_test.go +++ b/x/subspaces/keeper/subspaces_test.go @@ -315,10 +315,15 @@ func (suite *KeeperTestsuite) TestKeeper_DeleteSubspace() { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), )) - suite.k.SetUserPermissions(ctx, 1, 0, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", types.PermissionWrite) + suite.k.SetUserPermissions(ctx, + 1, + 0, + "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", + types.NewPermissions(types.PermissionEditSubspace), + ) }, subspaceID: 1, check: func(ctx sdk.Context) { diff --git a/x/subspaces/legacy/v2/keys.go b/x/subspaces/legacy/v2/keys.go index 7c16a59432..acf8424eb2 100644 --- a/x/subspaces/legacy/v2/keys.go +++ b/x/subspaces/legacy/v2/keys.go @@ -92,3 +92,11 @@ func GroupMemberStoreKey(subspaceID uint64, groupID uint32, user sdk.AccAddress) func UserPermissionStoreKey(subspaceID uint64, user sdk.AccAddress) []byte { return append(PermissionsStoreKey(subspaceID), GetAddressBytes(user)...) } + +// SplitUserPermissionKey splits the provided UserPermissionStoreKey into the related subspace id and user address +func SplitUserPermissionKey(key []byte) (subspaceID uint64, user sdk.AccAddress) { + key = key[1:] + subspaceID = GetSubspaceIDFromBytes(key[:8]) + user = GetAddressFromBytes(key[8:]) + return subspaceID, user +} diff --git a/x/subspaces/legacy/v2/keys_test.go b/x/subspaces/legacy/v2/keys_test.go new file mode 100644 index 0000000000..480424c690 --- /dev/null +++ b/x/subspaces/legacy/v2/keys_test.go @@ -0,0 +1,38 @@ +package v2_test + +import ( + "testing" + + sdk "github.com/cosmos/cosmos-sdk/types" + "github.com/stretchr/testify/require" + + v2 "github.com/desmos-labs/desmos/v3/x/subspaces/legacy/v2" +) + +func TestSplitUserPermissionKey(t *testing.T) { + user, err := sdk.AccAddressFromBech32("cosmos1ytez5aseztgvpwajnp6a9l69k8gd45mpv2j3jg") + require.NoError(t, err) + + testCases := []struct { + name string + key []byte + expSubspaceID uint64 + expUser sdk.AccAddress + }{ + { + name: "key is split properly", + key: v2.UserPermissionStoreKey(1, user), + expSubspaceID: 1, + expUser: user, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + subspaceID, user := v2.SplitUserPermissionKey(tc.key) + require.Equal(t, tc.expSubspaceID, subspaceID) + require.True(t, tc.expUser.Equals(user)) + }) + } +} diff --git a/x/subspaces/legacy/v2/models.go b/x/subspaces/legacy/v2/models.go index ee3d6d1878..355cd27b12 100644 --- a/x/subspaces/legacy/v2/models.go +++ b/x/subspaces/legacy/v2/models.go @@ -1,5 +1,7 @@ package v2 +// DONTCOVER + // NewUserGroup returns a new UserGroup instance func NewUserGroup(subspaceID uint64, id uint32, name, description string, permissions Permission) UserGroup { return UserGroup{ @@ -10,29 +12,3 @@ func NewUserGroup(subspaceID uint64, id uint32, name, description string, permis Permissions: permissions, } } - -// -------------------------------------------------------------------------------------------------------------------- - -// NewPermissionDetailUser returns a new PermissionDetail for the user with the given address and permission value -func NewPermissionDetailUser(user string, permission Permission) PermissionDetail { - return PermissionDetail{ - Sum: &PermissionDetail_User_{ - User: &PermissionDetail_User{ - User: user, - Permission: permission, - }, - }, - } -} - -// NewPermissionDetailGroup returns a new PermissionDetail for the user with the given id and permission value -func NewPermissionDetailGroup(groupID uint32, permission Permission) PermissionDetail { - return PermissionDetail{ - Sum: &PermissionDetail_Group_{ - Group: &PermissionDetail_Group{ - GroupID: groupID, - Permission: permission, - }, - }, - } -} diff --git a/x/subspaces/legacy/v2/permissions.go b/x/subspaces/legacy/v2/permissions.go index ee3a0b0f72..7a7634fb86 100644 --- a/x/subspaces/legacy/v2/permissions.go +++ b/x/subspaces/legacy/v2/permissions.go @@ -1,5 +1,10 @@ package v2 +import ( + "encoding/binary" + "sort" +) + // Permission represents a permission that can be set to a user or user group type Permission = uint32 @@ -39,10 +44,26 @@ var ( PermissionChangeInfo: "ChangeInfo", PermissionManageGroups: "ManageGroups", PermissionSetPermissions: "SetUserPermissions", + PermissionDeleteSubspace: "DeleteSubspace", PermissionEverything: "Everything", } ) +// MarshalPermission marshals the given permission to a byte array +func MarshalPermission(permission Permission) (permissionBytes []byte) { + permissionBytes = make([]byte, 4) + binary.BigEndian.PutUint32(permissionBytes, permission) + return +} + +// UnmarshalPermission reads the given byte array as a Permission object +func UnmarshalPermission(bz []byte) (permission Permission) { + if len(bz) < 4 { + return PermissionNothing + } + return binary.BigEndian.Uint32(bz) +} + // CombinePermissions combines all the given permissions into a single Permission object using the OR operator func CombinePermissions(permissions ...Permission) Permission { result := PermissionNothing @@ -52,6 +73,48 @@ func CombinePermissions(permissions ...Permission) Permission { return result } +// getValidPermissions returns the valid permissions slice +func getValidPermissions() []Permission { + validPermissions := make([]Permission, len(permissionsMap)) + + i := 0 + for perm := range permissionsMap { + validPermissions[i] = perm + i++ + } + + // Sort the permissions + sort.Slice(validPermissions, func(i, j int) bool { + return validPermissions[i] < validPermissions[j] + }) + + return validPermissions +} + +// SplitPermissions splits the given combined permission value into its individual values +func SplitPermissions(permission Permission) []Permission { + if permission == PermissionNothing { + return nil + } + + if permission == PermissionEverything { + return []Permission{PermissionEverything} + } + + var permissions []Permission + for _, perm := range getValidPermissions() { + if perm == PermissionNothing || perm == PermissionEverything { + continue + } + + if (permission & perm) == perm { + permissions = append(permissions, perm) + } + } + + return permissions +} + // SanitizePermission sanitizes the given permission to remove any unwanted bits set to 1 func SanitizePermission(permission Permission) Permission { mask := PermissionNothing diff --git a/x/subspaces/legacy/v2/permissions_test.go b/x/subspaces/legacy/v2/permissions_test.go new file mode 100644 index 0000000000..ecf11d5bb1 --- /dev/null +++ b/x/subspaces/legacy/v2/permissions_test.go @@ -0,0 +1,46 @@ +package v2_test + +import ( + "testing" + + "github.com/stretchr/testify/require" + + v2 "github.com/desmos-labs/desmos/v3/x/subspaces/legacy/v2" +) + +func TestSplitPermissions(t *testing.T) { + testCases := []struct { + name string + permission v2.Permission + expPermissions []v2.Permission + }{ + { + name: "single permission is split properly", + permission: v2.PermissionWrite, + expPermissions: []v2.Permission{v2.PermissionWrite}, + }, + { + name: "combined permission is split properly", + permission: v2.PermissionWrite | v2.PermissionChangeInfo | v2.PermissionSetPermissions | v2.PermissionDeleteSubspace, + expPermissions: []v2.Permission{v2.PermissionWrite, v2.PermissionChangeInfo, v2.PermissionSetPermissions, v2.PermissionDeleteSubspace}, + }, + { + name: "permission everything is returned properly", + permission: v2.PermissionEverything | v2.PermissionChangeInfo, + expPermissions: []v2.Permission{v2.PermissionEverything}, + }, + { + name: "permission nothing returns an empty slice", + permission: v2.PermissionNothing, + expPermissions: nil, + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + permissions := v2.SplitPermissions(tc.permission) + require.Equal(t, tc.expPermissions, permissions) + }) + } +} diff --git a/x/subspaces/legacy/v2/store.go b/x/subspaces/legacy/v2/store.go index eedfc913e6..c33454add9 100644 --- a/x/subspaces/legacy/v2/store.go +++ b/x/subspaces/legacy/v2/store.go @@ -4,8 +4,6 @@ import ( "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" - - "github.com/desmos-labs/desmos/v3/x/subspaces/types" ) // MigrateStore migrates the store from version 1 to version 2. @@ -59,7 +57,7 @@ func fixGroupsPermissions(store sdk.KVStore, cdc codec.BinaryCodec) error { type userPermissionDetails struct { subspaceID uint64 user sdk.AccAddress - permissions types.Permission + permissions Permission } // fixUsersPermissions iterates over all the users permissions and sanitizes their values @@ -78,7 +76,7 @@ func fixUsersPermissions(store sdk.KVStore) { user: GetAddressBytes(addressBz), // Sanitize the permission - permissions: SanitizePermission(types.UnmarshalPermission(iterator.Value())), + permissions: SanitizePermission(UnmarshalPermission(iterator.Value())), }) } @@ -86,6 +84,6 @@ func fixUsersPermissions(store sdk.KVStore) { // Store the new permissions for _, entry := range permissions { - store.Set(UserPermissionStoreKey(entry.subspaceID, entry.user), types.MarshalPermission(entry.permissions)) + store.Set(UserPermissionStoreKey(entry.subspaceID, entry.user), MarshalPermission(entry.permissions)) } } diff --git a/x/subspaces/legacy/v2/store_test.go b/x/subspaces/legacy/v2/store_test.go index d27ca5e543..d2c8415f1d 100644 --- a/x/subspaces/legacy/v2/store_test.go +++ b/x/subspaces/legacy/v2/store_test.go @@ -42,7 +42,7 @@ func TestMigrateStore(t *testing.T) { // Check the permissions var group v2.UserGroup cdc.MustUnmarshal(kvStore.Get(v2.GroupStoreKey(11, 11)), &group) - require.Equal(t, types.PermissionWrite, group.Permissions) + require.Equal(t, v2.PermissionWrite, group.Permissions) }, }, { @@ -53,7 +53,7 @@ func TestMigrateStore(t *testing.T) { addr, err := sdk.AccAddressFromBech32("cosmos12e7ejq92sma437d3svemgfvl8sul8lxfs69mjv") require.NoError(t, err) - kvStore.Set(v2.UserPermissionStoreKey(11, addr), types.MarshalPermission(0b1111111111111111111111111000001)) + kvStore.Set(v2.UserPermissionStoreKey(11, addr), v2.MarshalPermission(0b11111111111111111111111111000001)) }, check: func(ctx sdk.Context) { kvStore := ctx.KVStore(keys[types.StoreKey]) @@ -62,8 +62,8 @@ func TestMigrateStore(t *testing.T) { require.NoError(t, err) // Check the permissions - stored := types.UnmarshalPermission(kvStore.Get(v2.UserPermissionStoreKey(11, addr))) - require.Equal(t, types.PermissionWrite, stored) + stored := v2.UnmarshalPermission(kvStore.Get(v2.UserPermissionStoreKey(11, addr))) + require.Equal(t, v2.PermissionWrite, stored) }, }, } diff --git a/x/subspaces/legacy/v3/store.go b/x/subspaces/legacy/v3/store.go index 055268a078..2461d58328 100644 --- a/x/subspaces/legacy/v3/store.go +++ b/x/subspaces/legacy/v3/store.go @@ -1,15 +1,23 @@ package v3 import ( + "fmt" + + poststypes "github.com/desmos-labs/desmos/v3/x/posts/types" + "github.com/cosmos/cosmos-sdk/codec" "github.com/cosmos/cosmos-sdk/store/prefix" sdk "github.com/cosmos/cosmos-sdk/types" + v2 "github.com/desmos-labs/desmos/v3/x/subspaces/legacy/v2" "github.com/desmos-labs/desmos/v3/x/subspaces/types" ) -// MigrateStore migrates the store to version 3. -// The migration process includes the following operations: +// MigrateStore migrates the store from version 2 to version 3. +// The migration includes the following: +// +// - migrate all the group permissions from the old system to the new one +// - migrate all the user permissions from the old system to the new one // - set the NextSectionID to 1 for all the existing subspaces // - create the default section for all the existing subspaces func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) error { @@ -20,6 +28,16 @@ func MigrateStore(ctx sdk.Context, storeKey sdk.StoreKey, cdc codec.BinaryCodec) return err } + err = migrateUserGroupsPermissions(store, cdc) + if err != nil { + return err + } + + err = migrateUserPermissions(store, cdc) + if err != nil { + return err + } + return nil } @@ -44,3 +62,105 @@ func setupSubspacesSections(store sdk.KVStore, cdc codec.BinaryCodec) error { return nil } + +// migrateUserGroupsPermissions migrates all the user groups permissions from the old system to the new one +func migrateUserGroupsPermissions(store sdk.KVStore, cdc codec.BinaryCodec) error { + groupsStore := prefix.NewStore(store, v2.GroupsPrefix) + iterator := groupsStore.Iterator(nil, nil) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + var v2Group v2.UserGroup + err := cdc.Unmarshal(iterator.Value(), &v2Group) + if err != nil { + return err + } + + // Delete the old key + store.Delete(v2.GroupStoreKey(v2Group.SubspaceID, v2Group.ID)) + + // Migrate the permission + v3Permissions, err := MigratePermissions(v2Group.Permissions) + if err != nil { + return err + } + + // Store the new group + v3Group := types.NewUserGroup(v2Group.SubspaceID, types.RootSectionID, v2Group.ID, v2Group.Name, v2Group.Description, v3Permissions) + store.Set(types.GroupStoreKey(v3Group.SubspaceID, v3Group.SectionID, v3Group.ID), cdc.MustMarshal(&v3Group)) + } + + return nil +} + +// migrateUserPermissions migrates all the user permissions from the old system to the new one +func migrateUserPermissions(store sdk.KVStore, cdc codec.BinaryCodec) error { + permissionsStore := prefix.NewStore(store, v2.UserPermissionsStorePrefix) + iterator := permissionsStore.Iterator(nil, nil) + defer iterator.Close() + + for ; iterator.Valid(); iterator.Next() { + // Get the permissions value + subspaceID, user := v2.SplitUserPermissionKey(append(v2.UserPermissionsStorePrefix, iterator.Key()...)) + v2Permissions := v2.UnmarshalPermission(iterator.Value()) + + // Delete the old key + store.Delete(v2.UserPermissionStoreKey(subspaceID, user)) + + // Migrate the permissions + v3Permissions, err := MigratePermissions(v2Permissions) + if err != nil { + return err + } + + // If there are no permissions, just skip this migration + if len(v3Permissions) == 0 { + continue + } + + // Store the new permissions + userPermission := types.NewUserPermission(subspaceID, types.RootSectionID, user.String(), v3Permissions) + store.Set(types.UserPermissionStoreKey(subspaceID, types.RootSectionID, user.String()), cdc.MustMarshal(&userPermission)) + } + + return nil +} + +// MigratePermissions migrates the given v2 permissions to the new system +func MigratePermissions(permissions v2.Permission) (types.Permissions, error) { + v2PermissionsSlice := v2.SplitPermissions(permissions) + v3Permissions := make([]types.Permission, len(v2PermissionsSlice)) + for i, permission := range v2PermissionsSlice { + v3Permission, err := migratePermission(permission) + if err != nil { + return nil, err + } + v3Permissions[i] = v3Permission + } + return v3Permissions, nil +} + +// migratePermission migrates the given permission value to the corresponding new one +func migratePermission(permission v2.Permission) (types.Permission, error) { + switch permission { + + case v2.PermissionChangeInfo: + return types.PermissionEditSubspace, nil + case v2.PermissionManageGroups: + return types.PermissionManageGroups, nil + case v2.PermissionSetPermissions: + return types.PermissionSetPermissions, nil + case v2.PermissionDeleteSubspace: + return types.PermissionDeleteSubspace, nil + case v2.PermissionEverything: + return types.PermissionEverything, nil + + case v2.PermissionWrite: + return poststypes.PermissionWrite, nil + case v2.PermissionModerateContent: + return poststypes.PermissionModerateContent, nil + + default: + return "", fmt.Errorf("permission not supported: %d", permission) + } +} diff --git a/x/subspaces/legacy/v3/store_test.go b/x/subspaces/legacy/v3/store_test.go index 71d4049025..d8d0fb361e 100644 --- a/x/subspaces/legacy/v3/store_test.go +++ b/x/subspaces/legacy/v3/store_test.go @@ -4,6 +4,8 @@ import ( "testing" "time" + poststypes "github.com/desmos-labs/desmos/v3/x/posts/types" + v3 "github.com/desmos-labs/desmos/v3/x/subspaces/legacy/v3" sdk "github.com/cosmos/cosmos-sdk/types" @@ -13,6 +15,7 @@ import ( "github.com/desmos-labs/desmos/v3/app" "github.com/desmos-labs/desmos/v3/testutil" + v2 "github.com/desmos-labs/desmos/v3/x/subspaces/legacy/v2" "github.com/desmos-labs/desmos/v3/x/subspaces/types" ) @@ -58,6 +61,68 @@ func TestMigrateStore(t *testing.T) { require.Equal(t, types.DefaultSection(1), section) }, }, + { + name: "groups permissions are migrated properly", + store: func(ctx sdk.Context) { + kvStore := ctx.KVStore(keys[types.StoreKey]) + + group := v2.NewUserGroup( + 1, + 1, + "Test group", + "", + v2.PermissionWrite|v2.PermissionModerateContent, + ) + kvStore.Set(v2.GroupStoreKey(group.SubspaceID, group.ID), cdc.MustMarshal(&group)) + }, + check: func(ctx sdk.Context) { + kvStore := ctx.KVStore(keys[types.StoreKey]) + + // Make sure the old key does not exist + require.False(t, kvStore.Has(v2.GroupStoreKey(1, 1))) + + // Check the permissions + var group types.UserGroup + cdc.MustUnmarshal(kvStore.Get(types.GroupStoreKey(1, types.RootSectionID, 1)), &group) + require.Equal(t, types.NewUserGroup( + 1, + types.RootSectionID, + 1, + "Test group", + "", + types.CombinePermissions(poststypes.PermissionWrite, poststypes.PermissionModerateContent), + ), group) + }, + }, + { + name: "user permissions are migrated properly", + store: func(ctx sdk.Context) { + kvStore := ctx.KVStore(keys[types.StoreKey]) + + addr, err := sdk.AccAddressFromBech32("cosmos12e7ejq92sma437d3svemgfvl8sul8lxfs69mjv") + require.NoError(t, err) + + kvStore.Set(v2.UserPermissionStoreKey(1, addr), v2.MarshalPermission(v2.PermissionEverything)) + }, + check: func(ctx sdk.Context) { + kvStore := ctx.KVStore(keys[types.StoreKey]) + + // Make sure the old key does not exist + user, err := sdk.AccAddressFromBech32("cosmos12e7ejq92sma437d3svemgfvl8sul8lxfs69mjv") + require.NoError(t, err) + require.False(t, kvStore.Has(v2.UserPermissionStoreKey(1, user))) + + // Check the permissions + var stored types.UserPermission + cdc.MustUnmarshal(kvStore.Get(types.UserPermissionStoreKey(1, 0, "cosmos12e7ejq92sma437d3svemgfvl8sul8lxfs69mjv")), &stored) + require.Equal(t, types.NewUserPermission( + 1, + types.RootSectionID, + "cosmos12e7ejq92sma437d3svemgfvl8sul8lxfs69mjv", + types.NewPermissions(types.PermissionEverything), + ), stored) + }, + }, } for _, tc := range testCases { @@ -80,3 +145,61 @@ func TestMigrateStore(t *testing.T) { }) } } + +func TestMigratePermissions(t *testing.T) { + testCases := []struct { + name string + store func(ctx sdk.Context) + permissions v2.Permission + shouldErr bool + expPermissions types.Permissions + }{ + { + name: "single permission is migrated properly", + permissions: v2.PermissionSetPermissions, + shouldErr: false, + expPermissions: types.NewPermissions(types.PermissionSetPermissions), + }, + { + name: "combined permissions are migrated properly", + permissions: v2.PermissionWrite | + v2.PermissionModerateContent | + v2.PermissionChangeInfo | + v2.PermissionManageGroups | + v2.PermissionSetPermissions, + shouldErr: false, + expPermissions: types.NewPermissions( + poststypes.PermissionWrite, + poststypes.PermissionModerateContent, + types.PermissionEditSubspace, + types.PermissionManageGroups, + types.PermissionSetPermissions, + ), + }, + { + name: "permission nothing is migrated properly", + permissions: v2.PermissionNothing, + shouldErr: false, + expPermissions: types.Permissions{}, + }, + { + name: "permission everything is migrated properly", + permissions: v2.PermissionEverything, + shouldErr: false, + expPermissions: types.NewPermissions(types.PermissionEverything), + }, + } + + for _, tc := range testCases { + tc := tc + t.Run(tc.name, func(t *testing.T) { + permissions, err := v3.MigratePermissions(tc.permissions) + if tc.shouldErr { + require.Error(t, err) + } else { + require.NoError(t, err) + require.Equal(t, tc.expPermissions, permissions) + } + }) + } +} diff --git a/x/subspaces/simulation/decoder.go b/x/subspaces/simulation/decoder.go index 4b4820f379..8fd68b83fe 100644 --- a/x/subspaces/simulation/decoder.go +++ b/x/subspaces/simulation/decoder.go @@ -43,10 +43,10 @@ func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { return fmt.Sprintf("GroupMemberKeyA: %s\nGroupMemberKeyB: %s\n", kvA.Key, kvB.Key) case bytes.HasPrefix(kvA.Key, types.UserPermissionsStorePrefix): - var permissionA, permissionB uint32 - permissionA = types.UnmarshalPermission(kvA.Value) - permissionB = types.UnmarshalPermission(kvB.Value) - return fmt.Sprintf("PermissionKeyA: %d\nPermissionKeyB: %d\n", permissionA, permissionB) + var permissionA, permissionB types.UserPermission + cdc.MustUnmarshal(kvA.Value, &permissionA) + cdc.MustUnmarshal(kvB.Value, &permissionB) + return fmt.Sprintf("PermissionA: %s\nPermissionB: %s\n", &permissionA, &permissionB) case bytes.HasPrefix(kvA.Key, types.SectionIDPrefix): var sectionIDA, sectionIDB uint32 diff --git a/x/subspaces/simulation/decoder_test.go b/x/subspaces/simulation/decoder_test.go index 2e58894c6a..7f371de967 100644 --- a/x/subspaces/simulation/decoder_test.go +++ b/x/subspaces/simulation/decoder_test.go @@ -33,7 +33,7 @@ func TestDecodeStore(t *testing.T) { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ) section := types.NewSection( @@ -44,6 +44,13 @@ func TestDecodeStore(t *testing.T) { "This is a test section", ) + permission := types.NewUserPermission( + 1, + 1, + "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e", + types.NewPermissions(types.PermissionEverything), + ) + kvPairs := kv.Pairs{Pairs: []kv.Pair{ { Key: types.SubspaceIDKey, @@ -67,7 +74,7 @@ func TestDecodeStore(t *testing.T) { }, { Key: types.UserPermissionStoreKey(1, 0, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e"), - Value: types.MarshalPermission(types.PermissionWrite), + Value: cdc.MustMarshal(&permission), }, { Key: types.NextSectionIDStoreKey(1), @@ -97,8 +104,8 @@ func TestDecodeStore(t *testing.T) { group.String(), group.String())}, {"Group member", fmt.Sprintf("GroupMemberKeyA: %s\nGroupMemberKeyB: %s\n", types.GroupMemberStoreKey(1, 1, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e"), types.GroupMemberStoreKey(1, 1, "cosmos1nv9kkuads7f627q2zf4k9kwdudx709rjck3s7e"))}, - {"Permission", fmt.Sprintf("PermissionKeyA: %d\nPermissionKeyB: %d\n", - types.PermissionWrite, types.PermissionWrite)}, + {"Permission", fmt.Sprintf("PermissionA: %s\nPermissionB: %s\n", + &permission, &permission)}, {"Section ID", fmt.Sprintf("SectionIDA: %d\nSectionIDB: %d\n", 1, 1)}, {"Section", fmt.Sprintf("SectionA: %s\nSectionB: %s\n", §ion, §ion)}, {"other", ""}, diff --git a/x/subspaces/simulation/operations_groups.go b/x/subspaces/simulation/operations_groups.go index 0a788c0aec..47221f501e 100644 --- a/x/subspaces/simulation/operations_groups.go +++ b/x/subspaces/simulation/operations_groups.go @@ -5,6 +5,8 @@ package simulation import ( "math/rand" + poststypes "github.com/desmos-labs/desmos/v3/x/posts/types" + feeskeeper "github.com/desmos-labs/desmos/v3/x/fees/keeper" "github.com/desmos-labs/desmos/v3/testutil/simtesting" @@ -58,7 +60,7 @@ func SimulateMsgCreateUserGroup( // randomCreateUserGroupFields returns the data used to build a random MsgCreateUserGroup func randomCreateUserGroupFields( r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, -) (subspaceID uint64, update types.GroupUpdate, permissions types.Permission, account simtypes.Account, skip bool) { +) (subspaceID uint64, update types.GroupUpdate, permissions types.Permissions, account simtypes.Account, skip bool) { // Get a subspace id subspaces := k.GetAllSubspaces(ctx) if len(subspaces) == 0 { @@ -74,14 +76,13 @@ func randomCreateUserGroupFields( groupDescription := RandomDescription(r) // Get a default permission - permissions = RandomPermission(r, []types.Permission{ - types.PermissionWrite, - types.PermissionChangeInfo, - types.PermissionEverything, + permissions = RandomPermission(r, []types.Permissions{ + types.NewPermissions(poststypes.PermissionWrite), + types.NewPermissions(types.PermissionEditSubspace), }) // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspace.ID, types.CombinePermissions(types.PermissionManageGroups, types.PermissionSetPermissions)) + signers := k.GetUsersWithRootPermissions(ctx, subspace.ID, types.CombinePermissions(types.PermissionManageGroups, types.PermissionSetPermissions)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -150,7 +151,7 @@ func randomEditUserGroupFields( } // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspaceID, types.PermissionManageGroups) + signers := k.GetUsersWithRootPermissions(ctx, subspaceID, types.NewPermissions(types.PermissionManageGroups)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -222,7 +223,7 @@ func randomMoveUserGroupFields( newSectionID = section.ID // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspace.ID, types.PermissionEverything) + signers := k.GetUsersWithRootPermissions(ctx, subspace.ID, types.NewPermissions(types.PermissionEverything)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -267,7 +268,7 @@ func SimulateMsgSetUserGroupPermissions( // randomSetUserGroupPermissionsFields returns the data used to build a random MsgSetUserGroupPermissions func randomSetUserGroupPermissionsFields( r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, -) (subspaceID uint64, groupID uint32, permissions types.Permission, account simtypes.Account, skip bool) { +) (subspaceID uint64, groupID uint32, permissions types.Permissions, account simtypes.Account, skip bool) { // Get a subspace id subspaces := k.GetAllSubspaces(ctx) if len(subspaces) == 0 { @@ -291,7 +292,7 @@ func randomSetUserGroupPermissionsFields( permissions = RandomPermission(r, validPermissions) // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspace.ID, types.PermissionSetPermissions) + signers := k.GetUsersWithRootPermissions(ctx, subspace.ID, types.NewPermissions(types.PermissionSetPermissions)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -362,7 +363,7 @@ func randomDeleteUserGroupFields( groupID = group.ID // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspaceID, types.PermissionManageGroups) + signers := k.GetUsersWithRootPermissions(ctx, subspaceID, types.NewPermissions(types.PermissionManageGroups)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -436,7 +437,7 @@ func randomAddUserToUserGroupFields( user = userAccount.GetAddress().String() // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspaceID, types.PermissionSetPermissions) + signers := k.GetUsersWithRootPermissions(ctx, subspaceID, types.NewPermissions(types.PermissionSetPermissions)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -510,7 +511,7 @@ func randomRemoveUserFromUserGroupFields( user = RandomAddress(r, members) // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspaceID, types.PermissionSetPermissions) + signers := k.GetUsersWithRootPermissions(ctx, subspaceID, types.NewPermissions(types.PermissionSetPermissions)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid diff --git a/x/subspaces/simulation/operations_permissions.go b/x/subspaces/simulation/operations_permissions.go index 9f2455312c..84d1b3eeb5 100644 --- a/x/subspaces/simulation/operations_permissions.go +++ b/x/subspaces/simulation/operations_permissions.go @@ -51,7 +51,7 @@ func SimulateMsgSetUserPermissions( // randomSetUserPermissionsFields returns the data used to build a random MsgSetUserPermissions func randomSetUserPermissionsFields( r *rand.Rand, ctx sdk.Context, accs []simtypes.Account, k keeper.Keeper, -) (subspaceID uint64, target string, permissions types.Permission, account simtypes.Account, skip bool) { +) (subspaceID uint64, target string, permissions types.Permissions, account simtypes.Account, skip bool) { // Get a subspace id subspaces := k.GetAllSubspaces(ctx) if len(subspaces) == 0 { @@ -70,7 +70,7 @@ func randomSetUserPermissionsFields( permissions = RandomPermission(r, validPermissions) // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspace.ID, types.PermissionSetPermissions) + signers := k.GetUsersWithRootPermissions(ctx, subspace.ID, types.NewPermissions(types.PermissionSetPermissions)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid diff --git a/x/subspaces/simulation/operations_sections.go b/x/subspaces/simulation/operations_sections.go index 9e05505dab..e2670a3375 100644 --- a/x/subspaces/simulation/operations_sections.go +++ b/x/subspaces/simulation/operations_sections.go @@ -80,7 +80,7 @@ func randomCreateSectionFields( ) // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspace.ID, types.PermissionManageSections) + signers := k.GetUsersWithRootPermissions(ctx, subspace.ID, types.NewPermissions(types.PermissionManageSections)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -154,7 +154,7 @@ func randomEditSectionFields( ) // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspace.ID, types.PermissionManageSections) + signers := k.GetUsersWithRootPermissions(ctx, subspace.ID, types.NewPermissions(types.PermissionManageSections)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -230,7 +230,7 @@ func randomMoveSectionFields( newParentID = parent.ID // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspace.ID, types.PermissionManageSections) + signers := k.GetUsersWithRootPermissions(ctx, subspace.ID, types.NewPermissions(types.PermissionManageSections)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -301,7 +301,7 @@ func randomDeleteFields( } // Get a signer - signers, _ := k.GetUsersWithRootPermission(ctx, subspace.ID, types.PermissionManageSections) + signers := k.GetUsersWithRootPermissions(ctx, subspace.ID, types.NewPermissions(types.PermissionManageSections)) acc := GetAccount(RandomAddress(r, signers), accs) if acc == nil { // Skip the operation without error as the account is not valid diff --git a/x/subspaces/simulation/operations_subspaces.go b/x/subspaces/simulation/operations_subspaces.go index 2db5c56b5a..45dd8474e0 100644 --- a/x/subspaces/simulation/operations_subspaces.go +++ b/x/subspaces/simulation/operations_subspaces.go @@ -125,7 +125,7 @@ func randomEditSubspaceFields( subspaceID = subspace.ID // Get an editor - editors, _ := k.GetUsersWithRootPermission(ctx, subspace.ID, types.PermissionChangeInfo) + editors := k.GetUsersWithRootPermissions(ctx, subspace.ID, types.NewPermissions(types.PermissionEditSubspace)) acc := GetAccount(RandomAddress(r, editors), accs) if acc == nil { // Skip the operation without error as the account is not valid @@ -206,7 +206,7 @@ func randomDeleteSubspaceFields( subspaceID = subspace.ID // Get an editor - editors, _ := k.GetUsersWithRootPermission(ctx, subspace.ID, types.PermissionDeleteSubspace) + editors := k.GetUsersWithRootPermissions(ctx, subspace.ID, types.NewPermissions(types.PermissionDeleteSubspace)) acc := GetAccount(RandomAddress(r, editors), accs) if acc == nil { // Skip the operation without error as the account is not valid diff --git a/x/subspaces/simulation/utils.go b/x/subspaces/simulation/utils.go index 18df47224b..dd0be63ff0 100644 --- a/x/subspaces/simulation/utils.go +++ b/x/subspaces/simulation/utils.go @@ -6,6 +6,8 @@ import ( "math/rand" "time" + poststypes "github.com/desmos-labs/desmos/v3/x/posts/types" + authtypes "github.com/cosmos/cosmos-sdk/x/auth/types" simtypes "github.com/cosmos/cosmos-sdk/types/simulation" @@ -14,12 +16,12 @@ import ( ) var ( - validPermissions = []types.Permission{ - types.PermissionWrite | types.PermissionEditOwnContent | types.PermissionInteractWithContent, - types.PermissionWrite | types.PermissionInteractWithContent | types.PermissionModerateContent, - types.PermissionWrite | types.PermissionEditOwnContent | types.PermissionChangeInfo, - types.PermissionWrite | types.PermissionEditOwnContent | types.PermissionInteractWithContent | types.PermissionDeleteSubspace, - types.PermissionEverything, + validPermissions = []types.Permissions{ + types.CombinePermissions(poststypes.PermissionWrite, poststypes.PermissionEditOwnContent, poststypes.PermissionInteractWithContent), + types.CombinePermissions(poststypes.PermissionWrite, poststypes.PermissionInteractWithContent), + types.CombinePermissions(poststypes.PermissionWrite, poststypes.PermissionEditOwnContent), + types.CombinePermissions(poststypes.PermissionWrite, poststypes.PermissionEditOwnContent, poststypes.PermissionInteractWithContent, types.PermissionDeleteSubspace), + types.CombinePermissions(types.PermissionEverything), } ) @@ -90,7 +92,7 @@ func RandomGroup(r *rand.Rand, groups []types.UserGroup) types.UserGroup { } // RandomPermission returns a random permission from the given slice -func RandomPermission(r *rand.Rand, permissions []types.Permission) types.Permission { +func RandomPermission(r *rand.Rand, permissions []types.Permissions) types.Permissions { return permissions[r.Intn(len(permissions))] } diff --git a/x/subspaces/types/errors.go b/x/subspaces/types/errors.go index 23b188915e..3f3dc0e644 100644 --- a/x/subspaces/types/errors.go +++ b/x/subspaces/types/errors.go @@ -6,7 +6,6 @@ import ( var ( // ErrPermissionDenied is returned if a user cannot perform a specific action inside a subspace - ErrPermissionDenied = sdkerrors.Register(ModuleName, 1, "permission denied for user") + ErrPermissionDenied = sdkerrors.Register(ModuleName, 1, "permissions denied for user") ErrInvalidGenesis = sdkerrors.Register(ModuleName, 2, "invalid genesis state") - ErrInvalidSection = sdkerrors.Register(ModuleName, 3, "invalid section") ) diff --git a/x/subspaces/types/genesis.go b/x/subspaces/types/genesis.go index 417ffb9f13..e0723f9083 100644 --- a/x/subspaces/types/genesis.go +++ b/x/subspaces/types/genesis.go @@ -223,36 +223,6 @@ func (data SubspaceData) Validate() error { // ------------------------------------------------------------------------------------------------------------------- -// NewUserPermission returns a new UserPermission instance -func NewUserPermission(subspaceID uint64, sectionID uint32, user string, permissions Permission) UserPermission { - return UserPermission{ - SubspaceID: subspaceID, - SectionID: sectionID, - User: user, - Permissions: permissions, - } -} - -// Validate implements fmt.Validator -func (p UserPermission) Validate() error { - if p.SubspaceID == 0 { - return fmt.Errorf("invalid subspace id: %d", p.SubspaceID) - } - - if !IsPermissionValid(p.Permissions) { - return fmt.Errorf("invalid permission value: %b", p.Permissions) - } - - _, err := sdk.AccAddressFromBech32(p.User) - if err != nil { - return fmt.Errorf("invalid user address: %s", err) - } - - return nil -} - -// ------------------------------------------------------------------------------------------------------------------- - // NewUserGroupMemberEntry returns a new UserGroupMemberEntry instance func NewUserGroupMemberEntry(subspaceID uint64, groupID uint32, user string) UserGroupMemberEntry { return UserGroupMemberEntry{ diff --git a/x/subspaces/types/genesis.pb.go b/x/subspaces/types/genesis.pb.go index 7744eb024f..18fc3126ac 100644 --- a/x/subspaces/types/genesis.pb.go +++ b/x/subspaces/types/genesis.pb.go @@ -177,75 +177,6 @@ func (m *SubspaceData) GetNextSectionID() uint32 { return 0 } -// UserPermission represents a single Access Control List entry -type UserPermission struct { - SubspaceID uint64 `protobuf:"varint,1,opt,name=subspace_id,json=subspaceId,proto3" json:"subspace_id,omitempty"` - SectionID uint32 `protobuf:"varint,2,opt,name=section_id,json=sectionId,proto3" json:"section_id,omitempty"` - User string `protobuf:"bytes,3,opt,name=user,proto3" json:"user,omitempty"` - Permissions uint32 `protobuf:"varint,4,opt,name=permissions,proto3" json:"permissions,omitempty"` -} - -func (m *UserPermission) Reset() { *m = UserPermission{} } -func (m *UserPermission) String() string { return proto.CompactTextString(m) } -func (*UserPermission) ProtoMessage() {} -func (*UserPermission) Descriptor() ([]byte, []int) { - return fileDescriptor_e29defb77aaf744c, []int{2} -} -func (m *UserPermission) XXX_Unmarshal(b []byte) error { - return m.Unmarshal(b) -} -func (m *UserPermission) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { - if deterministic { - return xxx_messageInfo_UserPermission.Marshal(b, m, deterministic) - } else { - b = b[:cap(b)] - n, err := m.MarshalToSizedBuffer(b) - if err != nil { - return nil, err - } - return b[:n], nil - } -} -func (m *UserPermission) XXX_Merge(src proto.Message) { - xxx_messageInfo_UserPermission.Merge(m, src) -} -func (m *UserPermission) XXX_Size() int { - return m.Size() -} -func (m *UserPermission) XXX_DiscardUnknown() { - xxx_messageInfo_UserPermission.DiscardUnknown(m) -} - -var xxx_messageInfo_UserPermission proto.InternalMessageInfo - -func (m *UserPermission) GetSubspaceID() uint64 { - if m != nil { - return m.SubspaceID - } - return 0 -} - -func (m *UserPermission) GetSectionID() uint32 { - if m != nil { - return m.SectionID - } - return 0 -} - -func (m *UserPermission) GetUser() string { - if m != nil { - return m.User - } - return "" -} - -func (m *UserPermission) GetPermissions() uint32 { - if m != nil { - return m.Permissions - } - return 0 -} - // UserGroupMemberEntry contains the details of a user group member type UserGroupMemberEntry struct { SubspaceID uint64 `protobuf:"varint,1,opt,name=subspace_id,json=subspaceId,proto3" json:"subspace_id,omitempty"` @@ -257,7 +188,7 @@ func (m *UserGroupMemberEntry) Reset() { *m = UserGroupMemberEntry{} } func (m *UserGroupMemberEntry) String() string { return proto.CompactTextString(m) } func (*UserGroupMemberEntry) ProtoMessage() {} func (*UserGroupMemberEntry) Descriptor() ([]byte, []int) { - return fileDescriptor_e29defb77aaf744c, []int{3} + return fileDescriptor_e29defb77aaf744c, []int{2} } func (m *UserGroupMemberEntry) XXX_Unmarshal(b []byte) error { return m.Unmarshal(b) @@ -310,50 +241,47 @@ func (m *UserGroupMemberEntry) GetUser() string { func init() { proto.RegisterType((*GenesisState)(nil), "desmos.subspaces.v2.GenesisState") proto.RegisterType((*SubspaceData)(nil), "desmos.subspaces.v2.SubspaceData") - proto.RegisterType((*UserPermission)(nil), "desmos.subspaces.v2.UserPermission") proto.RegisterType((*UserGroupMemberEntry)(nil), "desmos.subspaces.v2.UserGroupMemberEntry") } func init() { proto.RegisterFile("desmos/subspaces/v2/genesis.proto", fileDescriptor_e29defb77aaf744c) } var fileDescriptor_e29defb77aaf744c = []byte{ - // 575 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x94, 0x94, 0xc1, 0x6a, 0xdb, 0x4c, - 0x14, 0x85, 0xad, 0x44, 0x7f, 0x62, 0x5f, 0xc5, 0xf6, 0xef, 0x71, 0x0a, 0x22, 0xb4, 0x92, 0x93, - 0x42, 0x71, 0xa1, 0x95, 0xc0, 0x5e, 0xb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 0x6c, 0xf4, 0x02, 0xda, 0xcc, 0xc4, 0xe7, 0x91, 0xda, 0x76, 0x99, 0xad, 0x93, - 0xc4, 0x6a, 0x33, 0xb5, 0xf1, 0xc1, 0x4d, 0xc7, 0x06, 0xc3, 0xe7, 0x9f, 0x76, 0x29, 0xfb, 0x37, - 0x01, 0x5a, 0x37, 0xe7, 0x72, 0xff, 0xf4, 0xcf, 0x00, 0x4a, 0x19, 0xb2, 0xe8, 0xcd, 0x24, 0x56, - 0x1b, 0xdb, 0xf7, 0x1b, 0x24, 0x7f, 0x1b, 0x21, 0x10, 0xd3, 0x66, 0xb2, 0xac, 0x0d, 0x83, 0x9d, - 0x51, 0x0f, 0xa4, 0xf2, 0x12, 0x89, 0x29, 0xc2, 0x28, 0x97, 0x4a, 0x89, 0x3f, 0x0b, 0x70, 0x58, - 0x35, 0xa9, 0xfb, 0xe7, 0x7e, 0x02, 0xf5, 0x5b, 0x0d, 0x97, 0x92, 0x58, 0xdd, 0xcf, 0x9b, 0xbd, - 0xef, 0xf0, 0x46, 0x57, 0x24, 0xde, 0xe6, 0x19, 0xbd, 0xb9, 0x4a, 0x14, 0xe1, 0x3a, 0x51, 0x84, - 0x5f, 0x89, 0x22, 0x7c, 0xd9, 0x28, 0xb5, 0xeb, 0x8d, 0x52, 0xfb, 0xb9, 0x51, 0x6a, 0x1f, 0x07, - 0x8e, 0x4b, 0x3f, 0x45, 0x33, 0x6d, 0x1e, 0x78, 0x7a, 0xb6, 0x6f, 0xcf, 0x17, 0xd6, 0x8c, 0xf0, - 0xb3, 0xbe, 0x1a, 0xea, 0xeb, 0xd2, 0x8f, 0x88, 0x5e, 0x2c, 0x31, 0x99, 0xed, 0xb1, 0xbf, 0xd0, - 0xf0, 0x4f, 0x00, 0x00, 0x00, 0xff, 0xff, 0x6b, 0xd0, 0xfa, 0xeb, 0xf7, 0x04, 0x00, 0x00, + // 534 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00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 0xdd, 0xe5, 0x18, 0xe1, 0xb6, 0x47, 0x37, 0x2c, 0x0b, 0x9b, 0x5a, 0xf6, 0xfa, + 0x68, 0xd0, 0x1e, 0x77, 0x92, 0x58, 0x95, 0x2e, 0xe8, 0x86, 0xf1, 0x9d, 0x67, 0x93, 0xb9, 0xe4, + 0x15, 0x1f, 0x16, 0x79, 0x8e, 0x3b, 0xdc, 0x24, 0xe6, 0x91, 0xda, 0xea, 0xdc, 0xd6, 0x4d, 0x62, + 0xb5, 0x9d, 0xda, 0xc4, 0xe0, 0x66, 0x93, 0x39, 0xc7, 0xe7, 0x9f, 0x56, 0x29, 0xfb, 0x27, 0x84, + 0x8f, 0xab, 0xce, 0xfd, 0xef, 0x67, 0x78, 0x82, 0x5b, 0x77, 0xe2, 0x4b, 0x49, 0xac, 0x36, 0xf3, + 0xe8, 0x4d, 0x5b, 0xc4, 0x26, 0xb8, 0x91, 0xfe, 0x4c, 0x9e, 0xf5, 0x60, 0xce, 0xd7, 0xbb, 0x3c, + 0xe3, 0xd7, 0x37, 0x89, 0x82, 0x6e, 0x13, 0x05, 0xfd, 0x48, 0x14, 0xf4, 0x79, 0xab, 0xd4, 0x6e, + 0xb7, 0x4a, 0xed, 0xfb, 0x56, 0xa9, 0x7d, 0x18, 0xda, 0x0e, 0xfb, 0x18, 0x2d, 0xb4, 0xa5, 0xef, + 0xea, 0xd9, 0xf4, 0x9e, 0xad, 0xcc, 0x05, 0x88, 0xb5, 0xbe, 0x1e, 0xe9, 0x9b, 0xd2, 0xb3, 0x66, + 0x57, 0x01, 0x85, 0xc5, 0x3e, 0x7f, 0xd3, 0xa3, 0x5f, 0x01, 0x00, 0x00, 0xff, 0xff, 0xa7, 0xe1, + 0x7e, 0xa8, 0x45, 0x04, 0x00, 0x00, } func (this *GenesisState) Equal(that interface{}) bool { @@ -458,39 +386,6 @@ func (this *SubspaceData) Equal(that interface{}) bool { } return true } -func (this *UserPermission) Equal(that interface{}) bool { - if that == nil { - return this == nil - } - - that1, ok := that.(*UserPermission) - if !ok { - that2, ok := that.(UserPermission) - if ok { - that1 = &that2 - } else { - return false - } - } - if that1 == nil { - return this == nil - } else if this == nil { - return false - } - if this.SubspaceID != that1.SubspaceID { - return false - } - if this.SectionID != that1.SectionID { - return false - } - if this.User != that1.User { - return false - } - if this.Permissions != that1.Permissions { - return false - } - return true -} func (this *UserGroupMemberEntry) Equal(that interface{}) bool { if that == nil { return this == nil @@ -671,51 +566,6 @@ func (m *SubspaceData) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } -func (m *UserPermission) Marshal() (dAtA []byte, err error) { - size := m.Size() - dAtA = make([]byte, size) - n, err := m.MarshalToSizedBuffer(dAtA[:size]) - if err != nil { - return nil, err - } - return dAtA[:n], nil -} - -func (m *UserPermission) MarshalTo(dAtA []byte) (int, error) { - size := m.Size() - return m.MarshalToSizedBuffer(dAtA[:size]) -} - -func (m *UserPermission) MarshalToSizedBuffer(dAtA []byte) (int, error) { - i := len(dAtA) - _ = i - var l int - _ = l - if m.Permissions != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.Permissions)) - i-- - dAtA[i] = 0x20 - } - if len(m.User) > 0 { - i -= len(m.User) - copy(dAtA[i:], m.User) - i = encodeVarintGenesis(dAtA, i, uint64(len(m.User))) - i-- - dAtA[i] = 0x1a - } - if m.SectionID != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.SectionID)) - i-- - dAtA[i] = 0x10 - } - if m.SubspaceID != 0 { - i = encodeVarintGenesis(dAtA, i, uint64(m.SubspaceID)) - i-- - dAtA[i] = 0x8 - } - return len(dAtA) - i, nil -} - func (m *UserGroupMemberEntry) Marshal() (dAtA []byte, err error) { size := m.Size() dAtA = make([]byte, size) @@ -833,28 +683,6 @@ func (m *SubspaceData) Size() (n int) { return n } -func (m *UserPermission) Size() (n int) { - if m == nil { - return 0 - } - var l int - _ = l - if m.SubspaceID != 0 { - n += 1 + sovGenesis(uint64(m.SubspaceID)) - } - if m.SectionID != 0 { - n += 1 + sovGenesis(uint64(m.SectionID)) - } - l = len(m.User) - if l > 0 { - n += 1 + l + sovGenesis(uint64(l)) - } - if m.Permissions != 0 { - n += 1 + sovGenesis(uint64(m.Permissions)) - } - return n -} - func (m *UserGroupMemberEntry) Size() (n int) { if m == nil { return 0 @@ -1260,145 +1088,6 @@ func (m *SubspaceData) Unmarshal(dAtA []byte) error { } return nil } -func (m *UserPermission) Unmarshal(dAtA []byte) error { - l := len(dAtA) - iNdEx := 0 - for iNdEx < l { - preIndex := iNdEx - var wire uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - wire |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - fieldNum := int32(wire >> 3) - wireType := int(wire & 0x7) - if wireType == 4 { - return fmt.Errorf("proto: UserPermission: wiretype end group for non-group") - } - if fieldNum <= 0 { - return fmt.Errorf("proto: UserPermission: illegal tag %d (wire type %d)", fieldNum, wire) - } - switch fieldNum { - case 1: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SubspaceID", wireType) - } - m.SubspaceID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SubspaceID |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 2: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field SectionID", wireType) - } - m.SectionID = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.SectionID |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - case 3: - if wireType != 2 { - return fmt.Errorf("proto: wrong wireType = %d for field User", wireType) - } - var stringLen uint64 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - stringLen |= uint64(b&0x7F) << shift - if b < 0x80 { - break - } - } - intStringLen := int(stringLen) - if intStringLen < 0 { - return ErrInvalidLengthGenesis - } - postIndex := iNdEx + intStringLen - if postIndex < 0 { - return ErrInvalidLengthGenesis - } - if postIndex > l { - return io.ErrUnexpectedEOF - } - m.User = string(dAtA[iNdEx:postIndex]) - iNdEx = postIndex - case 4: - if wireType != 0 { - return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType) - } - m.Permissions = 0 - for shift := uint(0); ; shift += 7 { - if shift >= 64 { - return ErrIntOverflowGenesis - } - if iNdEx >= l { - return io.ErrUnexpectedEOF - } - b := dAtA[iNdEx] - iNdEx++ - m.Permissions |= uint32(b&0x7F) << shift - if b < 0x80 { - break - } - } - default: - iNdEx = preIndex - skippy, err := skipGenesis(dAtA[iNdEx:]) - if err != nil { - return err - } - if (skippy < 0) || (iNdEx+skippy) < 0 { - return ErrInvalidLengthGenesis - } - if (iNdEx + skippy) > l { - return io.ErrUnexpectedEOF - } - iNdEx += skippy - } - } - - if iNdEx > l { - return io.ErrUnexpectedEOF - } - return nil -} func (m *UserGroupMemberEntry) Unmarshal(dAtA []byte) error { l := len(dAtA) iNdEx := 0 diff --git a/x/subspaces/types/genesis_test.go b/x/subspaces/types/genesis_test.go index 3821fbcb50..34d9581f35 100644 --- a/x/subspaces/types/genesis_test.go +++ b/x/subspaces/types/genesis_test.go @@ -92,15 +92,15 @@ func TestValidateGenesis(t *testing.T) { { name: "duplicated user permission returns error", genesis: types.NewGenesisState(1, nil, nil, nil, []types.UserPermission{ - types.NewUserPermission(1, 1, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.PermissionWrite), - types.NewUserPermission(1, 1, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.PermissionSetPermissions), + types.NewUserPermission(1, 1, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.NewPermissions(types.PermissionEditSubspace)), + types.NewUserPermission(1, 1, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.NewPermissions(types.PermissionSetPermissions)), }, nil, nil), shouldErr: true, }, { name: "invalid user permission returns error", genesis: types.NewGenesisState(1, nil, nil, nil, []types.UserPermission{ - types.NewUserPermission(0, 0, "", types.PermissionWrite), + types.NewUserPermission(0, 0, "", types.NewPermissions(types.PermissionEditSubspace)), }, nil, nil), shouldErr: true, }, @@ -113,7 +113,7 @@ func TestValidateGenesis(t *testing.T) { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), types.NewUserGroup( 1, @@ -121,7 +121,7 @@ func TestValidateGenesis(t *testing.T) { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, nil), shouldErr: true, @@ -135,7 +135,7 @@ func TestValidateGenesis(t *testing.T) { 0, "", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, nil), shouldErr: true, @@ -193,8 +193,8 @@ func TestValidateGenesis(t *testing.T) { types.NewSection(1, 1, 0, "Test section", "Test section"), }, []types.UserPermission{ - types.NewUserPermission(1, 0, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.PermissionWrite), - types.NewUserPermission(2, 0, "cosmos19gz9jn5pl6ke6qg5s4gt9ga9my7w8a0x3ar0qy", types.PermissionManageGroups), + types.NewUserPermission(1, 0, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.NewPermissions(types.PermissionEditSubspace)), + types.NewUserPermission(2, 0, "cosmos19gz9jn5pl6ke6qg5s4gt9ga9my7w8a0x3ar0qy", types.NewPermissions(types.PermissionManageGroups)), }, []types.UserGroup{ types.NewUserGroup( @@ -203,7 +203,7 @@ func TestValidateGenesis(t *testing.T) { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), types.NewUserGroup( 2, @@ -211,7 +211,7 @@ func TestValidateGenesis(t *testing.T) { 1, "Another test group", "This is another test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, []types.UserGroupMemberEntry{ @@ -290,22 +290,22 @@ func TestUserPermission_Validate(t *testing.T) { }{ { name: "invalid subspace id returns error", - entry: types.NewUserPermission(0, 1, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.PermissionWrite), + entry: types.NewUserPermission(0, 1, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.NewPermissions(types.PermissionEditSubspace)), shouldErr: true, }, { name: "invalid user returns error", - entry: types.NewUserPermission(1, 0, "", types.PermissionWrite), + entry: types.NewUserPermission(1, 0, "", types.NewPermissions(types.PermissionEditSubspace)), shouldErr: true, }, { name: "invalid permission returns error", - entry: types.NewUserPermission(1, 0, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", 9999), + entry: types.NewUserPermission(1, 0, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.NewPermissions("invalid")), shouldErr: true, }, { name: "valid user entry returns no error", - entry: types.NewUserPermission(1, 0, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.PermissionEverything), + entry: types.NewUserPermission(1, 0, "cosmos15p3m7a93luselt80ffzpf4jwtn9ama34ray0nd", types.NewPermissions(types.PermissionEverything)), shouldErr: false, }, } diff --git a/x/subspaces/types/hooks.go b/x/subspaces/types/hooks.go index d8a54fe1ae..ace3fc563a 100644 --- a/x/subspaces/types/hooks.go +++ b/x/subspaces/types/hooks.go @@ -25,8 +25,8 @@ type SubspacesHooks interface { AfterSubspaceGroupMemberRemoved(ctx sdk.Context, subspaceID uint64, groupID uint32, user string) // Must be called when a user is removed from a group AfterSubspaceGroupDeleted(ctx sdk.Context, subspaceID uint64, groupID uint32) // Must be called when a subspace group is deleted - AfterUserPermissionSet(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string, permissions Permission) // Must be called when a permission is set for a user - AfterUserPermissionRemoved(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string) // Must be called when a permission is removed for a user + AfterUserPermissionSet(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string, permissions Permissions) // Must be called when a permission is set for a user + AfterUserPermissionRemoved(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string) // Must be called when a permission is removed for a user } // -------------------------------------------------------------------------------------------------------------------- @@ -95,7 +95,7 @@ func (h MultiSubspacesHooks) AfterSubspaceGroupDeleted(ctx sdk.Context, subspace } // AfterUserPermissionSet implements SubspacesHook -func (h MultiSubspacesHooks) AfterUserPermissionSet(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string, permissions Permission) { +func (h MultiSubspacesHooks) AfterUserPermissionSet(ctx sdk.Context, subspaceID uint64, sectionID uint32, user string, permissions Permissions) { for _, hook := range h { hook.AfterUserPermissionSet(ctx, subspaceID, sectionID, user, permissions) } diff --git a/x/subspaces/types/models.go b/x/subspaces/types/models.go index 4def7501e1..0430b30a51 100644 --- a/x/subspaces/types/models.go +++ b/x/subspaces/types/models.go @@ -230,7 +230,7 @@ func ParseGroupID(value string) (uint32, error) { } // NewUserGroup returns a new UserGroup instance -func NewUserGroup(subspaceID uint64, sectionID uint32, id uint32, name, description string, permissions Permission) UserGroup { +func NewUserGroup(subspaceID uint64, sectionID uint32, id uint32, name, description string, permissions Permissions) UserGroup { return UserGroup{ SubspaceID: subspaceID, SectionID: sectionID, @@ -249,7 +249,7 @@ func DefaultUserGroup(subspaceID uint64) UserGroup { 0, "Default", "This is a default user group which all users are automatically part of", - PermissionNothing, + nil, ) } @@ -302,3 +302,33 @@ func NewGroupUpdate(name, description string) GroupUpdate { Description: description, } } + +// ------------------------------------------------------------------------------------------------------------------- + +// NewUserPermission returns a new UserPermission instance +func NewUserPermission(subspaceID uint64, sectionID uint32, user string, permissions Permissions) UserPermission { + return UserPermission{ + SubspaceID: subspaceID, + SectionID: sectionID, + User: user, + Permissions: permissions, + } +} + +// Validate implements fmt.Validator +func (p UserPermission) Validate() error { + if p.SubspaceID == 0 { + return fmt.Errorf("invalid subspace id: %d", p.SubspaceID) + } + + if !ArePermissionsValid(p.Permissions) { + return fmt.Errorf("invalid permissions: %s", p.Permissions) + } + + _, err := sdk.AccAddressFromBech32(p.User) + if err != nil { + return fmt.Errorf("invalid user address: %s", err) + } + + return nil +} diff --git a/x/subspaces/types/models.pb.go b/x/subspaces/types/models.pb.go index 257ca17874..f694d4bc2a 100644 --- a/x/subspaces/types/models.pb.go +++ b/x/subspaces/types/models.pb.go @@ -223,7 +223,7 @@ type UserGroup struct { // Optional description of this group Description string `protobuf:"bytes,5,opt,name=description,proto3" json:"description,omitempty" yaml:"description"` // Permissions that will be granted to all the users part of this group - Permissions uint32 `protobuf:"varint,6,opt,name=permissions,proto3" json:"permissions,omitempty" yaml:"permissions"` + Permissions Permissions `protobuf:"bytes,6,rep,name=permissions,proto3,castrepeated=Permissions" json:"permissions,omitempty" yaml:"permissions"` } func (m *UserGroup) Reset() { *m = UserGroup{} } @@ -294,59 +294,133 @@ func (m *UserGroup) GetDescription() string { return "" } -func (m *UserGroup) GetPermissions() uint32 { +func (m *UserGroup) GetPermissions() Permissions { if m != nil { return m.Permissions } + return nil +} + +// UserPermission represents a single Access Control List entry +type UserPermission struct { + SubspaceID uint64 `protobuf:"varint,1,opt,name=subspace_id,json=subspaceId,proto3" json:"subspace_id,omitempty"` + SectionID uint32 `protobuf:"varint,2,opt,name=section_id,json=sectionId,proto3" json:"section_id,omitempty"` + User string `protobuf:"bytes,3,opt,name=user,proto3" json:"user,omitempty"` + Permissions Permissions `protobuf:"bytes,4,rep,name=permissions,proto3,castrepeated=Permissions" json:"permissions,omitempty"` +} + +func (m *UserPermission) Reset() { *m = UserPermission{} } +func (m *UserPermission) String() string { return proto.CompactTextString(m) } +func (*UserPermission) ProtoMessage() {} +func (*UserPermission) Descriptor() ([]byte, []int) { + return fileDescriptor_a588429ec794f86a, []int{3} +} +func (m *UserPermission) XXX_Unmarshal(b []byte) error { + return m.Unmarshal(b) +} +func (m *UserPermission) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) { + if deterministic { + return xxx_messageInfo_UserPermission.Marshal(b, m, deterministic) + } else { + b = b[:cap(b)] + n, err := m.MarshalToSizedBuffer(b) + if err != nil { + return nil, err + } + return b[:n], nil + } +} +func (m *UserPermission) XXX_Merge(src proto.Message) { + xxx_messageInfo_UserPermission.Merge(m, src) +} +func (m *UserPermission) XXX_Size() int { + return m.Size() +} +func (m *UserPermission) XXX_DiscardUnknown() { + xxx_messageInfo_UserPermission.DiscardUnknown(m) +} + +var xxx_messageInfo_UserPermission proto.InternalMessageInfo + +func (m *UserPermission) GetSubspaceID() uint64 { + if m != nil { + return m.SubspaceID + } + return 0 +} + +func (m *UserPermission) GetSectionID() uint32 { + if m != nil { + return m.SectionID + } return 0 } +func (m *UserPermission) GetUser() string { + if m != nil { + return m.User + } + return "" +} + +func (m *UserPermission) GetPermissions() Permissions { + if m != nil { + return m.Permissions + } + return nil +} + func init() { proto.RegisterType((*Subspace)(nil), "desmos.subspaces.v2.Subspace") proto.RegisterType((*Section)(nil), "desmos.subspaces.v2.Section") proto.RegisterType((*UserGroup)(nil), "desmos.subspaces.v2.UserGroup") + proto.RegisterType((*UserPermission)(nil), "desmos.subspaces.v2.UserPermission") } func init() { proto.RegisterFile("desmos/subspaces/v2/models.proto", fileDescriptor_a588429ec794f86a) } var fileDescriptor_a588429ec794f86a = []byte{ - // 572 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0x31, 0x6f, 0xd3, 0x4e, - 0x18, 0xc6, 0x63, 0x27, 0x6d, 0xe3, 0x4b, 0xf3, 0x6f, 0xff, 0x4e, 0x85, 0xac, 0x0c, 0x3e, 0xeb, - 0x8a, 0x50, 0x06, 0xb0, 0xa5, 0x74, 0x41, 0x95, 0x18, 0x88, 0x40, 0x28, 0x12, 0x03, 0xba, 0xc2, - 0xc2, 0x12, 0x39, 0xf1, 0x11, 0x2c, 0xc5, 0x3e, 0xeb, 0xce, 0x09, 0x64, 0xe5, 0x13, 0x74, 0x64, - 0x41, 0xea, 0xc7, 0xe9, 0xd8, 0x91, 0x85, 0x03, 0x39, 0x0b, 0xb3, 0x3f, 0x01, 0xf2, 0x9d, 0xed, - 0x7a, 0x01, 0x81, 0x04, 0xdb, 0xdd, 0xfb, 0xfe, 0x9e, 0x37, 0xca, 0xf3, 0xbc, 0x3e, 0xe0, 0x04, - 0x84, 0x47, 0x94, 0x7b, 0x7c, 0x3d, 0xe7, 0x89, 0xbf, 0x20, 0xdc, 0xdb, 0x8c, 0xbd, 0x88, 0x06, - 0x64, 0xc5, 0xdd, 0x84, 0xd1, 0x94, 0x9a, 0x03, 0x45, 0xb8, 0x35, 0xe1, 0x6e, 0xc6, 0xc3, 0x93, - 0x25, 0x5d, 0x52, 0xd9, 0xf7, 0x8a, 0x93, 0x42, 0x87, 0x70, 0x49, 0xe9, 0x72, 0x45, 0x3c, 0x79, - 0x9b, 0xaf, 0xdf, 0x78, 0x69, 0x18, 0x11, 0x9e, 0xfa, 0x51, 0xa2, 0x00, 0xf4, 0xa1, 0x0d, 0xba, - 0x17, 0xe5, 0x1c, 0xf3, 0x14, 0xe8, 0x61, 0x60, 0x69, 0x8e, 0x36, 0xea, 0x4c, 0x06, 0x99, 0x80, - 0xfa, 0xf4, 0x49, 0x2e, 0xa0, 0xb1, 0xf5, 0xa3, 0xd5, 0x39, 0x0a, 0x03, 0x84, 0xf5, 0x30, 0x30, - 0x4f, 0x41, 0x27, 0xf6, 0x23, 0x62, 0xe9, 0x8e, 0x36, 0x32, 0x26, 0x47, 0xb9, 0x80, 0x3d, 0x05, - 0x14, 0x55, 0x84, 0x65, 0xd3, 0x7c, 0x08, 0x7a, 0x01, 0xe1, 0x0b, 0x16, 0x26, 0x69, 0x48, 0x63, - 0xab, 0x2d, 0xd9, 0x3b, 0xb9, 0x80, 0xa6, 0x62, 0x1b, 0x4d, 0x84, 0x9b, 0xa8, 0xe9, 0x81, 0x6e, - 0xca, 0x88, 0xcf, 0xd7, 0x6c, 0x6b, 0x75, 0xa4, 0x6c, 0x90, 0x0b, 0x78, 0xa4, 0x64, 0x55, 0x07, - 0xe1, 0x1a, 0x32, 0xef, 0x81, 0x3d, 0xfa, 0x2e, 0x26, 0xcc, 0xda, 0x93, 0xf4, 0x71, 0x2e, 0xe0, - 0xa1, 0xa2, 0x65, 0x19, 0x61, 0xd5, 0x36, 0xef, 0x83, 0x83, 0x05, 0x23, 0x7e, 0x4a, 0x99, 0xb5, - 0x2f, 0x49, 0x33, 0x17, 0xf0, 0x3f, 0x45, 0x96, 0x0d, 0x84, 0x2b, 0xc4, 0xf4, 0x41, 0x5f, 0x1e, - 0x43, 0x1a, 0xcf, 0x0a, 0xcf, 0xac, 0x03, 0x47, 0x1b, 0xf5, 0xc6, 0x43, 0x57, 0x19, 0xea, 0x56, - 0x86, 0xba, 0x2f, 0x2b, 0x43, 0x27, 0xce, 0xb5, 0x80, 0xad, 0x5c, 0xc0, 0x93, 0xc6, 0xcc, 0x4a, - 0x8e, 0x2e, 0xbf, 0x42, 0x0d, 0x1f, 0x56, 0xb5, 0x42, 0x74, 0xde, 0xfd, 0x78, 0x05, 0xb5, 0xef, - 0x57, 0x50, 0x43, 0x9f, 0x74, 0x70, 0x70, 0x41, 0x16, 0xf2, 0xff, 0x3f, 0x05, 0xbd, 0x2a, 0xd7, - 0x59, 0x1d, 0xc6, 0xdd, 0x4c, 0x40, 0x50, 0xc5, 0x24, 0x43, 0x29, 0x7d, 0x6c, 0xa0, 0x08, 0x83, - 0xea, 0x36, 0x0d, 0xca, 0x28, 0x8b, 0x8c, 0xfa, 0x3f, 0x8f, 0xf2, 0x11, 0x30, 0x12, 0x9f, 0x91, - 0x38, 0x2d, 0x7e, 0xa9, 0x2d, 0x59, 0x27, 0x13, 0xb0, 0xfb, 0x42, 0x16, 0xa5, 0xe2, 0x58, 0x29, - 0x6a, 0x0c, 0xe1, 0xae, 0x3a, 0x4f, 0x6f, 0x37, 0xa1, 0xf3, 0x07, 0x9b, 0xb0, 0xf7, 0xdb, 0x9b, - 0xd0, 0xf0, 0xe7, 0x8b, 0x0e, 0x8c, 0x57, 0x9c, 0xb0, 0x67, 0x8c, 0xae, 0x93, 0xbf, 0xe5, 0xd0, - 0x63, 0x00, 0xb8, 0xf2, 0x7c, 0x56, 0x3b, 0x85, 0x32, 0x01, 0x8d, 0x32, 0x09, 0x39, 0xe4, 0xff, - 0x72, 0x48, 0x0d, 0x22, 0x6c, 0x94, 0x97, 0xda, 0xe4, 0xf6, 0xaf, 0x4d, 0xfe, 0xb7, 0x2e, 0x15, - 0xca, 0x84, 0xb0, 0x28, 0xe4, 0x3c, 0xa4, 0x31, 0x97, 0xab, 0xdd, 0x6f, 0x2a, 0x1b, 0x4d, 0x84, - 0x9b, 0xe8, 0xad, 0xbf, 0x93, 0xe7, 0xd7, 0x99, 0xad, 0xdd, 0x64, 0xb6, 0xf6, 0x2d, 0xb3, 0xb5, - 0xcb, 0x9d, 0xdd, 0xba, 0xd9, 0xd9, 0xad, 0xcf, 0x3b, 0xbb, 0xf5, 0x7a, 0xbc, 0x0c, 0xd3, 0xb7, - 0xeb, 0xb9, 0xbb, 0xa0, 0x91, 0xa7, 0x5e, 0x9d, 0x07, 0x2b, 0x7f, 0xce, 0xcb, 0xb3, 0xb7, 0x39, - 0xf3, 0xde, 0x37, 0x1e, 0xaa, 0x74, 0x9b, 0x10, 0x3e, 0xdf, 0x97, 0xdf, 0xc6, 0xd9, 0x8f, 0x00, - 0x00, 0x00, 0xff, 0xff, 0x46, 0x67, 0x05, 0x9e, 0xc9, 0x04, 0x00, 0x00, + // 635 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x94, 0xbf, 0x6f, 0xd3, 0x4e, + 0x14, 0xc0, 0xe3, 0x24, 0x6d, 0xe3, 0x4b, 0x7f, 0x7d, 0xaf, 0xd5, 0x57, 0x56, 0x87, 0x9c, 0x75, + 0x05, 0x94, 0xa1, 0xd8, 0x22, 0x5d, 0x50, 0x25, 0x06, 0x22, 0x50, 0x55, 0x89, 0xa1, 0xba, 0xc2, + 0xc2, 0x52, 0x39, 0xf1, 0x11, 0x2c, 0xc5, 0x39, 0xeb, 0xce, 0x29, 0x74, 0xe5, 0x2f, 0xe8, 0xc8, + 0x82, 0xd4, 0x99, 0xbf, 0x82, 0xb1, 0x63, 0x47, 0xa6, 0x2b, 0x72, 0x16, 0x06, 0x26, 0xff, 0x05, + 0xc8, 0x77, 0xb6, 0xe3, 0x48, 0x05, 0x15, 0x09, 0xb6, 0x77, 0xf7, 0x3e, 0xef, 0xac, 0xf7, 0x79, + 0xe7, 0x03, 0xb6, 0x4f, 0x45, 0xc8, 0x84, 0x2b, 0xa6, 0x03, 0x11, 0x79, 0x43, 0x2a, 0xdc, 0xb3, + 0x9e, 0x1b, 0x32, 0x9f, 0x8e, 0x85, 0x13, 0x71, 0x16, 0x33, 0xb8, 0xa5, 0x09, 0xa7, 0x24, 0x9c, + 0xb3, 0xde, 0xce, 0xf6, 0x88, 0x8d, 0x98, 0xca, 0xbb, 0x59, 0xa4, 0xd1, 0x1d, 0x34, 0x62, 0x6c, + 0x34, 0xa6, 0xae, 0x5a, 0x0d, 0xa6, 0x6f, 0xdc, 0x38, 0x08, 0xa9, 0x88, 0xbd, 0x30, 0xd2, 0x00, + 0xfe, 0xd0, 0x00, 0xad, 0x93, 0xfc, 0x1c, 0xb8, 0x0b, 0xea, 0x81, 0x6f, 0x19, 0xb6, 0xd1, 0x6d, + 0xf6, 0xb7, 0x12, 0x89, 0xea, 0x47, 0xcf, 0x52, 0x89, 0xcc, 0x73, 0x2f, 0x1c, 0x1f, 0xe0, 0xc0, + 0xc7, 0xa4, 0x1e, 0xf8, 0x70, 0x17, 0x34, 0x27, 0x5e, 0x48, 0xad, 0xba, 0x6d, 0x74, 0xcd, 0xfe, + 0x46, 0x2a, 0x51, 0x5b, 0x03, 0xd9, 0x2e, 0x26, 0x2a, 0x09, 0x1f, 0x83, 0xb6, 0x4f, 0xc5, 0x90, + 0x07, 0x51, 0x1c, 0xb0, 0x89, 0xd5, 0x50, 0xec, 0xff, 0xa9, 0x44, 0x50, 0xb3, 0x95, 0x24, 0x26, + 0x55, 0x14, 0xba, 0xa0, 0x15, 0x73, 0xea, 0x89, 0x29, 0x3f, 0xb7, 0x9a, 0xaa, 0x6c, 0x2b, 0x95, + 0x68, 0x43, 0x97, 0x15, 0x19, 0x4c, 0x4a, 0x08, 0x3e, 0x00, 0x4b, 0xec, 0xdd, 0x84, 0x72, 0x6b, + 0x49, 0xd1, 0x9b, 0xa9, 0x44, 0xab, 0x9a, 0x56, 0xdb, 0x98, 0xe8, 0x34, 0xdc, 0x03, 0x2b, 0x43, + 0x4e, 0xbd, 0x98, 0x71, 0x6b, 0x59, 0x91, 0x30, 0x95, 0x68, 0x5d, 0x93, 0x79, 0x02, 0x93, 0x02, + 0x81, 0x1e, 0x58, 0x53, 0x61, 0xc0, 0x26, 0xa7, 0x99, 0x33, 0x6b, 0xc5, 0x36, 0xba, 0xed, 0xde, + 0x8e, 0xa3, 0x85, 0x3a, 0x85, 0x50, 0xe7, 0x65, 0x21, 0xb4, 0x6f, 0x5f, 0x49, 0x54, 0x4b, 0x25, + 0xda, 0xae, 0x9c, 0x59, 0x94, 0xe3, 0x8b, 0x1b, 0x64, 0x90, 0xd5, 0x62, 0x2f, 0x2b, 0x3a, 0x68, + 0x7d, 0xbc, 0x44, 0xc6, 0xf7, 0x4b, 0x64, 0xe0, 0x4f, 0x75, 0xb0, 0x72, 0x42, 0x87, 0xaa, 0xff, + 0xe7, 0xa0, 0x5d, 0xcc, 0xf5, 0xb4, 0x1c, 0xc6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xdb, 0xb8, + 0x5b, 0x0b, 0xfd, 0x17, 0x57, 0x49, 0xc7, 0xb8, 0x4e, 0x3a, 0xc6, 0xb7, 0xa4, 0x63, 0x5c, 0xcc, + 0x3a, 0xb5, 0xeb, 0x59, 0xa7, 0xf6, 0x75, 0xd6, 0xa9, 0xbd, 0xee, 0x8d, 0x82, 0xf8, 0xed, 0x74, + 0xe0, 0x0c, 0x59, 0xe8, 0xea, 0x77, 0xf4, 0xe1, 0xd8, 0x1b, 0x88, 0x3c, 0x76, 0xcf, 0xf6, 0xdd, + 0xf7, 0x95, 0xa7, 0x37, 0x3e, 0x8f, 0xa8, 0x18, 0x2c, 0xab, 0xbf, 0x7d, 0xff, 0x67, 0x00, 0x00, + 0x00, 0xff, 0xff, 0xd0, 0x46, 0x09, 0xc4, 0x9b, 0x05, 0x00, 0x00, } func (this *Subspace) Equal(that interface{}) bool { @@ -461,9 +535,52 @@ func (this *UserGroup) Equal(that interface{}) bool { if this.Description != that1.Description { return false } - if this.Permissions != that1.Permissions { + if len(this.Permissions) != len(that1.Permissions) { + return false + } + for i := range this.Permissions { + if this.Permissions[i] != that1.Permissions[i] { + return false + } + } + return true +} +func (this *UserPermission) Equal(that interface{}) bool { + if that == nil { + return this == nil + } + + that1, ok := that.(*UserPermission) + if !ok { + that2, ok := that.(UserPermission) + if ok { + that1 = &that2 + } else { + return false + } + } + if that1 == nil { + return this == nil + } else if this == nil { + return false + } + if this.SubspaceID != that1.SubspaceID { + return false + } + if this.SectionID != that1.SectionID { + return false + } + if this.User != that1.User { + return false + } + if len(this.Permissions) != len(that1.Permissions) { return false } + for i := range this.Permissions { + if this.Permissions[i] != that1.Permissions[i] { + return false + } + } return true } func (m *Subspace) Marshal() (dAtA []byte, err error) { @@ -609,10 +726,14 @@ func (m *UserGroup) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Permissions != 0 { - i = encodeVarintModels(dAtA, i, uint64(m.Permissions)) - i-- - dAtA[i] = 0x30 + if len(m.Permissions) > 0 { + for iNdEx := len(m.Permissions) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Permissions[iNdEx]) + copy(dAtA[i:], m.Permissions[iNdEx]) + i = encodeVarintModels(dAtA, i, uint64(len(m.Permissions[iNdEx]))) + i-- + dAtA[i] = 0x32 + } } if len(m.Description) > 0 { i -= len(m.Description) @@ -646,6 +767,55 @@ func (m *UserGroup) MarshalToSizedBuffer(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +func (m *UserPermission) Marshal() (dAtA []byte, err error) { + size := m.Size() + dAtA = make([]byte, size) + n, err := m.MarshalToSizedBuffer(dAtA[:size]) + if err != nil { + return nil, err + } + return dAtA[:n], nil +} + +func (m *UserPermission) MarshalTo(dAtA []byte) (int, error) { + size := m.Size() + return m.MarshalToSizedBuffer(dAtA[:size]) +} + +func (m *UserPermission) MarshalToSizedBuffer(dAtA []byte) (int, error) { + i := len(dAtA) + _ = i + var l int + _ = l + if len(m.Permissions) > 0 { + for iNdEx := len(m.Permissions) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Permissions[iNdEx]) + copy(dAtA[i:], m.Permissions[iNdEx]) + i = encodeVarintModels(dAtA, i, uint64(len(m.Permissions[iNdEx]))) + i-- + dAtA[i] = 0x22 + } + } + if len(m.User) > 0 { + i -= len(m.User) + copy(dAtA[i:], m.User) + i = encodeVarintModels(dAtA, i, uint64(len(m.User))) + i-- + dAtA[i] = 0x1a + } + if m.SectionID != 0 { + i = encodeVarintModels(dAtA, i, uint64(m.SectionID)) + i-- + dAtA[i] = 0x10 + } + if m.SubspaceID != 0 { + i = encodeVarintModels(dAtA, i, uint64(m.SubspaceID)) + i-- + dAtA[i] = 0x8 + } + return len(dAtA) - i, nil +} + func encodeVarintModels(dAtA []byte, offset int, v uint64) int { offset -= sovModels(v) base := offset @@ -740,8 +910,36 @@ func (m *UserGroup) Size() (n int) { if l > 0 { n += 1 + l + sovModels(uint64(l)) } - if m.Permissions != 0 { - n += 1 + sovModels(uint64(m.Permissions)) + if len(m.Permissions) > 0 { + for _, s := range m.Permissions { + l = len(s) + n += 1 + l + sovModels(uint64(l)) + } + } + return n +} + +func (m *UserPermission) Size() (n int) { + if m == nil { + return 0 + } + var l int + _ = l + if m.SubspaceID != 0 { + n += 1 + sovModels(uint64(m.SubspaceID)) + } + if m.SectionID != 0 { + n += 1 + sovModels(uint64(m.SectionID)) + } + l = len(m.User) + if l > 0 { + n += 1 + l + sovModels(uint64(l)) + } + if len(m.Permissions) > 0 { + for _, s := range m.Permissions { + l = len(s) + n += 1 + l + sovModels(uint64(l)) + } } return n } @@ -1336,10 +1534,162 @@ func (m *UserGroup) Unmarshal(dAtA []byte) error { m.Description = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 6: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthModels + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModels + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Permissions = append(m.Permissions, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex + default: + iNdEx = preIndex + skippy, err := skipModels(dAtA[iNdEx:]) + if err != nil { + return err + } + if (skippy < 0) || (iNdEx+skippy) < 0 { + return ErrInvalidLengthModels + } + if (iNdEx + skippy) > l { + return io.ErrUnexpectedEOF + } + iNdEx += skippy + } + } + + if iNdEx > l { + return io.ErrUnexpectedEOF + } + return nil +} +func (m *UserPermission) Unmarshal(dAtA []byte) error { + l := len(dAtA) + iNdEx := 0 + for iNdEx < l { + preIndex := iNdEx + var wire uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + wire |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + fieldNum := int32(wire >> 3) + wireType := int(wire & 0x7) + if wireType == 4 { + return fmt.Errorf("proto: UserPermission: wiretype end group for non-group") + } + if fieldNum <= 0 { + return fmt.Errorf("proto: UserPermission: illegal tag %d (wire type %d)", fieldNum, wire) + } + switch fieldNum { + case 1: if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SubspaceID", wireType) + } + m.SubspaceID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SubspaceID |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 2: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field SectionID", wireType) + } + m.SectionID = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.SectionID |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } + case 3: + if wireType != 2 { + return fmt.Errorf("proto: wrong wireType = %d for field User", wireType) + } + var stringLen uint64 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowModels + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + stringLen |= uint64(b&0x7F) << shift + if b < 0x80 { + break + } + } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthModels + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModels + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.User = string(dAtA[iNdEx:postIndex]) + iNdEx = postIndex + case 4: + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType) } - m.Permissions = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowModels @@ -1349,11 +1699,24 @@ func (m *UserGroup) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Permissions |= uint32(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthModels + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthModels + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Permissions = append(m.Permissions, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipModels(dAtA[iNdEx:]) diff --git a/x/subspaces/types/models_test.go b/x/subspaces/types/models_test.go index 617991c11a..a86b106121 100644 --- a/x/subspaces/types/models_test.go +++ b/x/subspaces/types/models_test.go @@ -477,7 +477,7 @@ func TestUserGroup_Validate(t *testing.T) { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), shouldErr: true, }, @@ -489,7 +489,7 @@ func TestUserGroup_Validate(t *testing.T) { 1, "", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), shouldErr: true, }, @@ -501,7 +501,7 @@ func TestUserGroup_Validate(t *testing.T) { 1, " ", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), shouldErr: true, }, @@ -535,7 +535,7 @@ func TestUserGroup_Update(t *testing.T) { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), update: types.NewGroupUpdate( types.DoNotModify, @@ -547,7 +547,7 @@ func TestUserGroup_Update(t *testing.T) { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, { @@ -558,7 +558,7 @@ func TestUserGroup_Update(t *testing.T) { 1, "Test group", "This is a test group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), update: types.NewGroupUpdate( "New group name", @@ -570,7 +570,7 @@ func TestUserGroup_Update(t *testing.T) { 1, "New group name", "New group description", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), ), }, } diff --git a/x/subspaces/types/msgs.go b/x/subspaces/types/msgs.go index 64f05ee9dd..9e5932a2e2 100644 --- a/x/subspaces/types/msgs.go +++ b/x/subspaces/types/msgs.go @@ -1,6 +1,7 @@ package types import ( + "fmt" "strings" sdk "github.com/cosmos/cosmos-sdk/types" @@ -397,7 +398,7 @@ func NewMsgCreateUserGroup( sectionID uint32, name string, description string, - permissions uint32, + permissions Permissions, creator string, ) *MsgCreateUserGroup { return &MsgCreateUserGroup{ @@ -426,6 +427,10 @@ func (msg MsgCreateUserGroup) ValidateBasic() error { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid group name: %s", msg.Name) } + if !ArePermissionsValid(msg.DefaultPermissions) { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid permissions: %s", msg.DefaultPermissions) + } + _, err := sdk.AccAddressFromBech32(msg.Creator) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid creator address") @@ -549,7 +554,7 @@ func (msg MsgMoveUserGroup) GetSigners() []sdk.AccAddress { func NewMsgSetUserGroupPermissions( subspaceID uint64, groupID uint32, - permissions Permission, + permissions Permissions, signer string, ) *MsgSetUserGroupPermissions { return &MsgSetUserGroupPermissions{ @@ -572,6 +577,10 @@ func (msg MsgSetUserGroupPermissions) ValidateBasic() error { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid subspace id: %d", msg.SubspaceID) } + if !ArePermissionsValid(msg.Permissions) { + return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "invalid permissions: %s", msg.Permissions) + } + _, err := sdk.AccAddressFromBech32(msg.Signer) if err != nil { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid signer address") @@ -758,7 +767,7 @@ func NewMsgSetUserPermissions( subspaceID uint64, sectionID uint32, user string, - permissions uint32, + permissions Permissions, signer string, ) *MsgSetUserPermissions { return &MsgSetUserPermissions{ @@ -792,6 +801,10 @@ func (msg MsgSetUserPermissions) ValidateBasic() error { return sdkerrors.Wrapf(sdkerrors.ErrInvalidAddress, "invalid signer address") } + if !ArePermissionsValid(msg.Permissions) { + return fmt.Errorf("invalid permissions value: %s", msg.Permissions) + } + if msg.User == msg.Signer { return sdkerrors.Wrapf(sdkerrors.ErrInvalidRequest, "cannot set the permissions for yourself") } diff --git a/x/subspaces/types/msgs.pb.go b/x/subspaces/types/msgs.pb.go index 4f8145b0d7..48fcbff2a2 100644 --- a/x/subspaces/types/msgs.pb.go +++ b/x/subspaces/types/msgs.pb.go @@ -743,7 +743,7 @@ type MsgCreateUserGroup struct { // (optional) Description of the group Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty" yaml:"description"` // Default permissions to be applied to the group - DefaultPermissions uint32 `protobuf:"varint,5,opt,name=default_permissions,json=defaultPermissions,proto3" json:"default_permissions,omitempty" yaml:"default_permissions"` + DefaultPermissions []string `protobuf:"bytes,5,rep,name=default_permissions,json=defaultPermissions,proto3" json:"default_permissions,omitempty" yaml:"default_permissions"` // Creator of the group Creator string `protobuf:"bytes,6,opt,name=creator,proto3" json:"creator,omitempty" yaml:"creator"` } @@ -809,11 +809,11 @@ func (m *MsgCreateUserGroup) GetDescription() string { return "" } -func (m *MsgCreateUserGroup) GetDefaultPermissions() uint32 { +func (m *MsgCreateUserGroup) GetDefaultPermissions() []string { if m != nil { return m.DefaultPermissions } - return 0 + return nil } func (m *MsgCreateUserGroup) GetCreator() string { @@ -1106,7 +1106,7 @@ type MsgSetUserGroupPermissions struct { // Id of the group for which to set the new permissions GroupID uint32 `protobuf:"varint,2,opt,name=group_id,json=groupId,proto3" json:"group_id,omitempty" yaml:"group_id"` // New permissions to be set to the group - Permissions uint32 `protobuf:"varint,3,opt,name=permissions,proto3" json:"permissions,omitempty" yaml:"permissions"` + Permissions []string `protobuf:"bytes,3,rep,name=permissions,proto3" json:"permissions,omitempty" yaml:"permissions"` // User setting the new permissions Signer string `protobuf:"bytes,4,opt,name=signer,proto3" json:"signer,omitempty" yaml:"signer"` } @@ -1158,11 +1158,11 @@ func (m *MsgSetUserGroupPermissions) GetGroupID() uint32 { return 0 } -func (m *MsgSetUserGroupPermissions) GetPermissions() uint32 { +func (m *MsgSetUserGroupPermissions) GetPermissions() []string { if m != nil { return m.Permissions } - return 0 + return nil } func (m *MsgSetUserGroupPermissions) GetSigner() string { @@ -1545,7 +1545,7 @@ type MsgSetUserPermissions struct { // User for which to set the permissions User string `protobuf:"bytes,3,opt,name=user,proto3" json:"user,omitempty" yaml:"user"` // Permissions to be set to the user - Permissions uint32 `protobuf:"varint,4,opt,name=permissions,proto3" json:"permissions,omitempty" yaml:"permissions"` + Permissions []string `protobuf:"bytes,4,rep,name=permissions,proto3" json:"permissions,omitempty" yaml:"permissions"` // User signing the message Signer string `protobuf:"bytes,5,opt,name=signer,proto3" json:"signer,omitempty" yaml:"signer"` } @@ -1604,11 +1604,11 @@ func (m *MsgSetUserPermissions) GetUser() string { return "" } -func (m *MsgSetUserPermissions) GetPermissions() uint32 { +func (m *MsgSetUserPermissions) GetPermissions() []string { if m != nil { return m.Permissions } - return 0 + return nil } func (m *MsgSetUserPermissions) GetSigner() string { @@ -1692,85 +1692,85 @@ func init() { func init() { proto.RegisterFile("desmos/subspaces/v2/msgs.proto", fileDescriptor_d549e2340fbe3f45) } var fileDescriptor_d549e2340fbe3f45 = []byte{ - // 1240 bytes of a gzipped FileDescriptorProto + // 1243 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe4, 0x99, 0x4d, 0x6f, 0xe3, 0x44, - 0x18, 0xc7, 0x6b, 0x27, 0xed, 0xb6, 0x4f, 0x9a, 0xbe, 0xb8, 0xfb, 0x92, 0x35, 0x10, 0x57, 0xb3, - 0xed, 0x96, 0x2e, 0xdb, 0x44, 0xca, 0x1e, 0x58, 0x56, 0xe2, 0xb0, 0x61, 0x17, 0x54, 0x41, 0x77, - 0x57, 0x5e, 0x10, 0x12, 0x12, 0xaa, 0x92, 0x7a, 0x70, 0x23, 0x9a, 0x38, 0xf2, 0x38, 0x2d, 0x3d, - 0xf7, 0xc2, 0x8d, 0x15, 0x1f, 0x00, 0xed, 0x01, 0x4e, 0x7c, 0x0a, 0x0e, 0x08, 0x8e, 0x7b, 0xe4, - 0x64, 0xa1, 0xf4, 0x02, 0x07, 0x38, 0xe4, 0xcc, 0x01, 0x79, 0xc6, 0x1e, 0x8f, 0x93, 0x38, 0xb1, - 0xab, 0x00, 0x01, 0x6e, 0xce, 0xcc, 0xdf, 0x33, 0xf3, 0xfc, 0x9e, 0x97, 0x99, 0x71, 0xa0, 0x68, - 0x60, 0xd2, 0xb4, 0x48, 0x99, 0x74, 0xea, 0xa4, 0x5d, 0x3b, 0xc0, 0xa4, 0x7c, 0x5c, 0x29, 0x37, - 0x89, 0x49, 0x4a, 0x6d, 0xdb, 0x72, 0x2c, 0x65, 0x8d, 0xf5, 0x97, 0x78, 0x7f, 0xe9, 0xb8, 0xa2, - 0x5e, 0x36, 0x2d, 0xd3, 0xa2, 0xfd, 0x65, 0xef, 0x89, 0x49, 0xd5, 0xf5, 0xa1, 0x43, 0x59, 0x06, - 0x3e, 0xf2, 0x07, 0x43, 0x67, 0x32, 0xac, 0xee, 0x11, 0xf3, 0x2d, 0x1b, 0xd7, 0x1c, 0xfc, 0xd4, - 0x97, 0x29, 0x37, 0x20, 0xdb, 0xaa, 0x35, 0x71, 0x41, 0x5a, 0x97, 0x5e, 0x5d, 0xa8, 0x2e, 0xf7, - 0x5c, 0x2d, 0x77, 0x5a, 0x6b, 0x1e, 0xdd, 0x43, 0x5e, 0x2b, 0xd2, 0x69, 0xa7, 0x72, 0x17, 0x72, - 0x06, 0x26, 0x07, 0x76, 0xa3, 0xed, 0x34, 0xac, 0x56, 0x41, 0xa6, 0xda, 0xab, 0x3d, 0x57, 0x53, - 0x98, 0x56, 0xe8, 0x44, 0xba, 0x28, 0x55, 0xca, 0x30, 0xef, 0xd8, 0xb8, 0x46, 0x3a, 0xf6, 0x69, - 0x21, 0x43, 0x5f, 0x5b, 0xeb, 0xb9, 0xda, 0x32, 0x7b, 0x2d, 0xe8, 0x41, 0x3a, 0x17, 0x29, 0x37, - 0x61, 0xd6, 0x3a, 0x69, 0x61, 0xbb, 0x90, 0xa5, 0xea, 0x95, 0x9e, 0xab, 0x2d, 0x32, 0x35, 0x6d, - 0x46, 0x3a, 0xeb, 0x56, 0x6e, 0xc3, 0xa5, 0x03, 0xcf, 0x12, 0xcb, 0x2e, 0xcc, 0x52, 0xa5, 0xd2, - 0x73, 0xb5, 0x25, 0xa6, 0xf4, 0x3b, 0x90, 0x1e, 0x48, 0xee, 0xcd, 0x7f, 0xfe, 0x5c, 0x9b, 0xf9, - 0xe5, 0xb9, 0x36, 0x83, 0xea, 0x70, 0x7d, 0x00, 0x82, 0x8e, 0x49, 0xdb, 0x6a, 0x11, 0xac, 0x3c, - 0x84, 0x5c, 0xc0, 0x6f, 0xbf, 0x61, 0x50, 0x26, 0xd9, 0xea, 0x46, 0xd7, 0xd5, 0x20, 0x90, 0xee, - 0x3e, 0x08, 0xad, 0x16, 0xa4, 0x48, 0x87, 0xe0, 0xd7, 0xae, 0x81, 0xbe, 0x97, 0x61, 0x79, 0x8f, - 0x98, 0x0f, 0x8d, 0x86, 0xc3, 0x39, 0x4f, 0x66, 0x68, 0xee, 0x2e, 0x39, 0x85, 0xbb, 0x32, 0x17, - 0x73, 0x57, 0x36, 0x95, 0xbb, 0x66, 0x47, 0xbb, 0x6b, 0x1b, 0xe6, 0x48, 0xc3, 0xf4, 0x84, 0x73, - 0x54, 0xb8, 0xda, 0x73, 0xb5, 0xbc, 0x6f, 0x2b, 0x6d, 0x47, 0xba, 0x2f, 0x10, 0x7c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x86, 0x19, 0xd4, 0xaa, 0x95, 0xe4, 0xda, 0x08, 0xe8, 0xb8, - 0x6d, 0x3d, 0xd6, 0x84, 0x98, 0x17, 0xe2, 0x41, 0x8f, 0xd9, 0x48, 0x3d, 0xdb, 0x87, 0x6c, 0xa2, - 0xb7, 0xc6, 0xf8, 0x4d, 0xf4, 0x71, 0x25, 0xb9, 0x36, 0x98, 0xb5, 0xfa, 0xde, 0x8f, 0xdd, 0xa2, - 0xf4, 0xa2, 0x5b, 0x94, 0x7e, 0xee, 0x16, 0xa5, 0x67, 0xe7, 0xc5, 0x99, 0x17, 0xe7, 0xc5, 0x99, - 0x9f, 0xce, 0x8b, 0x33, 0x1f, 0x55, 0xcc, 0x86, 0x73, 0xd8, 0xa9, 0x97, 0x0e, 0xac, 0x66, 0x99, - 0x8d, 0xbb, 0x73, 0x54, 0xab, 0x13, 0xff, 0xb9, 0x7c, 0x7c, 0xa7, 0xfc, 0x99, 0xf0, 0x2f, 0x87, - 0x73, 0xda, 0xc6, 0xa4, 0x3e, 0x47, 0xff, 0xe2, 0xb8, 0xf3, 0x67, 0x00, 0x00, 0x00, 0xff, 0xff, - 0x56, 0x84, 0xd9, 0xa5, 0x51, 0x19, 0x00, 0x00, + 0x18, 0xc7, 0x6b, 0x27, 0xe9, 0xcb, 0x93, 0xbe, 0xba, 0xfb, 0x92, 0x35, 0x10, 0x57, 0xb3, 0xed, + 0x76, 0xbb, 0x6c, 0x13, 0x29, 0x7b, 0x60, 0x59, 0x89, 0xc3, 0x86, 0x5d, 0x50, 0x05, 0xdd, 0x5d, + 0x79, 0x41, 0x48, 0x48, 0xa8, 0x4a, 0xea, 0xc1, 0x8d, 0x68, 0xe2, 0xc8, 0xe3, 0xb4, 0xf4, 0xdc, + 0x0b, 0x37, 0x56, 0x7c, 0x00, 0xb4, 0x07, 0x38, 0xf1, 0x29, 0x38, 0x20, 0x38, 0xee, 0x91, 0x93, + 0x85, 0xd2, 0x0b, 0x1c, 0xe0, 0x90, 0x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 0x9c, 0x7a, + 0x71, 0x56, 0x9c, 0xfa, 0xf9, 0xac, 0x38, 0xf5, 0x71, 0xc5, 0x6c, 0x38, 0x07, 0x9d, 0x7a, 0x69, + 0xdf, 0x6a, 0x96, 0xd9, 0xb8, 0xdb, 0x87, 0xb5, 0x3a, 0xf1, 0x9f, 0xcb, 0x47, 0x77, 0xca, 0x9f, + 0x0b, 0xff, 0x72, 0x38, 0x27, 0x6d, 0x4c, 0xea, 0xd3, 0xf4, 0x2f, 0x8e, 0x3b, 0x7f, 0x05, 0x00, + 0x00, 0xff, 0xff, 0x99, 0xd1, 0x9f, 0xb6, 0x51, 0x19, 0x00, 0x00, } // Reference imports to suppress errors if they are not otherwise used. @@ -2936,10 +2936,14 @@ func (m *MsgCreateUserGroup) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x32 } - if m.DefaultPermissions != 0 { - i = encodeVarintMsgs(dAtA, i, uint64(m.DefaultPermissions)) - i-- - dAtA[i] = 0x28 + if len(m.DefaultPermissions) > 0 { + for iNdEx := len(m.DefaultPermissions) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.DefaultPermissions[iNdEx]) + copy(dAtA[i:], m.DefaultPermissions[iNdEx]) + i = encodeVarintMsgs(dAtA, i, uint64(len(m.DefaultPermissions[iNdEx]))) + i-- + dAtA[i] = 0x2a + } } if len(m.Description) > 0 { i -= len(m.Description) @@ -3168,10 +3172,14 @@ func (m *MsgSetUserGroupPermissions) MarshalToSizedBuffer(dAtA []byte) (int, err i-- dAtA[i] = 0x22 } - if m.Permissions != 0 { - i = encodeVarintMsgs(dAtA, i, uint64(m.Permissions)) - i-- - dAtA[i] = 0x18 + if len(m.Permissions) > 0 { + for iNdEx := len(m.Permissions) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Permissions[iNdEx]) + copy(dAtA[i:], m.Permissions[iNdEx]) + i = encodeVarintMsgs(dAtA, i, uint64(len(m.Permissions[iNdEx]))) + i-- + dAtA[i] = 0x1a + } } if m.GroupID != 0 { i = encodeVarintMsgs(dAtA, i, uint64(m.GroupID)) @@ -3439,10 +3447,14 @@ func (m *MsgSetUserPermissions) MarshalToSizedBuffer(dAtA []byte) (int, error) { i-- dAtA[i] = 0x2a } - if m.Permissions != 0 { - i = encodeVarintMsgs(dAtA, i, uint64(m.Permissions)) - i-- - dAtA[i] = 0x20 + if len(m.Permissions) > 0 { + for iNdEx := len(m.Permissions) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Permissions[iNdEx]) + copy(dAtA[i:], m.Permissions[iNdEx]) + i = encodeVarintMsgs(dAtA, i, uint64(len(m.Permissions[iNdEx]))) + i-- + dAtA[i] = 0x22 + } } if len(m.User) > 0 { i -= len(m.User) @@ -3759,8 +3771,11 @@ func (m *MsgCreateUserGroup) Size() (n int) { if l > 0 { n += 1 + l + sovMsgs(uint64(l)) } - if m.DefaultPermissions != 0 { - n += 1 + sovMsgs(uint64(m.DefaultPermissions)) + if len(m.DefaultPermissions) > 0 { + for _, s := range m.DefaultPermissions { + l = len(s) + n += 1 + l + sovMsgs(uint64(l)) + } } l = len(m.Creator) if l > 0 { @@ -3860,8 +3875,11 @@ func (m *MsgSetUserGroupPermissions) Size() (n int) { if m.GroupID != 0 { n += 1 + sovMsgs(uint64(m.GroupID)) } - if m.Permissions != 0 { - n += 1 + sovMsgs(uint64(m.Permissions)) + if len(m.Permissions) > 0 { + for _, s := range m.Permissions { + l = len(s) + n += 1 + l + sovMsgs(uint64(l)) + } } l = len(m.Signer) if l > 0 { @@ -3987,8 +4005,11 @@ func (m *MsgSetUserPermissions) Size() (n int) { if l > 0 { n += 1 + l + sovMsgs(uint64(l)) } - if m.Permissions != 0 { - n += 1 + sovMsgs(uint64(m.Permissions)) + if len(m.Permissions) > 0 { + for _, s := range m.Permissions { + l = len(s) + n += 1 + l + sovMsgs(uint64(l)) + } } l = len(m.Signer) if l > 0 { @@ -5699,10 +5720,10 @@ func (m *MsgCreateUserGroup) Unmarshal(dAtA []byte) error { m.Description = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 5: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field DefaultPermissions", wireType) } - m.DefaultPermissions = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowMsgs @@ -5712,11 +5733,24 @@ func (m *MsgCreateUserGroup) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.DefaultPermissions |= uint32(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthMsgs + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMsgs + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.DefaultPermissions = append(m.DefaultPermissions, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex case 6: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Creator", wireType) @@ -6330,10 +6364,10 @@ func (m *MsgSetUserGroupPermissions) Unmarshal(dAtA []byte) error { } } case 3: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType) } - m.Permissions = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowMsgs @@ -6343,11 +6377,24 @@ func (m *MsgSetUserGroupPermissions) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Permissions |= uint32(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthMsgs + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMsgs + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Permissions = append(m.Permissions, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex case 4: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) @@ -7125,10 +7172,10 @@ func (m *MsgSetUserPermissions) Unmarshal(dAtA []byte) error { m.User = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 4: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType) } - m.Permissions = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowMsgs @@ -7138,11 +7185,24 @@ func (m *MsgSetUserPermissions) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Permissions |= uint32(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthMsgs + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthMsgs + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Permissions = append(m.Permissions, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex case 5: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Signer", wireType) diff --git a/x/subspaces/types/msgs_test.go b/x/subspaces/types/msgs_test.go index f7619b497c..25d93fa388 100644 --- a/x/subspaces/types/msgs_test.go +++ b/x/subspaces/types/msgs_test.go @@ -581,7 +581,7 @@ var msgCreateUserGroup = types.NewMsgCreateUserGroup( 0, "Group", "Description", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ) @@ -606,7 +606,7 @@ func TestMsgCreateUserGroup_ValidateBasic(t *testing.T) { 1, "group", "description", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ), shouldErr: true, @@ -618,7 +618,19 @@ func TestMsgCreateUserGroup_ValidateBasic(t *testing.T) { 1, "", "description", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), + "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", + ), + shouldErr: true, + }, + { + name: "invalid permissions return error", + msg: types.NewMsgCreateUserGroup( + 1, + 1, + "group", + "description", + types.NewPermissions("INVALID"), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ), shouldErr: true, @@ -630,7 +642,7 @@ func TestMsgCreateUserGroup_ValidateBasic(t *testing.T) { 1, "group", "description", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kl", ), shouldErr: true, @@ -655,7 +667,7 @@ func TestMsgCreateUserGroup_ValidateBasic(t *testing.T) { } func TestMsgCreateUserGroup_GetSignBytes(t *testing.T) { - expected := `{"type":"desmos/MsgCreateUserGroup","value":{"creator":"cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5","default_permissions":1,"description":"Description","name":"Group","subspace_id":"1"}}` + expected := `{"type":"desmos/MsgCreateUserGroup","value":{"creator":"cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5","default_permissions":["EDIT_SUBSPACE"],"description":"Description","name":"Group","subspace_id":"1"}}` require.Equal(t, expected, string(msgCreateUserGroup.GetSignBytes())) } @@ -816,7 +828,7 @@ func TestMsgMoveUserGroup_GetSigners(t *testing.T) { var msgSetUserGroupPermissions = types.NewMsgSetUserGroupPermissions( 1, 1, - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ) @@ -839,7 +851,17 @@ func TestMsgSetUserGroupPermissions_ValidateBasic(t *testing.T) { msg: types.NewMsgSetUserGroupPermissions( 0, 1, - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), + "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", + ), + shouldErr: true, + }, + { + name: "invalid permissions return error", + msg: types.NewMsgSetUserGroupPermissions( + 1, + 1, + types.NewPermissions("INVALID"), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ), shouldErr: true, @@ -849,7 +871,7 @@ func TestMsgSetUserGroupPermissions_ValidateBasic(t *testing.T) { msg: types.NewMsgSetUserGroupPermissions( 1, 1, - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kl", ), shouldErr: true, @@ -874,7 +896,7 @@ func TestMsgSetUserGroupPermissions_ValidateBasic(t *testing.T) { } func TestMsgSetUserGroupPermissions_GetSignBytes(t *testing.T) { - expected := `{"type":"desmos/MsgSetUserGroupPermissions","value":{"group_id":1,"permissions":1,"signer":"cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5","subspace_id":"1"}}` + expected := `{"type":"desmos/MsgSetUserGroupPermissions","value":{"group_id":1,"permissions":["EDIT_SUBSPACE"],"signer":"cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5","subspace_id":"1"}}` require.Equal(t, expected, string(msgSetUserGroupPermissions.GetSignBytes())) } @@ -1150,7 +1172,7 @@ var msgSetUserPermissions = types.NewMsgSetUserPermissions( 1, 0, "cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ) @@ -1174,7 +1196,7 @@ func TestMsgSetUserPermissions_ValidateBasic(t *testing.T) { 0, 1, "group", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ), shouldErr: true, @@ -1185,7 +1207,7 @@ func TestMsgSetUserPermissions_ValidateBasic(t *testing.T) { 1, 1, "", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ), shouldErr: true, @@ -1196,7 +1218,7 @@ func TestMsgSetUserPermissions_ValidateBasic(t *testing.T) { 1, 1, "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7d", ), shouldErr: true, @@ -1207,7 +1229,7 @@ func TestMsgSetUserPermissions_ValidateBasic(t *testing.T) { 1, 1, "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", - types.PermissionWrite, + types.NewPermissions(types.PermissionEditSubspace), "cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5", ), shouldErr: true, @@ -1232,7 +1254,7 @@ func TestMsgSetUserPermissions_ValidateBasic(t *testing.T) { } func TestMsgSetUserPermissions_GetSignBytes(t *testing.T) { - expected := `{"type":"desmos/MsgSetUserPermissions","value":{"permissions":1,"signer":"cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5","subspace_id":"1","user":"cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53"}}` + expected := `{"type":"desmos/MsgSetUserPermissions","value":{"permissions":["EDIT_SUBSPACE"],"signer":"cosmos1m0czrla04f7rp3zg7dsgc4kla54q7pc4xt00l5","subspace_id":"1","user":"cosmos1x5pjlvufs4znnhhkwe8v4tw3kz30f3lxgwza53"}}` require.Equal(t, expected, string(msgSetUserPermissions.GetSignBytes())) } diff --git a/x/subspaces/types/permissions.go b/x/subspaces/types/permissions.go index fc2602bf37..025bc7c67c 100644 --- a/x/subspaces/types/permissions.go +++ b/x/subspaces/types/permissions.go @@ -1,139 +1,155 @@ package types import ( - "encoding/binary" "fmt" + "regexp" "strings" ) -// Permission represents a permission that can be set to a user or user group -type Permission = uint32 - -const ( - // PermissionNothing represents the permission to do nothing - PermissionNothing = Permission(0) - - // PermissionWrite identifies users that can create content inside the subspace - PermissionWrite = Permission(1) +var ( + // PermissionEditSubspace allows to change the information of the subspace + PermissionEditSubspace = RegisterPermission("edit subspace") - // PermissionModerateContent allows users to moderate contents of other users (e.g. deleting it) - PermissionModerateContent = Permission(0b010) + // PermissionDeleteSubspace allows users to delete the subspace. + PermissionDeleteSubspace = RegisterPermission("delete subspace") - // PermissionChangeInfo allows to change the information of the subspace - PermissionChangeInfo = Permission(0b0100) + // PermissionManageSections allows users to manage a subspace sections + PermissionManageSections = RegisterPermission("manage sections") // PermissionManageGroups allows users to manage user groups and members - PermissionManageGroups = Permission(0b01000) + PermissionManageGroups = RegisterPermission("manage groups") // PermissionSetPermissions allows users to set other users' permissions (except PermissionSetPermissions). // This includes managing user groups and the associated permissions - PermissionSetPermissions = Permission(0b010000) - - // PermissionDeleteSubspace allows users to delete the subspace. - PermissionDeleteSubspace = Permission(0b100000) - - // PermissionManageSections allows users to manage subspace sections. - PermissionManageSections = Permission(0b1000000) - - // PermissionInteractWithContent allows users to interact with content inside the subspace (eg. polls) - PermissionInteractWithContent = Permission(0b10000000) - - // PermissionEditOwnContent allows users to edit their own content inside the subspace - PermissionEditOwnContent = Permission(0b100000000) - - // PermissionReportContent allows users to report contents - PermissionReportContent = Permission(0b1000000000) - - // PermissionDeleteOwnReports allows users to delete existing reports made by their own - PermissionDeleteOwnReports = Permission(0b10000000000) - - // PermissionManageReports allows users to manage other users reports - PermissionManageReports = Permission(0b100000000000) - - // PermissionManageReasons allows users to manage a subspace reasons for reporting - PermissionManageReasons = Permission(0b1000000000000) + PermissionSetPermissions = RegisterPermission("set permissions") // PermissionEverything allows to do everything. // This should usually be reserved only to the owner (which has it by default) - PermissionEverything = Permission(0b1111111111111) + PermissionEverything = RegisterPermission("everything") ) var ( - permissionsMap = map[Permission]string{ - PermissionNothing: "Nothing", - PermissionWrite: "Write", - PermissionModerateContent: "ModerateContent", - PermissionChangeInfo: "ChangeInfo", - PermissionManageGroups: "ManageGroups", - PermissionSetPermissions: "SetPermissions", - PermissionDeleteSubspace: "DeleteSubspace", - PermissionInteractWithContent: "InteractWithContent", - PermissionEditOwnContent: "EditOwnContent", - PermissionReportContent: "ReportContent", - PermissionDeleteOwnReports: "DeleteOwnReports", - PermissionManageReports: "ManageReports", - PermissionManageReasons: "ManageReasons", - PermissionEverything: "Everything", - } + // multipleSpacesRegex represents the regex used to search for multiple spaces when registering a permission + multipleSpacesRegex = regexp.MustCompile(`\s+`) + + // registeredPermissions represents the list of permissions that are registered and should be considered valid + registeredPermissions []Permission ) -// ParsePermission parses the given permission string as a single Permissions instance -func ParsePermission(permission string) (Permission, error) { - // Check inside the map if we have anything here - for permValue, permString := range permissionsMap { - if strings.EqualFold(permission, permString) { - return permValue, nil +// Permission represents a permission that can be set to a user or user group +type Permission = string + +// newPermission returns a new Permission containing the given value +func newPermission(permissionName string) Permission { + permissionName = multipleSpacesRegex.ReplaceAllString(permissionName, " ") + permissionName = strings.ReplaceAll(permissionName, " ", "_") + return strings.ToUpper(permissionName) +} + +// containsPermission tells whether the given permissions slice contains the provided permissions +func containsPermission(slice []Permission, permission Permission) bool { + for _, element := range slice { + if element == permission { + return true } } + return false +} + +// isPermissionRegistered checks if the given permissions is registered or not +func isPermissionRegistered(permission Permission) bool { + return containsPermission(registeredPermissions, permission) +} + +// RegisterPermission registers the permissions with the given name and returns its value +func RegisterPermission(permissionName string) Permission { + permission := newPermission(permissionName) + if isPermissionRegistered(permission) { + panic(fmt.Errorf("permissions %s has already been registered", permission)) + } - return 0, fmt.Errorf("invalid permission value: %s", permission) + registeredPermissions = append(registeredPermissions, permission) + return permission } -// SerializePermission serializes the given permission to a string value +// SerializePermission serializes the given permissions to a string value func SerializePermission(permission Permission) string { - return permissionsMap[permission] + return permission } -// MarshalPermission marshals the given permission to a byte array -func MarshalPermission(permission Permission) (permissionBytes []byte) { - permissionBytes = make([]byte, 4) - binary.BigEndian.PutUint32(permissionBytes, permission) - return +type Permissions []Permission + +// NewPermissions allows to build a new Permissions instance +func NewPermissions(permissions ...Permission) Permissions { + return permissions } -// UnmarshalPermission reads the given byte array as a Permission object -func UnmarshalPermission(bz []byte) (permission Permission) { - if len(bz) < 4 { - return PermissionNothing +// Equals returns true iff the given permissions slice is equals to this one +func (p Permissions) Equals(other Permissions) bool { + if len(p) != len(other) { + return false } - return binary.BigEndian.Uint32(bz) + + for i, element := range p { + if element != other[i] { + return false + } + } + + return true } -// CheckPermission checks whether the given permissions contain the specified permission -func CheckPermission(permissions Permission, permission Permission) bool { - return (permissions & permission) == permission +// CheckPermission checks whether the given permissions contain the specified permissions +func CheckPermission(permissions Permissions, permission Permission) bool { + // If PermissionEverything is set, every permission will be valid + if containsPermission(permissions, PermissionEverything) { + return true + } + + // Otherwise, check for the specific permissions + return containsPermission(permissions, permission) +} + +func CheckPermissions(permissions Permissions, toCheck Permissions) bool { + for _, permission := range toCheck { + if !CheckPermission(permissions, permission) { + return false + } + } + return true } // CombinePermissions combines all the given permissions into a single Permission object using the OR operator -func CombinePermissions(permissions ...Permission) Permission { - result := PermissionNothing - for _, permission := range permissions { - result |= permission +func CombinePermissions(permissions ...Permission) Permissions { + // If the given slice contains PermissionEverything, then just return that one + if containsPermission(permissions, PermissionEverything) { + return Permissions{PermissionEverything} } - return result + return SanitizePermissions(permissions) } -// SanitizePermission sanitizes the given permission to remove any unwanted bits set to 1 -func SanitizePermission(permission Permission) Permission { - mask := PermissionNothing - for perm := range permissionsMap { - mask = CombinePermissions(mask, perm) +// SanitizePermissions sanitizes the given permissions to remove any duplicate +func SanitizePermissions(permissions Permissions) (sanitized Permissions) { + existing := map[Permission]bool{} + for _, permission := range permissions { + if !isPermissionRegistered(permission) { + // Skip invalid permissions + continue + } + + if _, exists := existing[permission]; exists { + // If a permission already exists, skip it + continue + } + + sanitized = append(sanitized, permission) + existing[permission] = true } - return permission & mask + return sanitized } -// IsPermissionValid checks whether the given value represents a valid permission or not -func IsPermissionValid(permission Permission) bool { - return SanitizePermission(permission) == permission +// ArePermissionsValid checks whether the given value represents a valid permissions or not +func ArePermissionsValid(permissions Permissions) bool { + return SanitizePermissions(permissions).Equals(permissions) } diff --git a/x/subspaces/types/permissions_test.go b/x/subspaces/types/permissions_test.go index f6c29ca8e2..be4924e636 100644 --- a/x/subspaces/types/permissions_test.go +++ b/x/subspaces/types/permissions_test.go @@ -8,71 +8,65 @@ import ( "github.com/desmos-labs/desmos/v3/x/subspaces/types" ) -func TestMarshalPermission(t *testing.T) { +func TestRegisterPermission(t *testing.T) { testCases := []struct { name string - permission types.Permission - expected []byte + permission string + shouldErr bool + check func() }{ { - name: "zero permission", - permission: types.PermissionNothing, - expected: []byte{0, 0, 0, 0}, + name: "already registered permission returns error", + permission: types.PermissionEverything, + shouldErr: true, }, { - name: "non-zero permission", - permission: types.PermissionManageGroups, - expected: []byte{0, 0, 0, 8}, + name: "permission with spaces is registered properly", + permission: "custom permission", + shouldErr: false, + check: func() { + require.True(t, types.ArePermissionsValid(types.NewPermissions("CUSTOM_PERMISSION"))) + }, }, { - name: "high permission", - permission: types.PermissionSetPermissions, - expected: []byte{0, 0, 0, 16}, + name: "permission with multiple spaces is registered properly", + permission: "multiple spaces", + shouldErr: false, + check: func() { + require.True(t, types.ArePermissionsValid(types.NewPermissions("MULTIPLE_SPACES"))) + }, }, - } - - for _, tc := range testCases { - tc := tc - t.Run(tc.name, func(t *testing.T) { - bz := types.MarshalPermission(tc.permission) - require.Equal(t, tc.expected, bz) - }) - } -} - -func TestUnmarshalPermission(t *testing.T) { - testCases := []struct { - name string - bz []byte - expected types.Permission - }{ { - name: "empty byte array", - bz: []byte{}, - expected: types.PermissionNothing, + name: "permission with return space is registered properly", + permission: `return +space`, + shouldErr: false, + check: func() { + require.True(t, types.ArePermissionsValid(types.NewPermissions("RETURN_SPACE"))) + }, }, { - name: "nil bytes array", - bz: nil, - expected: types.PermissionNothing, - }, - { - name: "zero permission", - bz: []byte{0, 0, 0, 0}, - expected: types.PermissionNothing, - }, - { - name: "non-zero permission", - bz: []byte{0, 0, 0, 4}, - expected: types.PermissionChangeInfo, + name: "permission with multiple return and spaces is registered properly", + permission: `multiple + return spaces`, + shouldErr: false, + check: func() { + require.True(t, types.ArePermissionsValid(types.NewPermissions("MULTIPLE_RETURN_SPACES"))) + }, }, } for _, tc := range testCases { tc := tc t.Run(tc.name, func(t *testing.T) { - permission := types.UnmarshalPermission(tc.bz) - require.Equal(t, tc.expected, permission) + if tc.shouldErr { + require.Panics(t, func() { types.RegisterPermission(tc.permission) }) + } else { + require.NotPanics(t, func() { types.RegisterPermission(tc.permission) }) + if tc.check != nil { + tc.check() + } + } }) } } @@ -80,31 +74,31 @@ func TestUnmarshalPermission(t *testing.T) { func TestCheckPermission(t *testing.T) { testCases := []struct { name string - permissions types.Permission + permissions types.Permissions permission types.Permission expResult bool }{ { name: "same permission returns true", - permissions: types.PermissionWrite, - permission: types.PermissionWrite, + permissions: types.NewPermissions(types.PermissionEditSubspace), + permission: types.PermissionEditSubspace, expResult: true, }, { name: "different permission returns false", - permissions: types.PermissionWrite, + permissions: types.NewPermissions(types.PermissionEditSubspace), permission: types.PermissionSetPermissions, expResult: false, }, { name: "combined permission returns true when contains", - permissions: types.PermissionWrite | types.PermissionModerateContent | types.PermissionManageGroups, - permission: types.PermissionModerateContent, + permissions: types.CombinePermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace, types.PermissionManageGroups), + permission: types.PermissionDeleteSubspace, expResult: true, }, { name: "combined permission returns false when does not contain", - permissions: types.PermissionWrite | types.PermissionModerateContent | types.PermissionManageGroups, + permissions: types.CombinePermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace, types.PermissionManageGroups), permission: types.PermissionSetPermissions, expResult: false, }, @@ -123,27 +117,22 @@ func TestCombinePermissions(t *testing.T) { testCases := []struct { name string permissions []types.Permission - expResult types.Permission + expResult types.Permissions }{ { name: "combining the same permission returns the permission itself", - permissions: []types.Permission{types.PermissionWrite, types.PermissionWrite}, - expResult: types.PermissionWrite, - }, - { - name: "combining anything with PermissionNothing returns the permission itself", - permissions: []types.Permission{types.PermissionNothing, types.PermissionWrite}, - expResult: types.PermissionWrite, + permissions: []types.Permission{types.PermissionEditSubspace, types.PermissionEditSubspace}, + expResult: types.NewPermissions(types.PermissionEditSubspace), }, { name: "combining anything with PermissionEverything returns PermissionEverything", - permissions: []types.Permission{types.PermissionWrite, types.PermissionEverything}, - expResult: types.PermissionEverything, + permissions: []types.Permission{types.PermissionEditSubspace, types.PermissionEverything}, + expResult: types.NewPermissions(types.PermissionEverything), }, { name: "combining different permissions returns the correct result", - permissions: []types.Permission{types.PermissionWrite, types.PermissionManageGroups, types.PermissionSetPermissions}, - expResult: types.PermissionWrite | types.PermissionManageGroups | types.PermissionSetPermissions, + permissions: []types.Permission{types.PermissionEditSubspace, types.PermissionManageGroups, types.PermissionSetPermissions}, + expResult: types.CombinePermissions(types.PermissionEditSubspace, types.PermissionManageGroups, types.PermissionSetPermissions), }, } @@ -158,73 +147,68 @@ func TestCombinePermissions(t *testing.T) { func TestSanitizePermission(t *testing.T) { testCases := []struct { - name string - permission types.Permission - expResult types.Permission + name string + permissions types.Permissions + expResult types.Permissions }{ { - name: "valid permission returns the same value", - permission: types.PermissionWrite, - expResult: types.PermissionWrite, - }, - { - name: "combined permission returns the same value", - permission: types.PermissionWrite & types.PermissionChangeInfo, - expResult: types.PermissionWrite & types.PermissionChangeInfo, + name: "valid permission returns the same value", + permissions: types.NewPermissions(types.PermissionEditSubspace), + expResult: types.NewPermissions(types.PermissionEditSubspace), }, { - name: "invalid permission returns permission everything", - permission: 4294967295, - expResult: types.PermissionEverything, + name: "combined permission returns the same value", + permissions: types.CombinePermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace), + expResult: types.CombinePermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace), }, { - name: "extra bits are set to 0", - permission: 0b11111111111111111110000000000001, - expResult: types.PermissionWrite, + name: "invalid permission returns permission nothing", + permissions: types.NewPermissions(""), + expResult: nil, }, } for _, tc := range testCases { tc := tc t.Run(tc.name, func(t *testing.T) { - result := types.SanitizePermission(tc.permission) + result := types.SanitizePermissions(tc.permissions) require.Equal(t, tc.expResult, result) }) } } -func TestIsPermissionValid(t *testing.T) { +func TestArePermissionsValid(t *testing.T) { testCases := []struct { - name string - permission types.Permission - expValid bool + name string + permissions types.Permissions + expValid bool }{ { - name: "valid permission returns true", - permission: types.PermissionWrite, - expValid: true, + name: "valid permission returns true", + permissions: types.NewPermissions(types.PermissionEditSubspace), + expValid: true, }, { - name: "valid combined permission returns true", - permission: types.PermissionWrite & types.PermissionChangeInfo, - expValid: true, + name: "valid combined permission returns true", + permissions: types.NewPermissions(types.PermissionEditSubspace, types.PermissionDeleteSubspace), + expValid: true, }, { - name: "invalid permission returns false", - permission: 99999, - expValid: false, + name: "invalid permission returns false", + permissions: types.NewPermissions(""), + expValid: false, }, { - name: "invalid combined permission returns false", - permission: 0b11111111111111111111111111000001, - expValid: false, + name: "invalid combined permission returns false", + permissions: types.NewPermissions(types.PermissionEditSubspace, ""), + expValid: false, }, } for _, tc := range testCases { tc := tc t.Run(tc.name, func(t *testing.T) { - valid := types.IsPermissionValid(tc.permission) + valid := types.ArePermissionsValid(tc.permissions) require.Equal(t, tc.expValid, valid) }) } diff --git a/x/subspaces/types/query.go b/x/subspaces/types/query.go index b3d17b6696..5f6b74c474 100644 --- a/x/subspaces/types/query.go +++ b/x/subspaces/types/query.go @@ -71,28 +71,28 @@ func NewQueryUserPermissionsRequest(subspaceID uint64, user string) *QueryUserPe } // NewPermissionDetailUser returns a new PermissionDetail for the user with the given address and permission value -func NewPermissionDetailUser(subspaceID uint64, sectionID uint32, user string, permission Permission) PermissionDetail { +func NewPermissionDetailUser(subspaceID uint64, sectionID uint32, user string, permissions Permissions) PermissionDetail { return PermissionDetail{ SubspaceId: subspaceID, SectionId: sectionID, Sum: &PermissionDetail_User_{ User: &PermissionDetail_User{ User: user, - Permission: permission, + Permission: permissions, }, }, } } // NewPermissionDetailGroup returns a new PermissionDetail for the user with the given id and permission value -func NewPermissionDetailGroup(subspaceID uint64, sectionID uint32, groupID uint32, permission Permission) PermissionDetail { +func NewPermissionDetailGroup(subspaceID uint64, sectionID uint32, groupID uint32, permissions Permissions) PermissionDetail { return PermissionDetail{ SubspaceId: subspaceID, SectionId: sectionID, Sum: &PermissionDetail_Group_{ Group: &PermissionDetail_Group{ GroupID: groupID, - Permission: permission, + Permission: permissions, }, }, } diff --git a/x/subspaces/types/query.pb.go b/x/subspaces/types/query.pb.go index 95213339ec..89b0160979 100644 --- a/x/subspaces/types/query.pb.go +++ b/x/subspaces/types/query.pb.go @@ -800,7 +800,7 @@ var xxx_messageInfo_QueryUserPermissionsRequest proto.InternalMessageInfo // QueryUserPermissionsRequest is the response type for the // Query/UserPermissions method type QueryUserPermissionsResponse struct { - Permissions uint32 `protobuf:"varint,1,opt,name=permissions,proto3" json:"permissions,omitempty" yaml:"permissions"` + Permissions []string `protobuf:"bytes,1,rep,name=permissions,proto3" json:"permissions,omitempty" yaml:"permissions"` Details []PermissionDetail `protobuf:"bytes,2,rep,name=details,proto3" json:"details" yaml:"details"` } @@ -837,11 +837,11 @@ func (m *QueryUserPermissionsResponse) XXX_DiscardUnknown() { var xxx_messageInfo_QueryUserPermissionsResponse proto.InternalMessageInfo -func (m *QueryUserPermissionsResponse) GetPermissions() uint32 { +func (m *QueryUserPermissionsResponse) GetPermissions() []string { if m != nil { return m.Permissions } - return 0 + return nil } func (m *QueryUserPermissionsResponse) GetDetails() []PermissionDetail { @@ -949,8 +949,8 @@ func (*PermissionDetail) XXX_OneofWrappers() []interface{} { type PermissionDetail_User struct { // User for which the permission was set User string `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty" yaml:"user"` - // Permission set to the user - Permission uint32 `protobuf:"varint,2,opt,name=permission,proto3" json:"permission,omitempty" yaml:"permission"` + // Permissions set to the user + Permission []string `protobuf:"bytes,2,rep,name=permission,proto3" json:"permission,omitempty" yaml:"permission"` } func (m *PermissionDetail_User) Reset() { *m = PermissionDetail_User{} } @@ -990,8 +990,8 @@ var xxx_messageInfo_PermissionDetail_User proto.InternalMessageInfo type PermissionDetail_Group struct { // Unique id of the group GroupID uint32 `protobuf:"varint,1,opt,name=group_id,json=groupId,proto3" json:"group_id,omitempty" yaml:"group_id"` - // Permission set to the group - Permission uint32 `protobuf:"varint,2,opt,name=permission,proto3" json:"permission,omitempty"` + // Permissions set to the group + Permission []string `protobuf:"bytes,2,rep,name=permission,proto3" json:"permission,omitempty"` } func (m *PermissionDetail_Group) Reset() { *m = PermissionDetail_Group{} } @@ -1054,75 +1054,75 @@ func init() { proto.RegisterFile("desmos/subspaces/v2/query.proto", fileDescript var fileDescriptor_acc17cc7a389b584 = []byte{ // 1113 bytes of a gzipped FileDescriptorProto 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xbc, 0x97, 0xcf, 0x6f, 0x1b, 0x45, - 0x14, 0xc7, 0x3d, 0x89, 0x53, 0xdb, 0xcf, 0x2a, 0x29, 0x93, 0x36, 0x44, 0x26, 0xd9, 0x8d, 0x16, - 0x51, 0xd2, 0xa4, 0xdd, 0xc1, 0x4e, 0x2b, 0x4a, 0x40, 0x6d, 0x6a, 0xaa, 0xfc, 0x90, 0x00, 0x95, - 0x85, 0x8a, 0x1f, 0x97, 0x6a, 0x1d, 0x8f, 0x8c, 0x25, 0xdb, 0xeb, 0x7a, 0xec, 0x88, 0x28, 0x8a, - 0x40, 0x3d, 0x71, 0xe0, 0x80, 0x84, 0x04, 0xd7, 0x1c, 0x7a, 0xe4, 0xc2, 0x0d, 0x89, 0x03, 0x37, - 0x54, 0x4e, 0x44, 0xe2, 0xc2, 0xc9, 0x42, 0x09, 0x07, 0xce, 0xfe, 0x0b, 0xd0, 0xce, 0xce, 0xcc, - 0xae, 0xd7, 0x8b, 0xb3, 0x8e, 0xa3, 0xde, 0xec, 0x99, 0xf7, 0xe6, 0x7d, 0xde, 0x77, 0xde, 0xf3, - 0x3c, 0x83, 0x5e, 0xa6, 0xac, 0xee, 0x30, 0xc2, 0x3a, 0x25, 0xd6, 0xb4, 0x77, 0x28, 0x23, 0xbb, - 0x05, 0xf2, 0xb8, 0x43, 0x5b, 0x7b, 0x66, 0xb3, 0xe5, 0xb4, 0x1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6, 0xd0, 0xdf, 0xc7, 0x1a, 0xfa, 0xf6, 0x44, - 0x4b, 0x1c, 0x9d, 0x68, 0x89, 0xbf, 0x4e, 0xb4, 0xc4, 0x67, 0x85, 0x4a, 0xb5, 0xfd, 0x79, 0xa7, - 0x64, 0xee, 0x38, 0x75, 0x11, 0xe4, 0x46, 0xcd, 0x2e, 0x31, 0x19, 0x70, 0x77, 0x95, 0x7c, 0x11, - 0x08, 0xd4, 0xde, 0x6b, 0x52, 0x56, 0xba, 0xc0, 0xff, 0xfe, 0xaf, 0xfe, 0x17, 0x00, 0x00, 0xff, - 0xff, 0x0c, 0x3a, 0x51, 0x65, 0xb8, 0x10, 0x00, 0x00, + 0x14, 0xc7, 0x3d, 0x89, 0x53, 0xdb, 0xcf, 0x82, 0x96, 0x49, 0x1b, 0x22, 0x93, 0xec, 0x46, 0x8b, + 0x28, 0x69, 0xd2, 0xee, 0x12, 0xa7, 0x15, 0x25, 0xa0, 0x36, 0x35, 0x55, 0x7e, 0x48, 0x80, 0xca, + 0x42, 0xc5, 0x8f, 0x4b, 0xb5, 0x8e, 0x47, 0xc6, 0x92, 0xed, 0x75, 0x3d, 0x76, 0x44, 0x14, 0x45, + 0xa0, 0x9e, 0x38, 0x70, 0x40, 0x42, 0x82, 0x6b, 0x0e, 0x3d, 0x72, 0xe1, 0x86, 0xc4, 0x81, 0x1b, + 0x2a, 0x27, 0x22, 0x71, 0xe1, 0x64, 0xa1, 0x84, 0x03, 0x67, 0xff, 0x05, 0x68, 0x67, 0x67, 0x66, + 0x67, 0xd7, 0x8b, 0xb3, 0x8e, 0x23, 0x6e, 0xce, 0xcc, 0x7b, 0xf3, 0x3e, 0xef, 0x3b, 0xef, 0xed, + 0xbc, 0x80, 0x5e, 0x21, 0xb4, 0xe1, 0x52, 0x8b, 0x76, 0xcb, 0xb4, 0xe5, 0xec, 0x10, 0x6a, 0xed, + 0x16, 0xad, 0xc7, 0x5d, 0xd2, 0xde, 0x33, 0x5b, 0x6d, 0x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3c, 0x32, + 0x31, 0xfe, 0x0c, 0x23, 0x0b, 0x0f, 0x7b, 0x43, 0xc9, 0x22, 0x53, 0x99, 0xb1, 0xca, 0xc8, 0x6e, + 0xe0, 0xe5, 0x58, 0xb2, 0x10, 0x8f, 0x25, 0x47, 0xb1, 0x43, 0x04, 0x19, 0x7e, 0x12, 0x5e, 0x3c, + 0x35, 0x98, 0xc0, 0xba, 0x96, 0xc0, 0x92, 0x53, 0xad, 0x33, 0xaa, 0x35, 0x7c, 0x7b, 0x04, 0x2a, + 0x6b, 0x3f, 0x68, 0xf9, 0x03, 0xfc, 0x14, 0x01, 0x04, 0x73, 0x07, 0x1e, 0x52, 0x39, 0x03, 0x83, + 0x55, 0xe1, 0x7a, 0x32, 0x63, 0xce, 0xfa, 0x26, 0x63, 0xbd, 0x85, 0x57, 0x47, 0xb9, 0x5b, 0x8b, + 0x4f, 0x32, 0x3f, 0x20, 0xc8, 0xc9, 0x33, 0x87, 0xf5, 0x42, 0x74, 0x40, 0x29, 0x2c, 0x27, 0xb2, + 0xe5, 0x8c, 0x1b, 0x8c, 0x71, 0x1d, 0xdf, 0x39, 0x03, 0xa3, 0xb5, 0x2f, 0x3e, 0x04, 0x07, 0xf8, + 0x37, 0x04, 0x97, 0xa2, 0xef, 0x2f, 0x5e, 0x49, 0x40, 0x12, 0x9e, 0x3e, 0x0a, 0xc5, 0x51, 0x5c, + 0x78, 0x0e, 0xef, 0xb1, 0x1c, 0xb6, 0xf0, 0xc6, 0x78, 0x39, 0x58, 0x62, 0x28, 0xf8, 0x05, 0xc1, + 0xc5, 0xc8, 0x43, 0x88, 0x5f, 0x1b, 0xce, 0x35, 0xf8, 0xe2, 0x17, 0x56, 0x46, 0xf0, 0xe0, 0x89, + 0x6c, 0xb2, 0x44, 0xee, 0xe1, 0xbb, 0x23, 0x25, 0xa2, 0xbc, 0xb6, 0xd6, 0xbe, 0xf7, 0x22, 0x1c, + 0x94, 0xde, 0x79, 0x76, 0xac, 0xa1, 0xa3, 0x63, 0x0d, 0xfd, 0x75, 0xac, 0xa1, 0x6f, 0x4e, 0xb4, + 0xd4, 0xd1, 0x89, 0x96, 0xfa, 0xf3, 0x44, 0x4b, 0x7d, 0x5a, 0xac, 0xd6, 0x3a, 0x9f, 0x75, 0xcb, + 0xe6, 0x8e, 0xdb, 0xe0, 0x41, 0x6e, 0xd4, 0x9d, 0x32, 0x15, 0x01, 0x77, 0x57, 0xad, 0xcf, 0x95, + 0x40, 0x9d, 0xbd, 0x16, 0xa1, 0xe5, 0x0b, 0xec, 0xdf, 0xff, 0xd5, 0x7f, 0x03, 0x00, 0x00, 0xff, + 0xff, 0xdd, 0x01, 0xb5, 0x9b, 0xb8, 0x10, 0x00, 0x00, } func (this *PermissionDetail) Equal(that interface{}) bool { @@ -1231,9 +1231,14 @@ func (this *PermissionDetail_User) Equal(that interface{}) bool { if this.User != that1.User { return false } - if this.Permission != that1.Permission { + if len(this.Permission) != len(that1.Permission) { return false } + for i := range this.Permission { + if this.Permission[i] != that1.Permission[i] { + return false + } + } return true } func (this *PermissionDetail_Group) Equal(that interface{}) bool { @@ -1258,9 +1263,14 @@ func (this *PermissionDetail_Group) Equal(that interface{}) bool { if this.GroupID != that1.GroupID { return false } - if this.Permission != that1.Permission { + if len(this.Permission) != len(that1.Permission) { return false } + for i := range this.Permission { + if this.Permission[i] != that1.Permission[i] { + return false + } + } return true } @@ -2239,10 +2249,14 @@ func (m *QueryUserPermissionsResponse) MarshalToSizedBuffer(dAtA []byte) (int, e dAtA[i] = 0x12 } } - if m.Permissions != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.Permissions)) - i-- - dAtA[i] = 0x8 + if len(m.Permissions) > 0 { + for iNdEx := len(m.Permissions) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Permissions[iNdEx]) + copy(dAtA[i:], m.Permissions[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Permissions[iNdEx]))) + i-- + dAtA[i] = 0xa + } } return len(dAtA) - i, nil } @@ -2351,10 +2365,14 @@ func (m *PermissionDetail_User) MarshalToSizedBuffer(dAtA []byte) (int, error) { _ = i var l int _ = l - if m.Permission != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.Permission)) - i-- - dAtA[i] = 0x10 + if len(m.Permission) > 0 { + for iNdEx := len(m.Permission) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Permission[iNdEx]) + copy(dAtA[i:], m.Permission[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Permission[iNdEx]))) + i-- + dAtA[i] = 0x12 + } } if len(m.User) > 0 { i -= len(m.User) @@ -2386,10 +2404,14 @@ func (m *PermissionDetail_Group) MarshalToSizedBuffer(dAtA []byte) (int, error) _ = i var l int _ = l - if m.Permission != 0 { - i = encodeVarintQuery(dAtA, i, uint64(m.Permission)) - i-- - dAtA[i] = 0x10 + if len(m.Permission) > 0 { + for iNdEx := len(m.Permission) - 1; iNdEx >= 0; iNdEx-- { + i -= len(m.Permission[iNdEx]) + copy(dAtA[i:], m.Permission[iNdEx]) + i = encodeVarintQuery(dAtA, i, uint64(len(m.Permission[iNdEx]))) + i-- + dAtA[i] = 0x12 + } } if m.GroupID != 0 { i = encodeVarintQuery(dAtA, i, uint64(m.GroupID)) @@ -2653,8 +2675,11 @@ func (m *QueryUserPermissionsResponse) Size() (n int) { } var l int _ = l - if m.Permissions != 0 { - n += 1 + sovQuery(uint64(m.Permissions)) + if len(m.Permissions) > 0 { + for _, s := range m.Permissions { + l = len(s) + n += 1 + l + sovQuery(uint64(l)) + } } if len(m.Details) > 0 { for _, e := range m.Details { @@ -2717,8 +2742,11 @@ func (m *PermissionDetail_User) Size() (n int) { if l > 0 { n += 1 + l + sovQuery(uint64(l)) } - if m.Permission != 0 { - n += 1 + sovQuery(uint64(m.Permission)) + if len(m.Permission) > 0 { + for _, s := range m.Permission { + l = len(s) + n += 1 + l + sovQuery(uint64(l)) + } } return n } @@ -2732,8 +2760,11 @@ func (m *PermissionDetail_Group) Size() (n int) { if m.GroupID != 0 { n += 1 + sovQuery(uint64(m.GroupID)) } - if m.Permission != 0 { - n += 1 + sovQuery(uint64(m.Permission)) + if len(m.Permission) > 0 { + for _, s := range m.Permission { + l = len(s) + n += 1 + l + sovQuery(uint64(l)) + } } return n } @@ -4305,10 +4336,10 @@ func (m *QueryUserPermissionsResponse) Unmarshal(dAtA []byte) error { } switch fieldNum { case 1: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Permissions", wireType) } - m.Permissions = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -4318,11 +4349,24 @@ func (m *QueryUserPermissionsResponse) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Permissions |= uint32(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Permissions = append(m.Permissions, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex case 2: if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Details", wireType) @@ -4598,10 +4642,10 @@ func (m *PermissionDetail_User) Unmarshal(dAtA []byte) error { m.User = string(dAtA[iNdEx:postIndex]) iNdEx = postIndex case 2: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Permission", wireType) } - m.Permission = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -4611,11 +4655,24 @@ func (m *PermissionDetail_User) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Permission |= uint32(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Permission = append(m.Permission, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) @@ -4686,10 +4743,10 @@ func (m *PermissionDetail_Group) Unmarshal(dAtA []byte) error { } } case 2: - if wireType != 0 { + if wireType != 2 { return fmt.Errorf("proto: wrong wireType = %d for field Permission", wireType) } - m.Permission = 0 + var stringLen uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflowQuery @@ -4699,11 +4756,24 @@ func (m *PermissionDetail_Group) Unmarshal(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Permission |= uint32(b&0x7F) << shift + stringLen |= uint64(b&0x7F) << shift if b < 0x80 { break } } + intStringLen := int(stringLen) + if intStringLen < 0 { + return ErrInvalidLengthQuery + } + postIndex := iNdEx + intStringLen + if postIndex < 0 { + return ErrInvalidLengthQuery + } + if postIndex > l { + return io.ErrUnexpectedEOF + } + m.Permission = append(m.Permission, string(dAtA[iNdEx:postIndex])) + iNdEx = postIndex default: iNdEx = preIndex skippy, err := skipQuery(dAtA[iNdEx:]) diff --git a/x/subspaces/types/query.pb.gw.go b/x/subspaces/types/query.pb.gw.go index 617fcb8841..d37d4fa8dc 100644 --- a/x/subspaces/types/query.pb.gw.go +++ b/x/subspaces/types/query.pb.gw.go @@ -976,21 +976,21 @@ func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, clie } var ( - pattern_Query_Subspaces_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1}, []string{"desmos", "subspaces", "v1"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Subspaces_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1}, []string{"desmos", "subspaces", "v2"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_Subspace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3}, []string{"desmos", "subspaces", "v1", "subspace_id"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_Subspace_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3}, []string{"desmos", "subspaces", "v2", "subspace_id"}, "", runtime.AssumeColonVerbOpt(true))) pattern_Query_Sections_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"desmos", "subspaces", "v2", "subspace_id", "sections"}, "", runtime.AssumeColonVerbOpt(true))) pattern_Query_Section_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"desmos", "subspaces", "v2", "subspace_id", "sections", "section_id"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_UserGroups_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"desmos", "subspaces", "v1", "subspace_id", "groups"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_UserGroups_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3, 2, 4}, []string{"desmos", "subspaces", "v2", "subspace_id", "groups"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_UserGroup_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"desmos", "subspaces", "v1", "subspace_id", "groups", "group_id"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_UserGroup_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"desmos", "subspaces", "v2", "subspace_id", "groups", "group_id"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_UserGroupMembers_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5, 2, 6}, []string{"desmos", "subspaces", "v1", "subspace_id", "groups", "group_id", "members"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_UserGroupMembers_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5, 2, 6}, []string{"desmos", "subspaces", "v2", "subspace_id", "groups", "group_id", "members"}, "", runtime.AssumeColonVerbOpt(true))) - pattern_Query_UserPermissions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"desmos", "subspaces", "v1", "subspace_id", "permissions", "user"}, "", runtime.AssumeColonVerbOpt(true))) + pattern_Query_UserPermissions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 1, 1, 0, 4, 1, 5, 3, 2, 4, 1, 0, 4, 1, 5, 5}, []string{"desmos", "subspaces", "v2", "subspace_id", "permissions", "user"}, "", runtime.AssumeColonVerbOpt(true))) ) var (