Merge branch 'develop' into chore-logomark

This commit is contained in:
Susmitha Girumala authored and GitHub committed 2020-10-01 21:49:53 -04:00
commit e41ed61bde
28 files changed
+285 -28

No files matched your search

@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../utilities/confirm';
export default class ScopesScopeAuthMethodsRoute extends Route {
// =services
@@ -71,10 +72,11 @@ export default class ScopesScopeAuthMethodsRoute extends Route {
*/
@action
@loading
@confirm('questions.delete-confirm')
async delete(authMethod) {
try {
await authMethod.destroyRecord();
await this.transitionTo('scopes.scope.auth-methods');
await this.replaceWith('scopes.scope.auth-methods');
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
} catch (error) {
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../../../utilities/confirm';
export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route {
// =services
@@ -71,10 +72,11 @@ export default class ScopesScopeAuthMethodsAuthMethodAccountsRoute extends Route
*/
@action
@loading
async delete(account) {
@confirm('questions.delete-confirm')
async deleteAccount(account) {
try {
await account.destroyRecord();
await this.transitionTo('scopes.scope.auth-methods.auth-method.accounts');
await this.replaceWith('scopes.scope.auth-methods.auth-method.accounts');
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
} catch (error) {
+3 -1
View File
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../utilities/confirm';
export default class ScopesScopeGroupsRoute extends Route {
// =services
@@ -68,12 +69,13 @@ export default class ScopesScopeGroupsRoute extends Route {
*/
@action
@loading
@confirm('questions.delete-confirm')
async delete(group) {
try {
await group.destroyRecord();
await this.replaceWith('scopes.scope.groups');
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
await this.transitionTo('scopes.scope.groups');
} catch (error) {
//TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
@@ -3,6 +3,7 @@ import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { hash, all } from 'rsvp';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../../../utilities/confirm';
export default class ScopesScopeGroupsGroupMembersRoute extends Route {
// =services
@@ -38,10 +39,11 @@ export default class ScopesScopeGroupsGroupMembersRoute extends Route {
*/
@action
@loading
@confirm('questions.remove-confirm')
async removeMember(group, member) {
try {
await group.removeMember(member.id);
await this.refresh();
this.refresh();
this.notify.success(this.intl.t('notifications.remove-success'));
} catch (error) {
// TODO: replace with translated strings
+4 -1
View File
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../utilities/confirm';
export default class ScopesScopeProjectsRoute extends Route {
// =services
@@ -9,6 +10,7 @@ export default class ScopesScopeProjectsRoute extends Route {
@service intl;
@service notify;
@service session;
@service confirm;
// =methods
@@ -84,12 +86,13 @@ export default class ScopesScopeProjectsRoute extends Route {
*/
@action
@loading
@confirm('questions.delete-confirm')
async delete(project) {
try {
await project.destroyRecord();
await this.replaceWith('scopes.scope.projects');
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
this.transitionTo('scopes.scope.projects');
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../../../utilities/confirm';
export default class ScopesScopeProjectsProjectHostCatalogsRoute extends Route {
// =services
@@ -61,16 +62,17 @@ export default class ScopesScopeProjectsProjectHostCatalogsRoute extends Route {
/**
* Deletes the host catalog and redirects to index.
* @param {ProjectModel} project
* @param {HostCatalogModel} hostCatalog
*/
@action
@loading
async delete(project) {
@confirm('questions.delete-confirm')
async delete(hostCatalog) {
try {
await project.destroyRecord();
await hostCatalog.destroyRecord();
await this.replaceWith('scopes.scope.projects.project.host-catalogs');
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
this.transitionTo('scopes.scope.projects.project.host-catalogs');
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../../../../../utilities/confirm';
export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsRoute extends Route {
// =services
@@ -70,13 +71,14 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsRo
*/
@action
@loading
async delete(hostSet) {
@confirm('questions.delete-confirm')
async deleteHostSet(hostSet) {
try {
await hostSet.destroyRecord();
this.notify.success(this.intl.t('notifications.delete-success'));
this.transitionTo(
await this.replaceWith(
'scopes.scope.projects.project.host-catalogs.host-catalog.host-sets'
);
this.notify.success(this.intl.t('notifications.delete-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
@@ -3,6 +3,7 @@ import { hash, all } from 'rsvp';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../../../../../../../utilities/confirm';
export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsHostSetHostsRoute extends Route {
// =services
@@ -37,6 +38,7 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostSetsHo
*/
@action
@loading
@confirm('questions.remove-confirm')
async removeHost(hostSet, host) {
try {
const scopeID = this.modelFor('scopes.scope.projects.project').id;
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../../../../../utilities/confirm';
export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostsRoute extends Route {
// =services
@@ -70,14 +71,15 @@ export default class ScopesScopeProjectsProjectHostCatalogsHostCatalogHostsRoute
*/
@action
@loading
async delete(host) {
@confirm('questions.delete-confirm')
async deleteHost(host) {
try {
await host.destroyRecord();
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
this.transitionTo(
await this.replaceWith(
'scopes.scope.projects.project.host-catalogs.host-catalog.hosts'
);
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../../../utilities/confirm';
export default class ScopesScopeProjectsProjectTargetsRoute extends Route {
// =services
@@ -62,12 +63,13 @@ export default class ScopesScopeProjectsProjectTargetsRoute extends Route {
*/
@action
@loading
@confirm('questions.delete-confirm')
async delete(target) {
try {
await target.destroyRecord();
await this.replaceWith('scopes.scope.projects.project.targets');
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
this.transitionTo('scopes.scope.projects.project.targets');
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
@@ -3,6 +3,7 @@ import { all, hash } from 'rsvp';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../../../../../utilities/confirm';
export default class ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extends Route {
// =services
@@ -55,6 +56,7 @@ export default class ScopesScopeProjectsProjectTargetsTargetHostSetsRoute extend
*/
@action
@loading
@confirm('questions.remove-confirm')
async removeHostSet(target, hostSet) {
try {
await target.removeHostSet(hostSet.id);
+3 -1
View File
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../utilities/confirm';
export default class ScopesScopeRolesRoute extends Route {
// =services
@@ -68,12 +69,13 @@ export default class ScopesScopeRolesRoute extends Route {
*/
@action
@loading
@confirm('questions.delete-confirm')
async delete(role) {
try {
await role.destroyRecord();
await this.replaceWith('scopes.scope.roles');
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
this.transitionTo('scopes.scope.roles');
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
@@ -3,6 +3,7 @@ import { all, hash } from 'rsvp';
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../../../utilities/confirm';
export default class ScopesScopeRolesRolePrincipalsRoute extends Route {
// =services
@@ -65,6 +66,7 @@ export default class ScopesScopeRolesRolePrincipalsRoute extends Route {
*/
@action
@loading
@confirm('questions.remove-confirm')
async removePrincipal(principal) {
try {
const role = this.modelFor('scopes.scope.roles.role');
+3 -1
View File
@@ -2,6 +2,7 @@ import Route from '@ember/routing/route';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import loading from 'ember-loading/decorator';
import { confirm } from '../../../utilities/confirm';
export default class ScopesScopeUsersRoute extends Route {
// =services
@@ -69,12 +70,13 @@ export default class ScopesScopeUsersRoute extends Route {
*/
@action
@loading
@confirm('questions.delete-confirm')
async delete(user) {
try {
await user.destroyRecord();
await this.replaceWith('scopes.scope.users');
this.refresh();
this.notify.success(this.intl.t('notifications.delete-success'));
this.transitionTo('scopes.scope.users');
} catch (error) {
// TODO: replace with translated strings
this.notify.error(error.message, { closeAfter: null });
+53
View File
@@ -0,0 +1,53 @@
import Service from '@ember/service';
import { getOwner } from '@ember/application';
import { bind } from '@ember/runloop';
import { Promise, resolve } from 'rsvp';
import config from '../config/environment';
export default class ConfirmService extends Service {
// =attributes
/**
* When the confirm service is disabled, it always returns resolving promises.
* @type {boolean}
*/
enabled = config.enableConfirmService;
/**
* The window's confirm function, bound to the window scope.
* @type {Function}
*/
get confirmFn() {
// The Ember way of accessing globals...
const document =
getOwner(this).lookup('service:-document').documentElement;
// defaultView === window, but without using globals directly
const windowRef = document.parentNode.defaultView;
const { confirm } = windowRef;
return bind(windowRef, confirm);
}
// =methods
/**
* When the service is enabled, returns a promise that resolves if the user
* accepts the confirmation, otherwise rejects. If the service is disabled,
* this method always returns a resolving promise.
* @param {string} text
* @return {Promise}
*/
confirm(text) {
if (this.enabled) {
return new Promise((resolve, reject) => {
if (this.confirmFn(text)) {
return resolve();
} else {
return reject();
}
});
} else {
return resolve();
}
}
}
@@ -2,7 +2,7 @@
<dropdown.button
@style="danger"
@disabled={{@model.canSave}}
{{on "click" (route-action "delete" @model)}}
{{on "click" (route-action "deleteAccount" @model)}}
>
{{t 'actions.delete'}}
</dropdown.button>
@@ -19,4 +19,4 @@
>
{{t 'resources.host-catalog.actions.delete'}}
</dropdown.button>
</Rose::Dropdown>
</Rose::Dropdown>
@@ -5,8 +5,8 @@
<dropdown.button
@style="danger"
@disabled={{@model.canSave}}
{{on "click" (route-action "delete" @model)}}
{{on "click" (route-action "deleteHostSet" @model)}}
>
{{t 'resources.host-set.actions.delete'}}
</dropdown.button>
</Rose::Dropdown>
</Rose::Dropdown>
@@ -2,8 +2,8 @@
<dropdown.button
@style="danger"
@disabled={{@model.canSave}}
{{on "click" (route-action "delete" @model)}}
{{on "click" (route-action "deleteHost" @model)}}
>
{{t 'resources.host.actions.delete'}}
</dropdown.button>
</Rose::Dropdown>
</Rose::Dropdown>
+23
View File
@@ -0,0 +1,23 @@
import { getOwner } from '@ember/application';
/**
* Decorates a method whereby calls to the method will first request
* confirmation via the confirmation service. If the user accepts, the
* original method is executed. If the user denies, it is not.
*/
export function confirm(confirmationTextKey) {
return function (_target, _propertyKey, desc) {
const method = desc.value;
desc.value = function () {
const owner = getOwner(this);
const confirmService = owner.lookup('service:confirm');
const intl = owner.lookup('service:intl');
const text = intl.t(confirmationTextKey);
return confirmService.confirm(text)
// If user confirmed, execute the decorated method
.then(() => method.apply(this, arguments))
// If the user denied, gracefully handle promise rejection with no-op
.catch(() => {});
};
}
}
+2
View File
@@ -34,6 +34,7 @@ module.exports = function (environment) {
appName: APP_NAME,
notifyTimeout: 4000,
enableConfirmService: true,
contentSecurityPolicyHeader: 'Content-Security-Policy',
contentSecurityPolicyMeta: true,
@@ -98,6 +99,7 @@ module.exports = function (environment) {
// Notification timeout should be 0 for fast tests
ENV.notifyTimeout = 0;
ENV.enableConfirmService = false;
}
if (environment === 'production') {
+2 -1
View File
@@ -86,7 +86,8 @@
"qunit-dom": "^1.0.0",
"rose": "*",
"sass": "^1.26.5",
"sass-lint": "^1.13.1"
"sass-lint": "^1.13.1",
"sinon": "^9.1.0"
},
"engines": {
"node": "10.* || >= 12"
+23
View File
@@ -10,6 +10,7 @@ import {
//currentSession,
//invalidateSession,
} from 'ember-simple-auth/test-support';
import sinon from 'sinon';
module('Acceptance | projects', function (hooks) {
setupApplicationTest(hooks);
@@ -141,6 +142,28 @@ module('Acceptance | projects', function (hooks) {
assert.equal(getProjectScopesCount(), initialProjectScopesCount - 1);
});
test('can delete project with confirmation acceptance', async function (assert) {
assert.expect(2);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
window.confirm = sinon.fake.returns(true);
await visit(existingProjectURL);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getProjectScopesCount(), initialProjectScopesCount - 1);
assert.ok(window.confirm.calledOnce);
});
test('cannot delete project with confirmation denial', async function (assert) {
assert.expect(2);
const confirmService = this.owner.lookup('service:confirm');
confirmService.enabled = true;
window.confirm = sinon.fake.returns(false);
await visit(existingProjectURL);
await click('.rose-layout-page-actions .rose-dropdown-button-danger');
assert.equal(getProjectScopesCount(), initialProjectScopesCount);
assert.ok(window.confirm.calledOnce);
});
test('saving an existing project with invalid fields displays error messages', async function (assert) {
assert.expect(2);
this.server.patch('/scopes/:id', () => {
@@ -0,0 +1,12 @@
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Service | confirm', function(hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function(assert) {
let service = this.owner.lookup('service:confirm');
assert.ok(service);
});
});
+3
View File
@@ -18,6 +18,9 @@ titles:
actions: Actions
descriptions:
empty-set: There are no items to display yet. You may be able to add items or try back later.
questions:
delete-confirm: Are you sure you want to delete this resource?
remove-confirm: Are you sure you want to remove this association?
hashicorp:
title: HashiCorp
copyright: © 2020 HashiCorp