0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-02-22 06:45:46 +01:00

Refactor team visibility logic and update search input attributes

This commit is contained in:
Animesh Kumar 2026-02-13 21:52:17 +05:30
parent ed2ca46f30
commit be33fd7749
4 changed files with 38 additions and 17 deletions

View File

@ -596,3 +596,27 @@ func getUserTeamIDsQueryBuilder(orgID, userID int64) *builder.Builder {
"team_user.uid": userID,
})
}
// CanUserSeeAllTeams returns true if user can see all teams in organization
func (org *Organization) CanUserSeeAllTeams(ctx context.Context, userID int64) (bool, error) {
isOwner, err := org.IsOwnedBy(ctx, userID)
if err != nil {
return false, err
}
if isOwner {
return true, nil
}
teams, err := org.GetUserTeams(ctx, userID)
if err != nil {
return false, err
}
for _, team := range teams {
if team.IncludesAllRepositories && team.HasAdminAccess() {
return true, nil
}
}
return false, nil
}

View File

@ -67,7 +67,13 @@ func Teams(ctx *context.Context) {
},
}
if !ctx.Org.IsOwner {
canSeeAllTeams, err := ctx.Org.Organization.CanUserSeeAllTeams(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("CanUserSeeAllTeams", err)
return
}
if !canSeeAllTeams {
opts.UserID = ctx.Doer.ID
}

View File

@ -171,24 +171,15 @@ func OrgAssignment(orgAssignmentOpts OrgAssignmentOptions) func(ctx *Context) {
return
}
// Team.
if ctx.Org.IsMember {
shouldSeeAllTeams := false
if ctx.Org.IsOwner {
shouldSeeAllTeams = true
} else {
teams, err := org.GetUserTeams(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("GetUserTeams", err)
return
}
for _, team := range teams {
if team.IncludesAllRepositories && team.HasAdminAccess() {
shouldSeeAllTeams = true
break
}
}
shouldSeeAllTeams, err := org.CanUserSeeAllTeams(ctx, ctx.Doer.ID)
if err != nil {
ctx.ServerError("CanUserSeeAllTeams", err)
return
}
if shouldSeeAllTeams {
ctx.Org.Teams, err = org.LoadTeams(ctx)
if err != nil {

View File

@ -12,7 +12,7 @@
<div class="ui secondary filter menu tw-mx-0">
<form class="ui form ignore-dirty tw-flex-1" method="get">
<div class="ui fluid action input">
<input name="q" value="{{$.Keyword}}" placeholder="{{ctx.Locale.Tr "search.team_kind"}}" autofocus>
<input type="search" name="q" value="{{$.Keyword}}" placeholder="{{ctx.Locale.Tr "search.team_kind"}}" maxlength="255" spellcheck="false" autofocus>
<button class="ui primary button" type="submit">{{svg "octicon-search"}}</button>
</div>
</form>