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.
pull/30999/head^2
wxiaoguang 6 months ago committed by GitHub
parent 82a0c36332
commit edbf74c418
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 2
      routers/api/v1/repo/migrate.go
  2. 4
      routers/api/v1/repo/repo.go
  3. 2
      routers/web/repo/repo.go
  4. 2
      services/migrations/gitea_uploader.go
  5. 2
      services/repository/repository.go
  6. 2
      services/task/task.go
  7. 2
      templates/repo/create.tmpl
  8. 2
      templates/repo/migrate/codebase.tmpl
  9. 2
      templates/repo/migrate/git.tmpl
  10. 2
      templates/repo/migrate/gitbucket.tmpl
  11. 2
      templates/repo/migrate/gitea.tmpl
  12. 2
      templates/repo/migrate/github.tmpl
  13. 2
      templates/repo/migrate/gitlab.tmpl
  14. 2
      templates/repo/migrate/gogs.tmpl
  15. 2
      templates/repo/migrate/onedev.tmpl
  16. 3
      templates/repo/settings/options.tmpl

@ -175,7 +175,7 @@ func Migrate(ctx *context.APIContext) {
Description: opts.Description, Description: opts.Description,
OriginalURL: form.CloneAddr, OriginalURL: form.CloneAddr,
GitServiceType: gitServiceType, GitServiceType: gitServiceType,
IsPrivate: opts.Private, IsPrivate: opts.Private || setting.Repository.ForcePrivate,
IsMirror: opts.Mirror, IsMirror: opts.Mirror,
Status: repo_model.RepositoryBeingMigrated, Status: repo_model.RepositoryBeingMigrated,
}) })

