Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: subspaces CLI commands and Proto files wrong notations #815

Merged
merged 10 commits into from
Apr 12, 2022
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
type: fix
module: x/subspaces
pull_request: 815
description: Fixed wrong Proto files notations and added missing CLI commands
backward_compatible: true
date: 2022-04-11T10:16:02.044442Z
10 changes: 5 additions & 5 deletions client/docs/swagger-ui/swagger.yaml
Original file line number Diff line number Diff line change
@@ -4008,7 +4008,7 @@ paths:
group_id:
type: integer
format: int64
title: Error that is associated with the failure
title: Unique id of the group
permission:
type: integer
format: int64
@@ -7785,7 +7785,7 @@ definitions:
group_id:
type: integer
format: int64
title: Error that is associated with the failure
title: Unique id of the group
permission:
type: integer
format: int64
@@ -7797,7 +7797,7 @@ definitions:
group_id:
type: integer
format: int64
title: Error that is associated with the failure
title: Unique id of the group
permission:
type: integer
format: int64
@@ -7813,7 +7813,7 @@ definitions:
type: integer
format: int64
title: Permission set to the user
title: Success is a permission that has been set to a specific user
title: User is a permission that has been set to a specific user
desmos.subspaces.v1.QuerySubspaceResponse:
type: object
properties:
@@ -8064,7 +8064,7 @@ definitions:
group_id:
type: integer
format: int64
title: Error that is associated with the failure
title: Unique id of the group
permission:
type: integer
format: int64
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -324,12 +324,10 @@ github.com/ethereum/go-ethereum v1.10.16 h1:3oPrumn0bCW/idjcxMn5YYVCdK7VzJYIvwGZ
github.com/ethereum/go-ethereum v1.10.16/go.mod h1:Anj6cxczl+AHy63o4X9O8yWNHuN5wMpfb8MAnHkWn7Y=
github.com/facebookgo/ensure v0.0.0-20160127193407-b4ab57deab51/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c h1:8ISkoahWXwZR41ois5lSJBSVw4D0OV19Ht/JSTzvSv0=
github.com/facebookgo/ensure v0.0.0-20200202191622-63f1cf65ac4c/go.mod h1:Yg+htXGokKKdzcwhuNDwVvN+uBxDGXJ7G/VN1d8fa64=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052 h1:JWuenKqqX8nojtoVVWjGfOF9635RETekkoH6Cc9SX0A=
github.com/facebookgo/stack v0.0.0-20160209184415-751773369052/go.mod h1:UbMTZqLaRiH3MsBH8va0n7s1pQYcu3uTb8G4tygF4Zg=
github.com/facebookgo/subset v0.0.0-20150612182917-8dac2c3c4870/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4 h1:7HZCaLC5+BZpmbhCOZJ293Lz68O7PYrF2EzeiFMwCLk=
github.com/facebookgo/subset v0.0.0-20200203212716-c811ad88dec4/go.mod h1:5tD+neXqOorC30/tWg0LCSkrqj/AR6gu8yY8/fpw1q0=
github.com/fatih/color v1.3.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU=
6 changes: 3 additions & 3 deletions proto/desmos/subspaces/v1/models.proto
Original file line number Diff line number Diff line change
@@ -79,7 +79,7 @@ message PermissionDetail {
Group group = 2;
}

