diff --git a/addons/api/addon/generated/models/auth-method.js b/addons/api/addon/generated/models/auth-method.js index 4ba4158da..610f565f3 100644 --- a/addons/api/addon/generated/models/auth-method.js +++ b/addons/api/addon/generated/models/auth-method.js @@ -11,7 +11,7 @@ export default class GeneratedAuthMethodModel extends BaseModel { description: 'Specifies if this is the primary auth method for its scope.', readOnly: true, }) - primary; + is_primary; @attr('string', { description: 'The type of the resource, to help differentiate schemas', diff --git a/addons/api/addon/models/auth-method.js b/addons/api/addon/models/auth-method.js index f0df015f6..7686c2783 100644 --- a/addons/api/addon/models/auth-method.js +++ b/addons/api/addon/models/auth-method.js @@ -7,7 +7,7 @@ export default class AuthMethodModel extends GeneratedAuthMethodModel { /** * @type {boolean} */ - @equal('primary', true) isPrimary; + @equal('is_primary', true) isPrimary; /** * @type {boolean} diff --git a/addons/api/addon/serializers/auth-method.js b/addons/api/addon/serializers/auth-method.js index d707f4839..a8569c14d 100644 --- a/addons/api/addon/serializers/auth-method.js +++ b/addons/api/addon/serializers/auth-method.js @@ -2,8 +2,8 @@ import ApplicationSerializer from './application'; export default class AuthMethodSerializer extends ApplicationSerializer { /** - * Sorts the array in order of "primary" such that the primary method appears - * first. The "natural" order of auth methods places primary first. + * Sorts the array in order of "is_primary" such that the primary method + * appears first. The "natural" order of auth methods places primary first. * * @override * @return {object} @@ -11,8 +11,25 @@ export default class AuthMethodSerializer extends ApplicationSerializer { normalizeArrayResponse() { const normalized = super.normalizeArrayResponse(...arguments); normalized.data = normalized.data.sort((a) => - a.attributes.primary ? -1 : 1 + a.attributes.is_primary ? -1 : 1 ); return normalized; } + + /** + * Sets `is_primary` to `false` if it is missing in the response. The API + * omits "zero" values per: + * https://developers.google.com/protocol-buffers/docs/proto3#default + * + * TODO: generalize this so that all zero values are reified. + * @override + * @return {object} + */ + normalize() { + const normalized = super.normalize(...arguments); + if (!normalized.data.attributes.is_primary) { + normalized.data.attributes.is_primary = false; + } + return normalized; + } } diff --git a/addons/api/mirage/serializers/auth-method.js b/addons/api/mirage/serializers/auth-method.js index ecdcdf33c..8cb66934a 100644 --- a/addons/api/mirage/serializers/auth-method.js +++ b/addons/api/mirage/serializers/auth-method.js @@ -12,7 +12,7 @@ export default ApplicationSerializer.extend({ // as such with a read-only boolean field (this is how the API behaves). const isPrimary = model.scope && model.scope.primaryAuthMethodId === model.id; - json.primary = isPrimary; + json.is_primary = isPrimary; return json; }, }); diff --git a/addons/api/tests/unit/serializers/auth-method-test.js b/addons/api/tests/unit/serializers/auth-method-test.js index 9e850c01e..cd7fcd396 100644 --- a/addons/api/tests/unit/serializers/auth-method-test.js +++ b/addons/api/tests/unit/serializers/auth-method-test.js @@ -27,14 +27,14 @@ module('Unit | Serializer | auth method', function (hooks) { const serializer = store.serializerFor('auth-method'); const modelClass = store.createRecord('auth-method').constructor; const payload = { - items: [{ id: 1 }, { id: 2, primary: true }, { id: 3 }], + items: [{ id: 1 }, { id: 2, is_primary: true }, { id: 3 }], }; const normalizedArray = serializer.normalizeArrayResponse( store, modelClass, payload ); - assert.ok(payload.items[1].primary, 'Second payload item is primary'); + assert.ok(payload.items[1].is_primary, 'Second payload item is primary'); assert.deepEqual( normalizedArray, { @@ -43,19 +43,19 @@ module('Unit | Serializer | auth method', function (hooks) { { id: '2', type: 'auth-method', - attributes: { primary: true }, + attributes: { is_primary: true }, relationships: {}, }, { id: '1', type: 'auth-method', - attributes: {}, + attributes: { is_primary: false }, relationships: {}, }, { id: '3', type: 'auth-method', - attributes: {}, + attributes: { is_primary: false }, relationships: {}, }, ], diff --git a/ui/admin/config/environment.js b/ui/admin/config/environment.js index 6c5c66a86..a0350eae9 100644 --- a/ui/admin/config/environment.js +++ b/ui/admin/config/environment.js @@ -88,7 +88,7 @@ module.exports = function (environment) { featureFlags: { oidc: true, 'oidc-crud': false, - 'primary-auth-method': false, + 'primary-auth-method': true, search: false, filter: false, capabilities: false,