feat: 🎸 add set/remove primary actions

This commit is contained in:
Randall Morey committed 2021-03-26 12:47:49 -04:00
1 parent ae26d588a9
commit 60b7d0134a
7 files changed
+89 -7

No files matched your search

+5
View File
@@ -2,5 +2,10 @@ import GeneratedAuthMethodModel from '../generated/models/auth-method';
import { equal } from '@ember/object/computed';
export default class AuthMethodModel extends GeneratedAuthMethodModel {
// =attributes
/**
* @type {boolean}
*/
@equal('primary', true) isPrimary;
}
+2 -2
View File
@@ -66,8 +66,8 @@ export default function () {
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 });
if (scope.primaryAuthMethodId === id) {
scope.update({ primaryAuthMethodId: null });
}
return new Response(204);
});
+2 -2
View File
@@ -34,8 +34,8 @@ export default function (server) {
);
// Assign primary auth methods per scope
// TODO make this generic
globalScope.update({ primary_auth_method_id: globalAuthMethods[0].id });
orgScope.update({ primary_auth_method_id: orgAuthMethods[1].id });
globalScope.update({ primaryAuthMethodId: globalAuthMethods[0].id });
orgScope.update({ primaryAuthMethodId: orgAuthMethods[1].id });
// Groups and Users
server.createList('group', 1, { scope: globalScope }, 'withMembers');
+3 -3
View File
@@ -10,9 +10,9 @@ export default ApplicationSerializer.extend({
);
// If the scope marks this auth method as primary, designate it
// as such with a read-only boolean field (this is how the API behaves).
if (model.scope && model.scope.primary_auth_method_id === model.id) {
json.primary = true;
}
const isPrimary =
model.scope && model.scope.primaryAuthMethodId === model.id;
json.primary = isPrimary;
return json;
},
});