diff options
author | Achilleas Koutsou <achilleas.k@gmail.com> | 2020-09-03 21:04:22 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-04 03:04:22 +0800 |
commit | c4360747a3bdd0d5a5a673bfcdee05f9d911ba1e (patch) | |
tree | 4c8ca23dc3f449bc946b6c75c0fec8dd928dbb73 /internal/db | |
parent | 23ff182d1f8df2978785772bc58cf0ebfd2aeb0c (diff) |
repo: support unlisted but publicly accessible repositories (#6176)
Co-authored-by: ᴜɴᴋɴᴡᴏɴ <u@gogs.io>
Diffstat (limited to 'internal/db')
-rw-r--r-- | internal/db/action.go | 12 | ||||
-rw-r--r-- | internal/db/org.go | 2 | ||||
-rw-r--r-- | internal/db/repo.go | 20 |
3 files changed, 22 insertions, 12 deletions
diff --git a/internal/db/action.go b/internal/db/action.go index 77938f02..d744162f 100644 --- a/internal/db/action.go +++ b/internal/db/action.go @@ -188,7 +188,7 @@ func newRepoAction(e Engine, doer, owner *User, repo *Repository) (err error) { RepoID: repo.ID, RepoUserName: repo.Owner.Name, RepoName: repo.Name, - IsPrivate: repo.IsPrivate, + IsPrivate: repo.IsPrivate || repo.IsUnlisted, }) } @@ -205,7 +205,7 @@ func renameRepoAction(e Engine, actUser *User, oldRepoName string, repo *Reposit RepoID: repo.ID, RepoUserName: repo.Owner.Name, RepoName: repo.Name, - IsPrivate: repo.IsPrivate, + IsPrivate: repo.IsPrivate || repo.IsUnlisted, Content: oldRepoName, }); err != nil { return fmt.Errorf("notify watchers: %v", err) @@ -512,7 +512,7 @@ func CommitRepoAction(opts CommitRepoActionOptions) error { RepoUserName: repo.MustOwner().Name, RepoName: repo.Name, RefName: refName, - IsPrivate: repo.IsPrivate, + IsPrivate: repo.IsPrivate || repo.IsUnlisted, } apiRepo := repo.APIFormat(nil) @@ -628,7 +628,7 @@ func transferRepoAction(e Engine, doer, oldOwner *User, repo *Repository) (err e RepoID: repo.ID, RepoUserName: repo.Owner.Name, RepoName: repo.Name, - IsPrivate: repo.IsPrivate, + IsPrivate: repo.IsPrivate || repo.IsUnlisted, Content: path.Join(oldOwner.Name, repo.Name), }); err != nil { return fmt.Errorf("notifyWatchers: %v", err) @@ -659,7 +659,7 @@ func mergePullRequestAction(e Engine, doer *User, repo *Repository, issue *Issue RepoID: repo.ID, RepoUserName: repo.Owner.Name, RepoName: repo.Name, - IsPrivate: repo.IsPrivate, + IsPrivate: repo.IsPrivate || repo.IsUnlisted, }) } @@ -678,7 +678,7 @@ func mirrorSyncAction(opType ActionType, repo *Repository, refName string, data RepoUserName: repo.MustOwner().Name, RepoName: repo.Name, RefName: refName, - IsPrivate: repo.IsPrivate, + IsPrivate: repo.IsPrivate || repo.IsUnlisted, }) } diff --git a/internal/db/org.go b/internal/db/org.go index 1f043bec..0c257163 100644 --- a/internal/db/org.go +++ b/internal/db/org.go @@ -517,7 +517,7 @@ func (org *User) GetUserRepositories(userID int64, page, pageSize int) ([]*Repos repos := make([]*Repository, 0, pageSize) if err = x.Where("owner_id = ?", org.ID). And(builder.Or( - builder.Expr("is_private = ?", false), + builder.And(builder.Expr("is_private = ?", false), builder.Expr("is_unlisted = ?", false)), builder.In("id", teamRepoIDs))). Desc("updated_unix"). Limit(pageSize, (page-1)*pageSize). diff --git a/internal/db/repo.go b/internal/db/repo.go index 9c91d90f..6d1cb3d9 100644 --- a/internal/db/repo.go +++ b/internal/db/repo.go @@ -173,8 +173,11 @@ type Repository struct { NumOpenMilestones int `xorm:"-" gorm:"-" json:"-"` NumTags int `xorm:"-" gorm:"-" json:"-"` - IsPrivate bool - IsBare bool + IsPrivate bool + // TODO: When migrate to GORM, make sure to do a loose migration with `HasColumn` and `AddColumn`, + // see docs in https://gorm.io/docs/migration.html. + IsUnlisted bool + IsBare bool IsMirror bool *Mirror `xorm:"-" gorm:"-" json:"-"` @@ -717,6 +720,7 @@ type MigrateRepoOptions struct { Name string Description string IsPrivate bool + IsUnlisted bool IsMirror bool RemoteAddr string } @@ -746,6 +750,7 @@ func MigrateRepository(doer, owner *User, opts MigrateRepoOptions) (*Repository, Name: opts.Name, Description: opts.Description, IsPrivate: opts.IsPrivate, + IsUnlisted: opts.IsUnlisted, IsMirror: opts.IsMirror, }) if err != nil { @@ -920,6 +925,7 @@ type CreateRepoOptions struct { License string Readme string IsPrivate bool + IsUnlisted bool IsMirror bool AutoInit bool } @@ -1131,6 +1137,7 @@ func CreateRepository(doer, owner *User, opts CreateRepoOptions) (_ *Repository, LowerName: strings.ToLower(opts.Name), Description: opts.Description, IsPrivate: opts.IsPrivate, + IsUnlisted: opts.IsUnlisted, EnableWiki: true, EnableIssues: true, EnablePulls: true, @@ -1478,13 +1485,14 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e } for i := range forkRepos { forkRepos[i].IsPrivate = repo.IsPrivate + forkRepos[i].IsUnlisted = repo.IsUnlisted if err = updateRepository(e, forkRepos[i], true); err != nil { return fmt.Errorf("updateRepository[%d]: %v", forkRepos[i].ID, err) } } // Change visibility of generated actions - if _, err = e.Where("repo_id = ?", repo.ID).Cols("is_private").Update(&Action{IsPrivate: repo.IsPrivate}); err != nil { + if _, err = e.Where("repo_id = ?", repo.ID).Cols("is_private").Update(&Action{IsPrivate: repo.IsPrivate || repo.IsUnlisted}); err != nil { return fmt.Errorf("change action visibility of repository: %v", err) } } @@ -1687,6 +1695,7 @@ func GetUserRepositories(opts *UserRepoOptions) ([]*Repository, error) { sess := x.Where("owner_id=?", opts.UserID).Desc("updated_unix") if !opts.Private { sess.And("is_private=?", false) + sess.And("is_unlisted=?", false) } if opts.Page <= 0 { @@ -1760,11 +1769,11 @@ func SearchRepositoryByName(opts *SearchRepoOptions) (repos []*Repository, count // this does not include other people's private repositories even if opts.UserID is an admin. if !opts.Private && opts.UserID > 0 { sess.Join("LEFT", "access", "access.repo_id = repo.id"). - Where("repo.owner_id = ? OR access.user_id = ? OR repo.is_private = ? OR (repo.is_private = ? AND (repo.allow_public_wiki = ? OR repo.allow_public_issues = ?))", opts.UserID, opts.UserID, false, true, true, true) + Where("repo.owner_id = ? OR access.user_id = ? OR (repo.is_private = ? AND repo.is_unlisted = ?) OR (repo.is_private = ? AND (repo.allow_public_wiki = ? OR repo.allow_public_issues = ?))", opts.UserID, opts.UserID, false, false, true, true, true) } else { // Only return public repositories if opts.Private is not set if !opts.Private { - sess.And("repo.is_private = ? OR (repo.is_private = ? AND (repo.allow_public_wiki = ? OR repo.allow_public_issues = ?))", false, true, true, true) + sess.And("(repo.is_private = ? AND repo.is_unlisted = ?) OR (repo.is_private = ? AND (repo.allow_public_wiki = ? OR repo.allow_public_issues = ?))", false, false, true, true, true) } } if len(opts.Keyword) > 0 { @@ -2400,6 +2409,7 @@ func ForkRepository(doer, owner *User, baseRepo *Repository, name, desc string) Description: desc, DefaultBranch: baseRepo.DefaultBranch, IsPrivate: baseRepo.IsPrivate, + IsUnlisted: baseRepo.IsUnlisted, IsFork: true, ForkID: baseRepo.ID, } |