mirror of
https://github.com/harness/drone.git
synced 2025-05-03 21:11:08 +08:00
update template create api to accept namespace (#3121)
* update template create api to accept namespace * fixes issue were personal repos were not authorized on checkmembership
This commit is contained in:
parent
3fad0e59cb
commit
fe9ea60aad
@ -51,6 +51,11 @@ func CheckMembership(service core.OrganizationService, admin bool) func(http.Han
|
||||
return
|
||||
}
|
||||
|
||||
if user.Login == namespace {
|
||||
next.ServeHTTP(w, r)
|
||||
return
|
||||
}
|
||||
|
||||
isMember, isAdmin, err := service.Membership(ctx, user, namespace)
|
||||
if err != nil {
|
||||
render.Unauthorized(w, errors.ErrNotFound)
|
||||
|
@ -359,7 +359,7 @@ func (s Server) Handler() http.Handler {
|
||||
|
||||
r.Route("/templates", func(r chi.Router) {
|
||||
r.With(acl.CheckMembership(s.Orgs, false)).Get("/", template.HandleListAll(s.Template))
|
||||
r.With(acl.CheckMembership(s.Orgs, true)).Post("/", template.HandleCreate(s.Template))
|
||||
r.With(acl.CheckMembership(s.Orgs, true)).Post("/{namespace}", template.HandleCreate(s.Template))
|
||||
r.With(acl.CheckMembership(s.Orgs, false)).Get("/{namespace}", template.HandleList(s.Template))
|
||||
r.With(acl.CheckMembership(s.Orgs, false)).Get("/{namespace}/{name}", template.HandleFind(s.Template))
|
||||
r.With(acl.CheckMembership(s.Orgs, true)).Put("/{namespace}/{name}", template.HandleUpdate(s.Template))
|
||||
|
@ -8,6 +8,7 @@ package template
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"github.com/go-chi/chi"
|
||||
"net/http"
|
||||
|
||||
"github.com/drone/drone/core"
|
||||
@ -17,13 +18,13 @@ import (
|
||||
type templateInput struct {
|
||||
Name string `json:"name"`
|
||||
Data string `json:"data"`
|
||||
Namespace string `json:"namespace"`
|
||||
}
|
||||
|
||||
// HandleCreate returns an http.HandlerFunc that processes http
|
||||
// requests to create a new template.
|
||||
func HandleCreate(templateStore core.TemplateStore) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
namespace := chi.URLParam(r, "namespace")
|
||||
in := new(templateInput)
|
||||
err := json.NewDecoder(r.Body).Decode(in)
|
||||
if err != nil {
|
||||
@ -34,7 +35,7 @@ func HandleCreate(templateStore core.TemplateStore) http.HandlerFunc {
|
||||
t := &core.Template{
|
||||
Name: in.Name,
|
||||
Data: in.Data,
|
||||
Namespace: in.Namespace,
|
||||
Namespace: namespace,
|
||||
}
|
||||
|
||||
err = t.Validate()
|
||||
|
Loading…
Reference in New Issue
Block a user