Skip to content

Commit 458a1ac

Browse files
committed
respect ForcePrivate
1 parent 48173b0 commit 458a1ac

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

routers/web/repo/setting/setting.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ const (
4949
tplDeployKeys templates.TplName = "repo/settings/deploy_keys"
5050
)
5151

52+
func parseFormAccessMode(permission string, allowed ...perm.AccessMode) perm.AccessMode {
53+
// if site admin forces repositories to be private, then do not allow any other access mode,
54+
// otherwise the "force private" setting would be bypassed
55+
if setting.Repository.ForcePrivate {
56+
return perm.AccessModeNone
57+
}
58+
return perm.ParseAccessMode(permission, allowed...)
59+
}
60+
5261
// SettingsCtxData is a middleware that sets all the general context data for the
5362
// settings template.
5463
func SettingsCtxData(ctx *context.Context) {
@@ -449,7 +458,7 @@ func SettingsPost(ctx *context.Context) {
449458
units = append(units, repo_model.RepoUnit{
450459
RepoID: repo.ID,
451460
Type: unit_model.TypeCode,
452-
EveryoneAccessMode: perm.ParseAccessMode(form.DefaultCodeEveryoneAccess, perm.AccessModeNone, perm.AccessModeRead),
461+
EveryoneAccessMode: parseFormAccessMode(form.DefaultCodeEveryoneAccess, perm.AccessModeNone, perm.AccessModeRead),
453462
})
454463
} else if !unit_model.TypeCode.UnitGlobalDisabled() {
455464
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeCode)
@@ -475,7 +484,7 @@ func SettingsPost(ctx *context.Context) {
475484
RepoID: repo.ID,
476485
Type: unit_model.TypeWiki,
477486
Config: new(repo_model.UnitConfig),
478-
EveryoneAccessMode: perm.ParseAccessMode(form.DefaultWikiEveryoneAccess, perm.AccessModeNone, perm.AccessModeRead, perm.AccessModeWrite),
487+
EveryoneAccessMode: parseFormAccessMode(form.DefaultWikiEveryoneAccess, perm.AccessModeNone, perm.AccessModeRead, perm.AccessModeWrite),
479488
})
480489
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalWiki)
481490
} else {
@@ -525,7 +534,7 @@ func SettingsPost(ctx *context.Context) {
525534
AllowOnlyContributorsToTrackTime: form.AllowOnlyContributorsToTrackTime,
526535
EnableDependencies: form.EnableIssueDependencies,
527536
},
528-
EveryoneAccessMode: perm.ParseAccessMode(form.DefaultIssuesEveryoneAccess, perm.AccessModeNone, perm.AccessModeRead),
537+
EveryoneAccessMode: parseFormAccessMode(form.DefaultIssuesEveryoneAccess, perm.AccessModeNone, perm.AccessModeRead),
529538
})
530539
deleteUnitTypes = append(deleteUnitTypes, unit_model.TypeExternalTracker)
531540
} else {

0 commit comments

Comments
 (0)