mirror of
https://github.com/harness/drone.git
synced 2025-05-04 14:12:15 +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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if user.Login == namespace {
|
||||||
|
next.ServeHTTP(w, r)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
isMember, isAdmin, err := service.Membership(ctx, user, namespace)
|
isMember, isAdmin, err := service.Membership(ctx, user, namespace)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
render.Unauthorized(w, errors.ErrNotFound)
|
render.Unauthorized(w, errors.ErrNotFound)
|
||||||
|
@ -359,7 +359,7 @@ func (s Server) Handler() http.Handler {
|
|||||||
|
|
||||||
r.Route("/templates", func(r chi.Router) {
|
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, 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}", template.HandleList(s.Template))
|
||||||
r.With(acl.CheckMembership(s.Orgs, false)).Get("/{namespace}/{name}", template.HandleFind(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))
|
r.With(acl.CheckMembership(s.Orgs, true)).Put("/{namespace}/{name}", template.HandleUpdate(s.Template))
|
||||||
|
@ -8,6 +8,7 @@ package template
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/go-chi/chi"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/drone/drone/core"
|
"github.com/drone/drone/core"
|
||||||
@ -17,13 +18,13 @@ import (
|
|||||||
type templateInput struct {
|
type templateInput struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Data string `json:"data"`
|
Data string `json:"data"`
|
||||||
Namespace string `json:"namespace"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// HandleCreate returns an http.HandlerFunc that processes http
|
// HandleCreate returns an http.HandlerFunc that processes http
|
||||||
// requests to create a new template.
|
// requests to create a new template.
|
||||||
func HandleCreate(templateStore core.TemplateStore) http.HandlerFunc {
|
func HandleCreate(templateStore core.TemplateStore) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
namespace := chi.URLParam(r, "namespace")
|
||||||
in := new(templateInput)
|
in := new(templateInput)
|
||||||
err := json.NewDecoder(r.Body).Decode(in)
|
err := json.NewDecoder(r.Body).Decode(in)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -34,7 +35,7 @@ func HandleCreate(templateStore core.TemplateStore) http.HandlerFunc {
|
|||||||
t := &core.Template{
|
t := &core.Template{
|
||||||
Name: in.Name,
|
Name: in.Name,
|
||||||
Data: in.Data,
|
Data: in.Data,
|
||||||
Namespace: in.Namespace,
|
Namespace: namespace,
|
||||||
}
|
}
|
||||||
|
|
||||||
err = t.Validate()
|
err = t.Validate()
|
||||||
|
Loading…
Reference in New Issue
Block a user