Skip to content

Commit cb22128

Browse files
committed
Fix right checking to only needed ones
1 parent 1c48cc6 commit cb22128

File tree

5 files changed

+25
-9
lines changed

5 files changed

+25
-9
lines changed

models/repo.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,19 @@ func (repo *Repository) UnitEnabled(tp UnitType) bool {
392392
return false
393393
}
394394

395+
// AnyUnitEnabled if this repository has the any of the given units enabled
396+
func (repo *Repository) AnyUnitEnabled(tps ...UnitType) bool {
397+
repo.getUnits(x)
398+
for _, unit := range repo.Units {
399+
for _, tp := range tps {
400+
if unit.Type == tp {
401+
return true
402+
}
403+
}
404+
}
405+
return false
406+
}
407+
395408
var (
396409
// ErrUnitNotExist organization does not exist
397410
ErrUnitNotExist = errors.New("Unit does not exist")

modules/context/repo.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@ func LoadRepoUnits() macaron.Handler {
573573
}
574574
}
575575

576-
// CheckUnit will check whether
576+
// CheckUnit will check whether unit type is enabled
577577
func CheckUnit(unitType models.UnitType) macaron.Handler {
578578
return func(ctx *Context) {
579579
if !ctx.Repo.Repository.UnitEnabled(unitType) {
@@ -582,6 +582,15 @@ func CheckUnit(unitType models.UnitType) macaron.Handler {
582582
}
583583
}
584584

585+
// CheckAnyUnit will check whether any of the unit types are enabled
586+
func CheckAnyUnit(unitTypes ...models.UnitType) macaron.Handler {
587+
return func(ctx *Context) {
588+
if !ctx.Repo.Repository.AnyUnitEnabled(unitTypes...) {
589+
ctx.Handle(404, "CheckAnyUnit", fmt.Errorf("%s: %v", ctx.Tr("units.error.unit_not_allowed"), unitTypes))
590+
}
591+
}
592+
}
593+
585594
// GitHookService checks if repository Git hooks service has been enabled.
586595
func GitHookService() macaron.Handler {
587596
return func(ctx *Context) {

routers/repo/activity.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,11 @@
55
package repo
66

77
import (
8-
//"fmt"
98
"time"
10-
//"strings"
119

12-
//"code.gitea.io/git"
1310
"code.gitea.io/gitea/models"
14-
//"code.gitea.io/gitea/modules/auth"
1511
"code.gitea.io/gitea/modules/base"
1612
"code.gitea.io/gitea/modules/context"
17-
//"code.gitea.io/gitea/modules/log"
18-
//"code.gitea.io/gitea/modules/setting"
1913
)
2014

2115
const (

routers/routes/routes.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ func RegisterRoutes(m *macaron.Macaron) {
616616
m.Group("/activity", func() {
617617
m.Get("", repo.Activity)
618618
m.Get("/:period", repo.Activity)
619-
}, context.RepoRef(), repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode))
619+
}, context.RepoRef(), repo.MustBeNotBare, context.CheckAnyUnit(models.UnitTypePullRequests, models.UnitTypeIssues, models.UnitTypeReleases))
620620

621621
m.Get("/archive/*", repo.MustBeNotBare, context.CheckUnit(models.UnitTypeCode), repo.Download)
622622

templates/repo/header.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
</a>
9292
{{end}}
9393

94-
{{if and (.Repository.UnitEnabled $.UnitTypeCode) (not .IsBareRepo)}}
94+
{{if and (.Repository.AnyUnitEnabled $.UnitTypePullRequests $.UnitTypeIssues $.UnitTypeReleases) (not .IsBareRepo)}}
9595
<a class="{{if .PageIsActivity}}active{{end}} item" href="{{.RepoLink}}/activity">
9696
<i class="octicon octicon-pulse"></i> {{.i18n.Tr "repo.activity"}}
9797
</a>

0 commit comments

Comments
 (0)