mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 21:00:31 +00:00
Compare commits
8 Commits
docker-com
...
BIG-419-de
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
920c8ea95c | ||
|
|
8de3717587 | ||
|
|
cc863f774a | ||
|
|
bcd08284b4 | ||
|
|
8e8161f207 | ||
|
|
7b4b50cf4b | ||
|
|
bca3e51fdf | ||
|
|
6faa378577 |
68
.github/workflows/e2e.yml
vendored
Normal file
68
.github/workflows/e2e.yml
vendored
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
name: E2E
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- develop
|
||||||
|
paths:
|
||||||
|
- '**.ts'
|
||||||
|
- '**.tsx'
|
||||||
|
- '**/tsconfig.json'
|
||||||
|
- 'yarn.lock'
|
||||||
|
- '.github/workflows/e2e.yml'
|
||||||
|
pull_request:
|
||||||
|
paths:
|
||||||
|
- '**.ts'
|
||||||
|
- '**.tsx'
|
||||||
|
- '**/tsconfig.json'
|
||||||
|
- 'yarn.lock'
|
||||||
|
- '.github/workflows/e2e.yml'
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: 'bash'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test_setup:
|
||||||
|
name: Test setup
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
outputs:
|
||||||
|
preview_url: ${{ steps.waitForVercelPreviewDeployment.outputs.url }}
|
||||||
|
steps:
|
||||||
|
- name: Wait for Vercel preview deployment to be ready
|
||||||
|
uses: patrickedqvist/wait-for-vercel-preview@v1.3.1
|
||||||
|
id: waitForVercelPreviewDeployment
|
||||||
|
with:
|
||||||
|
token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
max_timeout: 3000
|
||||||
|
|
||||||
|
test_e2e:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
needs: test_setup
|
||||||
|
name: Playwright tests
|
||||||
|
timeout-minutes: 15
|
||||||
|
environment: ${{ vars.ENVIRONMENT_STAGE }}
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: 14 # Need for npm >=7.7
|
||||||
|
cache: 'npm'
|
||||||
|
|
||||||
|
- name: Install dependencies
|
||||||
|
run: npm install
|
||||||
|
|
||||||
|
- name: Install Playwright with deps
|
||||||
|
run: npx playwright install --with-deps
|
||||||
|
|
||||||
|
- name: Run tests
|
||||||
|
run: npm run test:e2e
|
||||||
|
env:
|
||||||
|
PLAYWRIGHT_TEST_BASE_URL: ${{ needs.test_setup.outputs.preview_url }}
|
||||||
|
|
||||||
|
- uses: actions/upload-artifact@v2
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: playwright-report
|
||||||
|
path: test-results/
|
||||||
|
retention-days: 30
|
||||||
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
node_modules/
|
node_modules/
|
||||||
data
|
data
|
||||||
.env
|
.env
|
||||||
|
test-results/
|
||||||
@@ -40,7 +40,7 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
# Mail
|
# Mail
|
||||||
- MAIL_HOST=${MAIL_HOST}
|
- MAIL_HOST=${MAIL_HOST}
|
||||||
- MAIL_USERNAME=${MAIL_USERNAM}
|
- MAIL_USERNAME=${MAIL_USERNAME}
|
||||||
- MAIL_PASSWORD=${MAIL_PASSWORD}
|
- MAIL_PASSWORD=${MAIL_PASSWORD}
|
||||||
- MAIL_PORT=${MAIL_PORT}
|
- MAIL_PORT=${MAIL_PORT}
|
||||||
- MAIL_SECURE=${MAIL_SECURE}
|
- MAIL_SECURE=${MAIL_SECURE}
|
||||||
|
|||||||
68
e2e/authentication.spec.ts
Normal file
68
e2e/authentication.spec.ts
Normal file
@@ -0,0 +1,68 @@
|
|||||||
|
import { test, expect, Page } from '@playwright/test';
|
||||||
|
|
||||||
|
let authPage: Page;
|
||||||
|
|
||||||
|
test.describe('authentication', () => {
|
||||||
|
test.beforeAll(async ({ browser }) => {
|
||||||
|
authPage = await browser.newPage();
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('login', () => {
|
||||||
|
test.beforeAll(async () => {
|
||||||
|
await authPage.goto('/auth/login');
|
||||||
|
});
|
||||||
|
test('should show the login page.', async () => {
|
||||||
|
await expect(authPage.locator('body')).toContainText(
|
||||||
|
"Don't have an account? Sign up"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test('should email and password be required.', async () => {
|
||||||
|
await authPage.getByRole('button', { name: 'Log in' }).click();
|
||||||
|
|
||||||
|
await expect(authPage.locator('form')).toContainText(
|
||||||
|
'Email is a required field'
|
||||||
|
);
|
||||||
|
await expect(authPage.locator('form')).toContainText(
|
||||||
|
'Password is a required field'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
test('should go to the register page when click on sign up link', async () => {
|
||||||
|
await authPage.getByRole('link', { name: 'Sign up' }).click();
|
||||||
|
await expect(authPage.url()).toContain('/auth/register');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('register', () => {
|
||||||
|
test.beforeAll(async () => {
|
||||||
|
await authPage.goto('/auth/register');
|
||||||
|
});
|
||||||
|
test('should first name, last name, email and password be required.', async () => {
|
||||||
|
await authPage.getByRole('button', { name: 'Register' }).click();
|
||||||
|
|
||||||
|
await expect(authPage.locator('form')).toContainText(
|
||||||
|
'First name is a required field'
|
||||||
|
);
|
||||||
|
await expect(authPage.locator('form')).toContainText(
|
||||||
|
'Last name is a required field'
|
||||||
|
);
|
||||||
|
await expect(authPage.locator('form')).toContainText(
|
||||||
|
'Email is a required field'
|
||||||
|
);
|
||||||
|
await expect(authPage.locator('form')).toContainText(
|
||||||
|
'Password is a required field'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('reset password', () => {
|
||||||
|
test.beforeAll(async () => {
|
||||||
|
await authPage.goto('/auth/send_reset_password');
|
||||||
|
});
|
||||||
|
test('should email be required.', async () => {
|
||||||
|
await authPage.getByRole('button', { name: 'Reset Password' }).click();
|
||||||
|
await expect(authPage.locator('form')).toContainText(
|
||||||
|
'Email is a required field'
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
26
package-lock.json
generated
26
package-lock.json
generated
@@ -941,6 +941,23 @@
|
|||||||
"esquery": "^1.0.1"
|
"esquery": "^1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"@playwright/test": {
|
||||||
|
"version": "1.32.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@playwright/test/-/test-1.32.3.tgz",
|
||||||
|
"integrity": "sha512-BvWNvK0RfBriindxhLVabi8BRe3X0J9EVjKlcmhxjg4giWBD/xleLcg2dz7Tx0agu28rczjNIPQWznwzDwVsZQ==",
|
||||||
|
"requires": {
|
||||||
|
"@types/node": "*",
|
||||||
|
"fsevents": "2.3.2",
|
||||||
|
"playwright-core": "1.32.3"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"playwright-core": {
|
||||||
|
"version": "1.32.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/playwright-core/-/playwright-core-1.32.3.tgz",
|
||||||
|
"integrity": "sha512-SB+cdrnu74ZIn5Ogh/8278ngEh9NEEV0vR4sJFmK04h2iZpybfbqBY0bX6+BLYWVdV12JLLI+JEFtSnYgR+mWg=="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"@tootallnate/once": {
|
"@tootallnate/once": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-2.0.0.tgz",
|
||||||
@@ -986,8 +1003,7 @@
|
|||||||
"@types/node": {
|
"@types/node": {
|
||||||
"version": "18.14.6",
|
"version": "18.14.6",
|
||||||
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.6.tgz",
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-18.14.6.tgz",
|
||||||
"integrity": "sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA==",
|
"integrity": "sha512-93+VvleD3mXwlLI/xASjw0FzKcwzl3OdTCzm1LaRfqgS21gfFtK3zDXM5Op9TeeMsJVOaJ2VRDpT9q4Y3d0AvA=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"@types/normalize-package-data": {
|
"@types/normalize-package-data": {
|
||||||
"version": "2.4.1",
|
"version": "2.4.1",
|
||||||
@@ -2304,6 +2320,12 @@
|
|||||||
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
|
"integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
|
"fsevents": {
|
||||||
|
"version": "2.3.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
|
||||||
|
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
|
||||||
|
"optional": true
|
||||||
|
},
|
||||||
"function-bind": {
|
"function-bind": {
|
||||||
"version": "1.1.1",
|
"version": "1.1.1",
|
||||||
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
"resolved": "https://registry.npmjs.org/function-bind/-/function-bind-1.1.1.tgz",
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
"dev:server": "lerna run dev --scope \"@bigcapital/server\"",
|
"dev:server": "lerna run dev --scope \"@bigcapital/server\"",
|
||||||
"build:server": "lerna run build --scope \"@bigcapital/server\"",
|
"build:server": "lerna run build --scope \"@bigcapital/server\"",
|
||||||
"serve:server": "lerna run serve --scope \"@bigcapital/server\"",
|
"serve:server": "lerna run serve --scope \"@bigcapital/server\"",
|
||||||
|
"test:e2e": "playwright test",
|
||||||
"prepare": "husky install"
|
"prepare": "husky install"
|
||||||
},
|
},
|
||||||
"workspaces": [
|
"workspaces": [
|
||||||
@@ -21,7 +22,8 @@
|
|||||||
"@commitlint/config-lerna-scopes": "^17.4.2",
|
"@commitlint/config-lerna-scopes": "^17.4.2",
|
||||||
"husky": "^8.0.3",
|
"husky": "^8.0.3",
|
||||||
"lerna": "^6.4.1",
|
"lerna": "^6.4.1",
|
||||||
"@commitlint/cli": "^17.4.2"
|
"@commitlint/cli": "^17.4.2",
|
||||||
|
"@playwright/test": "^1.32.3"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
"node": "14.x"
|
"node": "14.x"
|
||||||
@@ -30,6 +32,5 @@
|
|||||||
"hooks": {
|
"hooks": {
|
||||||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS"
|
||||||
}
|
}
|
||||||
},
|
}
|
||||||
"dependencies": {}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -92,6 +92,7 @@ export default class InviteUsersController extends BaseController {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
await this.inviteUsersService.sendInvite(tenantId, sendInviteDTO, user);
|
await this.inviteUsersService.sendInvite(tenantId, sendInviteDTO, user);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
type: 'success',
|
type: 'success',
|
||||||
code: 'INVITE.SENT.SUCCESSFULLY',
|
code: 'INVITE.SENT.SUCCESSFULLY',
|
||||||
|
|||||||
@@ -25,6 +25,7 @@ import SyncSystemSendInvite from '@/services/InviteUsers/SyncSystemSendInvite';
|
|||||||
import InviteSendMainNotification from '@/services/InviteUsers/InviteSendMailNotification';
|
import InviteSendMainNotification from '@/services/InviteUsers/InviteSendMailNotification';
|
||||||
import SyncTenantAcceptInvite from '@/services/InviteUsers/SyncTenantAcceptInvite';
|
import SyncTenantAcceptInvite from '@/services/InviteUsers/SyncTenantAcceptInvite';
|
||||||
import SyncTenantUserMutate from '@/services/Users/SyncTenantUserSaved';
|
import SyncTenantUserMutate from '@/services/Users/SyncTenantUserSaved';
|
||||||
|
import { SyncTenantUserDelete } from '@/services/Users/SyncTenantUserDeleted';
|
||||||
import OrgSyncTenantAdminUserSubscriber from '@/subscribers/Organization/SyncTenantAdminUser';
|
import OrgSyncTenantAdminUserSubscriber from '@/subscribers/Organization/SyncTenantAdminUser';
|
||||||
import OrgBuildSmsNotificationSubscriber from '@/subscribers/Organization/BuildSmsNotification';
|
import OrgBuildSmsNotificationSubscriber from '@/subscribers/Organization/BuildSmsNotification';
|
||||||
import PurgeUserAbilityCache from '@/services/Users/PurgeUserAbilityCache';
|
import PurgeUserAbilityCache from '@/services/Users/PurgeUserAbilityCache';
|
||||||
@@ -113,6 +114,7 @@ export const susbcribers = () => {
|
|||||||
SyncTenantAcceptInvite,
|
SyncTenantAcceptInvite,
|
||||||
InviteSendMainNotification,
|
InviteSendMainNotification,
|
||||||
SyncTenantUserMutate,
|
SyncTenantUserMutate,
|
||||||
|
SyncTenantUserDelete,
|
||||||
OrgSyncTenantAdminUserSubscriber,
|
OrgSyncTenantAdminUserSubscriber,
|
||||||
OrgBuildSmsNotificationSubscriber,
|
OrgBuildSmsNotificationSubscriber,
|
||||||
PurgeUserAbilityCache,
|
PurgeUserAbilityCache,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import { Inject, Service } from 'typedi';
|
|||||||
@Service()
|
@Service()
|
||||||
export default class InviteSendMainNotificationSubscribe {
|
export default class InviteSendMainNotificationSubscribe {
|
||||||
@Inject('agenda')
|
@Inject('agenda')
|
||||||
agenda: any;
|
private agenda: any;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attaches events with handlers.
|
* Attaches events with handlers.
|
||||||
|
|||||||
@@ -3,7 +3,6 @@ import uniqid from 'uniqid';
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import InviteUsersMailMessages from '@/services/InviteUsers/InviteUsersMailMessages';
|
|
||||||
import events from '@/subscribers/events';
|
import events from '@/subscribers/events';
|
||||||
import {
|
import {
|
||||||
ISystemUser,
|
ISystemUser,
|
||||||
@@ -13,7 +12,6 @@ import {
|
|||||||
IUserInvitedEventPayload,
|
IUserInvitedEventPayload,
|
||||||
IUserInviteResendEventPayload,
|
IUserInviteResendEventPayload,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import TenantsManagerService from '@/services/Tenancy/TenantsManager';
|
|
||||||
import { ERRORS } from './constants';
|
import { ERRORS } from './constants';
|
||||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||||
import RolesService from '@/services/Roles/RolesService';
|
import RolesService from '@/services/Roles/RolesService';
|
||||||
@@ -21,25 +19,13 @@ import RolesService from '@/services/Roles/RolesService';
|
|||||||
@Service()
|
@Service()
|
||||||
export default class InviteTenantUserService implements IInviteUserService {
|
export default class InviteTenantUserService implements IInviteUserService {
|
||||||
@Inject()
|
@Inject()
|
||||||
eventPublisher: EventPublisher;
|
private eventPublisher: EventPublisher;
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
tenancy: TenancyService;
|
private tenancy: TenancyService;
|
||||||
|
|
||||||
@Inject('logger')
|
|
||||||
logger: any;
|
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
mailMessages: InviteUsersMailMessages;
|
private rolesService: RolesService;
|
||||||
|
|
||||||
@Inject('repositories')
|
|
||||||
sysRepositories: any;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
tenantsManager: TenantsManagerService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
rolesService: RolesService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends invite mail to the given email from the given tenant and user.
|
* Sends invite mail to the given email from the given tenant and user.
|
||||||
@@ -99,8 +85,6 @@ export default class InviteTenantUserService implements IInviteUserService {
|
|||||||
): Promise<{
|
): Promise<{
|
||||||
user: ITenantUser;
|
user: ITenantUser;
|
||||||
}> {
|
}> {
|
||||||
const { User } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
// Retrieve the user by id or throw not found service error.
|
// Retrieve the user by id or throw not found service error.
|
||||||
const user = await this.getUserByIdOrThrowError(tenantId, userId);
|
const user = await this.getUserByIdOrThrowError(tenantId, userId);
|
||||||
|
|
||||||
|
|||||||
@@ -10,18 +10,18 @@ export class RoleTransformer extends Transformer {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Retrieves the localized role name if is predefined or stored name.
|
||||||
* @param role
|
* @param role
|
||||||
* @returns
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
public name(role) {
|
public name(role) {
|
||||||
return role.predefined ? this.context.i18n.__(role.name) : role.name;
|
return role.predefined ? this.context.i18n.__(role.name) : role.name;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Retrieves the localized role description if is predefined or stored description.
|
||||||
* @param role
|
* @param role
|
||||||
* @returns
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
public description(role) {
|
public description(role) {
|
||||||
return role.predefined
|
return role.predefined
|
||||||
|
|||||||
26
packages/server/src/services/Users/SyncTenantUserDeleted.ts
Normal file
26
packages/server/src/services/Users/SyncTenantUserDeleted.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import events from '@/subscribers/events';
|
||||||
|
import { ITenantUserDeletedPayload } from '@/interfaces';
|
||||||
|
import { SystemUser } from '@/system/models';
|
||||||
|
|
||||||
|
export class SyncTenantUserDelete {
|
||||||
|
/**
|
||||||
|
* Attaches events with handlers.
|
||||||
|
* @param bus
|
||||||
|
*/
|
||||||
|
public attach(bus) {
|
||||||
|
bus.subscribe(
|
||||||
|
events.tenantUser.onDeleted,
|
||||||
|
this.syncSystemUserOnceUserDeleted
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Deletes the system user once tenant user be deleted.
|
||||||
|
* @param {ITenantUserDeletedPayload} payload -
|
||||||
|
*/
|
||||||
|
private syncSystemUserOnceUserDeleted = async ({
|
||||||
|
tenantUser,
|
||||||
|
}: ITenantUserDeletedPayload) => {
|
||||||
|
await SystemUser.query().where('id', tenantUser.systemUserId).delete();
|
||||||
|
};
|
||||||
|
}
|
||||||
50
packages/server/src/services/Users/UserTransformer.ts
Normal file
50
packages/server/src/services/Users/UserTransformer.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||||
|
|
||||||
|
export class UserTransformer extends Transformer {
|
||||||
|
/**
|
||||||
|
* Exclude these attributes from user object.
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
public excludeAttributes = (): string[] => {
|
||||||
|
return ['role'];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Includeded attributes.
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
|
public includeAttributes = (): string[] => {
|
||||||
|
return ['roleName', 'roleDescription', 'roleSlug'];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the localized role name if is predefined or stored name.
|
||||||
|
* @param role
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
public roleName(user) {
|
||||||
|
return user.role.predefined
|
||||||
|
? this.context.i18n.__(user.role.name)
|
||||||
|
: user.role.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the localized role description if is predefined or stored description.
|
||||||
|
* @param user
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
public roleDescription(user) {
|
||||||
|
return user.role.predefined
|
||||||
|
? this.context.i18n.__(user.role.description)
|
||||||
|
: user.role.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the role slug.
|
||||||
|
* @param user
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
public roleSlug(user) {
|
||||||
|
return user.role.slug;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -14,12 +14,11 @@ import RolesService from '@/services/Roles/RolesService';
|
|||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { ERRORS } from './constants';
|
import { ERRORS } from './constants';
|
||||||
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
import { EventPublisher } from '@/lib/EventPublisher/EventPublisher';
|
||||||
|
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable';
|
||||||
|
import { UserTransformer } from './UserTransformer';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class UsersService {
|
export default class UsersService {
|
||||||
@Inject('repositories')
|
|
||||||
private repositories: any;
|
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
private rolesService: RolesService;
|
private rolesService: RolesService;
|
||||||
|
|
||||||
@@ -29,6 +28,9 @@ export default class UsersService {
|
|||||||
@Inject()
|
@Inject()
|
||||||
private eventPublisher: EventPublisher;
|
private eventPublisher: EventPublisher;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private transformer: TransformerInjectable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new user.
|
* Creates a new user.
|
||||||
* @param {number} tenantId - Tenant id.
|
* @param {number} tenantId - Tenant id.
|
||||||
@@ -91,9 +93,10 @@ export default class UsersService {
|
|||||||
// Retrieve user details or throw not found service error.
|
// Retrieve user details or throw not found service error.
|
||||||
const tenantUser = await this.getTenantUserOrThrowError(tenantId, userId);
|
const tenantUser = await this.getTenantUserOrThrowError(tenantId, userId);
|
||||||
|
|
||||||
// Validate the delete user should not be the last user.
|
// Validate the delete user should not be the last active user.
|
||||||
await this.validateNotLastUserDelete(tenantId);
|
if (tenantUser.isInviteAccepted) {
|
||||||
|
await this.validateNotLastUserDelete(tenantId);
|
||||||
|
}
|
||||||
// Delete user from the storage.
|
// Delete user from the storage.
|
||||||
await User.query().findById(userId).delete();
|
await User.query().findById(userId).delete();
|
||||||
|
|
||||||
@@ -183,7 +186,7 @@ export default class UsersService {
|
|||||||
|
|
||||||
const users = await User.query().withGraphFetched('role');
|
const users = await User.query().withGraphFetched('role');
|
||||||
|
|
||||||
return users;
|
return this.transformer.transform(tenantId, users, new UserTransformer());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -223,11 +226,13 @@ export default class UsersService {
|
|||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
*/
|
*/
|
||||||
private async validateNotLastUserDelete(tenantId: number) {
|
private async validateNotLastUserDelete(tenantId: number) {
|
||||||
const { systemUserRepository } = this.repositories;
|
const { User } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const usersFound = await systemUserRepository.find({ tenantId });
|
const inviteAcceptedUsers = await User.query()
|
||||||
|
.select(['id'])
|
||||||
|
.whereNotNull('invite_accepted_at');
|
||||||
|
|
||||||
if (usersFound.length === 1) {
|
if (inviteAcceptedUsers.length === 1) {
|
||||||
throw new ServiceError(ERRORS.CANNOT_DELETE_LAST_USER);
|
throw new ServiceError(ERRORS.CANNOT_DELETE_LAST_USER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -291,9 +296,9 @@ export default class UsersService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate the authorized user cannot mutate its role.
|
* Validate the authorized user cannot mutate its role.
|
||||||
* @param {ITenantUser} oldTenantUser
|
* @param {ITenantUser} oldTenantUser
|
||||||
* @param {IEditUserDTO} editUserDTO
|
* @param {IEditUserDTO} editUserDTO
|
||||||
* @param {ISystemUser} authorizedUser
|
* @param {ISystemUser} authorizedUser
|
||||||
*/
|
*/
|
||||||
validateMutateRoleNotAuthorizedUser(
|
validateMutateRoleNotAuthorizedUser(
|
||||||
oldTenantUser: ITenantUser,
|
oldTenantUser: ITenantUser,
|
||||||
@@ -307,5 +312,4 @@ export default class UsersService {
|
|||||||
throw new ServiceError(ERRORS.CANNOT_AUTHORIZED_USER_MUTATE_ROLE);
|
throw new ServiceError(ERRORS.CANNOT_AUTHORIZED_USER_MUTATE_ROLE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
38
playwright.config.ts
Normal file
38
playwright.config.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import path from 'path';
|
||||||
|
import { PlaywrightTestConfig, devices } from '@playwright/test';
|
||||||
|
import dotenv from 'dotenv';
|
||||||
|
|
||||||
|
dotenv.config();
|
||||||
|
|
||||||
|
// Reference: https://playwright.dev/docs/test-configuration
|
||||||
|
const config: PlaywrightTestConfig = {
|
||||||
|
// Timeout per test
|
||||||
|
timeout: 60 * 1000,
|
||||||
|
workers: 1,
|
||||||
|
// Test directory
|
||||||
|
testDir: path.join(__dirname, 'e2e'),
|
||||||
|
// If a test fails, retry it additional 2 times
|
||||||
|
retries: 0,
|
||||||
|
// Artifacts folder where screenshots, videos, and traces are stored.
|
||||||
|
outputDir: 'test-results/',
|
||||||
|
use: {
|
||||||
|
// Retry a test if its failing with enabled tracing. This allows you to analyse the DOM, console logs, network traffic etc.
|
||||||
|
// More information: https://playwright.dev/docs/trace-viewer
|
||||||
|
trace: 'retain-on-failure',
|
||||||
|
|
||||||
|
// All available context options: https://playwright.dev/docs/api/class-browser#browser-new-context
|
||||||
|
// contextOptions: {
|
||||||
|
// ignoreHTTPSErrors: true,
|
||||||
|
// },
|
||||||
|
baseURL: process.env.PLAYWRIGHT_TEST_BASE_URL || 'http://localhost:4000',
|
||||||
|
},
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'Desktop Chrome',
|
||||||
|
use: {
|
||||||
|
...devices['Desktop Chrome'],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
],
|
||||||
|
};
|
||||||
|
export default config;
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
{
|
{
|
||||||
"installCommand": "npm install && npm run bootstrap",
|
"installCommand": "npm install && npm run bootstrap",
|
||||||
"buildCommand": "CI='' npm run build:webapp",
|
"buildCommand": "CI='' npm run build:webapp",
|
||||||
"outputDirectory": "packages/webapp/build"
|
"outputDirectory": "packages/webapp/build",
|
||||||
}
|
"rewrites": [{
|
||||||
|
"source": "/(.*)",
|
||||||
|
"destination": "/"
|
||||||
|
}]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user