aboutsummaryrefslogtreecommitdiffstats
path: root/routers/api
diff options
context:
space:
mode:
authorqwerty287 <80460567+qwerty287@users.noreply.github.com>2022-05-01 17:39:04 +0200
committerGitHub <noreply@github.com>2022-05-01 17:39:04 +0200
commitac6c338428b83d0cb80764571e2402402beb2788 (patch)
tree8fca66a8fa01846018154d24d220975f7466309a /routers/api
parentedff571aa927f3c412ce91976e248ad4569b0c77 (diff)
downloadgitea-ac6c338428b83d0cb80764571e2402402beb2788.tar.gz
gitea-ac6c338428b83d0cb80764571e2402402beb2788.zip
Add API to check if team has repo access (#19540)
* Add API to check if team has repo access * Add test case
Diffstat (limited to 'routers/api')
-rw-r--r--routers/api/v1/api.go3
-rw-r--r--routers/api/v1/org/team.go49
2 files changed, 51 insertions, 1 deletions
diff --git a/routers/api/v1/api.go b/routers/api/v1/api.go
index ce0719ddd8..6587037ea3 100644
--- a/routers/api/v1/api.go
+++ b/routers/api/v1/api.go
@@ -1121,7 +1121,8 @@ func Routes() *web.Route {
m.Get("", org.GetTeamRepos)
m.Combo("/{org}/{reponame}").
Put(org.AddTeamRepository).
- Delete(org.RemoveTeamRepository)
+ Delete(org.RemoveTeamRepository).
+ Get(org.GetTeamRepo)
})
}, orgAssignment(false, true), reqToken(), reqTeamMembership())
diff --git a/routers/api/v1/org/team.go b/routers/api/v1/org/team.go
index 322196b819..b24c8a6235 100644
--- a/routers/api/v1/org/team.go
+++ b/routers/api/v1/org/team.go
@@ -558,6 +558,55 @@ func GetTeamRepos(ctx *context.APIContext) {
ctx.JSON(http.StatusOK, repos)
}
+// GetTeamRepo api for get a particular repo of team
+func GetTeamRepo(ctx *context.APIContext) {
+ // swagger:operation GET /teams/{id}/repos/{org}/{repo} organization orgListTeamRepo
+ // ---
+ // summary: List a particular repo of team
+ // produces:
+ // - application/json
+ // parameters:
+ // - name: id
+ // in: path
+ // description: id of the team
+ // type: integer
+ // format: int64
+ // required: true
+ // - name: org
+ // in: path
+ // description: organization that owns the repo to list
+ // type: string
+ // required: true
+ // - name: repo
+ // in: path
+ // description: name of the repo to list
+ // type: string
+ // required: true
+ // responses:
+ // "200":
+ // "$ref": "#/responses/Repository"
+ // "404":
+ // "$ref": "#/responses/notFound"
+
+ repo := getRepositoryByParams(ctx)
+ if ctx.Written() {
+ return
+ }
+
+ if !organization.HasTeamRepo(ctx, ctx.Org.Team.OrgID, ctx.Org.Team.ID, repo.ID) {
+ ctx.NotFound()
+ return
+ }
+
+ access, err := models.AccessLevel(ctx.Doer, repo)
+ if err != nil {
+ ctx.Error(http.StatusInternalServerError, "GetTeamRepos", err)
+ return
+ }
+
+ ctx.JSON(http.StatusOK, convert.ToRepo(repo, access))
+}
+
// getRepositoryByParams get repository by a team's organization ID and repo name
func getRepositoryByParams(ctx *context.APIContext) *repo_model.Repository {
repo, err := repo_model.GetRepositoryByName(ctx.Org.Team.OrgID, ctx.Params(":reponame"))