2023-03-01 09:39:41 -06:00
|
|
|
/**
|
|
|
|
|
* Copyright (c) HashiCorp, Inc.
|
|
|
|
|
* SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
*/
|
|
|
|
|
|
2020-07-22 17:16:20 -04:00
|
|
|
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';
|
2020-07-22 17:16:20 -04:00
|
|
|
|
|
|
|
|
export default factory.extend({
|
|
|
|
|
type: 'global',
|
|
|
|
|
|
2024-01-17 08:37:09 -08:00
|
|
|
authorized_actions() {
|
|
|
|
|
const authorizedActions = ['no-op', 'read', 'update'];
|
|
|
|
|
|
|
|
|
|
// Storage policies can only be attatched to global and org scopes.
|
|
|
|
|
if (this.type === 'global' || this.type === 'org') {
|
|
|
|
|
authorizedActions.push('attach-storage-policy', 'detach-storage-policy');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.type === 'org' || this.type === 'project') {
|
|
|
|
|
authorizedActions.push('delete');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return permissions.authorizedActionsFor('scope') || authorizedActions;
|
|
|
|
|
},
|
2021-08-31 15:03:40 -04:00
|
|
|
|
2022-08-01 16:04:41 -04:00
|
|
|
authorized_collection_actions() {
|
|
|
|
|
const collectionActions = {
|
2021-09-08 16:03:10 -04:00
|
|
|
scopes: ['create', 'list'],
|
2021-08-25 23:43:07 -07:00
|
|
|
groups: ['create', 'list'],
|
2021-09-02 09:48:28 -07:00
|
|
|
roles: ['create', 'list'],
|
2021-08-20 14:58:43 -04:00
|
|
|
};
|
2022-08-01 16:04:41 -04:00
|
|
|
|
2024-03-15 14:24:20 -07:00
|
|
|
// Resources that are available only on the global scope
|
2022-08-01 16:04:41 -04:00
|
|
|
if (this.type === 'global') {
|
|
|
|
|
collectionActions.workers = ['create:worker-led', 'list'];
|
2024-03-15 14:24:20 -07:00
|
|
|
collectionActions.aliases = ['create', 'list'];
|
2022-08-01 16:04:41 -04:00
|
|
|
}
|
|
|
|
|
|
2024-03-15 14:24:20 -07:00
|
|
|
// Resources that are only available on the global or the org scope
|
2023-03-10 14:20:58 -05:00
|
|
|
if (this.type === 'global' || this.type === 'org') {
|
|
|
|
|
collectionActions['storage-buckets'] = ['create', 'list'];
|
2023-03-16 13:49:04 -04:00
|
|
|
collectionActions['session-recordings'] = ['list'];
|
2023-11-02 16:08:25 -07:00
|
|
|
collectionActions.users = ['create', 'list'];
|
|
|
|
|
collectionActions['auth-methods'] = ['create', 'list'];
|
2024-01-03 11:52:17 -08:00
|
|
|
collectionActions['policies'] = ['create', 'list'];
|
2023-11-02 16:08:25 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.type === 'project') {
|
|
|
|
|
collectionActions['credential-stores'] = ['create', 'list'];
|
|
|
|
|
collectionActions['host-catalogs'] = ['create', 'list'];
|
|
|
|
|
collectionActions.sessions = ['list'];
|
|
|
|
|
collectionActions.targets = ['create', 'list'];
|
2023-03-10 14:20:58 -05:00
|
|
|
}
|
|
|
|
|
|
2022-08-01 16:04:41 -04:00
|
|
|
return collectionActions;
|
2021-08-20 14:58:43 -04:00
|
|
|
},
|
|
|
|
|
|
2022-06-01 14:02:18 -04:00
|
|
|
id: () => generateId('s_'),
|
2020-10-01 16:31:39 -04:00
|
|
|
|
2020-07-22 17:16:20 -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 },
|
|
|
|
|
},
|
2023-11-22 14:07:41 -05:00
|
|
|
'withChildren',
|
2021-03-04 15:47:38 -05:00
|
|
|
);
|
2020-07-22 17:16:20 -04:00
|
|
|
}
|
|
|
|
|
if (record.type === 'org') {
|
2020-08-14 10:46:17 -04:00
|
|
|
server.createList('scope', 3, {
|
2020-07-22 17:16:20 -04:00
|
|
|
type: 'project',
|
2021-03-04 15:47:38 -05:00
|
|
|
scope: { id: record.id, type: record.type },
|
2020-07-22 17:16:20 -04:00
|
|
|
});
|
|
|
|
|
}
|
2021-03-04 15:47:38 -05:00
|
|
|
},
|
|
|
|
|
}),
|
2020-07-22 17:16:20 -04:00
|
|
|
});
|