mirror of
https://github.com/coder/coder.git
synced 2025-07-15 22:20:27 +00:00
chore: don't require an organization to read starter templates (#14190)
This commit is contained in:
committed by
GitHub
parent
fab196043e
commit
ff785588fe
29
coderd/apidoc/docs.go
generated
29
coderd/apidoc/docs.go
generated
@ -3000,6 +3000,7 @@ const docTemplate = `{
|
||||
],
|
||||
"summary": "Get template examples by organization",
|
||||
"operationId": "get-template-examples-by-organization",
|
||||
"deprecated": true,
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
@ -3421,6 +3422,34 @@ const docTemplate = `{
|
||||
}
|
||||
}
|
||||
},
|
||||
"/templates/examples": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"CoderSessionToken": []
|
||||
}
|
||||
],
|
||||
"produces": [
|
||||
"application/json"
|
||||
],
|
||||
"tags": [
|
||||
"Templates"
|
||||
],
|
||||
"summary": "Get template examples",
|
||||
"operationId": "get-template-examples",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/codersdk.TemplateExample"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/templates/{template}": {
|
||||
"get": {
|
||||
"security": [
|
||||
|
25
coderd/apidoc/swagger.json
generated
25
coderd/apidoc/swagger.json
generated
@ -2630,6 +2630,7 @@
|
||||
"tags": ["Templates"],
|
||||
"summary": "Get template examples by organization",
|
||||
"operationId": "get-template-examples-by-organization",
|
||||
"deprecated": true,
|
||||
"parameters": [
|
||||
{
|
||||
"type": "string",
|
||||
@ -3005,6 +3006,30 @@
|
||||
}
|
||||
}
|
||||
},
|
||||
"/templates/examples": {
|
||||
"get": {
|
||||
"security": [
|
||||
{
|
||||
"CoderSessionToken": []
|
||||
}
|
||||
],
|
||||
"produces": ["application/json"],
|
||||
"tags": ["Templates"],
|
||||
"summary": "Get template examples",
|
||||
"operationId": "get-template-examples",
|
||||
"responses": {
|
||||
"200": {
|
||||
"description": "OK",
|
||||
"schema": {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"$ref": "#/definitions/codersdk.TemplateExample"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"/templates/{template}": {
|
||||
"get": {
|
||||
"security": [
|
||||
|
@ -871,7 +871,7 @@ func New(options *Options) *API {
|
||||
r.Route("/templates", func(r chi.Router) {
|
||||
r.Post("/", api.postTemplateByOrganization)
|
||||
r.Get("/", api.templatesByOrganization())
|
||||
r.Get("/examples", api.templateExamples)
|
||||
r.Get("/examples", api.templateExamplesByOrganization)
|
||||
r.Route("/{templatename}", func(r chi.Router) {
|
||||
r.Get("/", api.templateByOrganizationAndName)
|
||||
r.Route("/versions/{templateversionname}", func(r chi.Router) {
|
||||
@ -915,6 +915,7 @@ func New(options *Options) *API {
|
||||
apiKeyMiddleware,
|
||||
)
|
||||
r.Get("/", api.fetchTemplates(nil))
|
||||
r.Get("/examples", api.templateExamples)
|
||||
r.Route("/{template}", func(r chi.Router) {
|
||||
r.Use(
|
||||
httpmw.ExtractTemplateParam(options.Database),
|
||||
|
@ -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))
|
||||
|
||||
|
@ -1097,17 +1097,17 @@ func TestPreviousTemplateVersion(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestTemplateExamples(t *testing.T) {
|
||||
func TestStarterTemplates(t *testing.T) {
|
||||
t.Parallel()
|
||||
t.Run("OK", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
client := coderdtest.New(t, nil)
|
||||
user := coderdtest.CreateFirstUser(t, client)
|
||||
_ = coderdtest.CreateFirstUser(t, client)
|
||||
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
|
||||
defer cancel()
|
||||
|
||||
ex, err := client.TemplateExamples(ctx, user.OrganizationID)
|
||||
ex, err := client.StarterTemplates(ctx)
|
||||
require.NoError(t, err)
|
||||
ls, err := examples.List()
|
||||
require.NoError(t, err)
|
||||
|
Reference in New Issue
Block a user