From 5fe7486b2df20b9affc3b0264fe0272e45987978 Mon Sep 17 00:00:00 2001 From: VSevostyanov Date: Wed, 9 Oct 2024 21:45:13 +0200 Subject: [PATCH 1/3] HOME-1781: Added role id to contributor and group endpoints --- cmd/contributor.go | 14 ++++++++++---- cmd/teamusergroup.go | 22 ++++++++++++---------- go.mod | 2 +- go.sum | 8 ++------ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/cmd/contributor.go b/cmd/contributor.go index 922315d..0aec7b0 100644 --- a/cmd/contributor.go +++ b/cmd/contributor.go @@ -139,17 +139,23 @@ func init() { _ = contributorCreateCmd.MarkFlagRequired("email") fs.StringVar(&contributorCreate.Fullname, "fullname", "", "Full name (only valid for inviting users, who previously did not have an account in Lokalise).") fs.BoolVar(&contributorCreate.IsAdmin, "is-admin", false, "Whether the user has Admin access to the project.") + _ = fs.MarkDeprecated("is-admin", "--is-admin is deprecated and will be removed. Use admin-rights to set permissions to the user.") fs.BoolVar(&contributorCreate.IsReviewer, "is-reviewer", false, "Whether the user has Reviewer access to the project.") + _ = fs.MarkDeprecated("is-reviewer", "--is-reviewer is deprecated and will be removed. Use admin-rights to set permissions to the user.") + fs.Int64Var(&contributorCreate.RoleId, "role-id", 0, "Permission template id for the contributor. By setting this admin_rights will be ignored and a template will be assigned with predefined permission set.") fs.StringVar(&contributorLanguages, "languages", "", "List of languages, accessible to the user. Required if is_admin is set to false (JSON, see https://lokalise.com/api2docs/curl/#transition-create-contributors-post).") - fs.StringSliceVar(&contributorCreate.AdminRights, "admin-rights", []string{}, "Custom list of user permissions. Possible values are upload, activity, download, settings, statistics, keys, screenshots, contributors, languages. Omitted or empty parameter will set default admin rights for user role.") + fs.StringSliceVar(&contributorCreate.AdminRights, "admin-rights", []string{}, "Custom list of user permissions. Possible values are activity, contributors, branches_create, branches_main_modify, branches_merge, custom_status_modify, download, glossary, glossary_edit, glossary_delete, keys, manage_languages, review, screenshots, settings, statistics, tasks, upload. Omitted or empty parameter will set no rights for the user.") // Update flagContributorId(contributorUpdateCmd) fs = contributorUpdateCmd.Flags() - fs.BoolVar(&permissionUpdate.IsAdmin, "is-admin", false, "Whether the user has Admin access to the project.") - fs.BoolVar(&permissionUpdate.IsReviewer, "is-reviewer", false, "Whether the user has Reviewer access to the project.") + fs.BoolVar(&permissionUpdate.IsAdmin, "is-admin", false, "Whether the user has Admin access to the project. Deprecated.") + _ = fs.MarkDeprecated("is-admin", "--is-admin is deprecated and will be removed. Use admin-rights to set permissions to the user.") + fs.BoolVar(&permissionUpdate.IsReviewer, "is-reviewer", false, "Whether the user has Reviewer access to the project. Deprecated.") + _ = fs.MarkDeprecated("is-reviewer", "--is-reviewer is deprecated and will be removed. Use admin-rights to set permissions to the user.") fs.StringVar(&contributorLanguages, "languages", "", "List of languages, accessible to the user (JSON, see https://lokalise.com/api2docs/curl/#transition-update-a-contributor-put).") - fs.StringSliceVar(&permissionUpdate.AdminRights, "admin-rights", []string{}, "Custom list of user permissions. Possible values are upload, activity, download, settings, statistics, keys, screenshots, contributors, languages. Empty parameter will set default admin rights for user role.") + fs.StringSliceVar(&permissionUpdate.AdminRights, "admin-rights", []string{}, "Custom list of user permissions. Possible values are activity, contributors, branches_create, branches_main_modify, branches_merge, custom_status_modify, download, glossary, glossary_edit, glossary_delete, keys, manage_languages, review, screenshots, settings, statistics, tasks, upload. Empty parameter will set no rights for the user.") + fs.Int64Var(&permissionUpdate.RoleId, "role-id", 0, "Permission template id for the contributor. By setting this admin_rights will be ignored and a template will be assigned with predefined permission set.") // Retrieve, delete flagContributorId(contributorRetrieveCmd) diff --git a/cmd/teamusergroup.go b/cmd/teamusergroup.go index 1b1cf2f..5a99b54 100644 --- a/cmd/teamusergroup.go +++ b/cmd/teamusergroup.go @@ -193,12 +193,13 @@ func init() { fs := teamUserGroupCreateCmd.Flags() fs.StringVar(&newGroup.Name, "name", "", "Name of the group (required).") _ = teamUserGroupCreateCmd.MarkFlagRequired("name") - fs.BoolVar(&newGroup.IsReviewer, "is-reviewer", false, "Whether the group has reviewer access to the project (required).") - _ = teamUserGroupCreateCmd.MarkFlagRequired("is-reviewer") - fs.BoolVar(&newGroup.IsAdmin, "is-admin", false, "Whether the group has Admin access to the project (required).") - _ = teamUserGroupCreateCmd.MarkFlagRequired("is-admin") - fs.StringSliceVar(&newGroup.AdminRights, "admin-rights", []string{}, "List of group administrative permissions. Required if group has admin rights.") + fs.BoolVar(&newGroup.IsReviewer, "is-reviewer", false, "Whether the group has reviewer access to the project. ") + _ = fs.MarkDeprecated("is-reviewer", "--is-admin is deprecated and will be removed.") + fs.BoolVar(&newGroup.IsAdmin, "is-admin", false, "Whether the group has Admin access to the project.") + _ = fs.MarkDeprecated("is-admin", "--is-admin is deprecated and will be removed.") + fs.StringSliceVar(&newGroup.AdminRights, "admin-rights", []string{}, "List of group permissions.") fs.StringVar(&groupLanguages, "languages", "", "List of languages. Required if group doesn't have admin rights. JSON, see https://lokalise.com/api2docs/curl/#transition-create-a-group-post") + fs.Int64Var(&newGroup.RoleId, "role-id", 0, "Permission template id for the contributor. By setting this admin-rights will be ignored and a template will be assigned with predefined permission set.") // Retrieve, delete flagGroupId(teamUserGroupRetrieveCmd) @@ -209,12 +210,13 @@ func init() { fs = teamUserGroupUpdateCmd.Flags() fs.StringVar(&updateGroup.Name, "name", "", "Name of the group (required).") _ = teamUserGroupUpdateCmd.MarkFlagRequired("name") - fs.BoolVar(&updateGroup.IsReviewer, "is-reviewer", false, "Whether the group has reviewer access to the project (required).") - _ = teamUserGroupUpdateCmd.MarkFlagRequired("is-reviewer") - fs.BoolVar(&updateGroup.IsAdmin, "is-admin", false, "Whether the group has Admin access to the project (required).") - _ = teamUserGroupUpdateCmd.MarkFlagRequired("is-admin") - fs.StringSliceVar(&updateGroup.AdminRights, "admin-rights", []string{}, "List of group administrative permissions. Required if group has admin rights.") + fs.BoolVar(&updateGroup.IsReviewer, "is-reviewer", false, "Whether the group has reviewer access to the project. Deprecated and will be removed, with only admin-rights or role-id serving as a permission source.") + _ = fs.MarkDeprecated("is-reviewer", "--is-admin is deprecated and will be removed.") + fs.BoolVar(&updateGroup.IsAdmin, "is-admin", false, "Whether the group has Admin access to the project. Deprecated and will be removed, but still required as of now.") + _ = fs.MarkDeprecated("is-reviewer", "--is-admin is deprecated and will be removed.") + fs.StringSliceVar(&updateGroup.AdminRights, "admin-rights", []string{}, "List of group permissions.") fs.StringVar(&groupLanguages, "languages", "", "List of languages. Required if group doesn't have admin rights.") + fs.Int64Var(&updateGroup.RoleId, "role-id", 0, "Permission template id for the contributor. By setting this admin-rights will be ignored and a template will be assigned with predefined permission set.") // Add projects flagGroupId(teamUserGroupAddProjectsCmd) diff --git a/go.mod b/go.mod index ac9d375..ca464f0 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/lokalise/lokalise-cli-2-go go 1.21 require ( - github.com/lokalise/go-lokalise-api/v4 v4.1.2 + github.com/lokalise/go-lokalise-api/v4 v4.1.4 github.com/spf13/cobra v1.7.0 github.com/spf13/pflag v1.0.5 github.com/spf13/viper v1.16.0 diff --git a/go.sum b/go.sum index 047df3b..f45ef00 100644 --- a/go.sum +++ b/go.sum @@ -145,12 +145,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/lokalise/go-lokalise-api/v4 v3.4.0 h1:W1uVB6kD2bZeMknBGW2cDwZapg+fHzu6KDYfzM4C7G4= -github.com/lokalise/go-lokalise-api/v4 v3.4.0/go.mod h1:STLXSf6OiwRdBRpK+BtA6deHh1Qjb69mYnI99HnMRHo= -github.com/lokalise/go-lokalise-api/v4 v4.1.1 h1:qM8HeGobvfltVXnWGUdFRc5tCLEkxR6SoPpfEl7mZaw= -github.com/lokalise/go-lokalise-api/v4 v4.1.1/go.mod h1:wBcA49IR9o4h3PLuNHbN2tu5BfY3xmO3fFyzTyD0XPs= -github.com/lokalise/go-lokalise-api/v4 v4.1.2 h1:qdzbj2lRWXF4YESy6PUkdnbDoEnOql82RXmv8pr54nU= -github.com/lokalise/go-lokalise-api/v4 v4.1.2/go.mod h1:wBcA49IR9o4h3PLuNHbN2tu5BfY3xmO3fFyzTyD0XPs= +github.com/lokalise/go-lokalise-api/v4 v4.1.4 h1:wsTC3qgTxweCNc/jizfZLjZBB68tONedxt1+YiB4448= +github.com/lokalise/go-lokalise-api/v4 v4.1.4/go.mod h1:wBcA49IR9o4h3PLuNHbN2tu5BfY3xmO3fFyzTyD0XPs= github.com/magiconair/properties v1.8.7 h1:IeQXZAiQcpL9mgcAe1Nu6cX9LLw6ExEHKjN0VQdvPDY= github.com/magiconair/properties v1.8.7/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= From 64cd262e9707b1389626e01e26930f7318ec3ba1 Mon Sep 17 00:00:00 2001 From: VSevostyanov Date: Wed, 9 Oct 2024 21:46:14 +0200 Subject: [PATCH 2/3] HOME-1781: Added role id to contributor and group endpoints --- cmd/contributor.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/contributor.go b/cmd/contributor.go index 0aec7b0..4dc7f82 100644 --- a/cmd/contributor.go +++ b/cmd/contributor.go @@ -2,8 +2,8 @@ package cmd import ( "encoding/json" - "github.com/lokalise/go-lokalise-api/v4" + "github.com/spf13/cobra" ) From d8f48e7889037024895f6975bad3b07f9ba23cc8 Mon Sep 17 00:00:00 2001 From: VSevostyanov Date: Wed, 9 Oct 2024 21:53:33 +0200 Subject: [PATCH 3/3] HOME-1781: Added permission template endpoint --- cmd/permissiontemplate.go | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 cmd/permissiontemplate.go diff --git a/cmd/permissiontemplate.go b/cmd/permissiontemplate.go new file mode 100644 index 0000000..484dfdf --- /dev/null +++ b/cmd/permissiontemplate.go @@ -0,0 +1,32 @@ +package cmd + +import ( + "github.com/spf13/cobra" +) + +var permissionTemplateCmd = &cobra.Command{ + Use: "permission-template", + Short: "Manage permission templates for a team", + Long: "Manage all templates for permissions inside a team.", +} + +var permissionTemplateListCmd = &cobra.Command{ + Use: "list", + Short: "List permission templates", + Long: "Retrieves a list of permission templates.", + RunE: func(*cobra.Command, []string) error { + c := Api.PermissionTemplates() + data, err := c.ListPermissionRoles(teamId) + if err != nil { + return err + } + return printJson(data) + }, +} + +func init() { + permissionTemplateCmd.AddCommand(permissionTemplateListCmd) + rootCmd.AddCommand(permissionTemplateCmd) + + flagTeamId(permissionTemplateCmd) +}