Forráskód Böngészése

repo: Prepare for 'IsUnlisted' db change

gogs/gogs will add the repo.Unlisted feature at some point in the
future. G-Node/gogs already implemented this feature, but calls the
corresponding database field "Unlisted" instead of the gogs version
"IsUnlisted".
This commits prepares for the gogs/gogs change ahead of time.
M. Sonntag 4 éve
szülő
commit
cbc46d7ae2

+ 4 - 2
conf/locale/locale_en-US.ini

@@ -404,8 +404,10 @@ delete_account_desc = This account is going to be deleted permanently, do you wa
 owner = Owner
 repo_name = Repository Name
 repo_name_helper = Will be used to define the URL (path) of the repository. It must be one word (no spaces) and can contain letters (a-z, A-Z), numbers (0-9), dash (-), underscore (_), or dot (.) characters. Repository names should be short, unique and specific (do not use a generic name like "dataset", "plos_paper", etc).
-visibility = Private
-visiblity_helper = Accessible only to owner and assigned collaborators
+visibility = Visibility
+unlisted = Unlisted
+visiblity_helper = This repository is <span class="ui red text">Private</span>; accessible only to owner and assigned collaborators
+unlisted_helper = This repository is <span class="ui red text">Unlisted</span>
 visiblity_helper_forced = New repositories are private by default. You can change the state later.
 visiblity_fork_helper = (Change of this value will affect all forks)
 license_warn = Before making this public: Have you added a LICENSE file?

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 7 - 7
internal/assets/conf/conf_gen.go


+ 1 - 1
internal/assets/public/public_gen.go

@@ -20259,7 +20259,7 @@ func jsGogsJs() (*asset, error) {
 		return nil, err
 	}
 
-	info := bindataFileInfo{name: "js/gogs.js", size: 56457, mode: os.FileMode(0664), modTime: time.Unix(1606919529, 0)}
+	info := bindataFileInfo{name: "js/gogs.js", size: 56457, mode: os.FileMode(0664), modTime: time.Unix(1607001048, 0)}
 	a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8e, 0xb1, 0x47, 0xe5, 0x6f, 0x15, 0xa, 0xa3, 0xc2, 0xba, 0xb3, 0xa, 0x5c, 0x3e, 0x7b, 0xe5, 0xe9, 0x5b, 0xb8, 0xa6, 0x66, 0x59, 0xb4, 0xdc, 0xad, 0x65, 0xd4, 0x7, 0x7e, 0x1e, 0xd6, 0xeb}}
 	return a, nil
 }

A különbségek nem kerülnek megjelenítésre, a fájl túl nagy
+ 7 - 7
internal/assets/templates/templates_gen.go


+ 6 - 6
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,
 	})
 }
 

+ 1 - 1
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).

+ 11 - 4
internal/db/repo.go

@@ -174,8 +174,8 @@ type Repository struct {
 	NumTags             int `xorm:"-" gorm:"-" json:"-"`
 
 	IsPrivate bool
+	IsUnlisted  bool
 	IsBare    bool
-	Unlisted  bool
 
 	IsMirror bool
 	*Mirror  `xorm:"-" gorm:"-" json:"-"`
@@ -725,6 +725,7 @@ type MigrateRepoOptions struct {
 	Name        string
 	Description string
 	IsPrivate   bool
+	IsUnlisted  bool
 	IsMirror    bool
 	RemoteAddr  string
 }
@@ -754,6 +755,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 {
@@ -928,6 +930,7 @@ type CreateRepoOptions struct {
 	License     string
 	Readme      string
 	IsPrivate   bool
+	IsUnlisted  bool
 	IsMirror    bool
 	AutoInit    bool
 }
@@ -1139,6 +1142,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,
@@ -1486,13 +1490,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)
 		}
 	}
