Skip to content

Commit

Permalink
Sentinel policies moved within the Administration section
Browse files Browse the repository at this point in the history
  • Loading branch information
philrenaud committed May 10, 2024
1 parent 9a9b830 commit a157c53
Show file tree
Hide file tree
Showing 22 changed files with 51 additions and 47 deletions.
3 changes: 3 additions & 0 deletions .changelog/20483.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
ui: Added a UI for creating, editing and deleting Sentinel Policies
```
1 change: 0 additions & 1 deletion ui/app/adapters/sentinel-policy.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import { default as ApplicationAdapter } from './application';
import classic from 'ember-classic-decorator';

// TODO: Nomitch - Update this
@classic
export default class SentinelPolicyAdapter extends ApplicationAdapter {
pathForType = () => 'sentinel/policies';
Expand Down
6 changes: 4 additions & 2 deletions ui/app/components/sentinel-policy-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,10 @@ export default class SentinelPolicyEditorComponent extends Component {
});

if (shouldRedirectAfterSave) {
// TODO: GO TO THE SHOW PAGE INSTEAD
this.router.transitionTo('sentinel-policies.policy', this.policy.name);
this.router.transitionTo(
'administration.sentinel-policies.policy',
this.policy.name
);
}
} catch (err) {
let message = err.errors?.length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

import Controller from '@ember/controller';

export default class SentinelPoliciesController extends Controller {}
export default class AdministrationSentinelPoliciesController extends Controller {}
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ export default class SentinelPoliciesIndexController extends Controller {
@service notifications;

@action openPolicy(policy) {
this.router.transitionTo('sentinel-policies.policy', policy.name);
this.router.transitionTo(
'administration.sentinel-policies.policy',
policy.name
);
}

@action goToNewPolicy() {
this.router.transitionTo('sentinel-policies.new');
this.router.transitionTo('administration.sentinel-policies.new');
}

get columns() {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class SentinelPoliciesPolicyController extends Controller {
type: `success`,
destroyOnClick: false,
});
this.router.transitionTo('sentinel-policies.index');
this.router.transitionTo('administration.sentinel-policies.index');
} catch (err) {
// A failed delete resulted in errors when you then navigated away and back
// to the show page rollbackWithoutChangedAttrs fixes it, but there might
Expand Down
11 changes: 5 additions & 6 deletions ui/app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ Router.map(function () {
this.route('summary', { path: '*slug' });
});

this.route('sentinel-policies', function () {
this.route('new');
this.route('gallery');
this.route('policy', { path: '/:id' });
});

this.route('clients', function () {
this.route('client', { path: '/:node_id' }, function () {
this.route('monitor');
Expand Down Expand Up @@ -145,6 +139,11 @@ Router.map(function () {
path: '/:name',
});
});
this.route('sentinel-policies', function () {
this.route('new');
this.route('gallery');
this.route('policy', { path: '/:id' });
});
});
// Mirage-only route for testing OIDC flow
if (config['ember-cli-mirage']) {
Expand Down
4 changes: 3 additions & 1 deletion ui/app/routes/administration.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ export default class AdministrationRoute extends Route.extend(
this.can.cannot('list policies') ||
this.can.cannot('list roles') ||
this.can.cannot('list tokens') ||
this.can.cannot('list namespaces')
this.can.cannot('list namespaces') ||
this.can.cannot('list sentinel-policies')
) {
this.router.transitionTo('/jobs');
}
Expand All @@ -35,6 +36,7 @@ export default class AdministrationRoute extends Route.extend(
roles: this.store.findAll('role', { reload: true }),
tokens: this.store.findAll('token', { reload: true }),
namespaces: this.store.findAll('namespace', { reload: true }),
sentinelPolicies: this.store.findAll('sentinel-policy', { reload: true }),
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Route from '@ember/routing/route';
import classic from 'ember-classic-decorator';

@classic
export default class ClientsRoute extends Route {
export default class AdministrationSentinelPoliciesRoute extends Route {
@service store;

model() {
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion ui/app/styles/components/access-control.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

.section-cards {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
gap: 1rem;
& > div {
padding: 1rem;
Expand Down
11 changes: 11 additions & 0 deletions ui/app/templates/administration/index.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@
<p>Namespaces allow jobs and other objects to be segmented from each other.</p>
<Hds::Button @text="Create Namespace" @color="secondary" @iconPosition="leading" @icon="plus" @route="administration.namespaces.new" />
</Hds::Card::Container>
{{#if (can "read sentinel-policy")}}
<Hds::Card::Container @level="mid" @hasBorder={{true}} data-test-sentinel-policies-card>
<LinkTo
@route="administration.sentinel-policies"
>
{{this.model.sentinelPolicies.length}} {{pluralize "Sentinel Policy" this.model.sentinelPolicies.length}}
</LinkTo>
<p>Sentinel Policies allow operators to express rules as code and have those rules automatically enforced when jobs are planned.</p>
<Hds::Button @text="Create Sentinel Policy" @color="secondary" @iconPosition="leading" @icon="plus" @route="administration.sentinel-policies.new" />
</Hds::Card::Container>
{{/if}}
</div>
</section>
{{outlet}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
SPDX-License-Identifier: BUSL-1.1
~}}

<Breadcrumb @crumb={{hash label="Sentinel Policies" args=(array "sentinel-policies.index")}} />
<Breadcrumb @crumb={{hash label="Sentinel Policies" args=(array "administration.sentinel-policies.index")}} />
{{page-title "Sentinel Policies"}}
<PageLayout>
{{outlet}}
</PageLayout>
{{outlet}}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SPDX-License-Identifier: BUSL-1.1
~}}

<Breadcrumb @crumb={{hash label="Gallery" args=(array "sentinel-policies.gallery" )}} />
<Breadcrumb @crumb={{hash label="Gallery" args=(array "administration.sentinel-policies.gallery" )}} />
{{page-title "Sentinel Policy Gallery"}}
<section class="section">
<Hds::PageHeader class="variable-title" as |PH|>
Expand All @@ -27,9 +27,9 @@
</main>
<footer class="buttonset">
<Hds::ButtonSet class="button-group">
<Hds::Button @text="Apply" @route="sentinel-policies.new" @query={{hash template=this.selectedTemplate}}
<Hds::Button @text="Apply" @route="administration.sentinel-policies.new" @query={{hash template=this.selectedTemplate}}
disabled={{is-equal this.selectedTemplate null}} data-test-apply />
<Hds::Button @text="Cancel" @route="sentinel-policies.new" @color="secondary" data-test-cancel />
<Hds::Button @text="Cancel" @route="administration.sentinel-policies.new" @color="secondary" data-test-cancel />
</Hds::ButtonSet>
</footer>
</section>
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ SPDX-License-Identifier: BUSL-1.1
label="Create Policy"
}}
>
<Hds::Button @text="Create Policy" @icon="plus" @route="sentinel-policies.new" data-test-create-sentinel-policy />
<Hds::Button @text="Create from Scratch" @icon="plus" @route="administration.sentinel-policies.new" data-test-create-sentinel-policy />
</span>
<Hds::Button @text="Create from Template" @icon="plus" @route="administration.sentinel-policies.gallery" />
{{else}}
<Hds::Button @text="Create Policy" @icon="plus" disabled data-test-disabled-create-sentinel-policy />
{{/if}}
Expand All @@ -32,7 +33,7 @@ SPDX-License-Identifier: BUSL-1.1
<:body as |B|>
<B.Tr {{keyboard-shortcut enumerated=true action=(action "openPolicy" B.data) }} data-test-sentinel-policy-row>
<B.Td>
<LinkTo data-test-sentinel-policy-name={{B.data.name}} @route="sentinel-policies.policy"
<LinkTo data-test-sentinel-policy-name={{B.data.name}} @route="administration.sentinel-policies.policy"
@model={{B.data.name}}>{{B.data.name}}</LinkTo>
</B.Td>
<B.Td>{{B.data.description}}</B.Td>
Expand Down Expand Up @@ -61,8 +62,8 @@ SPDX-License-Identifier: BUSL-1.1
No Sentinel Policies
</h3>
<p class="empty-message-body">
Get started by <LinkTo @route="sentinel-policies.new">creating a policy from scratch</LinkTo> or
by <LinkTo @route="sentinel-policies.gallery">creating one from the policy gallery</LinkTo>.
Get started by <LinkTo @route="administration.sentinel-policies.new">creating a policy from scratch</LinkTo> or
by <LinkTo @route="administration.sentinel-policies.gallery">creating one from the policy gallery</LinkTo>.
</p>
</div>
{{/if}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SPDX-License-Identifier: BUSL-1.1
~}}

<Breadcrumb @crumb={{hash label="New" args=(array "sentinel-policies.new")}} />
<Breadcrumb @crumb={{hash label="New" args=(array "administration.sentinel-policies.new")}} />
{{page-title "Create a Policy"}}
<section class="section">
<Hds::PageHeader class="variable-title" as |PH|>
Expand All @@ -15,7 +15,7 @@
<Hds::Button
@text="Start from a template"
@color="secondary"
@route="sentinel-policies.gallery"
@route="administration.sentinel-policies.gallery"
data-test-choose-template
/>
</PH.Actions>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
SPDX-License-Identifier: BUSL-1.1
~}}

<Breadcrumb @crumb={{hash label=this.model.name args=(array "sentinel-policies.policy" this.model.name)}} />
<Breadcrumb @crumb={{hash label=this.model.name args=(array "administration.sentinel-policies.policy" this.model.name)}} />
{{page-title (concat "Sentinel Policy: " this.model.name)}}

<section class="section">
Expand Down
3 changes: 3 additions & 0 deletions ui/app/templates/components/administration-subnav.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@
<li><LinkTo @route="administration.roles" @activeClass="is-active">Roles</LinkTo></li>
<li><LinkTo @route="administration.policies" @activeClass="is-active">Policies</LinkTo></li>
<li><LinkTo @route="administration.namespaces" @activeClass="is-active">Namespaces</LinkTo></li>
{{#if (can "list sentinel policies")}}
<li><LinkTo @route="administration.sentinel-policies" @activeClass="is-active">Sentinel Policies</LinkTo></li>
{{/if}}
</ul>
</div>
17 changes: 0 additions & 17 deletions ui/app/templates/components/gutter-menu.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,6 @@
</LinkTo>
</li>
{{/if}}
{{#if (can "read sentinel-policy")}}
<li
{{keyboard-shortcut
menuLevel=true
pattern=(array "g" "x")
action=(action this.transitionTo 'sentinel-policies')
}}
>
<LinkTo
@route="sentinel-policies"
@activeClass="is-active"
data-test-gutter-link="optimize"
>
Sentinel
</LinkTo>
</li>
{{/if}}
</ul>
<p class="menu-label">
Cluster
Expand Down

0 comments on commit a157c53

Please sign in to comment.