From 7437f45d9a5da3b7f1a359eccd0416c6890be5ee Mon Sep 17 00:00:00 2001 From: bircni Date: Sun, 18 Oct 2026 17:14:46 +0200 Subject: [PATCH] fix(team): keep the access of read and write teams when editing --unit Signed-off-by: bircni --- internal/app/teams.go | 3 +++ internal/services/teams.go | 4 ++++ 2 files changed, 7 insertions(+) diff --git a/internal/app/teams.go b/internal/app/teams.go index adc412f9..48217868 100644 --- a/internal/app/teams.go +++ b/internal/app/teams.go @@ -415,6 +415,9 @@ $ tea team edit acme/developers --name devs --description "Core developers"`, if err != nil { return err } + if opts.Units != nil && !opts.ReplaceUnits && (team.Permission == "admin" || team.Permission == "owner") { + return clierr.Wrap(clierr.Usage, fmt.Errorf("--unit cannot restrict the %s access of team %s; pass --permission read or write, or --unit-replace", team.Permission, team.Slug())) + } edited, err := service.Edit(cmd.Context(), team.ID, opts) if err != nil { return err diff --git a/internal/services/teams.go b/internal/services/teams.go index 3a4debf1..9be986fd 100644 --- a/internal/services/teams.go +++ b/internal/services/teams.go @@ -250,6 +250,10 @@ func (s Teams) Edit(ctx context.Context, id int64, opts TeamOptions) (Team, erro opts.Units = current.Units case !opts.ReplaceUnits: units := maps.Clone(current.Units) + if len(units) == 0 && (current.Permission == "read" || current.Permission == "write") { + // The team grants its permission to every unit and has no unit policy yet. + units = UnitPolicy(current.Permission) + } maps.Copy(units, opts.Units) opts.Units = units }