feat: 🎸 initial grant scopes field for role form

This commit is contained in:
Randall Morey committed 2020-11-03 12:01:46 -05:00
1 parent ba686ccc4e
commit 81fb4268b9
7 files changed
+110 -2

No files matched your search

@@ -44,6 +44,44 @@
{{/if}}
</form.textarea>
<form.radioGroup @name="grant_scope_id" @selectedValue={{@model.grant_scope_id}} as |radioGroup|>
<Rose::Dropdown
@text={{concat (t "form.grant_scope.label") ": " this.selectedGrantScope.displayName}}
aria-describedby="helper-text-grant-scope"
as |dropdown|>
{{#each @grantScopes as |grantScope|}}
<dropdown.item>
<radioGroup.radio
@label={{grantScope.model.displayName}}
@value={{grantScope.model.id}}
/>
</dropdown.item>
{{#each grantScope.subScopes as |subScope|}}
<dropdown.item class="indent-1">
<radioGroup.radio
@label={{subScope.model.displayName}}
@value={{subScope.model.id}}
/>
</dropdown.item>
{{#each subScope.subScopes as |subSubScope|}}
<dropdown.item class="indent-2">
<radioGroup.radio
@label={{subSubScope.displayName}}
@value={{subSubScope.id}}
/>
</dropdown.item>
{{/each}}
{{/each}}
{{/each}}
</Rose::Dropdown>
<Rose::Form::HelperText @id="helper-text-grant-scope" @error={{@model.errors.grant_scope_id}}>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {{t "form.grant_scope.help"}}
</Rose::Form::HelperText>
</form.radioGroup>
<br>
<br>
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t "actions.edit-form"}}
+18
View File
@@ -0,0 +1,18 @@
import Component from '@glimmer/component';
import { computed } from '@ember/object';
export default class FormRoleGrantsComponent extends Component {
// =attributes
/**
* Returns the selected grant scope model.
* @type {ScopeModel}
*/
@computed('args.model.{store,grant_scope_id}')
get selectedGrantScope() {
return this.args.model.grant_scope_id
? this.args.model.store
.peekRecord('scope', this.args.model.grant_scope_id)
: null;
}
}
@@ -1,3 +1,32 @@
import Route from '@ember/routing/route';
export default class ScopesScopeRolesRoleIndexRoute extends Route {}
export default class ScopesScopeRolesRoleIndexRoute extends Route {
/**
* Load the role's scope and sub scopes into a hierarchical data structure.
* @param {Model} model
*/
async afterModel(model) {
const defaultScope = await this.store.findRecord('scope', model.scopeID);
const subScopes = (await this.store.query('scope', { scope_id: defaultScope.id }))
.map(scope => ({
model: scope,
subScopes: this.store.query('scope', { scope_id: scope.id })
}));
const grantScopes = [{
model: defaultScope,
subScopes
}];
this.set('grantScopes', grantScopes);
}
/**
* Adds `grantScopes` to the context.
* @param {Controller} controller
*/
setupController(controller) {
super.setupController(...arguments);
controller.set('grantScopes', this.grantScopes);
}
}
+12
View File
@@ -42,6 +42,18 @@
width: 100%;
}
}
.rose-dropdown {
.rose-dropdown-item {
&.indent-1 {
padding-left: sizing.rems(s) * 2;
}
&.indent-2 {
padding-left: sizing.rems(l) + sizing.rems(m);
}
}
}
}
.rose-table {
@@ -1,6 +1,6 @@
<Form::Role
@model={{@model}}
@grantScopes={{this.grantScopes}}
@submit={{route-action "save" @model}}
@cancel={{route-action "cancel" @model}}
/>
+8
View File
@@ -19,6 +19,7 @@ module('Acceptance | roles', function (hooks) {
scopes: {
global: null,
org: null,
project: null,
},
role: null,
};
@@ -36,6 +37,13 @@ module('Acceptance | roles', function (hooks) {
type: 'org',
scope: { id: 'global', type: 'global' },
});
// The project scope is not yet used for role tests (though it will be
// in the future). This is created simply to test the grant scope loading
// mechanism.
instances.scopes.project = this.server.create('scope', {
type: 'project',
scope: { id: instances.scopes.org.id, type: instances.scopes.org.type },
});
instances.role = this.server.create('role', {
scope: instances.scopes.org,
}, 'withPrincipals');
+3
View File
@@ -43,3 +43,6 @@ session_connection_limit:
help: The maximum number of connections allowed per session. For unlimited, specify "-1".
host_set:
label: Host Set
grant_scope:
label: Grant Scope
help: Specify the scope to which this role applies.