diff --git a/models/org_team.go b/models/org_team.go index 8508a176c..bc0e12b50 100644 --- a/models/org_team.go +++ b/models/org_team.go @@ -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 } diff --git a/models/repo.go b/models/repo.go index a651aae89..60c89836c 100644 --- a/models/repo.go +++ b/models/repo.go @@ -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. diff --git a/modules/context/repo.go b/modules/context/repo.go index 3dface7da..897cd3ca1 100644 --- a/modules/context/repo.go +++ b/modules/context/repo.go @@ -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)) } } diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go index b3cb3906a..23c7c7c30 100644 --- a/routers/api/v1/api.go +++ b/routers/api/v1/api.go @@ -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 } diff --git a/routers/repo/issue.go b/routers/repo/issue.go index f3799fdb9..473e82971 100644 --- a/routers/repo/issue.go +++ b/routers/repo/issue.go @@ -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 } diff --git a/routers/repo/wiki.go b/routers/repo/wiki.go index 2dcf37cc8..2a73fdc41 100644 --- a/routers/repo/wiki.go +++ b/routers/repo/wiki.go @@ -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 } diff --git a/templates/org/team/new.tmpl b/templates/org/team/new.tmpl index 79338394b..27335e247 100644 --- a/templates/org/team/new.tmpl +++ b/templates/org/team/new.tmpl @@ -57,7 +57,7 @@ {{range $t, $unit := $.Units}}