-
Notifications
You must be signed in to change notification settings - Fork 4
feat: added whitelist so that only specific people can join event #607
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { MigrationInterface, QueryRunner } from "typeorm"; | ||
|
|
||
| export class EventWhitelist1775081823814 implements MigrationInterface { | ||
| name = 'EventWhitelist1775081823814' | ||
|
|
||
| public async up(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(`ALTER TABLE "event_whitelists" DROP CONSTRAINT "FK_event_whitelists_event"`); | ||
| await queryRunner.query(`DROP INDEX "public"."UQ_event_whitelists_event_username_platform"`); | ||
| await queryRunner.query(`ALTER TABLE "event_whitelists" ALTER COLUMN "eventId" DROP NOT NULL`); | ||
| await queryRunner.query(`ALTER TABLE "event_whitelists" ADD CONSTRAINT "UQ_1e66e3e9750244ea3f6563a6d49" UNIQUE ("eventId", "username", "platform")`); | ||
|
Comment on lines
+9
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Keep A whitelist row without an event is invalid, and in PostgreSQL this new unique key will still allow duplicate 🤖 Prompt for AI Agents |
||
| await queryRunner.query(`ALTER TABLE "event_whitelists" ADD CONSTRAINT "FK_17ccbcee3723a35d6d691532c22" FOREIGN KEY ("eventId") REFERENCES "events"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); | ||
| } | ||
|
|
||
| public async down(queryRunner: QueryRunner): Promise<void> { | ||
| await queryRunner.query(`ALTER TABLE "event_whitelists" DROP CONSTRAINT "FK_17ccbcee3723a35d6d691532c22"`); | ||
| await queryRunner.query(`ALTER TABLE "event_whitelists" DROP CONSTRAINT "UQ_1e66e3e9750244ea3f6563a6d49"`); | ||
| await queryRunner.query(`ALTER TABLE "event_whitelists" ALTER COLUMN "eventId" SET NOT NULL`); | ||
| await queryRunner.query(`CREATE UNIQUE INDEX "UQ_event_whitelists_event_username_platform" ON "event_whitelists" ("eventId", "platform", "username") `); | ||
| await queryRunner.query(`ALTER TABLE "event_whitelists" ADD CONSTRAINT "FK_event_whitelists_event" FOREIGN KEY ("eventId") REFERENCES "events"("id") ON DELETE CASCADE ON UPDATE NO ACTION`); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import { IsArray, IsEnum, IsString, ValidateNested } from "class-validator"; | ||
| import { Type } from "class-transformer"; | ||
| import { WhitelistPlatform } from "../entities/event-whitelist.entity"; | ||
|
|
||
| export class WhitelistEntryDto { | ||
| @IsString() | ||
| username: string; | ||
|
|
||
| @IsEnum(WhitelistPlatform) | ||
| platform: WhitelistPlatform; | ||
| } | ||
|
|
||
| export class AddToWhitelistDto { | ||
| @IsArray() | ||
| @ValidateNested({ each: true }) | ||
| @Type(() => WhitelistEntryDto) | ||
| entries: WhitelistEntryDto[]; | ||
| } | ||
|
|
||
| export class BulkDeleteWhitelistDto { | ||
| @IsArray() | ||
| @IsString({ each: true }) | ||
| ids: string[]; | ||
| } | ||
|
Comment on lines
+13
to
+24
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
set -euo pipefail
# Verify whitelist id type
fd -i 'event-whitelist.entity.ts' | xargs -r rg -n -C2 'PrimaryGeneratedColumn|id'
# Verify whether service/controller already short-circuit empty arrays
fd -i 'event.service.ts' | xargs -r rg -n -C2 'whitelist|entries|ids|bulk'
fd -i 'event.controller.ts' | xargs -r rg -n -C2 'whitelist|bulk-delete'Repository: 42core-team/website Length of output: 5360 🏁 Script executed: cat -n api/src/event/dtos/whitelistDto.tsRepository: 42core-team/website Length of output: 799 Add Both Suggested DTO update-import { IsArray, IsEnum, IsString, ValidateNested } from "class-validator";
+import {
+ ArrayNotEmpty,
+ IsArray,
+ IsEnum,
+ IsString,
+ IsUUID,
+ ValidateNested,
+} from "class-validator";
export class AddToWhitelistDto {
`@IsArray`()
+ `@ArrayNotEmpty`()
`@ValidateNested`({ each: true })
`@Type`(() => WhitelistEntryDto)
entries: WhitelistEntryDto[];
}
export class BulkDeleteWhitelistDto {
`@IsArray`()
- `@IsString`({ each: true })
+ `@ArrayNotEmpty`()
+ `@IsUUID`("4", { each: true })
ids: string[];
}🤖 Prompt for AI Agents |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { | ||
| Entity, | ||
| Column, | ||
| PrimaryGeneratedColumn, | ||
| CreateDateColumn, | ||
| ManyToOne, | ||
| Unique, | ||
| } from "typeorm"; | ||
| import { EventEntity } from "./event.entity"; | ||
|
|
||
| export enum WhitelistPlatform { | ||
| GITHUB = "GITHUB", | ||
| FORTYTWO = "FORTYTWO", | ||
| } | ||
|
|
||
| @Entity("event_whitelists") | ||
| @Unique(["event", "username", "platform"]) | ||
| export class EventWhitelistEntity { | ||
| @PrimaryGeneratedColumn("uuid") | ||
| id: string; | ||
|
|
||
| @Column({ type: "enum", enum: WhitelistPlatform }) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's better when we just store a text type in the db instead of a enum |
||
| platform: WhitelistPlatform; | ||
|
|
||
| @Column() | ||
| username: string; | ||
|
|
||
| @ManyToOne(() => EventEntity, { | ||
| onDelete: "CASCADE", | ||
| }) | ||
| event: EventEntity; | ||
|
|
||
| @CreateDateColumn() | ||
| createdAt: Date; | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why did you make eventId nullable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't event_whitelists always have an event?