chore: 🤖 merge from main

This commit is contained in:
Randall Morey committed 2021-04-01 15:24:49 -04:00
commit c978958df2
41 files changed
+3534 -1001

No files matched your search

@@ -0,0 +1,13 @@
import Controller from '@ember/controller';
export default class ScopesScopeAuthMethodsIndexController extends Controller {
// =attributes
/**
* True if the current scope has a primary auth method set.
* @type {boolean}
*/
get hasPrimaryAuthMethod() {
return Boolean(this.scopeModel.primary_auth_method_id);
}
}
@@ -71,8 +71,67 @@ export default class ScopesScopeAuthMethodsRoute extends Route {
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('notifications.delete-success')
async delete(authMethod) {
const scopeModel = this.modelFor('scopes.scope');
await authMethod.destroyRecord();
// Reload the scope, since this is where the primary_auth_method_id is
// stored. An auth method deletion could affect this field.
await scopeModel.reload();
await this.replaceWith('scopes.scope.auth-methods');
this.refresh();
}
/**
* Elects the specified auth method to primary for the current scope.
* @param {AuthMethodModel} authMethod
* @param {string} authMethod.id
*/
@action
@loading
@confirm('resources.auth-method.questions.make-primary-confirm', {
title: 'resources.auth-method.questions.make-primary',
})
@notifyError(({ message }) => message, { catch: true })
@notifySuccess('resources.auth-method.notifications.make-primary-success')
async makePrimary({ id }) {
const scopeModel = this.modelFor('scopes.scope');
scopeModel.primary_auth_method_id = id;
// Attempt to save the change to the scope. If this operation fails,
// we rollback the change and rethrow the error so the user can be notified.
try {
await scopeModel.save();
} catch (e) {
scopeModel.rollbackAttributes();
throw e;
}
await this.refresh();
}
/**
* Sets the `primary_auth_method_id` field to null for the current scope
* and saves it if and only if the specified auth method is in fact primary
* for the current scope.
* @param {AuthMethodModel} authMethod
*/
@action
@loading
@confirm('resources.auth-method.questions.remove-as-primary-confirm', {
title: 'resources.auth-method.questions.remove-as-primary',
})
@notifyError(({ message }) => message, { catch: true })
@notifySuccess(
'resources.auth-method.notifications.remove-as-primary-success'
)
async removeAsPrimary(authMethod) {
const scopeModel = this.modelFor('scopes.scope');
scopeModel.primary_auth_method_id = null;
// Attempt to save the change to the scope. If this operation fails,
// we rollback the change and rethrow the error so the user can be notified.
try {
await scopeModel.save();
} catch (e) {
scopeModel.rollbackAttributes();
throw e;
}
await authMethod.reload();
}
}
@@ -1,3 +1,15 @@
import Route from '@ember/routing/route';
export default class ScopesScopeAuthMethodsIndexRoute extends Route {}
export default class ScopesScopeAuthMethodsIndexRoute extends Route {
// =methods
/**
* Adds the scope to the controller context.
* @param {Controller} controller
*/
setupController(controller) {
super.setupController(...arguments);
const scopeModel = this.modelFor('scopes.scope');
controller.scopeModel = scopeModel;
}
}
+1 -1
View File
@@ -113,7 +113,7 @@
</Rose::Dialog>
{{else}}
<Rose::Dialog
@heading={{t "actions.confirm"}}
@heading={{if confirmation.options.title (t confirmation.options.title) (t "actions.confirm")}}
@dismissButtonText={{t "actions.cancel"}}
@icon="alert-triangle"
@style="warning"
@@ -1,4 +1,22 @@
<Rose::Dropdown @text="{{t 'actions.manage'}}" @dropdownRight={{true}} as |dropdown|>
{{#if (feature-flag 'primary-auth-method')}}
{{#unless @model.isPrimary}}
<dropdown.button
@disabled={{@model.canSave}}
{{on "click" (route-action "makePrimary" @model)}}
>
{{t 'resources.auth-method.actions.make-primary'}}
</dropdown.button>
{{/unless}}
{{#if @model.isPrimary}}
<dropdown.button
@disabled={{@model.canSave}}
{{on "click" (route-action "removeAsPrimary" @model)}}
>
{{t 'resources.auth-method.actions.remove-as-primary'}}
</dropdown.button>
{{/if}}
{{/if}}
<dropdown.link
@route="scopes.scope.auth-methods.auth-method.accounts.new"
@model={{@model}}
@@ -1,5 +1,14 @@
<h2>
{{t "resources.auth-method.title"}}
{{#if (feature-flag 'primary-auth-method')}}
{{#if @model.isPrimary}}
&nbsp;
<Rose::Badge @style="success-outline">
{{t 'states.primary'}}
</Rose::Badge>
&nbsp;
{{/if}}
{{/if}}
<DocLink @doc="auth-method" @iconSize="large" />
</h2>
<p>{{t "resources.auth-method.description"}}</p>
@@ -30,12 +30,27 @@
<page.body>
{{#if @model}}
{{#if (feature-flag 'primary-auth-method')}}
{{#unless this.hasPrimaryAuthMethod}}
<Rose::Notification
@style="warning"
@heading={{t "resources.auth-method.messages.no-primary-auth-method.title"}}
>
{{t "resources.auth-method.messages.no-primary-auth-method.description"}}
</Rose::Notification>
{{/unless}}
{{/if}}
<Rose::Table as |table|>
<table.header as |header|>
<header.row as |row|>
<row.headerCell>{{t 'form.name.label'}}</row.headerCell>
<row.headerCell>{{t 'form.type.label'}}</row.headerCell>
<row.headerCell>{{t 'form.id.label'}}</row.headerCell>
{{#if (feature-flag 'primary-auth-method')}}
<row.cell></row.cell>
<row.headerCell>{{t 'titles.actions'}}</row.headerCell>
{{/if}}
</header.row>
</table.header>
@@ -69,6 +84,39 @@
<code>{{authMethod.id}}</code>
</Copyable>
</row.cell>
{{#if (feature-flag 'primary-auth-method')}}
<row.cell>
{{#if authMethod.isPrimary}}
<Rose::Badge @style="success-outline">
{{t 'states.primary'}}
</Rose::Badge>
{{/if}}
</row.cell>
<row.cell>
<Rose::Dropdown
@text={{t "actions.manage"}}
@dropdownRight={{true}}
@iconOnly={{true}}
@showCaret={{false}}
@icon="more-horizontal"
as |dropdown|>
{{#unless authMethod.isPrimary}}
<dropdown.button
{{on "click" (route-action "makePrimary" authMethod)}}
>
{{t 'resources.auth-method.actions.make-primary'}}
</dropdown.button>
{{/unless}}
{{#if authMethod.isPrimary}}
<dropdown.button
{{on "click" (route-action "removeAsPrimary" authMethod)}}
>
{{t 'resources.auth-method.actions.remove-as-primary'}}
</dropdown.button>
{{/if}}
</Rose::Dropdown>
</row.cell>
{{/if}}
</body.row>
{{/each}}
</table.body>
+7
View File
@@ -84,6 +84,10 @@ module.exports = function (environment) {
'ember-cli-mirage': {
directory: '../../addons/api/mirage',
},
featureFlags: {
'primary-auth-method': false,
},
};
// Unsafe policy is necessary in development and test environments, but should
@@ -116,6 +120,9 @@ module.exports = function (environment) {
// rather than automatically include API_HOST. Changes to CSP should
// be explicit.
if (API_HOST) ENV.contentSecurityPolicy['connect-src'].push(API_HOST);
// Enable features in development
ENV.featureFlags['primary-auth-method'] = true;
}
if (environment === 'test') {
+1
View File
@@ -62,6 +62,7 @@
"ember-concurrency": "^1.3.0",
"ember-exam": "^6.0.1",
"ember-export-application-global": "^2.0.1",
"ember-feature-flags": "^6.0.0",
"ember-inline-svg": "^1.0.0",
"ember-load-initializers": "^2.1.2",
"ember-maybe-import-regenerator": "^0.1.6",
@@ -10,6 +10,7 @@ import {
// //currentSession,
// //invalidateSession,
} from 'ember-simple-auth/test-support';
import { enableFeature } from 'ember-feature-flags/test-support';
module('Acceptance | auth methods', function (hooks) {
setupApplicationTest(hooks);
@@ -270,4 +271,118 @@ module('Acceptance | auth methods', function (hooks) {
'Displays field-level errors.'
);
});
test('user can make primary an auth method', async function (assert) {
assert.expect(2);
assert.notOk(
instances.scopes.org.primaryAuthMethodId,
'Primary auth method is not yet set.'
);
enableFeature('primary-auth-method');
await visit(urls.authMethod);
await click(
'.rose-layout-page-actions .rose-dropdown-content [type="button"]:first-child'
);
const scope = this.server.schema.scopes.find(instances.scopes.org.id);
assert.equal(
scope.primaryAuthMethodId,
instances.authMethod.id,
'Primary auth method is set.'
);
});
test('user is notified of error on make primary an auth method', async function (assert) {
assert.expect(2);
this.server.patch('/scopes/:id', () => {
return new Response(
400,
{},
{
status: 400,
code: 'fail',
message: 'Sorry!',
}
);
});
assert.notOk(
instances.scopes.org.primaryAuthMethodId,
'Primary auth method is not yet set.'
);
enableFeature('primary-auth-method');
await visit(urls.authMethod);
await click(
'.rose-layout-page-actions .rose-dropdown-content [type="button"]:first-child'
);
assert.ok(find('.rose-notification'));
});
test('user can remove as primary an auth method', async function (assert) {
assert.expect(2);
instances.scopes.org.update({
primaryAuthMethodId: instances.authMethod.id,
});
assert.ok(
instances.scopes.org.primaryAuthMethodId,
'Primary auth method is set.'
);
enableFeature('primary-auth-method');
await visit(urls.authMethod);
await click(
'.rose-layout-page-actions .rose-dropdown-content [type="button"]:first-child'
);
const scope = this.server.schema.scopes.find(instances.scopes.org.id);
assert.notOk(scope.primaryAuthMethodId, 'Primary auth method is unset.');
});
test('user is notified of error on remove as primary an auth method', async function (assert) {
assert.expect(2);
this.server.patch('/scopes/:id', () => {
return new Response(
400,
{},
{
status: 400,
code: 'fail',
message: 'Sorry!',
}
);
});
instances.scopes.org.update({
primaryAuthMethodId: instances.authMethod.id,
});
assert.ok(
instances.scopes.org.primaryAuthMethodId,
'Primary auth method is set.'
);
enableFeature('primary-auth-method');
await visit(urls.authMethod);
await click(
'.rose-layout-page-actions .rose-dropdown-content [type="button"]:first-child'
);
assert.ok(find('.rose-notification'));
});
test('user can make and remove primary auth methods from index', async function (assert) {
assert.expect(3);
assert.notOk(
instances.scopes.org.primaryAuthMethodId,
'Primary auth method is not yet set.'
);
enableFeature('primary-auth-method');
await visit(urls.authMethods);
await click(
'.rose-table-body .rose-table-row:first-child .rose-dropdown-content [type="button"]:first-child'
);
let scope = this.server.schema.scopes.find(instances.scopes.org.id);
assert.equal(
scope.primaryAuthMethodId,
instances.authMethod.id,
'Primary auth method is set.'
);
await click(
'.rose-table-body .rose-table-row:first-child .rose-dropdown-content [type="button"]:first-child'
);
scope = this.server.schema.scopes.find(instances.scopes.org.id);
assert.notOk(scope.primaryAuthMethodId, 'Primary auth method is unset.');
});
});
@@ -0,0 +1,14 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Controller | scopes/scope/auth-methods/index', function (hooks) {
setupTest(hooks);
// TODO: Replace this with your real tests.
test('it exists', function (assert) {
let controller = this.owner.lookup(
'controller:scopes/scope/auth-methods/index'
);
assert.ok(controller);
});
});