Files
threshold-ui/addons/api/app/mirage/factories/role.js
T
Lisbet AlvarezandZhihe Li 1d126dc074 feat: 🎸 Add linting to code editor (#3211)
* feat: 🎸 Add linting to code editor

* refactor: 💡 add missing case for wildcard type & ids field

* refactor: 💡 simplify condition + add more tests

* refactor: 💡 cleanup ids validation logic and add more lint erro

* refactor: 💡 simplify logic and add actions linting cases

* feat: 🎸 Add autocompletion to code editor (#3207)

* refactor: 💡 apply PR feedback

* refactor: 💡 PR feedback

* refactor: 💡 add noop action

* fix: 🐛 noop should not be suggested with resource type format

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

---------

Co-authored-by: Zhihe Li <zhihe.li@hashicorp.com>
2026-05-14 15:21:29 -04:00

72 lines
1.8 KiB
JavaScript

/**
* Copyright IBM Corp. 2021, 2026
* SPDX-License-Identifier: BUSL-1.1
*/
import factory from '../generated/factories/role';
import { trait } from 'miragejs';
import permissions from '../helpers/permissions';
import generateId from '../helpers/id';
import {
TYPE_SCOPE_GLOBAL,
TYPE_SCOPE_ORG,
TYPE_SCOPE_PROJECT,
} from 'api/models/scope';
export default factory.extend({
authorized_actions: () =>
permissions.authorizedActionsFor('role') || [
'no-op',
'read',
'update',
'delete',
'set-grants',
'add-principals',
'remove-principals',
'set-grant-scopes',
],
grant_strings: () => [
'ids=*;actions=*',
'ids=*;type=host-catalog;actions=create,read',
],
id: () => generateId('r_'),
grant_scope_ids: () => ['this'],
/**
* Adds grant scopes to the role.
*/
withScopes: trait({
afterCreate(role, server) {
const { scope } = role;
const newScope =
scope.id === 'global'
? server.create('scope', {
scope: { id: 'global', type: TYPE_SCOPE_GLOBAL },
type: 'org',
})
: server.create('scope', {
scope: { id: scope.id, type: TYPE_SCOPE_ORG },
type: TYPE_SCOPE_PROJECT,
});
role.update({ grant_scope_ids: ['this', newScope.id] });
},
}),
/**
* Adds principals to the role.
*/
withPrincipals: trait({
afterCreate(role, server) {
const { scope } = role;
const { id: scopeId } = scope;
const users = server.createList('user', 2, { scope });
const groups = server.createList('group', 2, { scope });
const managedGroups = server.schema.managedGroups.where({
scopeId,
}).models;
role.update({ users, groups, managedGroups });
},
}),
});