Skip to content

Commit

Permalink
fix bug user could change private repository to public when force pri…
Browse files Browse the repository at this point in the history
…vate enabled. (#6156) (#6165)
  • Loading branch information
lunny authored and zeripath committed Feb 23, 2019
1 parent 585dd13 commit 55063f2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
package repo

import (
"errors"
"strings"
"time"

Expand Down Expand Up @@ -36,6 +37,7 @@ const (
func Settings(ctx *context.Context) {
ctx.Data["Title"] = ctx.Tr("repo.settings")
ctx.Data["PageIsSettingsOptions"] = true
ctx.Data["ForcePrivate"] = setting.Repository.ForcePrivate
ctx.HTML(200, tplSettingsOptions)
}

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

visibilityChanged := repo.IsPrivate != form.Private
// when ForcePrivate enabled, you could change public repo to private, but could not change private to public
if visibilityChanged && setting.Repository.ForcePrivate && !form.Private {
ctx.ServerError("Force Private enabled", errors.New("cannot change private repository to public"))
return
}

repo.IsPrivate = form.Private
if err := models.UpdateRepository(repo, visibilityChanged); err != nil {
ctx.ServerError("UpdateRepository", err)
Expand Down
2 changes: 1 addition & 1 deletion templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<div class="inline field">
<label>{{.i18n.Tr "repo.visibility"}}</label>
<div class="ui checkbox">
<input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}>
<input name="private" type="checkbox" {{if .Repository.IsPrivate}}checked{{end}}{{if and $.ForcePrivate .Repository.IsPrivate}} readonly{{end}}>
<label>{{.i18n.Tr "repo.visibility_helper" | Safe}} {{if .Repository.NumForks}}<span class="text red">{{.i18n.Tr "repo.visibility_fork_helper"}}</span>{{end}}</label>
</div>
</div>
Expand Down

0 comments on commit 55063f2

Please sign in to comment.