diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2017-12-20 06:59:56 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-20 06:59:56 -0600 |
commit | 529482135c8e9304dd7cdf08772eaba61d903894 (patch) | |
tree | d505021b322cf06ab431fa508036221c4c46b677 /routers/repo | |
parent | e67b4055f9087cc381df437502f3cd912abb53ed (diff) | |
download | gitea-529482135c8e9304dd7cdf08772eaba61d903894.tar.gz gitea-529482135c8e9304dd7cdf08772eaba61d903894.zip |
Support default private when creating or migrating repository (#3239)
* support default private when creating or migrating repository
* fix fmt
* use string constants on repository default private in app.ini
* fix fmt
Diffstat (limited to 'routers/repo')
-rw-r--r-- | routers/repo/repo.go | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/routers/repo/repo.go b/routers/repo/repo.go index 36105bfe17..aedc4e5477 100644 --- a/routers/repo/repo.go +++ b/routers/repo/repo.go @@ -81,6 +81,19 @@ func checkContextUser(ctx *context.Context, uid int64) *models.User { return org } +func getRepoPrivate(ctx *context.Context) bool { + switch strings.ToLower(setting.Repository.DefaultPrivate) { + case setting.RepoCreatingLastUserVisibility: + return ctx.User.LastRepoVisibility + case setting.RepoCreatingPrivate: + return true + case setting.RepoCreatingPublic: + return false + default: + return ctx.User.LastRepoVisibility + } +} + // Create render creating repository page func Create(ctx *context.Context) { if !ctx.User.CanCreateRepo() { @@ -94,7 +107,7 @@ func Create(ctx *context.Context) { ctx.Data["Licenses"] = models.Licenses ctx.Data["Readmes"] = models.Readmes ctx.Data["readme"] = "Default" - ctx.Data["private"] = ctx.User.LastRepoVisibility + ctx.Data["private"] = getRepoPrivate(ctx) ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate ctxUser := checkContextUser(ctx, ctx.QueryInt64("org")) @@ -170,7 +183,7 @@ func CreatePost(ctx *context.Context, form auth.CreateRepoForm) { // Migrate render migration of repository page func Migrate(ctx *context.Context) { ctx.Data["Title"] = ctx.Tr("new_migrate") - ctx.Data["private"] = ctx.User.LastRepoVisibility + ctx.Data["private"] = getRepoPrivate(ctx) ctx.Data["IsForcedPrivate"] = setting.Repository.ForcePrivate ctx.Data["mirror"] = ctx.Query("mirror") == "1" ctx.Data["LFSActive"] = setting.LFS.StartServer |