mirror of
https://gitea.com/gitea/tea.git
synced 2026-10-26 11:01:25 +01:00
fix(team): merge team edit --unit into the current unit policy
Gitea replaces a team's whole unit policy on edit, so `tea team edit 5 --unit repo.wiki=write` revoked code, issue and pull request access. team edit now merges --unit into the current policy; --unit-replace keeps the old replacing behavior. Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
4 files changed
+83
-8
No files matched your search
+11
-2
@@ -35,7 +35,7 @@ func (a *application) teamCommand() *cobra.Command {
|
||||
group.AddCommand(list)
|
||||
for _, verb := range []string{"view", "create", "edit", "delete"} {
|
||||
var name, description, permission string
|
||||
var createRepo, allRepos, force bool
|
||||
var createRepo, allRepos, force, replaceUnits bool
|
||||
var units map[string]string
|
||||
command := &cobra.Command{Use: verb + " <id>", Short: titleCase(verb) + " an organization team", Args: argsExact(1)}
|
||||
switch verb {
|
||||
@@ -49,7 +49,12 @@ func (a *application) teamCommand() *cobra.Command {
|
||||
command.Flags().StringVar(&name, "name", "", "Team name")
|
||||
command.Flags().StringVar(&description, "description", "", "Team description")
|
||||
command.Flags().StringVar(&permission, "permission", "read", "Default access: read, write, admin")
|
||||
command.Flags().StringToStringVar(&units, "unit", nil, "Unit permissions, for example repo.code=write,repo.issues=read (replaces unit policy)")
|
||||
unitUsage := "Unit permissions, for example repo.code=write,repo.issues=read"
|
||||
if verb == "edit" {
|
||||
unitUsage = "Unit permissions to change, for example repo.wiki=write; merged into the current policy"
|
||||
command.Flags().BoolVar(&replaceUnits, "unit-replace", false, "Replace the whole unit policy with --unit; omitted units lose access")
|
||||
}
|
||||
command.Flags().StringToStringVar(&units, "unit", nil, unitUsage)
|
||||
command.Flags().BoolVar(&createRepo, "can-create-repo", false, "Allow creating organization repositories")
|
||||
command.Flags().BoolVar(&allRepos, "all-repositories", false, "Access every organization repository")
|
||||
}
|
||||
@@ -68,6 +73,9 @@ func (a *application) teamCommand() *cobra.Command {
|
||||
if err := oneOf("permission", permission, "read", "write", "admin"); err != nil {
|
||||
return err
|
||||
}
|
||||
if replaceUnits && !cmd.Flags().Changed("unit") {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("--unit-replace requires --unit"))
|
||||
}
|
||||
if cmd.Flags().Changed("unit") && (len(units) == 0 || permission == "admin") {
|
||||
return clierr.Wrap(clierr.Usage, errors.New("--unit needs a nonempty policy and cannot restrict administrator access"))
|
||||
}
|
||||
@@ -106,6 +114,7 @@ func (a *application) teamCommand() *cobra.Command {
|
||||
}
|
||||
if cmd.Flags().Changed("unit") {
|
||||
opts.Units = units
|
||||
opts.ReplaceUnits = replaceUnits
|
||||
}
|
||||
if cmd.Flags().Changed("can-create-repo") {
|
||||
opts.CanCreateRepo = &createRepo
|
||||
|
||||
Reference in new issue
Block a user