Skip to content

Commit

Permalink
move config options Service.EnableWiki, Server.EnableWiki to Repository
Browse files Browse the repository at this point in the history
Signed-off-by: Julian Picht <julian.picht@gmail.com>
  • Loading branch information
jpicht committed Aug 7, 2019
1 parent fe8ae36 commit c8d84df
Show file tree
Hide file tree
Showing 14 changed files with 35 additions and 35 deletions.
8 changes: 4 additions & 4 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ ACCESS_CONTROL_ALLOW_ORIGIN =
USE_COMPAT_SSH_URI = false
; Close issues as long as a commit on any branch marks it as fixed
DEFAULT_CLOSE_ISSUES_VIA_COMMITS_IN_ANY_BRANCH = false
; Set this to false to completely disable the wiki function
ENABLE_WIKI = true
; Set this to false to completely disable the issue function
ENABLE_ISSUES = true

[repository.editor]
; List of file extensions for which lines should be wrapped in the CodeMirror editor
Expand Down Expand Up @@ -424,10 +428,6 @@ SHOW_REGISTRATION_BUTTON = true
; When adding a repo to a team or creating a new repo all team members will watch the
; repo automatically if enabled
AUTO_WATCH_NEW_REPOS = true
; Set this to false to completely disable the wiki function
ENABLE_WIKI = true
; Set this to false to completely disable the issue function
ENABLE_ISSUES = true

