Files
threshold-ui/addons/api/mirage/factories/auth-method.js
T
0129784322 fix url when user tries to access resource with incorrect url (#1958)
* refactor: 💡 auth-method, account, & managed abilities & routes

* refactor: 💡 credential store resources abilities & routes

* refactor: 💡 group abilities & routes

* refactor: 💡 host-catalog resources abilities & routes

* refactor: 💡 role abilities & routes

* test: 💍 fix route-info-test

* test: 💍 fix host serializer tests

* test: 💍 fix create-test for host-sets

* refactor: 💡 session recording resources abilities & routes

* refactor: 💡 storage bucket abilities & routes

* refactor: 💡 target abilities & routes

* refactor: 💡 user abilities & routes

* refactor: 💡 worker abilities & routes

* refactor: 💡 remove ability changes and add comments

* Update ui/admin/app/utils/route-info.js

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>

* test: 💍 add test cases and rename util file

* refactor: 💡 remove dup file and update imports

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11282

* docs: ✏️ update comments & remove console.log

✅ Closes: https://hashicorp.atlassian.net/browse/ICU-11282

* Update ui/admin/app/routes/scopes/scope/auth-methods/auth-method.js

Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>

---------

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
Co-authored-by: Dharini Jeeva <dharini@hashicorp.com>
2023-11-02 16:08:25 -07:00

73 lines
2.0 KiB
JavaScript

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import factory from '../generated/factories/auth-method';
import { trait } from 'miragejs';
import permissions from '../helpers/permissions';
import generateId from '../helpers/id';
import {
TYPE_AUTH_METHOD_PASSWORD,
TYPE_AUTH_METHOD_OIDC,
TYPE_AUTH_METHOD_LDAP,
TYPES_AUTH_METHOD,
} from 'api/models/auth-method';
export default factory.extend({
authorized_actions: () =>
permissions.authorizedActionsFor('auth-method') || [
'no-op',
'read',
'update',
'delete',
'authenticate',
],
authorized_collection_actions() {
switch (this.type) {
case TYPE_AUTH_METHOD_PASSWORD:
return { accounts: ['create', 'list'] };
case TYPE_AUTH_METHOD_LDAP:
case TYPE_AUTH_METHOD_OIDC:
return {
accounts: ['create', 'list'],
'managed-groups': ['create', 'list'],
};
}
},
id: () => generateId('am_'),
// Cycle through available types
type: (i) => TYPES_AUTH_METHOD[i % TYPES_AUTH_METHOD.length],
/**
* Adds accounts (with associated users) to auth method and managed groups.
*/
withAccountsAndUsersAndManagedGroups: trait({
afterCreate(authMethod, server) {
const { scope, type } = authMethod;
server.createList('user', 5, { scope }).map((user) => {
const { id } = server.create('account', { scope, type, authMethod });
user.update({ accountIds: [id] });
});
if (type === TYPE_AUTH_METHOD_OIDC || type === TYPE_AUTH_METHOD_LDAP) {
server
.createList('managed-group', 2, { scope, authMethod })
.map((managedGroup) => {
const accounts = server.createList('account', 2, {
scope,
type,
authMethod,
});
const accountIds = accounts.map((account) => account.id);
managedGroup.update({ memberIds: accountIds });
});
}
},
}),
});