summaryrefslogtreecommitdiffstats
path: root/models/repo_list.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2019-10-28 18:31:55 +0000
committerGitHub <noreply@github.com>2019-10-28 18:31:55 +0000
commit5e6a008fba9a85c9a5319d93c1e52e183211a342 (patch)
tree1da9197537ea37a338838b52e479697f44a046ea /models/repo_list.go
parentaf8957bc4ce78613fe03cb1abc6c961dd67ff344 (diff)
downloadgitea-5e6a008fba9a85c9a5319d93c1e52e183211a342.tar.gz
gitea-5e6a008fba9a85c9a5319d93c1e52e183211a342.zip
Add basic repository lfs management (#7199)
This PR adds basic repository LFS management UI including the ability to find all possible pointers within the repository. Locks are not managed at present but would be addable through some simple additions. * Add basic repository lfs management * add auto-associate function * Add functionality to find commits with this lfs file * Add link to find commits on the lfs file view * Adjust commit view to state the likely branch causing the commit * Only read Oid from database
Diffstat (limited to 'models/repo_list.go')
-rw-r--r--models/repo_list.go48
1 files changed, 26 insertions, 22 deletions
diff --git a/models/repo_list.go b/models/repo_list.go
index 692d4d002f..c823647eba 100644
--- a/models/repo_list.go
+++ b/models/repo_list.go
@@ -176,28 +176,7 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
if opts.Private {
if !opts.UserIsAdmin && opts.UserID != 0 && opts.UserID != opts.OwnerID {
// OK we're in the context of a User
- // We should be Either
- cond = cond.And(builder.Or(
- // 1. Be able to see all non-private repositories that either:
- cond.And(
- builder.Eq{"is_private": false},
- builder.Or(
- // A. Aren't in organisations __OR__
- builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})),
- // B. Isn't a private organisation. (Limited is OK because we're logged in)
- builder.NotIn("owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"visibility": structs.VisibleTypePrivate}))),
- ),
- // 2. Be able to see all repositories that we have access to
- builder.In("id", builder.Select("repo_id").
- From("`access`").
- Where(builder.And(
- builder.Eq{"user_id": opts.UserID},
- builder.Gt{"mode": int(AccessModeNone)}))),
- // 3. Be able to see all repositories that we are in a team
- builder.In("id", builder.Select("`team_repo`.repo_id").
- From("team_repo").
- Where(builder.Eq{"`team_user`.uid": opts.UserID}).
- Join("INNER", "team_user", "`team_user`.team_id = `team_repo`.team_id"))))
+ cond = cond.And(accessibleRepositoryCondition(opts.UserID))
}
} else {
// Not looking at private organisations
@@ -316,6 +295,31 @@ func SearchRepository(opts *SearchRepoOptions) (RepositoryList, int64, error) {
return repos, count, nil
}
+// accessibleRepositoryCondition takes a user a returns a condition for checking if a repository is accessible
+func accessibleRepositoryCondition(userID int64) builder.Cond {
+ return builder.Or(
+ // 1. Be able to see all non-private repositories that either:
+ builder.And(
+ builder.Eq{"`repository`.is_private": false},
+ builder.Or(
+ // A. Aren't in organisations __OR__
+ builder.NotIn("`repository`.owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"type": UserTypeOrganization})),
+ // B. Isn't a private organisation. (Limited is OK because we're logged in)
+ builder.NotIn("`repository`.owner_id", builder.Select("id").From("`user`").Where(builder.Eq{"visibility": structs.VisibleTypePrivate}))),
+ ),
+ // 2. Be able to see all repositories that we have access to
+ builder.In("`repository`.id", builder.Select("repo_id").
+ From("`access`").
+ Where(builder.And(
+ builder.Eq{"user_id": userID},
+ builder.Gt{"mode": int(AccessModeNone)}))),
+ // 3. Be able to see all repositories that we are in a team
+ builder.In("`repository`.id", builder.Select("`team_repo`.repo_id").
+ From("team_repo").
+ Where(builder.Eq{"`team_user`.uid": userID}).
+ Join("INNER", "team_user", "`team_user`.team_id = `team_repo`.team_id")))
+}
+
// SearchRepositoryByName takes keyword and part of repository name to search,
// it returns results in given range and number of total results.
func SearchRepositoryByName(opts *SearchRepoOptions) (RepositoryList, int64, error) {