[webhook]
; Hook task queue length, increase if webhook shooting starts hanging
Expand Down
4 changes: 2 additions & 2 deletions models/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -1278,7 +1278,7 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
var units = make([]RepoUnit, 0, len(DefaultRepoUnits))
for _, tp := range DefaultRepoUnits {
if tp == UnitTypeIssues {
if !setting.Service.EnableIssues {
if !setting.Repository.EnableIssues {
continue
}
units = append(units, RepoUnit{
Expand All @@ -1291,7 +1291,7 @@ func createRepository(e *xorm.Session, doer, u *User, repo *Repository) (err err
},
})
} else if tp == UnitTypeWiki {
if !setting.Service.EnableWiki {
if !setting.Repository.EnableWiki {
continue
}
} else if tp == UnitTypePullRequests {
Expand Down
11 changes: 11 additions & 0 deletions modules/setting/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ var (
Issue struct {
LockReasons []string
} `ini:"repository.issue"`

// global feature flags
EnableWiki bool
EnableIssues bool
}{
AnsiCharset: "",
ForcePrivate: false,
Expand Down Expand Up @@ -121,6 +125,9 @@ var (
}{
LockReasons: strings.Split("Too heated,Off-topic,Spam,Resolved", ","),
},

EnableWiki: true,
EnableIssues: true,
}
RepoRootPath string
ScriptType = "bash"
Expand All @@ -147,6 +154,10 @@ func newRepository() {
}
ScriptType = sec.Key("SCRIPT_TYPE").MustString("bash")

// feature flags
Repository.EnableIssues = sec.Key("ENABLE_ISSUES").MustBool(true)
Repository.EnableWiki = sec.Key("ENABLE_WIKI").MustBool(true)

if err = Cfg.Section("repository").MapTo(&Repository); err != nil {
log.Fatal("Failed to map Repository settings: %v", err)
} else if err = Cfg.Section("repository.editor").MapTo(&Repository.Editor); err != nil {
Expand Down
13 changes: 1 addition & 12 deletions modules/setting/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

// Service settings
var Service = struct {
var Service struct {
DefaultOrgVisibility string
DefaultOrgVisibilityMode structs.VisibleType
ActiveCodeLives int
Expand Down Expand Up @@ -48,13 +48,6 @@ var Service = struct {
EnableOpenIDSignUp bool
OpenIDWhitelist []*regexp.Regexp
OpenIDBlacklist []*regexp.Regexp

// global feature flags
EnableWiki bool
EnableIssues bool
}{
EnableWiki: true,
EnableIssues: true,
}

func newService() {
Expand Down Expand Up @@ -90,10 +83,6 @@ func newService() {
Service.DefaultOrgVisibility = sec.Key("DEFAULT_ORG_VISIBILITY").In("public", structs.ExtractKeysFromMapString(structs.VisibilityModes))
Service.DefaultOrgVisibilityMode = structs.VisibilityModes[Service.DefaultOrgVisibility]

// feature flags
Service.EnableIssues = sec.Key("ENABLE_ISSUES").MustBool(true)
Service.EnableWiki = sec.Key("ENABLE_WIKI").MustBool(true)

sec = Cfg.Section("openid")
Service.EnableOpenIDSignIn = sec.Key("ENABLE_OPENID_SIGNIN").MustBool(!InstallLock)
Service.EnableOpenIDSignUp = sec.Key("ENABLE_OPENID_SIGNUP").MustBool(!Service.DisableRegistration && Service.EnableOpenIDSignIn)
Expand Down
2 changes: 1 addition & 1 deletion routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ func mustAllowPulls(ctx *context.APIContext) {
}

func mustEnableIssuesOrPulls(ctx *context.APIContext) {
if (!setting.Service.EnableIssues || !ctx.Repo.CanRead(models.UnitTypeIssues)) &&
if (!setting.Repository.EnableIssues || !ctx.Repo.CanRead(models.UnitTypeIssues)) &&
!(ctx.Repo.Repository.CanEnablePulls() && ctx.Repo.CanRead(models.UnitTypePullRequests)) {
if ctx.Repo.Repository.CanEnablePulls() && log.IsTrace() {
if ctx.IsSigned {
Expand Down
2 changes: 1 addition & 1 deletion routers/repo/activity.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func Activity(ctx *context.Context) {
var err error
if ctx.Data["Activity"], err = models.GetActivityStats(ctx.Repo.Repository, timeFrom,
ctx.Repo.CanRead(models.UnitTypeReleases),
setting.Service.EnableIssues && ctx.Repo.CanRead(models.UnitTypeIssues),
setting.Repository.EnableIssues && ctx.Repo.CanRead(models.UnitTypeIssues),
ctx.Repo.CanRead(models.UnitTypePullRequests),
ctx.Repo.CanRead(models.UnitTypeCode)); err != nil {
ctx.ServerError("GetActivityStats", err)
Expand Down
6 changes: 3 additions & 3 deletions routers/repo/issue.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func MustAllowUserComment(ctx *context.Context) {

// MustEnableIssues check if repository enable internal issues
func MustEnableIssues(ctx *context.Context) {
if !setting.Service.EnableIssues ||
if !setting.Repository.EnableIssues ||
(!ctx.Repo.CanRead(models.UnitTypeIssues) &&
!ctx.Repo.CanRead(models.UnitTypeExternalTracker)) {
ctx.NotFound("MustEnableIssues", nil)
Expand Down Expand Up @@ -988,7 +988,7 @@ func GetActionIssue(ctx *context.Context) *models.Issue {

func checkIssueRights(ctx *context.Context, issue *models.Issue) {
if issue.IsPull && !ctx.Repo.CanRead(models.UnitTypePullRequests) ||
!issue.IsPull && (!setting.Service.EnableIssues || !ctx.Repo.CanRead(models.UnitTypeIssues)) {
!issue.IsPull && (!setting.Repository.EnableIssues || !ctx.Repo.CanRead(models.UnitTypeIssues)) {
ctx.NotFound("IssueOrPullRequestUnitNotAllowed", nil)
}
}
Expand All @@ -1013,7 +1013,7 @@ func getActionIssues(ctx *context.Context) []*models.Issue {
return nil
}
// Check access rights for all issues
issueUnitEnabled := setting.Service.EnableIssues && ctx.Repo.CanRead(models.UnitTypeIssues)
issueUnitEnabled := setting.Repository.EnableIssues && ctx.Repo.CanRead(models.UnitTypeIssues)
prUnitEnabled := ctx.Repo.CanRead(models.UnitTypePullRequests)
for _, issue := range issues {
if issue.IsPull && !prUnitEnabled || !issue.IsPull && !issueUnitEnabled {
Expand Down
2 changes: 1 addition & 1 deletion routers/repo/issue_label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func TestUpdateIssueLabel_Clear(t *testing.T) {
}

func TestUpdateIssueLabel_Toggle(t *testing.T) {
setting.Service.EnableIssues = true
setting.Repository.EnableIssues = true
for _, testCase := range []struct {
Action string
IssueIDs []int64
Expand Down
4 changes: 2 additions & 2 deletions routers/repo/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
})
}

if form.EnableWiki && setting.Service.EnableWiki {
if form.EnableWiki && setting.Repository.EnableWiki {
if form.EnableExternalWiki {
if !validation.IsValidExternalURL(form.ExternalWikiURL) {
ctx.Flash.Error(ctx.Tr("repo.settings.external_wiki_url_error"))
Expand All @@ -242,7 +242,7 @@ func SettingsPost(ctx *context.Context, form auth.RepoSettingForm) {
}
}

if form.EnableIssues && setting.Service.EnableIssues {
if form.EnableIssues && setting.Repository.EnableIssues {
if form.EnableExternalTracker {
if !validation.IsValidExternalURL(form.ExternalTrackerURL) {
ctx.Flash.Error(ctx.Tr("repo.settings.external_tracker_url_error"))
Expand Down
2 changes: 1 addition & 1 deletion routers/repo/wiki.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const (

// MustEnableWiki check if wiki is enabled, if external then redirect
func MustEnableWiki(ctx *context.Context) {
if !setting.Service.EnableWiki {
if !setting.Repository.EnableWiki {
ctx.NotFound("MustEnableWiki", nil)
return
}
Expand Down
2 changes: 1 addition & 1 deletion routers/user/home.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ func Issues(ctx *context.Context) {
ctx.ServerError("GetUserRepoPermission", fmt.Errorf("[%d]%v", repoID, err))
return
}
if !setting.Service.EnableIssues || !perm.CanRead(models.UnitTypeIssues) {
if !setting.Repository.EnableIssues || !perm.CanRead(models.UnitTypeIssues) {
if log.IsTrace() {
log.Trace("Permission Denied: User %-v cannot read %-v of repo %-v\n"+
"User in repo has Permissions: %-+v",
Expand Down
2 changes: 1 addition & 1 deletion templates/base/head_navbar.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

{{if .IsSigned}}
<a class="item {{if .PageIsDashboard}}active{{end}}" href="{{AppSubUrl}}/">{{.i18n.Tr "dashboard"}}</a>
{{if .Service.EnableIssues}}
{{if .Repository.EnableIssues}}
<a class="item {{if .PageIsIssues}}active{{end}}" href="{{AppSubUrl}}/issues">{{.i18n.Tr "issues"}}</a>
{{end}}
<a class="item {{if .PageIsPulls}}active{{end}}" href="{{AppSubUrl}}/pulls">{{.i18n.Tr "pull_requests"}}</a>
Expand Down
6 changes: 3 additions & 3 deletions templates/repo/header.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
</a>
{{end}}

{{if and .Service.EnableIssues (.Permission.CanRead $.UnitTypeIssues)}}
{{if and .Repository.EnableIssues (.Permission.CanRead $.UnitTypeIssues)}}
<a class="{{if .PageIsIssueList}}active{{end}} item" href="{{.RepoLink}}/issues">
<i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} <span class="ui {{if not .Repository.NumOpenIssues}}gray{{else}}blue{{end}} small label">{{.Repository.NumOpenIssues}}</span>
</a>
{{end}}

{{if and .Service.EnableIssues (.Permission.CanRead $.UnitTypeExternalTracker)}}
{{if and .Repository.EnableIssues (.Permission.CanRead $.UnitTypeExternalTracker)}}
<a class="{{if .PageIsIssueList}}active{{end}} item" href="{{.RepoExternalIssuesLink}}" target="_blank" rel="noopener noreferrer">
<i class="octicon octicon-link-external"></i> {{.i18n.Tr "repo.issues"}} </span>
</a>
Expand All @@ -79,7 +79,7 @@
</a>
{{end}}

{{if and .Service.EnableWiki (or (.Permission.CanRead $.UnitTypeWiki) (.Permission.CanRead $.UnitTypeExternalWiki))}}
{{if and .Repository.EnableWiki (or (.Permission.CanRead $.UnitTypeWiki) (.Permission.CanRead $.UnitTypeExternalWiki))}}
<a class="{{if .PageIsWiki}}active{{end}} item" href="{{.RepoLink}}/wiki" {{if (.Permission.CanRead $.UnitTypeExternalWiki)}} target="_blank" rel="noopener noreferrer" {{end}}>
<i class="octicon octicon-book"></i> {{.i18n.Tr "repo.wiki"}}
</a>
Expand Down
6 changes: 3 additions & 3 deletions templates/repo/settings/options.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@
{{.i18n.Tr "repo.settings.advanced_settings"}}
</h4>
<div class="ui attached segment">
{{if and (not .Service.EnableWiki) (not .Service.EnableIssues) (not .Repository.CanEnablePulls)}}
{{if and (not .Repository.EnableWiki) (not .Repository.EnableIssues) (not .Repository.CanEnablePulls)}}
<div class="inline field">
<label>{{.i18n.Tr "repo.wiki.disabled"}}</label>
</div>
Expand All @@ -121,7 +121,7 @@
{{.CsrfTokenHtml}}
<input type="hidden" name="action" value="advanced">

{{if .Service.EnableWiki}}
{{if .Repository.EnableWiki}}
{{$isWikiEnabled := or (.Repository.UnitEnabled $.UnitTypeWiki) (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}
<div class="inline field">
<label>{{.i18n.Tr "repo.wiki"}}</label>
Expand Down Expand Up @@ -157,7 +157,7 @@

<div class="ui divider"></div>

{{if .Service.EnableIssues}}
{{if .Repository.EnableIssues}}
{{$isIssuesEnabled := or (.Repository.UnitEnabled $.UnitTypeIssues) (.Repository.UnitEnabled $.UnitTypeExternalTracker)}}
<div class="inline field">
<label>{{.i18n.Tr "repo.issues"}}</label>
Expand Down

0 comments on commit c8d84df

Please sign in to comment.