aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwxiaoguang <wxiaoguang@gmail.com>2024-05-20 08:56:45 +0800
committerGitHub <noreply@github.com>2024-05-20 00:56:45 +0000
commitedbf74c418061b013a5855f604dd6be6baf34132 (patch)
tree0c8fa83ec5f2eec37669d6eb75274a79de8f7e78
parent82a0c36332824b8ab41efdf6503e86170ce92f08 (diff)
downloadgitea-edbf74c418061b013a5855f604dd6be6baf34132.tar.gz
gitea-edbf74c418061b013a5855f604dd6be6baf34132.zip
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.
-rw-r--r--routers/api/v1/repo/migrate.go2
-rw-r--r--routers/api/v1/repo/repo.go4
-rw-r--r--routers/web/repo/repo.go2
-rw-r--r--services/migrations/gitea_uploader.go2
-rw-r--r--services/repository/repository.go2
-rw-r--r--services/task/task.go2
-rw-r--r--templates/repo/create.tmpl2
-rw-r--r--templates/repo/migrate/codebase.tmpl2
-rw-r--r--templates/repo/migrate/git.tmpl2
-rw-r--r--templates/repo/migrate/gitbucket.tmpl2
-rw-r--r--templates/repo/migrate/gitea.tmpl2
-rw-r--r--templates/repo/migrate/github.tmpl2
-rw-r--r--templates/repo/migrate/gitlab.tmpl2
-rw-r--r--templates/repo/migrate/gogs.tmpl2
-rw-r--r--templates/repo/migrate/onedev.tmpl2
-rw-r--r--templates/repo/settings/options.tmpl5
16 files changed, 19 insertions, 18 deletions
diff --git a/routers/api/v1/repo/migrate.go b/routers/api/v1/repo/migrate.go
index f246b08c0a..14c8c01f4e 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 e759142938..594f2d86f6 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 48be1c2296..71c582b5f9 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 c63383f5ca..4c8e036f05 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 d28200c0ad..b7aac3cfe0 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 e15cab7b3c..c90ee91270 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 c1c8c2185e..2e1de244ea 100644
--- a/templates/repo/create.tmpl
+++ b/templates/repo/create.tmpl
@@ -50,7 +50,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox">
{{if .IsForcedPrivate}}
- <input name="private" type="checkbox" checked readonly>
+ <input name="private" type="checkbox" checked disabled>
<label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}>
diff --git a/templates/repo/migrate/codebase.tmpl b/templates/repo/migrate/codebase.tmpl
index 439a883863..c8059b7c7b 100644
--- a/templates/repo/migrate/codebase.tmpl
+++ b/templates/repo/migrate/codebase.tmpl
@@ -89,7 +89,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox">
{{if .IsForcedPrivate}}
- <input name="private" type="checkbox" checked readonly>
+ <input name="private" type="checkbox" checked disabled>
<label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}>
diff --git a/templates/repo/migrate/git.tmpl b/templates/repo/migrate/git.tmpl
index db01b8d858..9c5f0d7d6d 100644
--- a/templates/repo/migrate/git.tmpl
+++ b/templates/repo/migrate/git.tmpl
@@ -63,7 +63,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox">
{{if .IsForcedPrivate}}
- <input name="private" type="checkbox" checked readonly>
+ <input name="private" type="checkbox" checked disabled>
<label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}>
diff --git a/templates/repo/migrate/gitbucket.tmpl b/templates/repo/migrate/gitbucket.tmpl
index d1f1db99ba..b667fa828a 100644
--- a/templates/repo/migrate/gitbucket.tmpl
+++ b/templates/repo/migrate/gitbucket.tmpl
@@ -105,7 +105,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox">
{{if .IsForcedPrivate}}
- <input name="private" type="checkbox" checked readonly>
+ <input name="private" type="checkbox" checked disabled>
<label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}>
diff --git a/templates/repo/migrate/gitea.tmpl b/templates/repo/migrate/gitea.tmpl
index 143f220449..3b8f377096 100644
--- a/templates/repo/migrate/gitea.tmpl
+++ b/templates/repo/migrate/gitea.tmpl
@@ -101,7 +101,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox">
{{if .IsForcedPrivate}}
- <input name="private" type="checkbox" checked readonly>
+ <input name="private" type="checkbox" checked disabled>
<label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}}
<input name="private" type="checkbox" {{if .private}} checked{{end}}>
diff --git a/templates/repo/migrate/github.tmpl b/templates/repo/migrate/github.tmpl
index dfb2b4bc46..3535eddfc2 100644
--- a/templates/repo/migrate/github.tmpl
+++ b/templates/repo/migrate/github.tmpl
@@ -103,7 +103,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox">
{{if .IsForcedPrivate}}
- <input name="private" type="checkbox" checked readonly>
+ <input name="private" type="checkbox" checked disabled>
<label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}>
diff --git a/templates/repo/migrate/gitlab.tmpl b/templates/repo/migrate/gitlab.tmpl
index 76c2828257..f705fb3090 100644
--- a/templates/repo/migrate/gitlab.tmpl
+++ b/templates/repo/migrate/gitlab.tmpl
@@ -100,7 +100,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox">
{{if .IsForcedPrivate}}
- <input name="private" type="checkbox" checked readonly>
+ <input name="private" type="checkbox" checked disabled>
<label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}>
diff --git a/templates/repo/migrate/gogs.tmpl b/templates/repo/migrate/gogs.tmpl
index b01d0eeb67..eca83b1636 100644
--- a/templates/repo/migrate/gogs.tmpl
+++ b/templates/repo/migrate/gogs.tmpl
@@ -103,7 +103,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox">
{{if .IsForcedPrivate}}
- <input name="private" type="checkbox" checked readonly>
+ <input name="private" type="checkbox" checked disabled>
<label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}}
<input name="private" type="checkbox" {{if .private}} checked{{end}}>
diff --git a/templates/repo/migrate/onedev.tmpl b/templates/repo/migrate/onedev.tmpl
index 8b2a2d8730..e1aad96ba4 100644
--- a/templates/repo/migrate/onedev.tmpl
+++ b/templates/repo/migrate/onedev.tmpl
@@ -89,7 +89,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox">
{{if .IsForcedPrivate}}
- <input name="private" type="checkbox" checked readonly>
+ <input name="private" type="checkbox" checked disabled>
<label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}>
diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl
index b94c202f16..3168384072 100644
--- a/templates/repo/settings/options.tmpl
+++ b/templates/repo/settings/options.tmpl
@@ -28,9 +28,10 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox" {{if and (not .Repository.IsPrivate) (gt .Repository.NumStars 0)}}data-tooltip-content="{{ctx.Locale.Tr "repo.stars_remove_warning"}}"{{end}}>
{{if .IsAdmin}}
- <input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}>
+ <input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}>
{{else}}
- <input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}{{if and $.ForcePrivate .Repository.IsPrivate}} readonly{{end}}>
+ <input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}{{if and $.ForcePrivate .Repository.IsPrivate}} disabled{{end}}>
+ {{if and .Repository.IsPrivate $.ForcePrivate}}<input type="hidden" name="private" value="{{.Repository.IsPrivate}}">{{end}}
{{end}}
<label>{{ctx.Locale.Tr "repo.visibility_helper"}} {{if .Repository.NumForks}}<span class="text red">{{ctx.Locale.Tr "repo.visibility_fork_helper"}}</span>{{end}}</label>
</div>