-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix edit team #32325
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
Draft
lunny
wants to merge
13
commits into
go-gitea:main
Choose a base branch
from
lunny:lunny/fix_edit_team
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Fix edit team #32325
Changes from 1 commit
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
df785f6
Fix edit team
lunny 8e1cac1
Use UpdateTeamOptions instead of multiple parameters of function
lunny 253ec37
Fix lint and test
lunny afade2f
Fix test
lunny c2ff613
Merge branch 'main' into lunny/fix_edit_team
lunny c0edbd4
Fix test
lunny d742634
Merge branch 'main' into lunny/fix_edit_team
lunny ec8fbde
Add more check
lunny c7da886
Fix test
lunny e1fe318
Merge branch 'main' into lunny/fix_edit_team
lunny 9c0cc9b
Fix lint
lunny c7262d6
Merge branch 'main' into lunny/fix_edit_team
lunny 088cffb
Fix update team
lunny File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// Copyright 2024 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package org | ||
|
||
import ( | ||
"context" | ||
|
||
"code.gitea.io/gitea/models" | ||
org_model "code.gitea.io/gitea/models/organization" | ||
"code.gitea.io/gitea/models/perm" | ||
unit_model "code.gitea.io/gitea/models/unit" | ||
) | ||
|
||
func UpdateTeam(ctx context.Context, team *org_model.Team, teamName, description string, isAdmin, includesAllRepositories, canCreateOrgRepo bool, unitPerms map[unit_model.Type]perm.AccessMode) error { | ||
var changedCols []string | ||
|
||
newAccessMode := perm.AccessModeRead | ||
if isAdmin { | ||
newAccessMode = perm.AccessModeAdmin | ||
} else { | ||
// if newAccessMode is less than admin accessmode, then it should be general accessmode, | ||
// so we should calculate the minial accessmode from units accessmodes. | ||
newAccessMode = unit_model.MinUnitAccessMode(unitPerms) | ||
} | ||
|
||
if !team.IsOwnerTeam() { | ||
team.Name = teamName | ||
if team.AccessMode != newAccessMode { | ||
team.AccessMode = newAccessMode | ||
changedCols = append(changedCols, "authorize") | ||
} | ||
|
||
if team.IncludesAllRepositories != includesAllRepositories { | ||
team.IncludesAllRepositories = includesAllRepositories | ||
changedCols = append(changedCols, "includes_all_repositories") | ||
} | ||
units := make([]*org_model.TeamUnit, 0, len(unitPerms)) | ||
for tp, perm := range unitPerms { | ||
units = append(units, &org_model.TeamUnit{ | ||
OrgID: team.OrgID, | ||
TeamID: team.ID, | ||
Type: tp, | ||
AccessMode: perm, | ||
}) | ||
} | ||
team.Units = units | ||
changedCols = append(changedCols, "units") | ||
if team.CanCreateOrgRepo != canCreateOrgRepo { | ||
team.CanCreateOrgRepo = canCreateOrgRepo | ||
changedCols = append(changedCols, "can_create_org_repo") | ||
} | ||
} else { | ||
team.CanCreateOrgRepo = true | ||
team.IncludesAllRepositories = true | ||
changedCols = append(changedCols, "can_create_org_repo", "includes_all_repositories") | ||
} | ||
|
||
if team.Description != description { | ||
changedCols = append(changedCols, "description") | ||
team.Description = description | ||
} | ||
|
||
return models.UpdateTeam(ctx, team, changedCols...) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.