feat(invitation): Improve invitation flow - Milestone 2 (#6804)
From PR: #6626 Resolves #6763 Resolves #6055 Resolves #6782 ## GTK I retain the 'Invite by link' feature to prevent any breaking changes. We could make the invitation by link optional through an admin setting, allowing users to rely solely on personal invitations. ## Todo - [x] Add an expiration date to an invitation - [x] Allow to renew an invitation to postpone the expiration date - [x] Refresh the UI - [x] Add the new personal token in the link sent to new user - [x] Display an error if a user tries to use an expired invitation - [x] Display an error if a user uses another mail than the one in the invitation --------- Co-authored-by: Charles Bochet <charles@twenty.com>
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
import { MigrationInterface, QueryRunner } from 'typeorm';
|
||||
|
||||
export class AddInvitation1724056827317 implements MigrationInterface {
|
||||
name = 'AddInvitation1724056827317';
|
||||
|
||||
public async up(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
'ALTER TABLE core."appToken" ALTER COLUMN "userId" DROP NOT NULL',
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE core."appToken" ADD CONSTRAINT "userIdIsNullWhenTypeIsInvitation" CHECK ("appToken".type != 'INVITATION_TOKEN' OR "appToken"."userId" IS NULL)`,
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
`ALTER TABLE core."appToken" ADD CONSTRAINT "userIdNotNullWhenTypeIsNotInvitation" CHECK ("appToken".type = 'INVITATION_TOKEN' OR "appToken"."userId" NOTNULL)`,
|
||||
);
|
||||
|
||||
await queryRunner.query('ALTER TABLE core."appToken" ADD "context" jsonb');
|
||||
|
||||
await queryRunner.query(
|
||||
'CREATE UNIQUE INDEX apptoken_unique_invitation_by_user_workspace ON core."appToken" ("workspaceId", ("context" ->> \'email\')) WHERE type = \'INVITATION_TOKEN\';',
|
||||
);
|
||||
}
|
||||
|
||||
public async down(queryRunner: QueryRunner): Promise<void> {
|
||||
await queryRunner.query(
|
||||
`DROP INDEX core.apptoken_unique_invitation_by_user_workspace;`,
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
'DELETE FROM "core"."appToken" WHERE "userId" IS NULL',
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
'ALTER TABLE core."appToken" DROP CONSTRAINT "userIdIsNullWhenTypeIsInvitation"',
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
'ALTER TABLE core."appToken" DROP CONSTRAINT "userIdNotNullWhenTypeIsNotInvitation"',
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
'ALTER TABLE core."appToken" DROP COLUMN "context"',
|
||||
);
|
||||
|
||||
await queryRunner.query(
|
||||
'ALTER TABLE core."appToken" ALTER COLUMN "userId" SET NOT NULL',
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user