@@ -1695,6 +1700,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 {
@@ -1768,11 +1774,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 {
@@ -2408,6 +2414,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,
 	}

+ 3 - 1
internal/form/repo.go

@@ -26,6 +26,7 @@ type CreateRepo struct {
 	UserID      int64  `binding:"Required"`
 	RepoName    string `binding:"Required;AlphaDashDot;MaxSize(100)"`
 	Private     bool
+	Unlisted    bool
 	Description string `binding:"MaxSize(512)"`
 	AutoInit    bool
 	Gitignores  string
@@ -45,6 +46,7 @@ type MigrateRepo struct {
 	RepoName     string `json:"repo_name" binding:"Required;AlphaDashDot;MaxSize(100)"`
 	Mirror       bool   `json:"mirror"`
 	Private      bool   `json:"private"`
+	Unlisted     bool   `json:"unlisted"`
 	Description  string `json:"description" binding:"MaxSize(512)"`
 }
 
@@ -92,7 +94,7 @@ type RepoSetting struct {
 	Interval      int
 	MirrorAddress string
 	Private       bool
-	Listed        bool
+	Unlisted      bool
 	EnablePrune   bool
 
 	// Advanced settings

+ 5 - 2
internal/route/api/v1/repo/repo.go

@@ -27,7 +27,8 @@ func Search(c *context.APIContext) {
 		Page:     c.QueryInt("page"),
 	}
 
-	// workaround for the all query with logged users
+	// GIN specific code
+	// Workaround for the all query with logged users (?)
 	if opts.Keyword == "." {
 		opts.Keyword = ""
 	}
@@ -68,9 +69,11 @@ func Search(c *context.APIContext) {
 		return
 	}
 
+	// GIN specific code
+	// 'for' has been modfied to accomodate search in commits as well (?)
 	results := make([]*api.Repository, 0, len(repos))
 	for i := range repos {
-		if !repos[i].Unlisted {
+		if !repos[i].IsUnlisted {
 			rep := repos[i].APIFormat(nil)
 			rep.Owner.Email = ""
 			results = append(results, rep)

+ 1 - 0
internal/route/repo/pull.go

@@ -60,6 +60,7 @@ func parseBaseRepository(c *context.Context) *db.Repository {
 	c.Data["repo_name"] = baseRepo.Name
 	c.Data["description"] = baseRepo.Description
 	c.Data["IsPrivate"] = baseRepo.IsPrivate
+	c.Data["IsUnlisted"] = baseRepo.IsUnlisted
 
 	if err = baseRepo.GetOwner(); err != nil {
 		c.Error(err, "get owner")

+ 2 - 0
internal/route/repo/repo.go

@@ -127,6 +127,7 @@ func CreatePost(c *context.Context, f form.CreateRepo) {
 		License:     f.License,
 		Readme:      f.Readme,
 		IsPrivate:   f.Private || conf.Repository.ForcePrivate,
+		IsUnlisted:  f.Unlisted,
 		AutoInit:    f.AutoInit,
 	})
 	if err == nil {
@@ -198,6 +199,7 @@ func MigratePost(c *context.Context, f form.MigrateRepo) {
 		Name:        f.RepoName,
 		Description: f.Description,
 		IsPrivate:   f.Private || conf.Repository.ForcePrivate,
+		IsUnlisted:  f.Unlisted,
 		IsMirror:    f.Mirror,
 		RemoteAddr:  remoteAddr,
 	})

+ 3 - 2
internal/route/repo/setting.go

@@ -88,11 +88,12 @@ func SettingsPost(c *context.Context, f form.RepoSetting) {
 		// Visibility of forked repository is forced sync with base repository.
 		if repo.IsFork {
 			f.Private = repo.BaseRepo.IsPrivate
+			f.Unlisted = repo.BaseRepo.IsUnlisted
 		}
 
-		visibilityChanged := repo.IsPrivate != f.Private
+		visibilityChanged := repo.IsPrivate != f.Private || repo.IsUnlisted != f.Unlisted
 		repo.IsPrivate = f.Private
-		repo.Unlisted = !f.Listed
+		repo.IsUnlisted = f.Unlisted
 		if err := db.UpdateRepository(repo, visibilityChanged); err != nil {
 			c.Error(err, "update repository")
 			return

+ 1 - 1
internal/route/routes_gin.go

@@ -6,7 +6,7 @@ func filterUnlistedRepos(repos []*db.Repository) []*db.Repository {
 	// Filter out Unlisted repositories
 	var showRep []*db.Repository
 	for _, repo := range repos {
-		if !repo.Unlisted {
+		if !repo.IsUnlisted {
 			showRep = append(showRep, repo)
 		}
 	}

+ 1 - 1
internal/route/search_gin.go

@@ -82,7 +82,7 @@ func collectSearchableRepoIDs(c *context.Context) ([]int64, error) {
 	// If it's not unlisted, add it to the set
 	// This will add public (listed) repositories
 	for _, r := range repos {
-		if !r.Unlisted {
+		if !r.IsUnlisted {
 			repoIDSet.add(r.ID)
 		}
 	}

+ 2 - 0
templates/explore/repo_list.tmpl

@@ -10,6 +10,8 @@
 						<a class="name" href="{{AppSubURL}}/{{if .Owner}}{{.Owner.Name}}{{else if $.Org}}{{$.Org.Name}}{{else}}{{$.Owner.Name}}{{end}}/{{.Name}}">{{if $.PageIsExplore}}{{.Owner.Name}} / {{end}}{{.Name}}</a>
 						{{if .IsPrivate}}
 							<span class="text gold"><i class="octicon octicon-lock"></i></span>
+						{{else if .IsUnlisted}}
+							<span><i class="octicon octicon-eye"></i></span>
 						{{else if .IsFork}}
 							<span><i class="octicon octicon-repo-forked"></i></span>
 						{{else if .IsMirror}}

+ 7 - 0
templates/repo/create.tmpl

@@ -50,6 +50,13 @@
 							{{end}}
 						</div>
 					</div>
+					<div class="inline field">
+						<label></label>
+						<div class="ui checkbox">
+							<input name="unlisted" type="checkbox">
+							<label>{{.i18n.Tr "repo.unlisted_helper" | Safe}}</label>
+						</div>
+					</div>
 					<div class="inline field {{if .Err_Description}}error{{end}}">
 						<label for="description">{{.i18n.Tr "repo.repo_desc"}}</label>
 						<textarea class="autosize" id="description" name="description" rows="3">{{.description}}</textarea>

+ 2 - 2
templates/repo/header.tmpl

@@ -7,9 +7,9 @@
 					<div class="ui huge breadcrumb">
 						{{if .UseCustomAvatar}}
 							<img class="ui mini spaced image" src="{{.RelAvatarLink}}">
-							<i class="{{if .IsPrivate}}mega-octicon octicon-lock{{else if .IsMirror}}mega-octicon octicon-repo-clone{{else if .IsFork}}mega-octicon octicon-repo-forked{{end}}"></i>
+							<i class="{{if .IsPrivate}}mega-octicon octicon-lock{{else if .IsUnlisted}}mega-octicon octicon-eye{{else if .IsMirror}}mega-octicon octicon-repo-clone{{else if .IsFork}}mega-octicon octicon-repo-forked{{end}}"></i>
 						{{else}}
-							<i class="mega-octicon octicon-{{if .IsPrivate}}lock{{else if .IsMirror}}repo-clone{{else if .IsFork}}repo-forked{{else}}repo{{end}}"></i>
+							<i class="mega-octicon octicon-{{if .IsPrivate}}lock{{else if .IsUnlisted}}eye{{else if .IsMirror}}repo-clone{{else if .IsFork}}repo-forked{{else}}repo{{end}}"></i>
 						{{end}}
 						<a href="{{AppSubURL}}/{{.Owner.Name}}">{{.Owner.Name}}</a>
 						<div class="divider"> / </div>

+ 7 - 0
templates/repo/migrate.tmpl

@@ -80,6 +80,13 @@
 							{{end}}
 						</div>
 					</div>
+					<div class="inline field">
+						<label></label>
+						<div class="ui checkbox">
+							<input name="unlisted" type="checkbox">
+							<label>{{.i18n.Tr "repo.unlisted_helper" | Safe}}</label>
+						</div>
+					</div>
 					<div class="inline field">
 						<label>{{.i18n.Tr "repo.migrate_type"}}</label>
 						<div class="ui checkbox">

+ 7 - 0
templates/repo/pulls/fork.tmpl

@@ -49,6 +49,13 @@
 							<input type="checkbox" {{if .IsPrivate}}checked{{end}}>
 							<label>{{.i18n.Tr "repo.visiblity_helper" | Safe}}</label>
 						</div>
+					</div>
+					<div class="inline field">
+						<label></label>
+						<div class="ui read-only checkbox">
+							<input type="checkbox" {{if .IsUnlisted}}checked{{end}}>
+							<label>{{.i18n.Tr "repo.unlisted_helper" | Safe}}</label>
+						</div>
 						<span class="help">{{.i18n.Tr "repo.fork_visiblity_helper"}}</span>
 					</div>
 					<div class="inline field {{if .Err_Description}}error{{end}}">

+ 13 - 10
templates/repo/settings/options.tmpl

@@ -31,18 +31,21 @@
 						{{if not .Repository.IsFork}}
 							<div class="inline field">
 								<label>{{.i18n.Tr "repo.visibility"}}</label>
-								<div class="ui checkbox" {{if .Repository.IsPrivate}}data-tooltip="{{.i18n.Tr "repo.license_warn"}}"{{end}}>
-									<input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}>
-									<label>{{.i18n.Tr "repo.visiblity_helper" | Safe}} {{if .Repository.NumForks}}<span class="text red">{{.i18n.Tr "repo.visiblity_fork_helper"}}</span>{{end}}</label>
+								<div class="ui segment">
+									<div class="field">
+										<div class="ui checkbox" {{if .Repository.IsPrivate}}data-tooltip="{{.i18n.Tr "repo.license_warn"}}"{{end}}>
+											<input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}>
+											<label>{{.i18n.Tr "repo.visiblity_helper" | Safe}} {{if .Repository.NumForks}}<span class="text red">{{.i18n.Tr "repo.visiblity_fork_helper"}}</span>{{end}}</label>
+										</div>
+									</div>
+									<div class="field">
+										<div class="ui checkbox">
+											<input name="unlisted" type="checkbox" {{if .Repository.IsUnlisted}}checked{{end}}>
+											<label>{{.i18n.Tr "repo.unlisted_helper" | Safe}} {{if .Repository.NumForks}}<span class="text red">{{.i18n.Tr "repo.visiblity_fork_helper"}}</span>{{end}}</label>
+										</div>
+									</div>
 								</div>
 							</div>
-						<div class="inline field">
-							<label>{{.i18n.Tr "repo.listed"}}</label>
-							<div class="ui checkbox">
-								<input name="listed" type="checkbox" {{if not .Repository.Unlisted}}checked{{end}}>
-								<label>{{.i18n.Tr "repo.listed_helper" | Safe}}</label>
-							</div>
-						</div>
 						{{end}}
 
 						<div class="field">

Nem az összes módosított fájl került megjelenítésre, mert túl sok fájl változott