diff options
author | Jimmy Praet <jimmy.praet@telenet.be> | 2020-12-27 20:58:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-27 21:58:03 +0200 |
commit | 40274b4a935fff50e223751ce3653c2549352b10 (patch) | |
tree | a526f098018a04bbb12bccbebc6122ca209fa732 /models | |
parent | 25f8970b2cc5d2c9fd357ef2c60a54886154f6c9 (diff) | |
download | gitea-40274b4a935fff50e223751ce3653c2549352b10.tar.gz gitea-40274b4a935fff50e223751ce3653c2549352b10.zip |
Team dashboards (#14159)
Diffstat (limited to 'models')
-rw-r--r-- | models/action.go | 10 | ||||
-rw-r--r-- | models/org.go | 32 | ||||
-rw-r--r-- | models/repo_list.go | 5 | ||||
-rw-r--r-- | models/user_heatmap.go | 10 |
4 files changed, 49 insertions, 8 deletions
diff --git a/models/action.go b/models/action.go index ccf161192e..2fdab7f4e9 100644 --- a/models/action.go +++ b/models/action.go @@ -289,6 +289,7 @@ func (a *Action) GetIssueContent() string { // GetFeedsOptions options for retrieving feeds type GetFeedsOptions struct { RequestedUser *User // the user we want activity for + RequestedTeam *Team // the team we want activity for Actor *User // the user viewing the activity IncludePrivate bool // include private actions OnlyPerformedBy bool // only actions performed by requested user @@ -357,6 +358,15 @@ func activityQueryCondition(opts GetFeedsOptions) (builder.Cond, error) { } } + if opts.RequestedTeam != nil { + env := opts.RequestedUser.AccessibleTeamReposEnv(opts.RequestedTeam) + teamRepoIDs, err := env.RepoIDs(1, opts.RequestedUser.NumRepos) + if err != nil { + return nil, fmt.Errorf("GetTeamRepositories: %v", err) + } + cond = cond.And(builder.In("repo_id", teamRepoIDs)) + } + cond = cond.And(builder.Eq{"user_id": opts.RequestedUser.ID}) if opts.OnlyPerformedBy { diff --git a/models/org.go b/models/org.go index 84f2892e4a..c93a30fd77 100644 --- a/models/org.go +++ b/models/org.go @@ -746,6 +746,7 @@ type AccessibleReposEnvironment interface { type accessibleReposEnv struct { org *User user *User + team *Team teamIDs []int64 e Engine keyword string @@ -782,16 +783,31 @@ func (org *User) accessibleReposEnv(e Engine, userID int64) (AccessibleReposEnvi }, nil } +// AccessibleTeamReposEnv an AccessibleReposEnvironment for the repositories in `org` +// that are accessible to the specified team. +func (org *User) AccessibleTeamReposEnv(team *Team) AccessibleReposEnvironment { + return &accessibleReposEnv{ + org: org, + team: team, + e: x, + orderBy: SearchOrderByRecentUpdated, + } +} + func (env *accessibleReposEnv) cond() builder.Cond { var cond = builder.NewCond() - if env.user == nil || !env.user.IsRestricted { - cond = cond.Or(builder.Eq{ - "`repository`.owner_id": env.org.ID, - "`repository`.is_private": false, - }) - } - if len(env.teamIDs) > 0 { - cond = cond.Or(builder.In("team_repo.team_id", env.teamIDs)) + if env.team != nil { + cond = cond.And(builder.Eq{"team_repo.team_id": env.team.ID}) + } else { + if env.user == nil || !env.user.IsRestricted { + cond = cond.Or(builder.Eq{ + "`repository`.owner_id": env.org.ID, + "`repository`.is_private": false, + }) + } + if len(env.teamIDs) > 0 { + cond = cond.Or(builder.In("team_repo.team_id", env.teamIDs)) + } } if env.keyword != "" { cond = cond.And(builder.Like{"`repository`.lower_name", strings.ToLower(env.keyword)}) diff --git a/models/repo_list.go b/models/repo_list.go index 355b801a7e..de3562a2ab 100644 --- a/models/repo_list.go +++ b/models/repo_list.go @@ -138,6 +138,7 @@ type SearchRepoOptions struct { Keyword string OwnerID int64 PriorityOwnerID int64 + TeamID int64 OrderBy SearchOrderBy Private bool // Include private repositories in results StarredByID int64 @@ -294,6 +295,10 @@ func SearchRepositoryCondition(opts *SearchRepoOptions) builder.Cond { cond = cond.And(accessCond) } + if opts.TeamID > 0 { + cond = cond.And(builder.In("`repository`.id", builder.Select("`team_repo`.repo_id").From("team_repo").Where(builder.Eq{"`team_repo`.team_id": opts.TeamID}))) + } + if opts.Keyword != "" { // separate keyword var subQueryCond = builder.NewCond() diff --git a/models/user_heatmap.go b/models/user_heatmap.go index 425817e6d1..f518249111 100644 --- a/models/user_heatmap.go +++ b/models/user_heatmap.go @@ -17,6 +17,15 @@ type UserHeatmapData struct { // GetUserHeatmapDataByUser returns an array of UserHeatmapData func GetUserHeatmapDataByUser(user *User, doer *User) ([]*UserHeatmapData, error) { + return getUserHeatmapData(user, nil, doer) +} + +// GetUserHeatmapDataByUserTeam returns an array of UserHeatmapData +func GetUserHeatmapDataByUserTeam(user *User, team *Team, doer *User) ([]*UserHeatmapData, error) { + return getUserHeatmapData(user, team, doer) +} + +func getUserHeatmapData(user *User, team *Team, doer *User) ([]*UserHeatmapData, error) { hdata := make([]*UserHeatmapData, 0) if !activityReadable(user, doer) { @@ -39,6 +48,7 @@ func GetUserHeatmapDataByUser(user *User, doer *User) ([]*UserHeatmapData, error cond, err := activityQueryCondition(GetFeedsOptions{ RequestedUser: user, + RequestedTeam: team, Actor: doer, IncludePrivate: true, // don't filter by private, as we already filter by repo access IncludeDeleted: true, |