From 45931be4dac27bdea6f42288404701d86e55f81a Mon Sep 17 00:00:00 2001 From: Lisbet Alvarez <107949262+lisbet-alvarez@users.noreply.github.com> Date: Mon, 8 Jul 2024 14:48:42 -0700 Subject: [PATCH] =?UTF-8?q?refactor:=20=F0=9F=92=A1=20add=20grant=20scopes?= =?UTF-8?q?=20applied=20badge=20(#2374)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 💡 add grant scopes applied badge * test: 💍 add extra asserts --- addons/core/translations/resources/en-us.yaml | 4 ++ .../controllers/scopes/scope/roles/index.js | 3 ++ .../templates/scopes/scope/roles/index.hbs | 18 +++++++- ui/admin/tests/acceptance/roles/list-test.js | 41 ++++++++++++++++++- 4 files changed, 64 insertions(+), 2 deletions(-) diff --git a/addons/core/translations/resources/en-us.yaml b/addons/core/translations/resources/en-us.yaml index 05d3c67f3..67a37f68d 100644 --- a/addons/core/translations/resources/en-us.yaml +++ b/addons/core/translations/resources/en-us.yaml @@ -529,8 +529,12 @@ role: messages: welcome: title: Welcome to Roles + tooltips: + yes: The grants on this role have been applied to this scope. + no: The grants on this role have not been applied to this scope. titles: new: New Role + grants-applied: Grants applied on this scope? actions: create: Create Role delete: Delete Role diff --git a/ui/admin/app/controllers/scopes/scope/roles/index.js b/ui/admin/app/controllers/scopes/scope/roles/index.js index 40825e8f6..03c526243 100644 --- a/ui/admin/app/controllers/scopes/scope/roles/index.js +++ b/ui/admin/app/controllers/scopes/scope/roles/index.js @@ -11,6 +11,7 @@ import { tracked } from '@glimmer/tracking'; import { debounce } from 'core/decorators/debounce'; import { confirm } from 'core/decorators/confirm'; import { notifySuccess, notifyError } from 'core/decorators/notify'; +import { GRANT_SCOPE_THIS } from 'api/models/role'; export default class ScopesScopeRolesIndexController extends Controller { // =services @@ -26,6 +27,8 @@ export default class ScopesScopeRolesIndexController extends Controller { @tracked page = 1; @tracked pageSize = 10; + grantScopeThis = GRANT_SCOPE_THIS; + // =actions /** diff --git a/ui/admin/app/templates/scopes/scope/roles/index.hbs b/ui/admin/app/templates/scopes/scope/roles/index.hbs index 464b2de2c..a9206d2b0 100644 --- a/ui/admin/app/templates/scopes/scope/roles/index.hbs +++ b/ui/admin/app/templates/scopes/scope/roles/index.hbs @@ -46,13 +46,14 @@ @model={{@model.roles}} @columns={{array (hash label=(t 'form.name.label')) + (hash label=(t 'resources.role.titles.grants-applied')) (hash label=(t 'form.id.label')) }} @density='short' @valign='middle' > <:body as |B|> - + {{#if (can 'read role' B.data)}} @@ -63,6 +64,21 @@ {{/if}}

{{B.data.description}}

+ + {{#if (includes this.grantScopeThis B.data.grant_scope_ids)}} + + + + {{else}} + + + + {{/if}} + + `tbody [data-test-role-row="${id}"] td:nth-child(2) .hds-badge__text`; + const ROLE_TOOLTIP_BTN_SELECTOR = (id) => + `tbody [data-test-role-row="${id}"] td:nth-child(2) .hds-tooltip-button`; + const ROLE_TOOLTIP_CONTENT_SELECTOR = (id) => + `tbody [data-test-role-row="${id}"] td:nth-child(2) [data-tippy-root]`; const SEARCH_INPUT_SELECTOR = '.search-filtering [type="search"]'; const NO_RESULTS_MSG_SELECTOR = '[data-test-no-role-results]'; @@ -122,4 +136,29 @@ module('Acceptance | roles | list', function (hooks) { assert.dom(`[href="${urls.role2}"]`).doesNotExist(); assert.dom(NO_RESULTS_MSG_SELECTOR).includesText('No results found'); }); + + test('correct badge in grants applied column is visible to user', async function (assert) { + instances.role1.grant_scope_ids = instances.role1.grant_scope_ids.filter( + (id) => id !== GRANT_SCOPE_THIS, + ); + await visit(urls.orgScope); + + await click(`[href="${urls.roles}"]`); + + assert.true(instances.role2.grant_scope_ids.includes(GRANT_SCOPE_THIS)); + assert.dom(ROLE_BADGE_SELECTOR(instances.role1.id)).hasText('No'); + assert.dom(ROLE_BADGE_SELECTOR(instances.role2.id)).hasText('Yes'); + + await focus(ROLE_TOOLTIP_BTN_SELECTOR(instances.role1.id)); + + assert + .dom(ROLE_TOOLTIP_CONTENT_SELECTOR(instances.role1.id)) + .hasText('The grants on this role have not been applied to this scope.'); + + await focus(ROLE_TOOLTIP_BTN_SELECTOR(instances.role2.id)); + + assert + .dom(ROLE_TOOLTIP_CONTENT_SELECTOR(instances.role2.id)) + .hasText('The grants on this role have been applied to this scope.'); + }); });