Skip to content

Commit 55063f2

Browse files
lunnyzeripath
authored andcommitted
fix bug user could change private repository to public when force private enabled. (#6156) (#6165)
1 parent 585dd13 commit 55063f2

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

routers/repo/setting.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
package repo
77

88
import (
9+
"errors"
910
"strings"
1011
"time"
1112

@@ -36,6 +37,7 @@ const (
3637
func Settings(ctx *context.Context) {
3738
ctx.Data["Title"] = ctx.Tr("repo.settings")
3839
ctx.Data["PageIsSettingsOptions"] = true
40+
ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate
3941
ctx.HTML(200, tplSettingsOptions)
4042
}
4143

@@ -94,6 +96,12 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
9496
}
9597

9698
visibilityChanged := repo.IsPrivate != form.Private
99+
// when ForcePrivate enabled, you could change public repo to private, but could not change private to public
100+
if visibilityChanged && setting.Repository.ForcePrivate && !form.Private {
101+
ctx.ServerError("Force Private enabled", errors.New("cannot change private repository to public"))
102+
return
103+
}
104+
97105
repo.IsPrivate = form.Private
98106
if err := models.UpdateRepository(repo, visibilityChanged); err != nil {
99107
ctx.ServerError("UpdateRepository", err)

templates/repo/settings/options.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<div class="inline field">
2020
<label>{{.i18n.Tr "repo.visibility"}}</label>
2121
<div class="ui checkbox">
22-
<input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}>
22+
<input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}{{if and $.ForcePrivate .Repository.IsPrivate}} readonly{{end}}>
2323
<label>{{.i18n.Tr "repo.visibility_helper" | Safe}} {{if .Repository.NumForks}}<span class="text red">{{.i18n.Tr "repo.visibility_fork_helper"}}</span>{{end}}</label>
2424
</div>
2525
</div>

0 commit comments

Comments
 (0)