Files
threshold-ui/addons/api/mirage/factories/scope.js
T

72 lines
1.8 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) HashiCorp, Inc.
* SPDX-License-Identifier: MPL-2.0
*/
import factory from '../generated/factories/scope';
2023-01-09 08:48:49 -08:00
import { trait } from 'miragejs';
2021-08-31 15:03:40 -04:00
import permissions from '../helpers/permissions';
2022-06-01 14:02:18 -04:00
import generateId from '../helpers/id';
export default factory.extend({
type: 'global',
2021-08-31 15:03:40 -04:00
authorized_actions: () =>
permissions.authorizedActionsFor('scope') || [
'no-op',
'read',
'update',
'delete',
],
authorized_collection_actions() {
const collectionActions = {
scopes: ['create', 'list'],
2021-08-24 14:46:21 -04:00
users: ['create', 'list'],
2021-08-31 19:41:11 -07:00
sessions: ['list'],
2021-08-25 23:43:07 -07:00
groups: ['create', 'list'],
2021-09-02 09:48:28 -07:00
roles: ['create', 'list'],
2021-09-02 13:52:04 -07:00
targets: ['create', 'list'],
2021-09-01 14:02:27 -07:00
'credential-stores': ['create', 'list'],
2021-08-30 19:16:58 -07:00
'auth-methods': ['create', 'list'],
2021-09-02 10:22:47 -07:00
'host-catalogs': ['create', 'list'],
};
// Worker permissions only available on the global scope
if (this.type === 'global') {
collectionActions.workers = ['create:worker-led', 'list'];
}
// Session recording resources are only available on global or org scope
if (this.type === 'global' || this.type === 'org') {
collectionActions['storage-buckets'] = ['create', 'list'];
2023-03-16 13:49:04 -04:00
collectionActions['session-recordings'] = ['list'];
}
return collectionActions;
},
2022-06-01 14:02:18 -04:00
id: () => generateId('s_'),
2020-10-01 16:31:39 -04:00
withChildren: trait({
afterCreate(record, server) {
if (record.type === 'global') {
2021-03-04 15:47:38 -05:00
server.createList(
'scope',
1,
{
type: 'org',
scope: { id: record.id, type: record.type },
},
'withChildren'
);
}
if (record.type === 'org') {
2020-08-14 10:46:17 -04:00
server.createList('scope', 3, {
type: 'project',
2021-03-04 15:47:38 -05:00
scope: { id: record.id, type: record.type },
});
}
2021-03-04 15:47:38 -05:00
},
}),
});