-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Support org/user level projects #22235
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
Merged
Merged
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
bb64be1
support org level projects
lunny c5266e3
Fix move
lunny 420c5cd
Change the repo ref
lunny 0436072
improve FindProjects
lunny 4a5eb97
Fix lint
lunny 24ce5fc
Merge branch 'main' into lunny/org_project
lunny 8de5ae3
Merge branch 'main' into lunny/org_project
lunny 68e6c14
Fix lint
lunny c39fca7
improve menus
lunny 2c40716
Fix test
lunny 44a56ed
Merge branch 'main' into lunny/org_project
lunny 2c081a5
support user level projects
lunny b2c2deb
Fix test
lunny 2a1365f
Merge branch 'main' into lunny/org_project
lunny 547c309
improvement
lunny d0a3680
Fix test
lunny f94cb43
Merge branch 'main' into lunny/org_project
lunny ada5889
Use project-symblink icon for org level project
lunny a4ce734
Fix test
lunny afbd579
Merge branch 'main' into lunny/org_project
lunny ed07255
fix test
lunny 959ba4b
Merge branch 'main' into lunny/org_project
lunny 7a97a60
Merge branch 'main' into lunny/org_project
lunny a3322d2
Fix bug
lunny 1889007
Merge branch 'main' into lunny/org_project
6543 cccf1e9
Merge branch 'main' into lunny/org_project
lunny a094dc8
Merge branch 'main' into lunny/org_project
lunny c4f1e41
Merge branch 'main' into lunny/org_project
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
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,128 @@ | ||||||||||||
// Copyright 2022 The Gitea Authors. All rights reserved. | ||||||||||||
// SPDX-License-Identifier: MIT | ||||||||||||
|
||||||||||||
package organization | ||||||||||||
|
||||||||||||
import ( | ||||||||||||
"context" | ||||||||||||
"strings" | ||||||||||||
|
||||||||||||
"code.gitea.io/gitea/models/db" | ||||||||||||
"code.gitea.io/gitea/models/perm" | ||||||||||||
repo_model "code.gitea.io/gitea/models/repo" | ||||||||||||
"code.gitea.io/gitea/models/unit" | ||||||||||||
|
||||||||||||
"xorm.io/builder" | ||||||||||||
) | ||||||||||||
|
||||||||||||
type TeamList []*Team | ||||||||||||
|
||||||||||||
func (t TeamList) LoadUnits(ctx context.Context) error { | ||||||||||||
for _, team := range t { | ||||||||||||
if err := team.getUnits(ctx); err != nil { | ||||||||||||
return err | ||||||||||||
} | ||||||||||||
} | ||||||||||||
return nil | ||||||||||||
} | ||||||||||||
|
||||||||||||
func (t TeamList) UnitMaxAccess(tp unit.Type) perm.AccessMode { | ||||||||||||
maxAccess := perm.AccessModeNone | ||||||||||||
for _, team := range t { | ||||||||||||
if team.IsOwnerTeam() { | ||||||||||||
return perm.AccessModeOwner | ||||||||||||
} | ||||||||||||
for _, teamUnit := range team.Units { | ||||||||||||
if teamUnit.Type != tp { | ||||||||||||
continue | ||||||||||||
} | ||||||||||||
if teamUnit.AccessMode > maxAccess { | ||||||||||||
Comment on lines
+36
to
+39
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
? |
||||||||||||
maxAccess = teamUnit.AccessMode | ||||||||||||
} | ||||||||||||
} | ||||||||||||
} | ||||||||||||
return maxAccess | ||||||||||||
} | ||||||||||||
|
||||||||||||
// SearchTeamOptions holds the search options | ||||||||||||
type SearchTeamOptions struct { | ||||||||||||
db.ListOptions | ||||||||||||
UserID int64 | ||||||||||||
Keyword string | ||||||||||||
OrgID int64 | ||||||||||||
IncludeDesc bool | ||||||||||||
} | ||||||||||||
|
||||||||||||
func (opts *SearchTeamOptions) toCond() builder.Cond { | ||||||||||||
cond := builder.NewCond() | ||||||||||||
|
||||||||||||
if len(opts.Keyword) > 0 { | ||||||||||||
lowerKeyword := strings.ToLower(opts.Keyword) | ||||||||||||
var keywordCond builder.Cond = builder.Like{"lower_name", lowerKeyword} | ||||||||||||
if opts.IncludeDesc { | ||||||||||||
keywordCond = keywordCond.Or(builder.Like{"LOWER(description)", lowerKeyword}) | ||||||||||||
} | ||||||||||||
cond = cond.And(keywordCond) | ||||||||||||
} | ||||||||||||
|
||||||||||||
if opts.OrgID > 0 { | ||||||||||||
cond = cond.And(builder.Eq{"`team`.org_id": opts.OrgID}) | ||||||||||||
} | ||||||||||||
|
||||||||||||
if opts.UserID > 0 { | ||||||||||||
cond = cond.And(builder.Eq{"team_user.uid": opts.UserID}) | ||||||||||||
} | ||||||||||||
|
||||||||||||
return cond | ||||||||||||
} | ||||||||||||
|
||||||||||||
// SearchTeam search for teams. Caller is responsible to check permissions. | ||||||||||||
func SearchTeam(opts *SearchTeamOptions) (TeamList, int64, error) { | ||||||||||||
sess := db.GetEngine(db.DefaultContext) | ||||||||||||
|
||||||||||||
opts.SetDefaultValues() | ||||||||||||
cond := opts.toCond() | ||||||||||||
|
||||||||||||
if opts.UserID > 0 { | ||||||||||||
sess = sess.Join("INNER", "team_user", "team_user.team_id = team.id") | ||||||||||||
} | ||||||||||||
sess = db.SetSessionPagination(sess, opts) | ||||||||||||
|
||||||||||||
teams := make([]*Team, 0, opts.PageSize) | ||||||||||||
count, err := sess.Where(cond).OrderBy("lower_name").FindAndCount(&teams) | ||||||||||||
if err != nil { | ||||||||||||
return nil, 0, err | ||||||||||||
} | ||||||||||||
|
||||||||||||
return teams, count, nil | ||||||||||||
} | ||||||||||||
|
||||||||||||
// GetRepoTeams gets the list of teams that has access to the repository | ||||||||||||
func GetRepoTeams(ctx context.Context, repo *repo_model.Repository) (teams TeamList, err error) { | ||||||||||||
return teams, db.GetEngine(ctx). | ||||||||||||
Join("INNER", "team_repo", "team_repo.team_id = team.id"). | ||||||||||||
Where("team.org_id = ?", repo.OwnerID). | ||||||||||||
And("team_repo.repo_id=?", repo.ID). | ||||||||||||
OrderBy("CASE WHEN name LIKE '" + OwnerTeamName + "' THEN '' ELSE name END"). | ||||||||||||
Find(&teams) | ||||||||||||
} | ||||||||||||
|
||||||||||||
// GetUserOrgTeams returns all teams that user belongs to in given organization. | ||||||||||||
func GetUserOrgTeams(ctx context.Context, orgID, userID int64) (teams TeamList, err error) { | ||||||||||||
return teams, db.GetEngine(ctx). | ||||||||||||
Join("INNER", "team_user", "team_user.team_id = team.id"). | ||||||||||||
Where("team.org_id = ?", orgID). | ||||||||||||
And("team_user.uid=?", userID). | ||||||||||||
Find(&teams) | ||||||||||||
} | ||||||||||||
|
||||||||||||
// GetUserRepoTeams returns user repo's teams | ||||||||||||
func GetUserRepoTeams(ctx context.Context, orgID, userID, repoID int64) (teams TeamList, err error) { | ||||||||||||
return teams, db.GetEngine(ctx). | ||||||||||||
Join("INNER", "team_user", "team_user.team_id = team.id"). | ||||||||||||
Join("INNER", "team_repo", "team_repo.team_id = team.id"). | ||||||||||||
Where("team.org_id = ?", orgID). | ||||||||||||
And("team_user.uid=?", userID). | ||||||||||||
And("team_repo.repo_id=?", repoID). | ||||||||||||
Find(&teams) | ||||||||||||
} |
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
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.