]> source.dussan.org Git - gitea.git/commitdiff
Fix "force private" logic (#31012) (#31021)
authorGiteabot <teabot@gitea.io>
Mon, 20 May 2024 02:27:52 +0000 (10:27 +0800)
committerGitHub <noreply@github.com>
Mon, 20 May 2024 02:27:52 +0000 (10:27 +0800)
Backport #31012 by wxiaoguang

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
16 files changed:
routers/api/v1/repo/migrate.go
routers/api/v1/repo/repo.go
routers/web/repo/repo.go
services/migrations/gitea_uploader.go
services/repository/repository.go
services/task/task.go
templates/repo/create.tmpl
templates/repo/migrate/codebase.tmpl
templates/repo/migrate/git.tmpl
templates/repo/migrate/gitbucket.tmpl
templates/repo/migrate/gitea.tmpl
templates/repo/migrate/github.tmpl
templates/repo/migrate/gitlab.tmpl
templates/repo/migrate/gogs.tmpl
templates/repo/migrate/onedev.tmpl
templates/repo/settings/options.tmpl

index 2caaa130e8d012c78df194a9bf5ab7d263f9047c..44db2fe15c209db56ac479397e02e5db3d2f379f 100644 (file)
@@ -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,
        })
index e759142938168f8a736f824ab4c028531ea64668..594f2d86f6a6c6f26e10d352e0b3b2db687b14b9 100644 (file)
@@ -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,
index 48be1c22968fbe4b041ccd366013d3101b22f348..71c582b5f98e5375780808037c2a0043e67ddb77 100644 (file)
@@ -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,
index 87691bf729617f7ade7f9e3217f741a6003c5d21..bfe2afa8ccc0d0b3a874225085333bee7f4673b4 100644 (file)
@@ -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,
                })
index d28200c0adc5d59274b3114c0b6d532e76147528..b7aac3cfe0d8e5fba5dec5f406f18bb1cb0a0ac0 100644 (file)
@@ -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
index e15cab7b3c97fffa79bc780c3f9cb5602d8305ad..c90ee912709381c8d52d33b3fd32086d36b0d18b 100644 (file)
@@ -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,
        })
index c1c8c2185e9f23128b3ffc3b221eb7bd97d96e19..2e1de244ea19c1eab24c5db6b91697f7f2e154dc 100644 (file)
@@ -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}}>
index 439a8838637a6effce55cfe36e3ba421c286afd9..c8059b7c7b0994e8f9208c8dd18b24c168ff1118 100644 (file)
@@ -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}}>
index db01b8d85822d827e53473bf063103e1cd722b48..9c5f0d7d6dad2bff8567cbfcc209fc03aac45edd 100644 (file)
@@ -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}}>
index d1f1db99ba79de7c08c5a0cbb584a555a2ab1cbe..b667fa828a2fdbdf3812fd7df418a7a208f6854b 100644 (file)
                                                <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}}>
index 143f2204495d2f391fac4b4afece9859234ac091..3b8f377096cc3b76af336a3a408edd7f90d0e0d7 100644 (file)
                                                <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}}>
index dfb2b4bc469d81e3f6eb60471fe07ce3cb4e458f..3535eddfc2067cfe3eb2c7171108a96948a208c2 100644 (file)
                                                <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}}>
index 76c282825762554cb0fb8cfd1e80df48d3b4fd25..f705fb3090c60070703bfc2a7182bee3d82625a7 100644 (file)
                                                <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}}>
index b01d0eeb67cde2149ff6a9de51c260bae6ea48cc..eca83b163617f46f34f04c0ce33f933b8048ca03 100644 (file)
                                                <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}}>
index 8b2a2d8730218e2478aac272093353515696d75b..e1aad96ba40491b834dcf29972d16351f758dfb5 100644 (file)
@@ -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}}>
index b94c202f168d13c923906207a91042e4b0675f06..3168384072bec6ca66509d98eb20887564bc0793 100644 (file)
                                                <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>