Merge pull request #846 from hashicorp/feature-managed-group-create

Feature managed group create
This commit is contained in:
Susmitha Girumala authored and GitHub committed 2021-11-11 11:45:22 -05:00
commit b7214c55a4
15 files changed
+154 -18

No files matched your search

+8
View File
@@ -5,6 +5,14 @@ import { A } from '@ember/array';
export default class ManagedGroupModel extends GeneratedManagedGroupModel {
// =attributes
// =error attributes
// These attributes exist solely to capture errors on nested fields.
// See the application adapter's error normalization method for
// more information.
@attr('string', { readOnly: true }) attributes_filter;
/**
* Members is read-only under normal circumstances. But members can
* be persisted via calls to `addMembers()` or `removeMembers()`.
+1
View File
@@ -523,6 +523,7 @@ export default function () {
);
this.get('/managed-groups/:id');
this.del('/managed-groups/:id');
this.post('/managed-groups');
/* Uncomment the following line and the Response import above
* Then change the response code to simulate error responses.
@@ -1,8 +1,12 @@
import factory from '../generated/factories/managed-group';
import { random } from 'faker';
import permissions from '../helpers/permissions';
const types = ['oidc'];
export default factory.extend({
id: (i) => `managed-groups-id-${i}`,
type: (i) => types[i % types.length],
authorized_actions: () =>
permissions.authorizedActionsFor('managed-group') || [
@@ -11,4 +15,13 @@ export default factory.extend({
'update',
'delete',
],
attributes() {
switch (this.type) {
case 'oidc':
return {
filter: random.words(),
};
}
},
});
@@ -11,15 +11,4 @@ export default Factory.extend({
created_time: () => date.recent(),
updated_time: () => date.recent(),
version: () => datatype.number(),
type: 'oidc',
attributes: function () {
switch (this.type) {
case 'oidc':
return {
filter: random.words(),
};
default:
return;
}
},
});
@@ -357,3 +357,4 @@ managed-group:
description: A managed group represents a collection of accounts.
actions:
delete: Delete Managed Group
create: Create Managed Group
@@ -1,4 +1,11 @@
<Rose::Form as |form|>
<Rose::Form
@onSubmit={{@submit}}
@cancel={{@cancel}}
@disabled={{@model.isSaving}}
@error={{@model.errors.base}}
@showEditToggle={{if @model.isNew false true}}
as |form|
>
<form.input
@value={{@model.type}}
@label={{t 'form.type.label'}}
@@ -46,10 +53,27 @@
</form.textarea>
<form.input
@name='filter'
@type='text'
@value={{@model.attributes.filter}}
@helperText={{t 'form.filter.help'}}
@label={{t 'form.filter.label'}}
readonly={{true}}
@disabled={{true}}
@error={{@model.errors.attributes_filter}}
@helperText={{t 'form.filter.help'}}
as |field|
>
{{#if @model.errors.filter}}
<field.errors as |errors|>
{{#each @model.errors.filter as |error|}}
<errors.message>{{error.message}}</errors.message>
{{/each}}
</field.errors>
{{/if}}
</form.input>
<form.actions
@disabled={{if @model.cannotSave @model.cannotSave}}
@enableEditText={{t 'actions.edit-form'}}
@submitText={{t 'actions.save'}}
@cancelText={{t 'actions.cancel'}}
/>
</Rose::Form>
+1
View File
@@ -61,6 +61,7 @@ Router.map(function () {
{ path: ':managed_group_id' },
function () {}
);
this.route('new');
});
});
this.route('new');
@@ -1,14 +1,19 @@
import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { confirm } from 'core/decorators/confirm';
import { inject as service } from '@ember/service';
import loading from 'ember-loading/decorator';
import { confirm } from 'core/decorators/confirm';
import { notifySuccess, notifyError } from 'core/decorators/notify';
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends Route {
// =services
@service intl;
@service notify;
@service can;
//=methods
/**
*
* @returns {Promise{[ManagedGroupsModel]}}
@@ -33,6 +38,24 @@ export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsRoute extends
}
}
/**
* Save a managed group in current scope.
* @param {ManagedGroupModel} managedGroup
*/
@action
@loading
@notifyError(({ message }) => message)
@notifySuccess(({ isNew }) =>
isNew ? 'notifications.create-success' : 'notifications.save-success'
)
async save(managedGroup) {
await managedGroup.save();
await this.transitionTo(
'scopes.scope.auth-methods.auth-method.managed-groups'
);
this.refresh();
}
/**
* Delete a managed group in current scope and redirect to index
* @param {ManagedGroupModel} managed group
@@ -0,0 +1,36 @@
import Route from '@ember/routing/route';
export default class ScopesScopeAuthMethodsAuthMethodManagedGroupsNewRoute extends Route {
// =methods
model() {
const { id: auth_method_id, type } = this.modelFor(
'scopes.scope.auth-methods.auth-method'
);
return this.store.createRecord('managed-group', {
type,
auth_method_id,
});
}
renderTemplate() {
super.renderTemplate(...arguments);
this.render(
'scopes/scope/auth-methods/auth-method/managed-groups/new/-header',
{
into: 'scopes/scope/auth-methods/auth-method',
outlet: 'header',
}
);
this.render('_empty', {
into: 'scopes/scope/auth-methods/auth-method',
outlet: 'actions',
});
this.render('_empty', {
into: 'scopes/scope/auth-methods/auth-method',
outlet: 'navigation',
});
}
}
@@ -67,6 +67,18 @@
</dropdown.link>
{{/if}}
{{#if (feature-flag 'managed-groups')}}
{{! TODO: Add capabilities }}
{{#if @model.isOIDC}}
<dropdown.link
@route='scopes.scope.auth-methods.auth-method.managed-groups.new'
@model={{@model}}
>
{{t 'resources.managed-group.actions.create'}}
</dropdown.link>
{{/if}}
{{/if}}
{{#if (can 'delete model' @model)}}
<dropdown.separator />
<dropdown.button
@@ -18,8 +18,10 @@
@route='scopes.scope.auth-methods.auth-method.managed-groups.managed-group'
@model={{managed-group.id}}
>
{{managed-group.name}}
{{managed-group.displayName}}
</LinkTo>
{{else}}
{{managed-group.displayName}}
{{/if}}
</row.headerCell>
<row.cell>{{managed-group.description}}</row.cell>
@@ -0,0 +1,5 @@
<Form::ManagedGroup
@model={{@model}}
@submit={{route-action 'save' @model}}
@cancel={{route-action 'cancel' @model}}
/>
@@ -0,0 +1,5 @@
<h2>
{{t 'titles.new'}}
{{! TODO: change the icon link }}
<DocLink @doc='account.new' @iconSize='large' />
</h2>
@@ -0,0 +1,16 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module(
'Unit | Route | scopes/scope/auth-methods/auth-method/managed-groups/new',
function (hooks) {
setupTest(hooks);
test('it exists', function (assert) {
let route = this.owner.lookup(
'route:scopes/scope/auth-methods/auth-method/managed-groups/new'
);
assert.ok(route);
});
}
);