Merge pull request #531 from hashicorp/chore-enable-primary-auth-method
chore: 🤖 enable primary auth method feature
This commit is contained in:
6 files changed
+29
-12
No files matched your search
@@ -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',
|
||||
|
||||
@@ -7,7 +7,7 @@ export default class AuthMethodModel extends GeneratedAuthMethodModel {
|
||||
/**
|
||||
* @type {boolean}
|
||||
*/
|
||||
@equal('primary', true) isPrimary;
|
||||
@equal('is_primary', true) isPrimary;
|
||||
|
||||
/**
|
||||
* @type {boolean}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
},
|
||||
});
|
||||
@@ -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: {},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in new issue
Block a user