-
Notifications
You must be signed in to change notification settings - Fork 2k
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] Policies UI #13976
Merged
Merged
[ui] Policies UI #13976
Changes from all commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
d9ee09e
Policies routes and controllers
mikenomitch 63e29b9
wat
mikenomitch 02b9011
Policies and index route
philrenaud 554cf36
Basic policies page
mikenomitch a1f8be7
Foo
mikenomitch a939566
mike
philrenaud 8b48819
Model saving using json
philrenaud 29cb20e
Rules instead of RulesJSON
philrenaud fd5732d
Flashmessages and rerouting etc
philrenaud 0eaa971
Adding defaults and whatnot
mikenomitch 0ddca60
Linked entities stuff
mikenomitch b2ed369
Removed unnecessary update function and fixed z index
mikenomitch 0f36ab9
Fixing create issue
mikenomitch f91c2d7
Adding basic policy abilities and restrictions
mikenomitch 1d5aa38
Adding breadcrumbs
mikenomitch 290b9b9
Removing console logs
mikenomitch 8a3b9c4
Cancan conditionals
mikenomitch 3ad14e2
Swap out policy prefix
mikenomitch e742e41
Conflict resolution and learn guide link updated
philrenaud 749ec5a
Modernizing the hackathon code, adding autofocus to codemirror, and m…
philrenaud 63f1cd7
Lintfixes
philrenaud a91d236
Remove unused policy row
philrenaud d97814f
Partially-written acceptance tests
philrenaud 0e98b20
Keyboard shortcuts for policies
philrenaud 444b825
Non-save test case and mirage endpoints
philrenaud c31730d
A11y test
philrenaud ec2ec78
Number of assert expectations
philrenaud ff4acba
Create new policy tests
philrenaud 5baee47
Deletion tests
philrenaud d4cfdee
Pre-review cleanup
philrenaud 9cd72c6
remove an unneeded z-index
philrenaud b32bc00
Corrected the data-test attr name
philrenaud c94d6b1
Chesterton's Style Property
philrenaud d5d9c6d
Using rsvp hash to do concurrent fetches
philrenaud 67791b1
Reset test token on completion
philrenaud 57b9a74
Using an error formatter on policy save rejection
philrenaud 698068b
HCL syntax highlighting with ruby mode and vars example
philrenaud File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
```release-note:improvement | ||
ui: Added a Policy Editor interface for management tokens | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import AbstractAbility from './abstract'; | ||
import { alias } from '@ember/object/computed'; | ||
import classic from 'ember-classic-decorator'; | ||
|
||
@classic | ||
export default class Policy extends AbstractAbility { | ||
@alias('selfTokenIsManagement') canRead; | ||
@alias('selfTokenIsManagement') canList; | ||
@alias('selfTokenIsManagement') canWrite; | ||
@alias('selfTokenIsManagement') canUpdate; | ||
@alias('selfTokenIsManagement') canDestroy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<form class="edit-policy" autocomplete="off" {{on "submit" this.save}}> | ||
{{#if @policy.isNew }} | ||
<label> | ||
<span> | ||
Policy Name | ||
</span> | ||
<Input | ||
data-test-policy-name-input | ||
@type="text" | ||
@value={{@policy.name}} | ||
class="input" | ||
{{autofocus}} | ||
/> | ||
</label> | ||
{{/if}} | ||
|
||
<div class="boxed-section"> | ||
<div class="boxed-section-head"> | ||
Policy Definition | ||
</div> | ||
<div class="boxed-section-body is-full-bleed"> | ||
|
||
<div | ||
class="policy-editor" | ||
data-test-policy-editor | ||
{{code-mirror | ||
screenReaderLabel="Policy definition" | ||
theme="hashi" | ||
mode="ruby" | ||
[email protected] | ||
onUpdate=this.updatePolicyRules | ||
autofocus=(not @policy.isNew) | ||
extraKeys=(hash Cmd-Enter=this.save) | ||
}} /> | ||
</div> | ||
</div> | ||
|
||
<div> | ||
<label> | ||
<span> | ||
Description (optional) | ||
</span> | ||
<Input | ||
data-test-policy-description | ||
@value={{@policy.description}} | ||
class="input" | ||
/> | ||
</label> | ||
</div> | ||
|
||
<footer> | ||
{{#if (can "update policy")}} | ||
<button | ||
class="button is-primary" | ||
type="submit" | ||
> | ||
Save Policy | ||
</button> | ||
{{/if}} | ||
</footer> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import Component from '@glimmer/component'; | ||
import { action } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
import { alias } from '@ember/object/computed'; | ||
import messageForError from 'nomad-ui/utils/message-from-adapter-error'; | ||
|
||
export default class PolicyEditorComponent extends Component { | ||
@service flashMessages; | ||
@service router; | ||
@service store; | ||
|
||
@alias('args.policy') policy; | ||
|
||
@action updatePolicyRules(value) { | ||
this.policy.set('rules', value); | ||
} | ||
|
||
@action async save(e) { | ||
if (e instanceof Event) { | ||
e.preventDefault(); // code-mirror "command+enter" submits the form, but doesnt have a preventDefault() | ||
} | ||
try { | ||
const nameRegex = '^[a-zA-Z0-9-]{1,128}$'; | ||
if (!this.policy.name?.match(nameRegex)) { | ||
throw new Error( | ||
'Policy name must be 1-128 characters long and can only contain letters, numbers, and dashes.' | ||
); | ||
} | ||
|
||
if ( | ||
this.policy.isNew && | ||
this.store.peekRecord('policy', this.policy.name) | ||
) { | ||
throw new Error( | ||
`A policy with name ${this.policy.name} already exists.` | ||
); | ||
} | ||
|
||
this.policy.id = this.policy.name; | ||
|
||
await this.policy.save(); | ||
|
||
this.flashMessages.add({ | ||
title: 'Policy Saved', | ||
type: 'success', | ||
destroyOnClick: false, | ||
timeout: 5000, | ||
}); | ||
|
||
this.router.transitionTo('policies'); | ||
} catch (error) { | ||
console.log('error and its', error); | ||
this.flashMessages.add({ | ||
title: `Error creating Policy ${this.policy.name}`, | ||
message: messageForError(error), | ||
type: 'error', | ||
destroyOnClick: false, | ||
sticky: true, | ||
}); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import Controller from '@ember/controller'; | ||
import { inject as service } from '@ember/service'; | ||
import { action } from '@ember/object'; | ||
|
||
export default class PoliciesIndexController extends Controller { | ||
@service router; | ||
get policies() { | ||
return this.model.policies.map((policy) => { | ||
policy.tokens = this.model.tokens.filter((token) => { | ||
return token.policies.includes(policy); | ||
}); | ||
return policy; | ||
}); | ||
} | ||
|
||
@action openPolicy(policy) { | ||
this.router.transitionTo('policies.policy', policy.name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// @ts-check | ||
import Controller from '@ember/controller'; | ||
import { action } from '@ember/object'; | ||
import { inject as service } from '@ember/service'; | ||
import { tracked } from '@glimmer/tracking'; | ||
import { task } from 'ember-concurrency'; | ||
|
||
export default class PoliciesPolicyController extends Controller { | ||
@service flashMessages; | ||
@service router; | ||
|
||
@tracked isDeleting = false; | ||
|
||
@action | ||
onDeletePrompt() { | ||
this.isDeleting = true; | ||
} | ||
|
||
@action | ||
onDeleteCancel() { | ||
this.isDeleting = false; | ||
} | ||
|
||
@task(function* () { | ||
try { | ||
yield this.model.deleteRecord(); | ||
yield this.model.save(); | ||
this.flashMessages.add({ | ||
title: 'Policy Deleted', | ||
type: 'success', | ||
destroyOnClick: false, | ||
timeout: 5000, | ||
}); | ||
this.router.transitionTo('policies'); | ||
} catch (err) { | ||
this.flashMessages.add({ | ||
title: `Error deleting Policy ${this.model.name}`, | ||
message: err, | ||
type: 'error', | ||
destroyOnClick: false, | ||
sticky: true, | ||
}); | ||
} | ||
}) | ||
deletePolicy; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import Route from '@ember/routing/route'; | ||
import withForbiddenState from 'nomad-ui/mixins/with-forbidden-state'; | ||
import WithModelErrorHandling from 'nomad-ui/mixins/with-model-error-handling'; | ||
import { inject as service } from '@ember/service'; | ||
import { hash } from 'rsvp'; | ||
|
||
export default class PoliciesRoute extends Route.extend( | ||
withForbiddenState, | ||
WithModelErrorHandling | ||
) { | ||
@service can; | ||
@service store; | ||
@service router; | ||
|
||
beforeModel() { | ||
if (this.can.cannot('list policies')) { | ||
this.router.transitionTo('/jobs'); | ||
} | ||
} | ||
|
||
async model() { | ||
return await hash({ | ||
policies: this.store.query('policy', { reload: true }), | ||
tokens: this.store.query('token', { reload: true }), | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Side-effect, but this PR illustrated the need to make code mirrors autofocusable