refactor(core): Remove roleId indirection (no-changelog) (#8413)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-01-24 13:38:57 +01:00
committed by GitHub
parent 1affebd85e
commit d6deceacde
139 changed files with 922 additions and 1684 deletions

View File

@@ -17,7 +17,6 @@ import {
} from './shared/random';
import * as testDb from './shared/testDb';
import * as utils from './shared/utils/';
import { getGlobalAdminRole, getGlobalMemberRole } from './shared/db/roles';
import { createMember, createOwner, createUser, createUserShell } from './shared/db/users';
import { ExternalHooks } from '@/ExternalHooks';
import { InternalHooks } from '@/InternalHooks';
@@ -56,8 +55,7 @@ describe('POST /invitations/:id/accept', () => {
});
test('should fill out a member shell', async () => {
const globalMemberRole = await getGlobalMemberRole();
const memberShell = await createUserShell(globalMemberRole);
const memberShell = await createUserShell('global:member');
const memberData = {
inviterId: owner.id,
@@ -78,7 +76,7 @@ describe('POST /invitations/:id/accept', () => {
lastName,
personalizationAnswers,
password,
globalRole,
role,
isPending,
apiKey,
globalScopes,
@@ -91,8 +89,7 @@ describe('POST /invitations/:id/accept', () => {
expect(personalizationAnswers).toBeNull();
expect(password).toBeUndefined();
expect(isPending).toBe(false);
expect(globalRole.scope).toBe('global');
expect(globalRole.name).toBe('member');
expect(role).toBe('global:member');
expect(apiKey).not.toBeDefined();
expect(globalScopes).toBeDefined();
expect(globalScopes).not.toHaveLength(0);
@@ -110,8 +107,7 @@ describe('POST /invitations/:id/accept', () => {
});
test('should fill out an admin shell', async () => {
const globalAdminRole = await getGlobalAdminRole();
const adminShell = await createUserShell(globalAdminRole);
const adminShell = await createUserShell('global:admin');
const memberData = {
inviterId: owner.id,
@@ -132,7 +128,7 @@ describe('POST /invitations/:id/accept', () => {
lastName,
personalizationAnswers,
password,
globalRole,
role,
isPending,
apiKey,
globalScopes,
@@ -145,8 +141,7 @@ describe('POST /invitations/:id/accept', () => {
expect(personalizationAnswers).toBeNull();
expect(password).toBeUndefined();
expect(isPending).toBe(false);
expect(globalRole.scope).toBe('global');
expect(globalRole.name).toBe('admin');
expect(role).toBe('global:admin');
expect(apiKey).not.toBeDefined();
expect(globalScopes).toBeDefined();
expect(globalScopes).not.toHaveLength(0);
@@ -166,11 +161,9 @@ describe('POST /invitations/:id/accept', () => {
test('should fail with invalid payloads', async () => {
const memberShellEmail = randomEmail();
const globalMemberRole = await getGlobalMemberRole();
const memberShell = await Container.get(UserRepository).save({
email: memberShellEmail,
globalRole: globalMemberRole,
role: 'global:member',
});
const invalidPayloads = [
@@ -219,8 +212,7 @@ describe('POST /invitations/:id/accept', () => {
});
test('should fail with already accepted invite', async () => {
const globalMemberRole = await getGlobalMemberRole();
const member = await createUser({ globalRole: globalMemberRole });
const member = await createUser({ role: 'global:member' });
const memberData = {
inviterId: owner.id,
@@ -334,7 +326,7 @@ describe('POST /invitations', () => {
const response = await ownerAgent
.post('/invitations')
.send([{ email: randomEmail(), role: 'admin' }])
.send([{ email: randomEmail(), role: 'global:admin' }])
.expect(200);
const [result] = response.body.data as UserInvitationResponse[];
@@ -349,11 +341,11 @@ describe('POST /invitations', () => {
test('should reinvite member', async () => {
mailer.invite.mockResolvedValue({ emailSent: false });
await ownerAgent.post('/invitations').send([{ email: randomEmail(), role: 'member' }]);
await ownerAgent.post('/invitations').send([{ email: randomEmail(), role: 'global:member' }]);
await ownerAgent
.post('/invitations')
.send([{ email: randomEmail(), role: 'member' }])
.send([{ email: randomEmail(), role: 'global:member' }])
.expect(200);
});
@@ -361,11 +353,11 @@ describe('POST /invitations', () => {
license.isAdvancedPermissionsLicensed.mockReturnValue(true);
mailer.invite.mockResolvedValue({ emailSent: false });
await ownerAgent.post('/invitations').send([{ email: randomEmail(), role: 'admin' }]);
await ownerAgent.post('/invitations').send([{ email: randomEmail(), role: 'global:admin' }]);
await ownerAgent
.post('/invitations')
.send([{ email: randomEmail(), role: 'admin' }])
.send([{ email: randomEmail(), role: 'global:admin' }])
.expect(200);
});
@@ -375,7 +367,7 @@ describe('POST /invitations', () => {
await ownerAgent
.post('/invitations')
.send([{ email: randomEmail(), role: 'admin' }])
.send([{ email: randomEmail(), role: 'global:admin' }])
.expect(403);
});
@@ -384,8 +376,7 @@ describe('POST /invitations', () => {
mailer.invite.mockResolvedValue({ emailSent: true });
const globalMemberRole = await getGlobalMemberRole();
const memberShell = await createUserShell(globalMemberRole);
const memberShell = await createUserShell('global:member');
const newUser = randomEmail();