mirror of
https://github.com/go-gitea/gitea.git
synced 2026-04-03 21:12:09 +02:00
add ability to search for repository activity based on repo groups
This commit is contained in:
parent
da30652db0
commit
bb55e2db5c
@ -451,6 +451,7 @@ type GetFeedsOptions struct {
|
||||
db.ListOptions
|
||||
RequestedUser *user_model.User // the user we want activity for
|
||||
RequestedTeam *organization.Team // the team we want activity for
|
||||
RequestedGroup *group_model.Group // the group we want activity for
|
||||
RequestedRepo *repo_model.Repository // the repo we want activity for
|
||||
RequestedGroup *group_model.Group // the repo group we want activity for
|
||||
Actor *user_model.User // the user viewing the activity
|
||||
@ -531,8 +532,16 @@ func ActivityQueryCondition(ctx context.Context, opts GetFeedsOptions) (builder.
|
||||
if opts.Actor == nil || !opts.Actor.IsAdmin {
|
||||
cond = cond.And(builder.In("repo_id", repo_model.AccessibleRepoIDsQuery(opts.Actor)))
|
||||
}
|
||||
|
||||
if opts.RequestedRepo != nil {
|
||||
if opts.RequestedGroup != nil {
|
||||
cond = cond.And(builder.In("`action`.repo_id",
|
||||
builder.Select("id").
|
||||
From("repository").
|
||||
Where(builder.Or(
|
||||
builder.In("`repository`.group_id", group_model.ChildGroupCond(opts.RequestedGroup.ID)),
|
||||
builder.Eq{"`repository`.group_id": opts.RequestedGroup.ID}),
|
||||
),
|
||||
))
|
||||
} else if opts.RequestedRepo != nil {
|
||||
// repo's actions could have duplicate items, see the comment of NotifyWatchers
|
||||
// so here we only filter the "original items", aka: user_id == act_user_id
|
||||
cond = cond.And(
|
||||
|
||||
@ -363,6 +363,23 @@ func ParentGroupCond(ctx context.Context, idStr string, groupID int64) builder.C
|
||||
return builder.In(idStr, groupList)
|
||||
}
|
||||
|
||||
// ChildGroupCond returns a condition recursively matching a group and its descendants
|
||||
func ChildGroupCond(firstParent int64) builder.Cond {
|
||||
if firstParent < 0 {
|
||||
firstParent = 0
|
||||
}
|
||||
return builder.Expr(`with recursive groups as (
|
||||
select * from repo_group
|
||||
WHERE parent_group_id = ?
|
||||
|
||||
union all
|
||||
|
||||
select subgroup.*
|
||||
from repo_group subgroup
|
||||
join groups g on g.id = subgroup.parent_group_id
|
||||
) select g.id from groups g`, firstParent)
|
||||
}
|
||||
|
||||
func UpdateGroup(ctx context.Context, group *Group) error {
|
||||
sess := db.GetEngine(ctx)
|
||||
_, err := sess.Table(group.TableName()).ID(group.ID).Update(group)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user