mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-05-25 11:22:16 +00:00
Add collaborative repositories to the dashboard (#2205)
* Add collaborative repositories to the dashboard Remove some unused code from the Dashboard func * fix some bug and some refactor * fix tests
This commit is contained in:
parent
faf4b503b2
commit
1a5fe4326f
6 changed files with 71 additions and 80 deletions
|
@ -15,6 +15,7 @@ import (
|
|||
"unicode"
|
||||
|
||||
"github.com/Unknwon/com"
|
||||
"github.com/go-xorm/builder"
|
||||
"github.com/go-xorm/xorm"
|
||||
|
||||
"code.gitea.io/git"
|
||||
|
@ -712,10 +713,13 @@ type GetFeedsOptions struct {
|
|||
IncludePrivate bool // include private actions
|
||||
OnlyPerformedBy bool // only actions performed by requested user
|
||||
IncludeDeleted bool // include deleted actions
|
||||
Collaborate bool // Include collaborative repositories
|
||||
}
|
||||
|
||||
// GetFeeds returns actions according to the provided options
|
||||
func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
|
||||
cond := builder.NewCond()
|
||||
|
||||
var repoIDs []int64
|
||||
if opts.RequestedUser.IsOrganization() {
|
||||
env, err := opts.RequestedUser.AccessibleReposEnv(opts.RequestingUserID)
|
||||
|
@ -725,26 +729,28 @@ func GetFeeds(opts GetFeedsOptions) ([]*Action, error) {
|
|||
if repoIDs, err = env.RepoIDs(1, opts.RequestedUser.NumRepos); err != nil {
|
||||
return nil, fmt.Errorf("GetUserRepositories: %v", err)
|
||||
}
|
||||
|
||||
cond = cond.And(builder.In("repo_id", repoIDs))
|
||||
}
|
||||
|
||||
if opts.Collaborate {
|
||||
cond = builder.Eq{"user_id": opts.RequestedUser.ID}.Or(
|
||||
builder.Expr(`repo_id IN (SELECT repo_id FROM "access" WHERE access.user_id = ?)`, opts.RequestedUser.ID))
|
||||
} else {
|
||||
cond = builder.Eq{"user_id": opts.RequestedUser.ID}
|
||||
}
|
||||
|
||||
actions := make([]*Action, 0, 20)
|
||||
sess := x.Limit(20).
|
||||
Desc("id").
|
||||
Where("user_id = ?", opts.RequestedUser.ID)
|
||||
if opts.OnlyPerformedBy {
|
||||
sess.And("act_user_id = ?", opts.RequestedUser.ID)
|
||||
cond = cond.And(builder.Eq{"act_user_id": opts.RequestedUser.ID})
|
||||
}
|
||||
if !opts.IncludePrivate {
|
||||
sess.And("is_private = ?", false)
|
||||
}
|
||||
if opts.RequestedUser.IsOrganization() {
|
||||
sess.In("repo_id", repoIDs)
|
||||
cond = cond.And(builder.Eq{"is_private": false})
|
||||
}
|
||||
|
||||
if !opts.IncludeDeleted {
|
||||
sess.And("is_deleted = ?", false)
|
||||
|
||||
cond = cond.And(builder.Eq{"is_deleted": false})
|
||||
}
|
||||
|
||||
return actions, sess.Find(&actions)
|
||||
actions := make([]*Action, 0, 20)
|
||||
return actions, x.Limit(20).Desc("id").Where(cond).Find(&actions)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue