refactor: 💡 primary auth method should be detected on scope
rather than the synthetic `primary` field on auth method
This commit is contained in:
4 files changed
+35
-3
No files matched your search
@@ -60,7 +60,17 @@ export default function () {
|
||||
this.post('/auth-methods');
|
||||
this.get('/auth-methods/:id');
|
||||
this.patch('/auth-methods/:id');
|
||||
this.del('/auth-methods/:id');
|
||||
this.del('/auth-methods/:id', ({ authMethods }, { params: { id } }) => {
|
||||
const authMethod = authMethods.find(id);
|
||||
const scope = authMethod.scope;
|
||||
authMethod.destroy();
|
||||
// If the primary auth method is deleted, the associated scope's
|
||||
// primary_auth_method_id field should be set to null.
|
||||
if (scope.primary_auth_method_id === id) {
|
||||
scope.update({ primary_auth_method_id: null });
|
||||
}
|
||||
return new Response(204);
|
||||
});
|
||||
|
||||
// Auth Method Accounts
|
||||
this.get(
|
||||
|
||||
@@ -1,7 +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 this.model.filterBy('isPrimary');
|
||||
return this.scopeModel.primary_auth_method_id;
|
||||
}
|
||||
}
|
||||
@@ -71,7 +71,11 @@ 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();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user