Skip to content

Commit 9d86559

Browse files
committed
EnableUnit() -> UnitEnabled()
1 parent 31411a9 commit 9d86559

File tree

9 files changed

+29
-36
lines changed

9 files changed

+29
-36
lines changed

models/org_team.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,8 @@ func (t *Team) RemoveRepository(repoID int64) error {
192192
return sess.Commit()
193193
}
194194

195-
// EnableUnit returns if the team enables unit type t
196-
func (t *Team) EnableUnit(tp UnitType) bool {
195+
// UnitEnabled returns if the team has the given unit type enabled
196+
func (t *Team) UnitEnabled(tp UnitType) bool {
197197
if len(t.UnitTypes) == 0 {
198198
return true
199199
}

models/repo.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,8 +398,8 @@ func (repo *Repository) getUnitsByUserID(e Engine, userID int64, isAdmin bool) (
398398
return nil
399399
}
400400

401-
// EnableUnit if this repository enabled some unit
402-
func (repo *Repository) EnableUnit(tp UnitType) bool {
401+
// UnitEnabled if this repository has the given unit enabled
402+
func (repo *Repository) UnitEnabled(tp UnitType) bool {
403403
repo.getUnits(x)
404404
for _, unit := range repo.Units {
405405
if unit.Type == tp {
@@ -658,7 +658,7 @@ func (repo *Repository) CanEnablePulls() bool {
658658

659659
// AllowsPulls returns true if repository meets the requirements of accepting pulls and has them enabled.
660660
func (repo *Repository) AllowsPulls() bool {
661-
return repo.CanEnablePulls() && repo.EnableUnit(UnitTypePullRequests)
661+
return repo.CanEnablePulls() && repo.UnitEnabled(UnitTypePullRequests)
662662
}
663663

664664
// CanEnableEditor returns true if repository meets the requirements of web editor.

modules/context/repo.go

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -523,14 +523,7 @@ func LoadRepoUnits() macaron.Handler {
523523
// CheckUnit will check whether
524524
func CheckUnit(unitType models.UnitType) macaron.Handler {
525525
return func(ctx *Context) {
526-
var find bool
527-
for _, unit := range ctx.Repo.Repository.Units {
528-
if unit.Type == unitType {
529-
find = true
530-
break
531-
}
532-
}
533-
if !find {
526+
if !ctx.Repo.Repository.UnitEnabled(unitType) {
534527
ctx.Handle(404, "CheckUnit", fmt.Errorf("%s: %v", ctx.Tr("units.error.unit_not_allowed"), unitType))
535528
}
536529
}

routers/api/v1/api.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ func orgAssignment(args ...bool) macaron.Handler {
235235
}
236236

237237
func mustEnableIssues(ctx *context.APIContext) {
238-
if !ctx.Repo.Repository.EnableUnit(models.UnitTypeIssues) {
238+
if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) {
239239
ctx.Status(404)
240240
return
241241
}

routers/repo/issue.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,8 @@ var (
5959

6060
// MustEnableIssues check if repository enable internal issues
6161
func MustEnableIssues(ctx *context.Context) {
62-
if !ctx.Repo.Repository.EnableUnit(models.UnitTypeIssues) &&
63-
!ctx.Repo.Repository.EnableUnit(models.UnitTypeExternalTracker) {
62+
if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeIssues) &&
63+
!ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalTracker) {
6464
ctx.Handle(404, "MustEnableIssues", nil)
6565
return
6666
}

routers/repo/wiki.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ const (
3131

3232
// MustEnableWiki check if wiki is enabled, if external then redirect
3333
func MustEnableWiki(ctx *context.Context) {
34-
if !ctx.Repo.Repository.EnableUnit(models.UnitTypeWiki) &&
35-
!ctx.Repo.Repository.EnableUnit(models.UnitTypeExternalWiki) {
34+
if !ctx.Repo.Repository.UnitEnabled(models.UnitTypeWiki) &&
35+
!ctx.Repo.Repository.UnitEnabled(models.UnitTypeExternalWiki) {
3636
ctx.Handle(404, "MustEnableWiki", nil)
3737
return
3838
}

templates/org/team/new.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
{{range $t, $unit := $.Units}}
5858
<div class="field">
5959
<div class="ui toggle checkbox">
60-
<input type="checkbox" class="hidden" name="units" value="{{$unit.Type}}"{{if $.Team.EnableUnit $unit.Type}} checked{{end}}>
60+
<input type="checkbox" class="hidden" name="units" value="{{$unit.Type}}"{{if $.Team.UnitEnabled $unit.Type}} checked{{end}}>
6161
<label>{{$.i18n.Tr $unit.NameKey}}</label>
6262
<span class="help">{{$.i18n.Tr $unit.DescKey}}</span>
6363
</div>

templates/repo/header.tmpl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,19 +49,19 @@
4949
{{if not .IsDiffCompare}}
5050
<div class="ui tabs container">
5151
<div class="ui tabular stackable menu navbar">
52-
{{if .Repository.EnableUnit $.UnitTypeCode}}
52+
{{if .Repository.UnitEnabled $.UnitTypeCode}}
5353
<a class="{{if .PageIsViewCode}}active{{end}} item" href="{{.RepoLink}}">
5454
<i class="octicon octicon-code"></i> {{.i18n.Tr "repo.code"}}
5555
</a>
5656
{{end}}
5757

58-
{{if .Repository.EnableUnit $.UnitTypeIssues}}
58+
{{if .Repository.UnitEnabled $.UnitTypeIssues}}
5959
<a class="{{if .PageIsIssueList}}active{{end}} item" href="{{.RepoLink}}/issues">
6060
<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>
6161
</a>
6262
{{end}}
6363

64-
{{if .Repository.EnableUnit $.UnitTypeExternalTracker}}
64+
{{if .Repository.UnitEnabled $.UnitTypeExternalTracker}}
6565
<a class="{{if .PageIsIssueList}}active{{end}} item" href="{{.RepoLink}}/issues">
6666
<i class="octicon octicon-issue-opened"></i> {{.i18n.Tr "repo.issues"}} </span>
6767
</a>
@@ -73,19 +73,19 @@
7373
</a>
7474
{{end}}
7575

76-
{{if and (.Repository.EnableUnit $.UnitTypeCode) (not .IsBareRepo)}}
76+
{{if and (.Repository.UnitEnabled $.UnitTypeCode) (not .IsBareRepo)}}
7777
<a class="{{if (or (.PageIsCommits) (.PageIsDiff))}}active{{end}} item" href="{{.RepoLink}}/commits/{{EscapePound .BranchName}}">
7878
<i class="octicon octicon-history"></i> {{.i18n.Tr "repo.commits"}} <span class="ui {{if not .CommitsCount}}gray{{else}}blue{{end}} small label">{{.CommitsCount}}</span>
7979
</a>
8080
{{end}}
8181

82-
{{if and (.Repository.EnableUnit $.UnitTypeReleases) (not .IsBareRepo) }}
82+
{{if and (.Repository.UnitEnabled $.UnitTypeReleases) (not .IsBareRepo) }}
8383
<a class="{{if .PageIsReleaseList}}active{{end}} item" href="{{.RepoLink}}/releases">
8484
<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>
8585
</a>
8686
{{end}}
8787

88-
{{if or (.Repository.EnableUnit $.UnitTypeWiki) (.Repository.EnableUnit $.UnitTypeExternalWiki)}}
88+
{{if or (.Repository.UnitEnabled $.UnitTypeWiki) (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}
8989
<a class="{{if .PageIsWiki}}active{{end}} item" href="{{.RepoLink}}/wiki">
9090
<i class="octicon octicon-book"></i> {{.i18n.Tr "repo.wiki"}}
9191
</a>

templates/repo/settings/options.tmpl

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@
9393
{{.CsrfTokenHtml}}
9494
<input type="hidden" name="action" value="advanced">
9595

96-
{{$isWikiEnabled := or (.Repository.EnableUnit $.UnitTypeWiki) (.Repository.EnableUnit $.UnitTypeExternalWiki)}}
96+
{{$isWikiEnabled := or (.Repository.UnitEnabled $.UnitTypeWiki) (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}
9797
<div class="inline field">
9898
<label>{{.i18n.Tr "repo.wiki"}}</label>
9999
<div class="ui checkbox">
@@ -104,17 +104,17 @@
104104
<div class="field {{if not $isWikiEnabled}}disabled{{end}}" id="wiki_box">
105105
<div class="field">
106106
<div class="ui radio checkbox">
107-
<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}}/>
107+
<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}}/>
108108
<label>{{.i18n.Tr "repo.settings.use_internal_wiki"}}</label>
109109
</div>
110110
</div>
111111
<div class="field">
112112
<div class="ui radio checkbox">
113-
<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}}/>
113+
<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}}/>
114114
<label>{{.i18n.Tr "repo.settings.use_external_wiki"}}</label>
115115
</div>
116116
</div>
117-
<div class="field {{if not (.Repository.EnableUnit $.UnitTypeExternalWiki)}}disabled{{end}}" id="external_wiki_box">
117+
<div class="field {{if not (.Repository.UnitEnabled $.UnitTypeExternalWiki)}}disabled{{end}}" id="external_wiki_box">
118118
<label for="external_wiki_url">{{.i18n.Tr "repo.settings.external_wiki_url"}}</label>
119119
<input id="external_wiki_url" name="external_wiki_url" type="url" value="{{(.Repository.MustGetUnit $.UnitTypeExternalWiki).ExternalWikiConfig.ExternalWikiURL}}">
120120
<p class="help">{{.i18n.Tr "repo.settings.external_wiki_url_desc"}}</p>
@@ -123,7 +123,7 @@
123123

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

126-
{{$isIssuesEnabled := or (.Repository.EnableUnit $.UnitTypeIssues) (.Repository.EnableUnit $.UnitTypeExternalTracker)}}
126+
{{$isIssuesEnabled := or (.Repository.UnitEnabled $.UnitTypeIssues) (.Repository.UnitEnabled $.UnitTypeExternalTracker)}}
127127
<div class="inline field">
128128
<label>{{.i18n.Tr "repo.issues"}}</label>
129129
<div class="ui checkbox">
@@ -134,17 +134,17 @@
134134
<div class="field {{if not $isIssuesEnabled}}disabled{{end}}" id="issue_box">
135135
<div class="field">
136136
<div class="ui radio checkbox">
137-
<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}}/>
137+
<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}}/>
138138
<label>{{.i18n.Tr "repo.settings.use_internal_issue_tracker"}}</label>
139139
</div>
140140
</div>
141141
<div class="field">
142142
<div class="ui radio checkbox">
143-
<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}}/>
143+
<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}}/>
144144
<label>{{.i18n.Tr "repo.settings.use_external_issue_tracker"}}</label>
145145
</div>
146146
</div>
147-
<div class="field {{if not (.Repository.EnableUnit $.UnitTypeExternalTracker)}}disabled{{end}}" id="external_issue_box">
147+
<div class="field {{if not (.Repository.UnitEnabled $.UnitTypeExternalTracker)}}disabled{{end}}" id="external_issue_box">
148148
<div class="field">
149149
<label for="external_tracker_url">{{.i18n.Tr "repo.settings.external_tracker_url"}}</label>
150150
<input id="external_tracker_url" name="external_tracker_url" type="url" value="{{(.Repository.MustGetUnit $.UnitTypeExternalTracker).ExternalTrackerConfig.ExternalTrackerURL}}">
@@ -181,7 +181,7 @@
181181
<div class="inline field">
182182
<label>{{.i18n.Tr "repo.pulls"}}</label>
183183
<div class="ui checkbox">
184-
<input name="enable_pulls" type="checkbox" {{if .Repository.EnableUnit $.UnitTypePullRequests}}checked{{end}}>
184+
<input name="enable_pulls" type="checkbox" {{if .Repository.UnitEnabled $.UnitTypePullRequests}}checked{{end}}>
185185
<label>{{.i18n.Tr "repo.settings.pulls_desc"}}</label>
186186
</div>
187187
</div>
@@ -222,7 +222,7 @@
222222
</div>
223223
</div>
224224

225-
{{if .Repository.EnableUnit $.UnitTypeWiki}}
225+
{{if .Repository.UnitEnabled $.UnitTypeWiki}}
226226
<div class="ui divider"></div>
227227

228228
<div class="item">
@@ -354,7 +354,7 @@
354354
</div>
355355
</div>
356356

357-
{{if .Repository.EnableUnit $.UnitTypeWiki}}
357+
{{if .Repository.UnitEnabled $.UnitTypeWiki}}
358358
<div class="ui small modal" id="delete-wiki-modal">
359359
<div class="header">
360360
{{.i18n.Tr "repo.settings.wiki-delete"}}

0 commit comments

Comments
 (0)