mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
chore: don't require an organization to read starter templates (#14190)
This commit is contained in:
+29
-1
@@ -821,7 +821,8 @@ func (api *API) templateDAUs(rw http.ResponseWriter, r *http.Request) {
|
||||
// @Param organization path string true "Organization ID" format(uuid)
|
||||
// @Success 200 {array} codersdk.TemplateExample
|
||||
// @Router /organizations/{organization}/templates/examples [get]
|
||||
func (api *API) templateExamples(rw http.ResponseWriter, r *http.Request) {
|
||||
// @Deprecated Use /templates/examples instead
|
||||
func (api *API) templateExamplesByOrganization(rw http.ResponseWriter, r *http.Request) {
|
||||
var (
|
||||
ctx = r.Context()
|
||||
organization = httpmw.OrganizationParam(r)
|
||||
@@ -844,6 +845,33 @@ func (api *API) templateExamples(rw http.ResponseWriter, r *http.Request) {
|
||||
httpapi.Write(ctx, rw, http.StatusOK, ex)
|
||||
}
|
||||
|
||||
// @Summary Get template examples
|
||||
// @ID get-template-examples
|
||||
// @Security CoderSessionToken
|
||||
// @Produce json
|
||||
// @Tags Templates
|
||||
// @Success 200 {array} codersdk.TemplateExample
|
||||
// @Router /templates/examples [get]
|
||||
func (api *API) templateExamples(rw http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
|
||||
if !api.Authorize(r, policy.ActionRead, rbac.ResourceTemplate.AnyOrganization()) {
|
||||
httpapi.ResourceNotFound(rw)
|
||||
return
|
||||
}
|
||||
|
||||
ex, err := examples.List()
|
||||
if err != nil {
|
||||
httpapi.Write(ctx, rw, http.StatusInternalServerError, codersdk.Response{
|
||||
Message: "Internal error fetching examples.",
|
||||
Detail: err.Error(),
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
httpapi.Write(ctx, rw, http.StatusOK, ex)
|
||||
}
|
||||
|
||||
func (api *API) convertTemplates(templates []database.Template) []codersdk.Template {
|
||||
apiTemplates := make([]codersdk.Template, 0, len(templates))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user