@ -252,7 +252,7 @@ func CreateUserRepo(ctx *context.APIContext, owner *user_model.User, opt api.Cre
Gitignores: opt.Gitignores, Gitignores: opt.Gitignores,
License: opt.License, License: opt.License,
Readme: opt.Readme, Readme: opt.Readme,
IsPrivate: opt.Private, IsPrivate: opt.Private || setting.Repository.ForcePrivate,
AutoInit: opt.AutoInit, AutoInit: opt.AutoInit,
DefaultBranch: opt.DefaultBranch, DefaultBranch: opt.DefaultBranch,
TrustModel: repo_model.ToTrustModel(opt.TrustModel), TrustModel: repo_model.ToTrustModel(opt.TrustModel),
@ -364,7 +364,7 @@ func Generate(ctx *context.APIContext) {
Name: form.Name, Name: form.Name,
DefaultBranch: form.DefaultBranch, DefaultBranch: form.DefaultBranch,
Description: form.Description, Description: form.Description,
Private: form.Private, Private: form.Private || setting.Repository.ForcePrivate,
GitContent: form.GitContent, GitContent: form.GitContent,
Topics: form.Topics, Topics: form.Topics,
GitHooks: form.GitHooks, GitHooks: form.GitHooks,

@ -248,7 +248,7 @@ func CreatePost(ctx *context.Context) {
opts := repo_service.GenerateRepoOptions{ opts := repo_service.GenerateRepoOptions{
Name: form.RepoName, Name: form.RepoName,
Description: form.Description, Description: form.Description,
Private: form.Private, Private: form.Private || setting.Repository.ForcePrivate,
GitContent: form.GitContent, GitContent: form.GitContent,
Topics: form.Topics, Topics: form.Topics,
GitHooks: form.GitHooks, GitHooks: form.GitHooks,

@ -107,7 +107,7 @@ func (g *GiteaLocalUploader) CreateRepo(repo *base.Repository, opts base.Migrate
Description: repo.Description, Description: repo.Description,
OriginalURL: repo.OriginalURL, OriginalURL: repo.OriginalURL,
GitServiceType: opts.GitServiceType, GitServiceType: opts.GitServiceType,
IsPrivate: opts.Private, IsPrivate: opts.Private || setting.Repository.ForcePrivate,
IsMirror: opts.Mirror, IsMirror: opts.Mirror,
Status: repo_model.RepositoryBeingMigrated, Status: repo_model.RepositoryBeingMigrated,
}) })

@ -85,7 +85,7 @@ func PushCreateRepo(ctx context.Context, authUser, owner *user_model.User, repoN
repo, err := CreateRepository(ctx, authUser, owner, CreateRepoOptions{ repo, err := CreateRepository(ctx, authUser, owner, CreateRepoOptions{
Name: repoName, Name: repoName,
IsPrivate: setting.Repository.DefaultPushCreatePrivate, IsPrivate: setting.Repository.DefaultPushCreatePrivate || setting.Repository.ForcePrivate,
}) })
if err != nil { if err != nil {
return nil, err return nil, err

@ -107,7 +107,7 @@ func CreateMigrateTask(ctx context.Context, doer, u *user_model.User, opts base.
Description: opts.Description, Description: opts.Description,
OriginalURL: opts.OriginalURL, OriginalURL: opts.OriginalURL,
GitServiceType: opts.GitServiceType, GitServiceType: opts.GitServiceType,
IsPrivate: opts.Private, IsPrivate: opts.Private || setting.Repository.ForcePrivate,
IsMirror: opts.Mirror, IsMirror: opts.Mirror,
Status: repo_model.RepositoryBeingMigrated, Status: repo_model.RepositoryBeingMigrated,
}) })

@ -50,7 +50,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label> <label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox"> <div class="ui checkbox">
{{if .IsForcedPrivate}} {{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> <label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}} {{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}> <input name="private" type="checkbox" {{if .private}}checked{{end}}>

@ -89,7 +89,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label> <label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox"> <div class="ui checkbox">
{{if .IsForcedPrivate}} {{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> <label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}} {{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}> <input name="private" type="checkbox" {{if .private}}checked{{end}}>

@ -63,7 +63,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label> <label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox"> <div class="ui checkbox">
{{if .IsForcedPrivate}} {{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> <label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}} {{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}> <input name="private" type="checkbox" {{if .private}}checked{{end}}>

@ -105,7 +105,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label> <label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox"> <div class="ui checkbox">
{{if .IsForcedPrivate}} {{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> <label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}} {{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}> <input name="private" type="checkbox" {{if .private}}checked{{end}}>

@ -101,7 +101,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label> <label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox"> <div class="ui checkbox">
{{if .IsForcedPrivate}} {{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> <label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}} {{else}}
<input name="private" type="checkbox" {{if .private}} checked{{end}}> <input name="private" type="checkbox" {{if .private}} checked{{end}}>

@ -103,7 +103,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label> <label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox"> <div class="ui checkbox">
{{if .IsForcedPrivate}} {{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> <label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}} {{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}> <input name="private" type="checkbox" {{if .private}}checked{{end}}>

@ -100,7 +100,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label> <label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox"> <div class="ui checkbox">
{{if .IsForcedPrivate}} {{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> <label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}} {{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}> <input name="private" type="checkbox" {{if .private}}checked{{end}}>

@ -103,7 +103,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label> <label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox"> <div class="ui checkbox">
{{if .IsForcedPrivate}} {{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> <label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}} {{else}}
<input name="private" type="checkbox" {{if .private}} checked{{end}}> <input name="private" type="checkbox" {{if .private}} checked{{end}}>

@ -89,7 +89,7 @@
<label>{{ctx.Locale.Tr "repo.visibility"}}</label> <label>{{ctx.Locale.Tr "repo.visibility"}}</label>
<div class="ui checkbox"> <div class="ui checkbox">
{{if .IsForcedPrivate}} {{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> <label>{{ctx.Locale.Tr "repo.visibility_helper_forced"}}</label>
{{else}} {{else}}
<input name="private" type="checkbox" {{if .private}}checked{{end}}> <input name="private" type="checkbox" {{if .private}}checked{{end}}>

@ -30,7 +30,8 @@
{{if .IsAdmin}} {{if .IsAdmin}}
<input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}> <input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}>
{{else}} {{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}} {{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> <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> </div>

Loading…
Cancel
Save