Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: don't require an organization to read starter templates#14190

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
aslilac merged 2 commits intomainfromorgless-starter-templates
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes fromall 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
29 changes: 29 additions & 0 deletionscoderd/apidoc/docs.go
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

25 changes: 25 additions & 0 deletionscoderd/apidoc/swagger.json
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

3 changes: 2 additions & 1 deletioncoderd/coderd.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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) {
Expand DownExpand Up@@ -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),
Expand Down
30 changes: 29 additions & 1 deletioncoderd/templates.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -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)
Expand All@@ -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))

Expand Down
6 changes: 3 additions & 3 deletionscoderd/templateversions_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1097,17 +1097,17 @@ func TestPreviousTemplateVersion(t *testing.T) {
})
}

funcTestTemplateExamples(t *testing.T) {
funcTestStarterTemplates(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)
Expand Down
13 changes: 10 additions & 3 deletionscodersdk/templates.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -472,9 +472,16 @@ type AgentStatsReportResponse struct {
TxBytes int64 `json:"tx_bytes"`
}

// TemplateExamples lists example templates embedded in coder.
func (c *Client) TemplateExamples(ctx context.Context, organizationID uuid.UUID) ([]TemplateExample, error) {
res, err := c.Request(ctx, http.MethodGet, fmt.Sprintf("/api/v2/organizations/%s/templates/examples", organizationID), nil)
// TemplateExamples lists example templates available in Coder.
//
// Deprecated: Use StarterTemplates instead.
func (c *Client) TemplateExamples(ctx context.Context, _ uuid.UUID) ([]TemplateExample, error) {
return c.StarterTemplates(ctx)
}

// StarterTemplates lists example templates available in Coder.
func (c *Client) StarterTemplates(ctx context.Context) ([]TemplateExample, error) {
res, err := c.Request(ctx, http.MethodGet, "/api/v2/templates/examples", nil)
if err != nil {
return nil, err
}
Expand Down
54 changes: 54 additions & 0 deletionsdocs/api/templates.md
View file
Open in desktop

Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.

10 changes: 3 additions & 7 deletionssite/src/api/api.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -483,7 +483,7 @@ class ApiMethods {
};

deleteToken = async (keyId: string): Promise<void> => {
await this.axios.delete("/api/v2/users/me/keys/" +keyId);
await this.axios.delete(`/api/v2/users/me/keys/${keyId}`);
};

createToken = async (
Expand DownExpand Up@@ -1754,12 +1754,8 @@ class ApiMethods {
/**
* @param organization Can be the organization's ID or name
*/
getTemplateExamples = async (
organization: string,
): Promise<TypesGen.TemplateExample[]> => {
const response = await this.axios.get(
`/api/v2/organizations/${organization}/templates/examples`,
);
getTemplateExamples = async (): Promise<TypesGen.TemplateExample[]> => {
const response = await this.axios.get(`/api/v2/templates/examples`);

return response.data;
};
Expand Down
9 changes: 3 additions & 6 deletionssite/src/api/queries/templates.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -112,13 +112,10 @@ export const setGroupRole = (
};
};

export const templateExamples = (organizationId: string) => {
export const templateExamples = () => {
return {
queryKey: [
...getTemplatesByOrganizationQueryKey(organizationId),
"examples",
],
queryFn: () => API.getTemplateExamples(organizationId),
queryKey: ["templates", "examples"],
queryFn: () => API.getTemplateExamples(),
};
};

Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -31,7 +31,7 @@ export const ImportStarterTemplateView: FC<CreateTemplatePageViewProps> = ({
const { multiple_organizations: organizationsEnabled } =
useFeatureVisibility();
const [searchParams] = useSearchParams();
const templateExamplesQuery = useQuery(templateExamples("default"));
const templateExamplesQuery = useQuery(templateExamples());
const templateExample = templateExamplesQuery.data?.find(
(e) => e.id === searchParams.get("exampleId")!,
);
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ import { StarterTemplatesPageView } from "./StarterTemplatesPageView";

const CreateTemplatesGalleryPage: FC = () => {
const { experiments } = useDashboard();
const templateExamplesQuery = useQuery(templateExamples("default"));
const templateExamplesQuery = useQuery(templateExamples());
const starterTemplatesByTag = templateExamplesQuery.data
? // Currently, the scratch template should not be displayed on the starter templates page.
getTemplatesByTag(removeScratchExample(templateExamplesQuery.data))
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,7 +8,7 @@ import { StarterTemplatePageView } from "./StarterTemplatePageView";

const StarterTemplatePage: FC = () => {
const { exampleId } = useParams() as { exampleId: string };
const templateExamplesQuery = useQuery(templateExamples("default"));
const templateExamplesQuery = useQuery(templateExamples());
const starterTemplate = templateExamplesQuery.data?.find(
(example) => example.id === exampleId,
);
Expand Down
2 changes: 1 addition & 1 deletionsite/src/pages/TemplatesPage/TemplatesPage.tsx
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -11,7 +11,7 @@ export const TemplatesPage: FC = () => {

const templatesQuery = useQuery(templates());
const examplesQuery = useQuery({
...templateExamples("default"),
...templateExamples(),
enabled: permissions.createTemplates,
});
const error = templatesQuery.error || examplesQuery.error;
Expand Down
6 changes: 3 additions & 3 deletionssite/src/testHelpers/handlers.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -47,9 +47,6 @@ export const handlers = [
http.get("/api/v2/organizations/:organizationId", () => {
return HttpResponse.json(M.MockOrganization);
}),
http.get("/api/v2/organizations/:organizationId/templates/examples", () => {
return HttpResponse.json([M.MockTemplateExample, M.MockTemplateExample2]);
}),
http.get(
"/api/v2/organizations/:organizationId/templates/:templateId",
() => {
Expand DownExpand Up@@ -81,6 +78,9 @@ export const handlers = [
),

// templates
http.get("/api/v2/templates/examples", () => {
return HttpResponse.json([M.MockTemplateExample, M.MockTemplateExample2]);
}),
http.get("/api/v2/templates/:templateId", () => {
return HttpResponse.json(M.MockTemplate);
}),
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp