From edbf74c418061b013a5855f604dd6be6baf34132 Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Mon, 20 May 2024 08:56:45 +0800 Subject: [PATCH] Fix "force private" logic (#31012) When creating a repo, the "FORCE_PRIVATE" config option should be respected, `readonly` doesn't work for checkbox, so it should use `disabled` attribute. --- routers/api/v1/repo/migrate.go | 2 +- routers/api/v1/repo/repo.go | 4 ++-- routers/web/repo/repo.go | 2 +- services/migrations/gitea_uploader.go | 2 +- services/repository/repository.go | 2 +- services/task/task.go | 2 +- templates/repo/create.tmpl | 2 +- templates/repo/migrate/codebase.tmpl | 2 +- templates/repo/migrate/git.tmpl | 2 +- templates/repo/migrate/gitbucket.tmpl | 2 +- templates/repo/migrate/gitea.tmpl | 2 +- templates/repo/migrate/github.tmpl | 2 +- templates/repo/migrate/gitlab.tmpl | 2 +- templates/repo/migrate/gogs.tmpl | 2 +- templates/repo/migrate/onedev.tmpl | 2 +- templates/repo/settings/options.tmpl | 5 +++-- 16 files changed, 19 insertions(+), 18 deletions(-) diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go index f246b08c0..14c8c01f4 100644 --- a/routers/api/v1/repo/migrate.go +++ b/routers/api/v1/repo/migrate.go @@ -175,7 +175,7 @@ func Migrate(ctx *context.APIContext) { Description: opts.Description, OriginalURL: form.CloneAddr, GitServiceType: gitServiceType, - IsPrivate: opts.Private, + IsPrivate: opts.Private || setting.Repository.ForcePrivate, IsMirror: opts.Mirror, Status: repo_model.RepositoryBeingMigrated, }) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index e75914293..594f2d86f 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -252,7 +252,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre Gitignores: opt.Gitignores, License: opt.License, Readme: opt.Readme, - IsPrivate: opt.Private, + IsPrivate: opt.Private || setting.Repository.ForcePrivate, AutoInit: opt.AutoInit, DefaultBranch: opt.DefaultBranch, TrustModel: repo_model.ToTrustModel(opt.TrustModel), @@ -364,7 +364,7 @@ func Generate(ctx *context.APIContext) { Name: form.Name, DefaultBranch: form.DefaultBranch, Description: form.Description, - Private: form.Private, + Private: form.Private || setting.Repository.ForcePrivate, GitContent: form.GitContent, Topics: form.Topics, GitHooks: form.GitHooks, diff --git a/routers/web/repo/repo.go b/routers/web/repo/repo.go index 48be1c229..71c582b5f 100644 --- a/routers/web/repo/repo.go +++ b/routers/web/repo/repo.go @@ -248,7 +248,7 @@ func CreatePost(ctx *context.Context) { opts := repo_service.GenerateRepoOptions{ Name: form.RepoName, Description: form.Description, - Private: form.Private, + Private: form.Private || setting.Repository.ForcePrivate, GitContent: form.GitContent, Topics: form.Topics, GitHooks: form.GitHooks, diff --git a/services/migrations/gitea_uploader.go b/services/migrations/gitea_uploader.go index c63383f5c..4c8e036f0 100644 --- a/services/migrations/gitea_uploader.go +++ b/services/migrations/gitea_uploader.go @@ -107,7 +107,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate Description: repo.Description, OriginalURL: repo.OriginalURL, GitServiceType: opts.GitServiceType, - IsPrivate: opts.Private, + IsPrivate: opts.Private || setting.Repository.ForcePrivate, IsMirror: opts.Mirror, Status: repo_model.RepositoryBeingMigrated, }) diff --git a/services/repository/repository.go b/services/repository/repository.go index d28200c0a..b7aac3cfe 100644 --- a/services/repository/repository.go +++ b/services/repository/repository.go @@ -85,7 +85,7 @@ func PushCreateRepo(ctx context.Context, authUser, owner *user_model.User, repoN repo, err := CreateRepository(ctx, authUser, owner, CreateRepoOptions{ Name: repoName, - IsPrivate: setting.Repository.DefaultPushCreatePrivate, + IsPrivate: setting.Repository.DefaultPushCreatePrivate || setting.Repository.ForcePrivate, }) if err != nil { return nil, err diff --git a/services/task/task.go b/services/task/task.go index e15cab7b3..c90ee9127 100644 --- a/services/task/task.go +++ b/services/task/task.go @@ -107,7 +107,7 @@ func CreateMigrateTask(ctx context.Context, doer, u *user_model.User, opts base. Description: opts.Description, OriginalURL: opts.OriginalURL, GitServiceType: opts.GitServiceType, - IsPrivate: opts.Private, + IsPrivate: opts.Private || setting.Repository.ForcePrivate, IsMirror: opts.Mirror, Status: repo_model.RepositoryBeingMigrated, }) diff --git a/templates/repo/create.tmpl b/templates/repo/create.tmpl index c1c8c2185..2e1de244e 100644 --- a/templates/repo/create.tmpl +++ b/templates/repo/create.tmpl @@ -50,7 +50,7 @@
{{if .IsForcedPrivate}} - + {{else}} diff --git a/templates/repo/migrate/codebase.tmpl b/templates/repo/migrate/codebase.tmpl index 439a88386..c8059b7c7 100644 --- a/templates/repo/migrate/codebase.tmpl +++ b/templates/repo/migrate/codebase.tmpl @@ -89,7 +89,7 @@
{{if .IsForcedPrivate}} - + {{else}} diff --git a/templates/repo/migrate/git.tmpl b/templates/repo/migrate/git.tmpl index db01b8d85..9c5f0d7d6 100644 --- a/templates/repo/migrate/git.tmpl +++ b/templates/repo/migrate/git.tmpl @@ -63,7 +63,7 @@
{{if .IsForcedPrivate}} - + {{else}} diff --git a/templates/repo/migrate/gitbucket.tmpl b/templates/repo/migrate/gitbucket.tmpl index d1f1db99b..b667fa828 100644 --- a/templates/repo/migrate/gitbucket.tmpl +++ b/templates/repo/migrate/gitbucket.tmpl @@ -105,7 +105,7 @@
{{if .IsForcedPrivate}} - + {{else}} diff --git a/templates/repo/migrate/gitea.tmpl b/templates/repo/migrate/gitea.tmpl index 143f22044..3b8f37709 100644 --- a/templates/repo/migrate/gitea.tmpl +++ b/templates/repo/migrate/gitea.tmpl @@ -101,7 +101,7 @@
{{if .IsForcedPrivate}} - + {{else}} diff --git a/templates/repo/migrate/github.tmpl b/templates/repo/migrate/github.tmpl index dfb2b4bc4..3535eddfc 100644 --- a/templates/repo/migrate/github.tmpl +++ b/templates/repo/migrate/github.tmpl @@ -103,7 +103,7 @@
{{if .IsForcedPrivate}} - + {{else}} diff --git a/templates/repo/migrate/gitlab.tmpl b/templates/repo/migrate/gitlab.tmpl index 76c282825..f705fb309 100644 --- a/templates/repo/migrate/gitlab.tmpl +++ b/templates/repo/migrate/gitlab.tmpl @@ -100,7 +100,7 @@
{{if .IsForcedPrivate}} - + {{else}} diff --git a/templates/repo/migrate/gogs.tmpl b/templates/repo/migrate/gogs.tmpl index b01d0eeb6..eca83b163 100644 --- a/templates/repo/migrate/gogs.tmpl +++ b/templates/repo/migrate/gogs.tmpl @@ -103,7 +103,7 @@
{{if .IsForcedPrivate}} - + {{else}} diff --git a/templates/repo/migrate/onedev.tmpl b/templates/repo/migrate/onedev.tmpl index 8b2a2d873..e1aad96ba 100644 --- a/templates/repo/migrate/onedev.tmpl +++ b/templates/repo/migrate/onedev.tmpl @@ -89,7 +89,7 @@
{{if .IsForcedPrivate}} - + {{else}} diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index b94c202f1..316838407 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -28,9 +28,10 @@
{{if .IsAdmin}} - + {{else}} - + + {{if and .Repository.IsPrivate $.ForcePrivate}}{{end}} {{end}}