// Success is a permission that has been set to a specific user
// User is a permission that has been set to a specific user
message User {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;
@@ -96,10 +96,10 @@ message PermissionDetail {
option (gogoproto.goproto_getters) = false;
option (gogoproto.equal) = true;

// Error that is associated with the failure
// Unique id of the group
uint32 group_id = 1 [
(gogoproto.customname) = "GroupID",
(gogoproto.moretags) = "yaml:\"error\""
(gogoproto.moretags) = "yaml:\"group_id\""
];

// Permission set to the group
2 changes: 1 addition & 1 deletion x/profiles/types/msgs_chain_links.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions x/profiles/types/query_chain_links.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions x/subspaces/client/cli/cli_test.go
Original file line number Diff line number Diff line change
@@ -277,6 +277,49 @@ func (s *IntegrationTestSuite) TestCmdQueryUserGroups() {
}
}

func (s *IntegrationTestSuite) TestCmdQueryUserGroup() {
val := s.network.Validators[0]
testCases := []struct {
name string
args []string
shouldErr bool
expResponse types.QueryUserGroupResponse
}{
{
name: "user group is returned correctly",
args: []string{
"2",
"0",
fmt.Sprintf("--%s=json", tmcli.OutputFlag),
},
shouldErr: false,
expResponse: types.QueryUserGroupResponse{
Group: types.DefaultUserGroup(2),
},
},
}

for _, tc := range testCases {
tc := tc

s.Run(tc.name, func() {
cmd := cli.GetCmdQueryUserGroup()
clientCtx := val.ClientCtx
out, err := clitestutil.ExecTestCLICmd(clientCtx, cmd, tc.args)

if tc.shouldErr {
s.Require().Error(err)
} else {
s.Require().NoError(err)

var response types.QueryUserGroupResponse
s.Require().NoError(clientCtx.JSONCodec.UnmarshalJSON(out.Bytes(), &response), out.String())
s.Require().Equal(tc.expResponse.Group, response.Group)
}
})
}
}

func (s *IntegrationTestSuite) TestCmdQueryUserGroupMembers() {
val := s.network.Validators[0]
testCases := []struct {
52 changes: 49 additions & 3 deletions x/subspaces/client/cli/query.go
Original file line number Diff line number Diff line change
@@ -115,6 +115,7 @@ func GetGroupsQueryCmd() *cobra.Command {

groupsQueryCmd.AddCommand(
GetCmdQueryUserGroups(),
GetCmdQueryUserGroup(),
GetCmdQueryUserGroupMembers(),
)

@@ -127,7 +128,7 @@ func GetCmdQueryUserGroups() *cobra.Command {
Use: "list [subspace-id]",
Short: "Query groups in the given subspace with optional pagination",
Example: fmt.Sprintf(`
%s query subspaces user-groups 1 --page=2 --limit=100`,
%s query subspaces groups list 1 --page=2 --limit=100`,
version.AppName),
Args: cobra.ExactArgs(1),
RunE: func(cmd *cobra.Command, args []string) error {
@@ -165,13 +166,55 @@ func GetCmdQueryUserGroups() *cobra.Command {
return cmd
}

func GetCmdQueryUserGroup() *cobra.Command {
dadamu marked this conversation as resolved.
Show resolved Hide resolved
cmd := &cobra.Command{
Use: "group [subspace-id] [group-id]",
Short: "Query the group with the given id in the given subspace",
Example: fmt.Sprintf(`
%s query subspaces groups group 1 2`,
version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
return err
}
queryClient := types.NewQueryClient(clientCtx)

subspaceID, err := types.ParseSubspaceID(args[0])
if err != nil {
return err
}

groupID, err := types.ParseGroupID(args[1])
if err != nil {
return err
}

res, err := queryClient.UserGroup(
context.Background(),
types.NewQueryUserGroupRequest(subspaceID, groupID),
)
if err != nil {
return err
}

return clientCtx.PrintProto(res)
},
}

flags.AddQueryFlagsToCmd(cmd)

return cmd
}

// GetCmdQueryUserGroupMembers returns the command to query the members of a specific user group
func GetCmdQueryUserGroupMembers() *cobra.Command {
cmd := &cobra.Command{
Use: "members [subspace-id] [group-id]",
Short: "Query members in the given group with optional pagination",
Example: fmt.Sprintf(`
%s query subspaces user-group-members 1 1 --page=2 --limit=100`,
%s query subspaces groups memebers 1 1 --page=2 --limit=100`,
version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
@@ -219,7 +262,10 @@ func GetCmdQueryUserPermissions() *cobra.Command {
cmd := &cobra.Command{
Use: "permissions [subspace-id] [user]",
Short: "Query permissions of the given user",
Args: cobra.ExactArgs(2),
Example: fmt.Sprintf(`
%s query subspaces permissions 1 desmos13p5pamrljhza3fp4es5m3llgmnde5fzcpq6nud`,
version.AppName),
Args: cobra.ExactArgs(2),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientQueryContext(cmd)
if err != nil {
11 changes: 6 additions & 5 deletions x/subspaces/client/cli/tx.go
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@ func NewTxCmd() *cobra.Command {
subspacesTxCmd.AddCommand(
GetCmdCreateSubspace(),
GetCmdEditSubspace(),
GetCmdDeleteSubspace(),

NewGroupsTxCmd(),

@@ -224,7 +225,7 @@ func NewGroupsTxCmd() *cobra.Command {
// GetCmdCreateUserGroup returns the command to create a user group
func GetCmdCreateUserGroup() *cobra.Command {
cmd := &cobra.Command{
Use: "create [subspace-id] [group-name] [[permissions]]",
Use: "create [subspace-id] [group-name]",
Args: cobra.MinimumNArgs(2),
Short: "Create a new user group within a subspace",
Long: fmt.Sprintf(`Create a new user group within the subspace having the provided id.
@@ -235,7 +236,7 @@ The permissions of this group can be set using the %[2]s flag.
If no permissions are set, the default PermissionNothing will be used instead.
Multiple permissions must be specified separating them with a comma (,).`, FlagDescription, FlagPermissions),
Example: fmt.Sprintf(`
%s tx subspaces groups create-user-group 1 "Admins" \
%s tx subspaces groups create 1 "Admins" \
--description "Group of the subspace admins" \
--permissions "Write,ModerateContent,SetUserPermissions" \
--from alice
@@ -402,7 +403,7 @@ func GetCmdDeleteUserGroup() *cobra.Command {
Args: cobra.ExactArgs(2),
Short: "Delete a user group from a subspace",
Example: fmt.Sprintf(`
%s tx subspaces groups delete-user-group 1 1 --from alice
%s tx subspaces groups delete 1 1 --from alice
`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
clientCtx, err := client.GetClientTxContext(cmd)
@@ -441,7 +442,7 @@ func GetCmdAddUserToUserGroup() *cobra.Command {
Args: cobra.ExactArgs(3),
Short: "Add a user to a user group",
Example: fmt.Sprintf(`
%s tx subspaces groups add-user-to-user-group 1 1 desmos1p8r4guvdze03md4g9zclhh6mr8ljvtd80pehr3 \
%s tx subspaces groups add-user 1 1 desmos1p8r4guvdze03md4g9zclhh6mr8ljvtd80pehr3 \
--from alice
`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
@@ -483,7 +484,7 @@ func GetCmdRemoveUserFromUserGroup() *cobra.Command {
Args: cobra.ExactArgs(3),
Short: "Remove a user from a user group",
Example: fmt.Sprintf(`
%s tx subspaces groups remove-user-from-user-group 1 1 desmos1p8r4guvdze03md4g9zclhh6mr8ljvtd80pehr3 \
%s tx subspaces groups remove-user 1 1 desmos1p8r4guvdze03md4g9zclhh6mr8ljvtd80pehr3 \
--from alice
`, version.AppName),
RunE: func(cmd *cobra.Command, args []string) error {
Loading