feat: 🎸 add No scopes add to roles/role/scopes route (#2338)

* feat: 🎸 add No scopes add to roles/role/scopes route

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13878

* feat: 🎸 add new role ability

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13878

* refactor: 💡 fix permission for setting grant scopes on role

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-13878
This commit is contained in:
Cameron Perera authored and Lisbet Alvarez committed 2024-07-15 17:23:00 -07:00
1 parent 2bc314d271
commit 85bce84356
9 files changed
+67 -7

No files matched your search

@@ -9,7 +9,10 @@ export default class ScopesScopeRolesRoleScopesRoute extends Route {
async model() {
const role = this.modelFor('scopes.scope.roles.role');
if (!GRANT_SCOPE_KEYWORDS.some((id) => role.grant_scope_ids.includes(id))) {
if (
role.grant_scope_ids &&
!GRANT_SCOPE_KEYWORDS.some((id) => role.grant_scope_ids.includes(id))
) {
await this.store.query('scope', {
scope_id: role.scope.id,
recursive: true,
+7
View File
@@ -1036,3 +1036,10 @@
.loading-indicator {
margin-top: 20%;
}
// Roles
.role-grant-scopes {
.hds-application-state {
margin-top: 3rem;
}
}
@@ -40,7 +40,7 @@
<Roles::Role::Nav @model={{@model}} />
</page.navigation>
<page.body>
<page.body class='role-grant-scopes'>
{{#if @model.grant_scope_ids}}
<Hds::Table
@model={{@model.grantScopes}}
@@ -147,6 +147,21 @@
</B.Tr>
</:body>
</Hds::Table>
{{else}}
<Hds::ApplicationState as |A|>
<A.Header @title={{t 'resources.role.scope.messages.title'}} />
<A.Body @text={{t 'resources.role.scope.messages.description'}} />
{{#if (can 'setGrantScopes role' @model)}}
<A.Footer as |F|>
{{! TODO: Update route to manage-scopes once it is implemented }}
<F.Link::Standalone
@icon='plus-circle'
@text={{t 'resources.role.scope.messages.action'}}
@route='scopes.scope.roles.role.scopes'
/>
</A.Footer>
{{/if}}
</Hds::ApplicationState>
{{/if}}
</page.body>
@@ -75,4 +75,22 @@ module('Acceptance | roles | scopes', function (hooks) {
`/scopes/${instances.scopes.global.id}/scopes`,
);
});
test('user sees no scopes message and action when role has no grant scopes', async function (assert) {
instances.role.update({ grant_scope_ids: [] });
await visit(urls.roleScopes);
assert.dom('.role-grant-scopes div').includesText('No scopes added');
assert.dom('.role-grant-scopes div div:nth-child(3) a').isVisible();
});
test('user does not see action to add scopes when role has no grant scopes without proper permissions', async function (assert) {
instances.role.update({
grant_scope_ids: [],
authorized_actions: instances.role.authorized_actions.filter(
(action) => action !== 'set-grant-scopes',
),
});
await visit(urls.roleScopes);
assert.dom('.role-grant-scopes div div:nth-child(3) a').doesNotExist();
});
});