diff --git a/app/models/globalrole.js b/app/models/globalrole.js
index 6b1cf6e6c..aa58d662c 100644
--- a/app/models/globalrole.js
+++ b/app/models/globalrole.js
@@ -9,15 +9,23 @@ const SPECIAL = [BASE, ADMIN, USER];
export default Resource.extend({
+ access: service(),
intl: service(),
router: service(),
- canRemove: false,
// I think its safe to hack around this - wjw
_displayState: 'active',
// because of this the state shows as "Unknown" with bright yellow background
stateColor: 'text-success',
+ canClone: computed('access.me', 'id', function() {
+ return this.access.allows('globalrole', 'create', 'global');
+ }),
+
+ canRemove: computed('id', 'builtin', function() {
+ return !this.builtin;
+ }),
+
isHidden: computed('id', function() {
return SPECIAL.includes(get(this, 'id'));
}),
@@ -74,5 +82,14 @@ export default Resource.extend({
edit() {
this.get('router').transitionTo('global-admin.security.roles.edit', this.get('id'), { queryParams: { type: 'global' } });
},
+
+ clone() {
+ this.router.transitionTo('global-admin.security.roles.new', {
+ queryParams: {
+ context: 'global',
+ id: this.id
+ }
+ });
+ }
}
});
diff --git a/app/styles/components/_searchable-select.scss b/app/styles/components/_searchable-select.scss
index 871c96a6b..f210564b0 100644
--- a/app/styles/components/_searchable-select.scss
+++ b/app/styles/components/_searchable-select.scss
@@ -43,6 +43,7 @@
font-weight: bold;
border-bottom: 1px solid $accent-border;
background: $dropdown-bg;
+ text-align: left;
}
> div {
padding-left: $indent + $group-indent;
diff --git a/lib/global-admin/addon/components/new-edit-role/component.js b/lib/global-admin/addon/components/new-edit-role/component.js
index c614c3ab0..2d43e6c8e 100644
--- a/lib/global-admin/addon/components/new-edit-role/component.js
+++ b/lib/global-admin/addon/components/new-edit-role/component.js
@@ -1,10 +1,11 @@
-import { alias, equal, or } from '@ember/object/computed';
+import { alias, or } from '@ember/object/computed';
import { inject as service } from '@ember/service';
import Component from '@ember/component';
-import NewOrEdit from 'ui/mixins/new-or-edit';
import C from 'ui/utils/constants';
import layout from './template';
import { get, computed, set } from '@ember/object';
+import { isEmpty } from '@ember/utils';
+import ViewNewEdit from 'shared/mixins/view-new-edit';
const ruleVerbs = C.RULE_VERBS.map((verb) => `rolesPage.new.form.allow.${ verb }`);
@@ -23,22 +24,22 @@ const BASIC_CONTEXT = [
},
];
-export default Component.extend(NewOrEdit, {
- intl: service(),
- router: service(),
+export default Component.extend(ViewNewEdit, {
+ intl: service(),
+ router: service(),
layout,
- model: null,
+ model: null,
- ruleArray: null,
- roleArray: null,
- readOnly: null,
- roleType: null,
- contexts: BASIC_CONTEXT,
+ ruleArray: null,
+ roleArray: null,
+ readOnly: null,
+ roleType: null,
+ contexts: BASIC_CONTEXT,
+ mode: 'new',
ruleVerbs,
- primaryResource: alias('model.role'),
- isGlobal: equal('roleType', 'global'),
- readOnlyBuiltInOrGlobal: or('readOnly', 'builtIn', 'isGlobal'),
+ primaryResource: alias('model.role'),
+ readOnlyOrBuiltIn: or('readOnly', 'builtIn', 'isView'),
init() {
this._super(...arguments);
@@ -119,6 +120,59 @@ export default Component.extend(NewOrEdit, {
return get(this, 'model.roles').filter((role) => get(this, 'model.role.id') !== role.id);
}),
+ ruleResources: computed('model.globalRoles.[]', 'model.roleTemplates.[]', function() {
+ const {
+ model: { globalRoles, roles: roleTemplates },
+ roleType
+ } = this;
+ let groupedResourceRules;
+
+ switch (roleType) {
+ case 'global':
+ if (!isEmpty(globalRoles)) {
+ groupedResourceRules = this.getRuleResourceList(globalRoles);
+ }
+ break;
+ default:
+ if (!isEmpty(roleTemplates)) {
+ groupedResourceRules = this.getRuleResourceList(roleTemplates.filterBy('context', roleType));
+ }
+ break;
+ }
+
+ return groupedResourceRules;
+ }),
+
+ getRuleResourceList(roles) {
+ const groupedResourceRules = [];
+
+ roles.forEach((role) => {
+ if (!isEmpty(role.rules)) {
+ // currently is ungrouped but can be grouped.
+ // The problem is that these are just default resources in a particular role,
+ // they are not unique so they show up duplicated under different groups.
+ // we need some discussion whether this is okay or not
+ // const group = role.name;
+
+ role.rules.forEach((rule) => {
+ if (!isEmpty(rule.resources)) {
+ rule.resources.forEach((resource) => {
+ if (resource !== '*') {
+ groupedResourceRules.push({
+ // group,
+ label: resource,
+ value: resource
+ });
+ }
+ });
+ }
+ });
+ }
+ });
+
+ return groupedResourceRules.uniqBy('value').sortBy('label');
+ },
+
getDefaultField(type) {
let out = '';
diff --git a/lib/global-admin/addon/components/new-edit-role/template.hbs b/lib/global-admin/addon/components/new-edit-role/template.hbs
index 6eb93d2c6..da1b31566 100644
--- a/lib/global-admin/addon/components/new-edit-role/template.hbs
+++ b/lib/global-admin/addon/components/new-edit-role/template.hbs
@@ -1,9 +1,9 @@
-{{#unless readOnlyBuiltInOrGlobal}}
+{{#unless readOnlyOrBuiltIn}}
{{form-name-description
model=model.role
@@ -22,7 +22,7 @@
{{/unless}}
-{{#if (and model.role.description readOnlyBuiltInOrGlobal)}}
+{{#if (and model.role.description readOnlyOrBuiltIn)}}
{{banner-message
color="bg-secondary mb-0 mt-10"
@@ -65,7 +65,7 @@
{{/if}}
- {{#if editing}}
+ {{#if isEdit}}
{{t "rolesPage.new.form.locked.detail"}}
@@ -105,7 +105,7 @@
{{/if}}
- {{#if editing}}
+ {{#if isEdit}}
{{t "rolesPage.new.form.locked.detail"}}
@@ -125,7 +125,7 @@
title=(t "rolesPage.resources.title")
}}
{{#if ruleArray.length}}
-
+
{{#each ruleVerbs as |verb|}}
@@ -140,21 +140,23 @@
{{#each ruleArray as |rule|}}
- {{role-rule-row
- readOnly=readOnlyBuiltInOrGlobal
- rule=rule
- remove=(action "removeRule")
- }}
+
{{/each}}
- {{else if readOnlyBuiltInOrGlobal}}
+ {{else if readOnlyOrBuiltIn}}
{{t "generic.none"}}
{{/if}}
- {{#unless readOnlyBuiltInOrGlobal}}
+ {{#unless readOnlyOrBuiltIn}}