Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ui] Read-based checks for viewing templates and write-based checks for saving them #23458

Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .changelog/23458.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
ui: Fix an issue where access to Job Templates in the UI was restricted to variable.write access
```
2 changes: 1 addition & 1 deletion ui/app/templates/components/job-editor.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
Paste or author HCL or JSON to submit to your cluster, or select from a list of templates. A plan will be requested before the job is submitted. You can also attach a job spec by uploading a job file or dragging & dropping a file to the editor.
</p>

{{#if (can "write variable" path="*" namespace="*")}}
{{#if (can "read variable" path="nomad/job-templates/*" namespace="*")}}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance I thought this would get us into trouble, but the write policy for Variables is a little different than it is for anything else:

Create or update Variables at this path. Includes the "list" capability but not the "read" or "destroy" capabilities.

👍

<Hds::ButtonSet>
<label
class="job-spec-upload hds-button hds-button--color-secondary hds-button--size-medium"
Expand Down
18 changes: 10 additions & 8 deletions ui/app/templates/components/job-editor/edit.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,16 @@
data-test-plan
@text="Plan"
/>
{{#if @data.job.isNew}}
<Hds::Button
@text="Save as template"
@color="secondary"
@route="jobs.run.templates.new"
{{on "click" @fns.onSaveAs}}
data-test-save-as-template
/>
{{#if (can "write variable" path="nomad/job-templates/*" namespace="*")}}
{{#if @data.job.isNew}}
<Hds::Button
@text="Save as template"
@color="secondary"
@route="jobs.run.templates.new"
{{on "click" @fns.onSaveAs}}
data-test-save-as-template
/>
{{/if}}
{{/if}}
<Hds::Button
@text="Save as .nomad.hcl"
Expand Down
7 changes: 5 additions & 2 deletions ui/app/templates/jobs/run/templates/manage.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,11 @@
<:body as |B|>
<B.Tr>
<B.Td>
{{#if B.data.isDefaultJobTemplate}}
{{format-template-label B.data.path}}
{{#if (or
B.data.isDefaultJobTemplate
(not (can "write variable" path="nomad/job-templates/*" namespace="*"))
)}}
{{format-template-label B.data.path}}
{{else}}
<LinkTo @route="jobs.run.templates.template" @model={{concat B.data.path "@" B.data.namespace}} data-test-edit-template={{B.data.path}}>
{{format-template-label B.data.path}}
Expand Down
Loading