Skip to content

Repo permission bug fixes #513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 0 additions & 30 deletions modules/context/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,36 +75,6 @@ func APIContexter() macaron.Handler {
}
}

// ExtractOwnerAndRepo returns a handler that populates the `Repo.Owner` and
// `Repo.Repository` fields of an APIContext
func ExtractOwnerAndRepo() macaron.Handler {
return func(ctx *APIContext) {
owner, err := models.GetUserByName(ctx.Params(":username"))
if err != nil {
if models.IsErrUserNotExist(err) {
ctx.Error(422, "", err)
} else {
ctx.Error(500, "GetUserByName", err)
}
return
}

repo, err := models.GetRepositoryByName(owner.ID, ctx.Params(":reponame"))
if err != nil {
if models.IsErrRepoNotExist(err) {
ctx.Status(404)
} else {
ctx.Error(500, "GetRepositoryByName", err)
}
return
}
ctx.Repo.Owner = owner
ctx.Data["Owner"] = owner
ctx.Repo.Repository = repo
ctx.Data["Repository"] = repo
}
}

// ReferencesGitRepo injects the GitRepo into the Context
func ReferencesGitRepo() macaron.Handler {
return func(ctx *APIContext) {
Expand Down
8 changes: 3 additions & 5 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("", user.IsStarring)
m.Put("", user.Star)
m.Delete("", user.Unstar)
}, context.ExtractOwnerAndRepo())
}, repoAssignment())
})

m.Get("/subscriptions", user.GetMyWatchedRepos)
Expand All @@ -258,11 +258,9 @@ func RegisterRoutes(m *macaron.Macaron) {

m.Group("/repos", func() {
m.Post("/migrate", bind(auth.MigrateRepoForm{}), repo.Migrate)
m.Combo("/:username/:reponame", context.ExtractOwnerAndRepo()).
Get(repo.Get).
Delete(repo.Delete)

m.Group("/:username/:reponame", func() {
m.Combo("").Get(repo.Get).Delete(repo.Delete)
m.Group("/hooks", func() {
m.Combo("").Get(repo.ListHooks).
Post(bind(api.CreateHookOption{}), repo.CreateHook)
Expand Down Expand Up @@ -330,7 +328,7 @@ func RegisterRoutes(m *macaron.Macaron) {
m.Get("", user.IsWatching)
m.Put("", user.Watch)
m.Delete("", user.Unwatch)
}, context.ExtractOwnerAndRepo())
})
m.Get("/editorconfig/:filename", context.RepoRef(), repo.GetEditorconfig)
m.Group("/pulls", func() {
m.Combo("").Get(bind(api.ListPullRequestsOptions{}), repo.ListPullRequests).Post(reqRepoWriter(), bind(api.CreatePullRequestOption{}), repo.CreatePullRequest)
Expand Down
4 changes: 4 additions & 0 deletions routers/api/v1/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,10 @@ func GetByID(ctx *context.APIContext) {
// Delete one repository
// see https://github.com/gogits/go-gogs-client/wiki/Repositories#delete
func Delete(ctx *context.APIContext) {
if !ctx.Repo.IsAdmin() {
ctx.Error(403, "", "Must have admin rights")
return
}
owner := ctx.Repo.Owner
repo := ctx.Repo.Repository

Expand Down