summaryrefslogtreecommitdiffstats
path: root/routers/api/v1/admin
diff options
context:
space:
mode:
authorUnknwon <u@gogs.io>2016-04-04 19:41:34 -0400
committerUnknwon <u@gogs.io>2016-04-04 19:41:34 -0400
commitd27ca649c7e5ccec97ba285cc529c7b3d8f71ac4 (patch)
tree0427090ae99a5c5d69a28d910df8bd41affc9385 /routers/api/v1/admin
parentd9900e4dbc2f2182ea06ad3ecdcf714da002dd24 (diff)
downloadgitea-d27ca649c7e5ccec97ba285cc529c7b3d8f71ac4.tar.gz
gitea-d27ca649c7e5ccec97ba285cc529c7b3d8f71ac4.zip
api/admin: add/remove organization team repository
Diffstat (limited to 'routers/api/v1/admin')
-rw-r--r--routers/api/v1/admin/org_repo.go49
1 files changed, 49 insertions, 0 deletions
diff --git a/routers/api/v1/admin/org_repo.go b/routers/api/v1/admin/org_repo.go
new file mode 100644
index 0000000000..71c84ad0ef
--- /dev/null
+++ b/routers/api/v1/admin/org_repo.go
@@ -0,0 +1,49 @@
+// Copyright 2016 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package admin
+
+import (
+ "github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/context"
+)
+
+func GetRepositoryByParams(ctx *context.APIContext) *models.Repository {
+ repo, err := models.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))
+ if err != nil {
+ if models.IsErrRepoNotExist(err) {
+ ctx.Status(404)
+ } else {
+ ctx.Error(500, "GetRepositoryByName", err)
+ }
+ return nil
+ }
+ return repo
+}
+
+func AddTeamRepository(ctx *context.APIContext) {
+ repo := GetRepositoryByParams(ctx)
+ if ctx.Written() {
+ return
+ }
+ if err := ctx.Org.Team.AddRepository(repo); err != nil {
+ ctx.Error(500, "AddRepository", err)
+ return
+ }
+
+ ctx.Status(204)
+}
+
+func RemoveTeamRepository(ctx *context.APIContext) {
+ repo := GetRepositoryByParams(ctx)
+ if ctx.Written() {
+ return
+ }
+ if err := ctx.Org.Team.RemoveRepository(repo.ID); err != nil {
+ ctx.Error(500, "RemoveRepository", err)
+ return
+ }
+
+ ctx.Status(204)
+}