]> source.dussan.org Git - gitea.git/commitdiff
EnableUnit() -> UnitEnabled() (#2242)
authorEthan Koenig <etk39@cornell.edu>
Wed, 2 Aug 2017 08:46:54 +0000 (01:46 -0700)
committerLauris BH <lauris@nix.lv>
Wed, 2 Aug 2017 08:46:54 +0000 (11:46 +0300)
models/org_team.go
models/repo.go
modules/context/repo.go
routers/api/v1/api.go
routers/repo/issue.go
routers/repo/wiki.go
templates/org/team/new.tmpl
templates/repo/header.tmpl
templates/repo/settings/options.tmpl

index 8508a176c195e847252505bb50219a958d87f4bb..bc0e12b5043d1fb417bc979854ac9f4524bb9156 100644 (file)
@@ -192,8 +192,8 @@ func (t *Team) RemoveRepository(repoID int64) error {
        return sess.Commit()
 }
 
-// EnableUnit returns if the team enables unit type t
-func (t *Team) EnableUnit(tp UnitType) bool {
+// UnitEnabled returns if the team has the given unit type enabled
+func (t *Team) UnitEnabled(tp UnitType) bool {
        if len(t.UnitTypes) == 0 {
                return true
        }
index a651aae89b1af9f5337f8545750a874de13820cc..60c89836c01bf70036f6e260cfdb634dcdf41eb1 100644 (file)
@@ -398,8 +398,8 @@ func (repo *Repository) getUnitsByUserID(e Engine, userID int64, isAdmin bool) (
        return nil
 }
 
-// EnableUnit if this repository enabled some unit
-func (repo *Repository) EnableUnit(tp UnitType) bool {
+// UnitEnabled if this repository has the given unit enabled
+func (repo *Repository) UnitEnabled(tp UnitType) bool {
        repo.getUnits(x)
        for _, unit := range repo.Units {
                if unit.Type == tp {
@@ -658,7 +658,7 @@ func (repo *Repository) CanEnablePulls() bool {
 
 // AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
 func (repo *Repository) AllowsPulls() bool {
-       return repo.CanEnablePulls() && repo.EnableUnit(UnitTypePullRequests)
+       return repo.CanEnablePulls() && repo.UnitEnabled(UnitTypePullRequests)
 }
 
 // CanEnableEditor returns true if repository meets the requirements of web editor.
index 3dface7da77e4580794e27e982eda62f7b00d6c3..897cd3ca1a5b9a7d4b2e3213f6bf20307439f448 100644 (file)
@@ -523,14 +523,7 @@ func LoadRepoUnits() macaron.Handler {
 // CheckUnit will check whether
 func CheckUnit(unitType models.UnitType) macaron.Handler {
        return func(ctx *Context) {
-               var find bool
-               for _, unit := range ctx.Repo.Repository.Units {
-                       if unit.Type == unitType {
-                               find = true
-                               break
-                       }
-               }
-               if !find {
+               if !ctx.Repo.Repository.UnitEnabled(unitType) {
                        ctx.Handle(404, "CheckUnit", fmt.Errorf("%s: %v", ctx.Tr("units.error.unit_not_allowed"), unitType))
                }
        }
index b3cb3906a3119714e9ffaa506a51cdd98fc07dfc..23c7c7c3052fcec7ea219990b68ca2d7075cd0e0 100644 (file)
@@ -235,7 +235,7 @@ func orgAssignment(args ...bool) macaron.Handler {
 }
 
 func mustEnableIssues(ctx *context.APIContext) {
-       if !ctx.Repo.Repository.EnableUnit(models.UnitTypeIssues) {
+       if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) {
                ctx.Status(404)
                return
        }
index f3799fdb993fe90ddbf741c7905c778d69351916..473e82971393d3f1b0d14f367ae81ca1b1485611 100644 (file)
@@ -59,8 +59,8 @@ var (
 
 // MustEnableIssues check if repository enable internal issues
 func MustEnableIssues(ctx *context.Context) {
-       if !ctx.Repo.Repository.EnableUnit(models.UnitTypeIssues) &&
-               !ctx.Repo.Repository.EnableUnit(models.UnitTypeExternalTracker) {
+       if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) &&
+               !ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalTracker) {
                ctx.Handle(404, "MustEnableIssues", nil)
                return
        }
index 2dcf37cc869e2d0e1929110648e9ed0874b975dd..2a73fdc41e9fdb8aac2dca9acf84047c634c8bb4 100644 (file)
@@ -31,8 +31,8 @@ const (
 
 // MustEnableWiki check if wiki is enabled, if external then redirect
 func MustEnableWiki(ctx *context.Context) {
-       if !ctx.Repo.Repository.EnableUnit(models.UnitTypeWiki) &&
-               !ctx.Repo.Repository.EnableUnit(models.UnitTypeExternalWiki) {
+       if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeWiki) &&
+               !ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalWiki) {
                ctx.Handle(404, "MustEnableWiki", nil)
                return
        }
index 79338394bfd4cf0a5112b13ee93fe224b5905ef0..27335e247a216ca0ce42d280bd02eadbfabac415 100644 (file)
@@ -57,7 +57,7 @@
                                                        {{range $t, $unit := $.Units}}
                                                        <div class="field">
                                                                <div class="ui toggle checkbox">
-                                                                       <input type="checkbox" class="hidden" name="units" value="{{$unit.Type}}"{{if $.Team.EnableUnit $unit.Type}} checked{{end}}>
+                                                                       <input type="checkbox" class="hidden" name="units" value="{{$unit.Type}}"{{if $.Team.UnitEnabled $unit.Type}} checked{{end}}>
                                                                        <label>{{$.i18n.Tr $unit.NameKey}}</label>
                                                                        <span class="help">{{$.i18n.Tr $unit.DescKey}}</span>
                                                                </div>
index db636eb9bd7b503cb9944073f94b91b27194f411..7c91000488fda0faca9eaa4540b52fe2ad031e0f 100644 (file)
 {{if not .IsDiffCompare}}
        <div class="ui tabs container">
                <div class="ui tabular stackable menu navbar">
-                       {{if .Repository.EnableUnit $.UnitTypeCode}}
+                       {{if .Repository.UnitEnabled $.UnitTypeCode}}
                        <a class="{{if .PageIsViewCode}}active{{end}} item" href="{{.RepoLink}}">
                                <i class="octicon octicon-code"></i> {{.i18n.Tr "repo.code"}}
                        </a>
                        {{end}}
 
-                       {{if .Repository.EnableUnit $.UnitTypeIssues}}
+                       {{if .Repository.UnitEnabled $.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 .Repository.EnableUnit $.UnitTypeExternalTracker}}
+                       {{if .Repository.UnitEnabled $.UnitTypeExternalTracker}}
                                <a class="{{if .PageIsIssueList}}active{{end}} item" href="{{.RepoLink}}/issues">
                                        <i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} </span>
                                </a>
                                </a>
                        {{end}}
 
-                       {{if and (.Repository.EnableUnit $.UnitTypeCode) (not .IsBareRepo)}}
+                       {{if and (.Repository.UnitEnabled $.UnitTypeCode) (not .IsBareRepo)}}
                        <a class="{{if (or (.PageIsCommits) (.PageIsDiff))}}active{{end}} item" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}">
                                <i class="octicon octicon-history"></i> {{.i18n.Tr "repo.commits"}} <span class="ui {{if not .CommitsCount}}gray{{else}}blue{{end}} small label">{{.CommitsCount}}</span>
                        </a>
                        {{end}}
 
-                       {{if and (.Repository.EnableUnit $.UnitTypeReleases) (not .IsBareRepo) }}
+                       {{if and (.Repository.UnitEnabled $.UnitTypeReleases) (not .IsBareRepo) }}
                        <a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases">
                                <i class="octicon octicon-tag"></i> {{.i18n.Tr "repo.releases"}} <span class="ui {{if not .Repository.NumTags}}gray{{else}}blue{{end}} small label">{{.Repository.NumTags}}</span>
                        </a>
                        {{end}}
 
-                       {{if or (.Repository.EnableUnit $.UnitTypeWiki) (.Repository.EnableUnit $.UnitTypeExternalWiki)}}
+                       {{if or (.Repository.UnitEnabled $.UnitTypeWiki) (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}
                                <a class="{{if .PageIsWiki}}active{{end}} item" href="{{.RepoLink}}/wiki">
                                        <i class="octicon octicon-book"></i> {{.i18n.Tr "repo.wiki"}}
                                </a>
index 8ad09d4306d782f4a6aad43d31ad325a59b3615b..8a7ea218bc9b5034fa3928a0c44c0725a2ceafc7 100644 (file)
@@ -93,7 +93,7 @@
                                {{.CsrfTokenHtml}}
                                <input type="hidden" name="action" value="advanced">
 
-                               {{$isWikiEnabled := or (.Repository.EnableUnit $.UnitTypeWiki) (.Repository.EnableUnit $.UnitTypeExternalWiki)}}
+                               {{$isWikiEnabled := or (.Repository.UnitEnabled $.UnitTypeWiki) (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}
                                <div class="inline field">
                                        <label>{{.i18n.Tr "repo.wiki"}}</label>
                                        <div class="ui checkbox">
                                <div class="field {{if not $isWikiEnabled}}disabled{{end}}" id="wiki_box">
                                        <div class="field">
                                                <div class="ui radio checkbox">
-                                                       <input class="hidden enable-system-radio" tabindex="0" name="enable_external_wiki" type="radio" value="false" data-target="#external_wiki_box" {{if not (.Repository.EnableUnit $.UnitTypeExternalWiki)}}checked{{end}}/>
+                                                       <input class="hidden enable-system-radio" tabindex="0" name="enable_external_wiki" type="radio" value="false" data-target="#external_wiki_box" {{if not (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}checked{{end}}/>
                                                        <label>{{.i18n.Tr "repo.settings.use_internal_wiki"}}</label>
                                                </div>
                                        </div>
                                        <div class="field">
                                                <div class="ui radio checkbox">
-                                                       <input class="hidden enable-system-radio" tabindex="0" name="enable_external_wiki" type="radio" value="true" data-target="#external_wiki_box" {{if .Repository.EnableUnit $.UnitTypeExternalWiki}}checked{{end}}/>
+                                                       <input class="hidden enable-system-radio" tabindex="0" name="enable_external_wiki" type="radio" value="true" data-target="#external_wiki_box" {{if .Repository.UnitEnabled $.UnitTypeExternalWiki}}checked{{end}}/>
                                                        <label>{{.i18n.Tr "repo.settings.use_external_wiki"}}</label>
                                                </div>
                                        </div>
-                                       <div class="field {{if not (.Repository.EnableUnit $.UnitTypeExternalWiki)}}disabled{{end}}" id="external_wiki_box">
+                                       <div class="field {{if not (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}disabled{{end}}" id="external_wiki_box">
                                                <label for="external_wiki_url">{{.i18n.Tr "repo.settings.external_wiki_url"}}</label>
                                                <input id="external_wiki_url" name="external_wiki_url" type="url" value="{{(.Repository.MustGetUnit $.UnitTypeExternalWiki).ExternalWikiConfig.ExternalWikiURL}}">
                                                <p class="help">{{.i18n.Tr "repo.settings.external_wiki_url_desc"}}</p>
 
                                <div class="ui divider"></div>
 
-                               {{$isIssuesEnabled := or (.Repository.EnableUnit $.UnitTypeIssues) (.Repository.EnableUnit $.UnitTypeExternalTracker)}}
+                               {{$isIssuesEnabled := or (.Repository.UnitEnabled $.UnitTypeIssues) (.Repository.UnitEnabled $.UnitTypeExternalTracker)}}
                                <div class="inline field">
                                        <label>{{.i18n.Tr "repo.issues"}}</label>
                                        <div class="ui checkbox">
                                <div class="field {{if not $isIssuesEnabled}}disabled{{end}}" id="issue_box">
                                        <div class="field">
                                                <div class="ui radio checkbox">
-                                                       <input class="hidden enable-system-radio" tabindex="0" name="enable_external_tracker" type="radio" value="false" data-target="#external_issue_box" {{if not (.Repository.EnableUnit $.UnitTypeExternalTracker)}}checked{{end}}/>
+                                                       <input class="hidden enable-system-radio" tabindex="0" name="enable_external_tracker" type="radio" value="false" data-target="#external_issue_box" {{if not (.Repository.UnitEnabled $.UnitTypeExternalTracker)}}checked{{end}}/>
                                                        <label>{{.i18n.Tr "repo.settings.use_internal_issue_tracker"}}</label>
                                                </div>
                                        </div>
                                        <div class="field">
                                                <div class="ui radio checkbox">
-                                                       <input class="hidden enable-system-radio" tabindex="0" name="enable_external_tracker" type="radio" value="true" data-target="#external_issue_box" {{if .Repository.EnableUnit $.UnitTypeExternalTracker}}checked{{end}}/>
+                                                       <input class="hidden enable-system-radio" tabindex="0" name="enable_external_tracker" type="radio" value="true" data-target="#external_issue_box" {{if .Repository.UnitEnabled $.UnitTypeExternalTracker}}checked{{end}}/>
                                                        <label>{{.i18n.Tr "repo.settings.use_external_issue_tracker"}}</label>
                                                </div>
                                        </div>
-                                       <div class="field {{if not (.Repository.EnableUnit $.UnitTypeExternalTracker)}}disabled{{end}}" id="external_issue_box">
+                                       <div class="field {{if not (.Repository.UnitEnabled $.UnitTypeExternalTracker)}}disabled{{end}}" id="external_issue_box">
                                                <div class="field">
                                                        <label for="external_tracker_url">{{.i18n.Tr "repo.settings.external_tracker_url"}}</label>
                                                        <input id="external_tracker_url" name="external_tracker_url" type="url" value="{{(.Repository.MustGetUnit $.UnitTypeExternalTracker).ExternalTrackerConfig.ExternalTrackerURL}}">
                                        <div class="inline field">
                                                <label>{{.i18n.Tr "repo.pulls"}}</label>
                                                <div class="ui checkbox">
-                                                       <input name="enable_pulls" type="checkbox" {{if .Repository.EnableUnit $.UnitTypePullRequests}}checked{{end}}>
+                                                       <input name="enable_pulls" type="checkbox" {{if .Repository.UnitEnabled $.UnitTypePullRequests}}checked{{end}}>
                                                        <label>{{.i18n.Tr "repo.settings.pulls_desc"}}</label>
                                                </div>
                                        </div>
                                </div>
                        </div>
 
-                       {{if .Repository.EnableUnit $.UnitTypeWiki}}
+                       {{if .Repository.UnitEnabled $.UnitTypeWiki}}
                                <div class="ui divider"></div>
 
                                <div class="item">
                </div>
        </div>
 
-       {{if .Repository.EnableUnit $.UnitTypeWiki}}
+       {{if .Repository.UnitEnabled $.UnitTypeWiki}}
        <div class="ui small modal" id="delete-wiki-modal">
                <div class="header">
                        {{.i18n.Tr "repo.settings.wiki-delete"}}