summaryrefslogtreecommitdiffstats
path: root/modules/context
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2017-05-18 22:54:24 +0800
committerGitHub <noreply@github.com>2017-05-18 22:54:24 +0800
commitfd6034aaf23af1ce03bcba0babcbe7675ce093ee (patch)
tree9720f416facdef02a76bd56ca50669cc1f17eb88 /modules/context
parent5db5e16ab61f25f21cb17ee4895679b9830641a5 (diff)
downloadgitea-fd6034aaf23af1ce03bcba0babcbe7675ce093ee.tar.gz
gitea-fd6034aaf23af1ce03bcba0babcbe7675ce093ee.zip
Add units to team (#947)
* add units to team * fix lint * finish team setting backend * finished permission controll on routes * fix import blank line * add unit check on ssh/http pull and push and fix test failed * fix fixtures data * remove unused code
Diffstat (limited to 'modules/context')
-rw-r--r--modules/context/repo.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/modules/context/repo.go b/modules/context/repo.go
index d2e5e0079c..555513c9e1 100644
--- a/modules/context/repo.go
+++ b/modules/context/repo.go
@@ -493,6 +493,37 @@ func RequireRepoWriter() macaron.Handler {
}
}
+// LoadRepoUnits loads repsitory's units, it should be called after repository and user loaded
+func LoadRepoUnits() macaron.Handler {
+ return func(ctx *Context) {
+ var userID int64
+ if ctx.User != nil {
+ userID = ctx.User.ID
+ }
+ err := ctx.Repo.Repository.LoadUnitsByUserID(userID)
+ if err != nil {
+ ctx.Handle(500, "LoadUnitsByUserID", err)
+ return
+ }
+ }
+}
+
+// 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 {
+ ctx.Handle(404, "CheckUnit", fmt.Errorf("%s: %v", ctx.Tr("units.error.unit_not_allowed"), unitType))
+ }
+ }
+}
+
// GitHookService checks if repository Git hooks service has been enabled.
func GitHookService() macaron.Handler {
return func(ctx *Context) {