Skip to content

Commit d93986c

Browse files
refactor: πŸ’‘ remove route-action usage from credential-stores (#2172)
* refactor: πŸ’‘ remove route-action usage from credential-stores βœ… Closes: https://hashicorp.atlassian.net/browse/ICU-12604
1 parent 879c196 commit d93986c

File tree

32 files changed

+412
-250
lines changed

32 files changed

+412
-250
lines changed

β€Žui/admin/app/components/credential-stores/credential-store/actions/index.hbsβ€Ž

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
<dropdown.button
3131
@style='danger'
3232
@disabled={{@model.canSave}}
33-
{{on 'click' (route-action 'delete' @model)}}
33+
{{on 'click' @delete}}
3434
>
3535
{{t 'resources.credential-store.actions.delete'}}
3636
</dropdown.button>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Controller, { inject as controller } from '@ember/controller';
2+
3+
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesCredentialLibraryIndexController extends Controller {
4+
@controller(
5+
'scopes/scope/credential-stores/credential-store/credential-libraries/index',
6+
)
7+
credentialLibraries;
8+
}
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import Controller, { inject as controller } from '@ember/controller';
2+
import { action } from '@ember/object';
3+
import { loading } from 'ember-loading';
4+
import { confirm } from 'core/decorators/confirm';
5+
import { notifySuccess, notifyError } from 'core/decorators/notify';
6+
import { inject as service } from '@ember/service';
7+
8+
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesIndexController extends Controller {
9+
@controller('scopes/scope/credential-stores/index') credentialStores;
10+
11+
// =services
12+
13+
@service can;
14+
@service router;
15+
16+
// =actions
17+
18+
/**
19+
* Rollback changes on a credential library.
20+
* @param {CredentialLibraryModel} credentialLibrary
21+
*/
22+
@action
23+
async cancel(credentialLibrary) {
24+
const { isNew } = credentialLibrary;
25+
credentialLibrary.rollbackAttributes();
26+
if (isNew)
27+
await this.router.transitionTo(
28+
'scopes.scope.credential-stores.credential-store.credential-libraries',
29+
);
30+
}
31+
32+
/**
33+
* Handle save of a credential library
34+
* @param {CredentialLibraryModel} credentialLibrary
35+
*/
36+
@action
37+
@loading
38+
@notifyError(({ message }) => message)
39+
@notifySuccess(({ isNew }) =>
40+
isNew ? 'notifications.create-success' : 'notifications.save-success',
41+
)
42+
async save(credentialLibrary) {
43+
await credentialLibrary.save();
44+
if (this.can.can('read model', credentialLibrary)) {
45+
await this.router.transitionTo(
46+
'scopes.scope.credential-stores.credential-store.credential-libraries.credential-library',
47+
credentialLibrary,
48+
);
49+
} else {
50+
await this.router.transitionTo(
51+
'scopes.scope.credential-stores.credential-store.credential-libraries',
52+
);
53+
}
54+
await this.router.refresh();
55+
}
56+
57+
/**
58+
* Handle delete of a credential library
59+
* @param {CredentialLibraryModel} credentialLibrary
60+
*/
61+
@action
62+
@loading
63+
@confirm('questions.delete-confirm')
64+
@notifyError(({ message }) => message, { catch: true })
65+
@notifySuccess('notifications.delete-success')
66+
async delete(credentialLibrary) {
67+
await credentialLibrary.destroyRecord();
68+
await this.router.replaceWith(
69+
'scopes.scope.credential-stores.credential-store.credential-libraries',
70+
);
71+
await this.router.refresh();
72+
}
73+
74+
/**
75+
* Copies the contents of array fields in order to force the instance
76+
* into a dirty state. This ensures that `model.rollbackAttributes()` reverts
77+
* to the original expected array.
78+
*
79+
* The deep copy implemented here is required to ensure that both the
80+
* array itself and its members are all new.
81+
*
82+
* @param {credentialLibraryModel} credentialLibrary
83+
*/
84+
@action
85+
edit(credentialLibrary) {
86+
const { critical_options, extensions } = credentialLibrary;
87+
credentialLibrary.critical_options = structuredClone(critical_options);
88+
credentialLibrary.extensions = structuredClone(extensions);
89+
}
90+
91+
/**
92+
* Update type of credential library
93+
* @param {string} type
94+
*/
95+
@action
96+
async changeType(type) {
97+
await this.router.replaceWith({ queryParams: { type } });
98+
}
99+
}

β€Žui/admin/app/controllers/scopes/scope/credential-stores/credential-store/credential-libraries/new.jsβ€Ž

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* SPDX-License-Identifier: MPL-2.0
44
*/
55

6-
import Controller from '@ember/controller';
6+
import Controller, { inject as controller } from '@ember/controller';
77

88
export default class ScopesScopeCredentialStoresCredentialStoreCredentialLibrariesNewController extends Controller {
9-
// =services
9+
@controller(
10+
'scopes/scope/credential-stores/credential-store/credential-libraries/index',
11+
)
12+
credentialLibraries;
1013

1114
// =attributes
1215
queryParams = ['type'];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import Controller, { inject as controller } from '@ember/controller';
2+
3+
export default class ScopesScopeCredentialStoresCredentialStoreCredentialsCredentialIndexController extends Controller {
4+
@controller(
5+
'scopes/scope/credential-stores/credential-store/credentials/index',
6+
)
7+
credentials;
8+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import Controller, { inject as controller } from '@ember/controller';
2+
import { action } from '@ember/object';
3+
import { loading } from 'ember-loading';
4+
import { confirm } from 'core/decorators/confirm';
5+
import { notifySuccess, notifyError } from 'core/decorators/notify';
6+
import { inject as service } from '@ember/service';
7+
8+
export default class ScopesScopeCredentialStoresCredentialStoreCredentialsIndexController extends Controller {
9+
@controller('scopes/scope/credential-stores/index') credentialStores;
10+
11+
// =services
12+
13+
@service can;
14+
@service router;
15+
16+
// =actions
17+
18+
/**
19+
* Rollback changes on a credential.
20+
* @param {CredentialModel} credential
21+
*/
22+
@action
23+
async cancel(credential) {
24+
const { isNew } = credential;
25+
credential.rollbackAttributes();
26+
if (isNew)
27+
await this.router.transitionTo(
28+
'scopes.scope.credential-stores.credential-store.credentials',
29+
);
30+
}
31+
32+
/**
33+
* Handle save of a credential
34+
* @param {CredentialModel} credential
35+
*/
36+
@action
37+
@loading
38+
@notifyError(({ message }) => message)
39+
@notifySuccess(({ isNew }) =>
40+
isNew ? 'notifications.create-success' : 'notifications.save-success',
41+
)
42+
async save(credential) {
43+
await credential.save();
44+
if (this.can.can('read credential', credential)) {
45+
await this.router.transitionTo(
46+
'scopes.scope.credential-stores.credential-store.credentials.credential',
47+
credential,
48+
);
49+
} else {
50+
await this.router.transitionTo(
51+
'scopes.scope.credential-stores.credential-store.credentials',
52+
);
53+
}
54+
await this.router.refresh();
55+
}
56+
/**
57+
* Handle delete of a credential
58+
* @param {Credential} credential
59+
*/
60+
@action
61+
@loading
62+
@confirm('questions.delete-confirm')
63+
@notifyError(({ message }) => message, { catch: true })
64+
@notifySuccess('notifications.delete-success')
65+
async delete(credential) {
66+
await credential.destroyRecord();
67+
await this.router.replaceWith(
68+
'scopes.scope.credential-stores.credential-store.credentials',
69+
);
70+
await this.router.refresh();
71+
}
72+
73+
/**
74+
* Update type of credential
75+
* @param {string} type
76+
*/
77+
@action
78+
async changeType(type) {
79+
await this.router.replaceWith({ queryParams: { type } });
80+
}
81+
}

β€Žui/admin/app/controllers/scopes/scope/credential-stores/credential-store/credentials/new.jsβ€Ž

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@
33
* SPDX-License-Identifier: MPL-2.0
44
*/
55

6-
import Controller from '@ember/controller';
6+
import Controller, { inject as controller } from '@ember/controller';
77

88
export default class ScopesScopeCredentialStoresCredentialStoreCredentialsNewController extends Controller {
9-
// =services
9+
@controller(
10+
'scopes/scope/credential-stores/credential-store/credentials/index',
11+
)
12+
credentials;
1013

1114
// =attributes
1215

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import Controller, { inject as controller } from '@ember/controller';
2+
3+
export default class ScopesScopeCredentialStoresCredentialStoreIndexController extends Controller {
4+
@controller('scopes/scope/credential-stores/index') credentialStores;
5+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
import Controller from '@ember/controller';
2+
import { inject as service } from '@ember/service';
3+
import { action } from '@ember/object';
4+
import { loading } from 'ember-loading';
5+
import { confirm } from 'core/decorators/confirm';
6+
import { notifySuccess, notifyError } from 'core/decorators/notify';
7+
8+
export default class ScopesScopeCredentialStoresIndexController extends Controller {
9+
// =services
10+
11+
@service can;
12+
@service router;
13+
14+
// =actions
15+
16+
/**
17+
* Handle save
18+
* @param {CredentialStoreModel} credentialStore
19+
*/
20+
@action
21+
@loading
22+
@notifyError(({ message }) => message)
23+
@notifySuccess('notifications.save-success')
24+
async save(credentialStore) {
25+
await credentialStore.save();
26+
if (this.can.can('read model', credentialStore)) {
27+
await this.router.transitionTo(
28+
'scopes.scope.credential-stores.credential-store',
29+
credentialStore,
30+
);
31+
} else {
32+
await this.router.transitionTo('scopes.scope.credential-stores');
33+
}
34+
await this.router.refresh();
35+
}
36+
37+
/**
38+
* Rollback changes on credential stores.
39+
* @param {CredentialStoreModel} credentialStore
40+
*/
41+
@action
42+
async cancel(credentialStore) {
43+
const { isNew } = credentialStore;
44+
credentialStore.rollbackAttributes();
45+
if (isNew) {
46+
await this.router.transitionTo('scopes.scope.credential-stores');
47+
}
48+
}
49+
50+
/**
51+
* Deletes the credential store and redirects to index
52+
* @param {CredentialStoreModel} credentialStore
53+
*/
54+
@action
55+
@loading
56+
@confirm('questions.delete-confirm')
57+
@notifyError(({ message }) => message, { catch: true })
58+
@notifySuccess('notifications.delete-success')
59+
async delete(credentialStore) {
60+
await credentialStore.destroyRecord();
61+
await this.router.replaceWith('scopes.scope.credential-stores');
62+
await this.router.refresh();
63+
}
64+
65+
/**
66+
* Update type of credential store
67+
* @param {string} type
68+
*/
69+
@action
70+
async changeType(type) {
71+
await this.router.replaceWith({ queryParams: { type } });
72+
}
73+
}

β€Žui/admin/app/controllers/scopes/scope/credential-stores/new.jsβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
* SPDX-License-Identifier: MPL-2.0
44
*/
55

6-
import Controller from '@ember/controller';
6+
import Controller, { inject as controller } from '@ember/controller';
77

88
export default class ScopesScopeCredentialStoresNewController extends Controller {
9-
// =services
9+
@controller('scopes/scope/credential-stores/index') credentialStores;
1010

1111
// =attributes
1212
queryParams = ['type'];

0 commit comments

Comments
Β (0)