Skip to content

Commit

Permalink
Make Pro Team email checks case-insensitive (#288)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoinejaussoin authored Aug 9, 2021
1 parent 6f90b74 commit 930d41f
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ When using the Docker deployment, your database runs from a container. But if yo

- Support OKTA for authentication
- Speeding up the migration on production (using transpiled JavaScript instead of TypeScript via ts-node)
- Making email checks for Pro Team subscriptions case-insensitive. 👏 Thanks Nico! ([#287](https://github.com/antoinejaussoin/retro-board/issues/287))

### Version 4.5.0

Expand Down
2 changes: 1 addition & 1 deletion backend/src/db/entities/UserView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ select
from users u
left join subscriptions s on s."ownerId" = u.id and s.active is true
left join subscriptions s2 on u.email = ANY(s2.members) and s2.active is true
left join subscriptions s2 on lower(u.email) = any(lower(s2.members::text)::text[]) and s2.active is true
left join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true
`,
})
Expand Down
64 changes: 64 additions & 0 deletions backend/src/db/migrations/1628539922827-Compare-Email-Lowercase.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import {MigrationInterface, QueryRunner} from "typeorm";

export class CompareEmailLowercase1628539922827 implements MigrationInterface {
name = 'CompareEmailLowercase1628539922827'

public async up(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "schema" = $2 AND "name" = $3`, ["VIEW","public","user_view"]);
await queryRunner.query(`DROP VIEW "user_view"`);
await queryRunner.query(`CREATE VIEW "user_view" AS
select
u.id,
u.name,
u."accountType",
u.username,
u.currency,
u."stripeId",
u.photo,
u.language,
u.email,
u.trial,
s.id as "ownSubscriptionsId",
s.plan as "ownPlan",
coalesce(s.id, s2.id, s3.id) as "subscriptionsId",
coalesce(s.active, s2.active, s3.active, false) as "pro",
coalesce(s.plan, s2.plan, s3.plan) as "plan",
coalesce(s.domain, s2.domain, s3.domain) as "domain"
from users u
left join subscriptions s on s."ownerId" = u.id and s.active is true
left join subscriptions s2 on lower(u.email) = any(lower(s2.members::text)::text[]) and s2.active is true
left join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true
`);
await queryRunner.query(`INSERT INTO "typeorm_metadata"("type", "schema", "name", "value") VALUES ($1, $2, $3, $4)`, ["VIEW","public","user_view","select \n u.id,\n u.name,\n u.\"accountType\",\n u.username,\n u.currency,\n u.\"stripeId\",\n u.photo,\n u.language,\n u.email,\n u.trial,\n s.id as \"ownSubscriptionsId\",\n s.plan as \"ownPlan\",\n coalesce(s.id, s2.id, s3.id) as \"subscriptionsId\",\n coalesce(s.active, s2.active, s3.active, false) as \"pro\",\n coalesce(s.plan, s2.plan, s3.plan) as \"plan\",\n coalesce(s.domain, s2.domain, s3.domain) as \"domain\"\nfrom users u \n\nleft join subscriptions s on s.\"ownerId\" = u.id and s.active is true\nleft join subscriptions s2 on lower(u.email) = any(lower(s2.members::text)::text[]) and s2.active is true\nleft join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true"]);
}

public async down(queryRunner: QueryRunner): Promise<void> {
await queryRunner.query(`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "schema" = $2 AND "name" = $3`, ["VIEW","public","user_view"]);
await queryRunner.query(`DROP VIEW "user_view"`);
await queryRunner.query(`CREATE VIEW "user_view" AS select
u.id,
u.name,
u."accountType",
u.username,
u.currency,
u."stripeId",
u.photo,
u.language,
u.email,
u.trial,
s.id as "ownSubscriptionsId",
s.plan as "ownPlan",
coalesce(s.id, s2.id, s3.id) as "subscriptionsId",
coalesce(s.active, s2.active, s3.active, false) as "pro",
coalesce(s.plan, s2.plan, s3.plan) as "plan",
coalesce(s.domain, s2.domain, s3.domain) as "domain"
from users u
left join subscriptions s on s."ownerId" = u.id and s.active is true
left join subscriptions s2 on u.email = ANY(s2.members) and s2.active is true
left join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true`);
await queryRunner.query(`INSERT INTO "typeorm_metadata"("type", "schema", "name", "value") VALUES ($1, $2, $3, $4)`, ["VIEW","public","user_view","select \n u.id,\n u.name,\n u.\"accountType\",\n u.username,\n u.currency,\n u.\"stripeId\",\n u.photo,\n u.language,\n u.email,\n u.trial,\n s.id as \"ownSubscriptionsId\",\n s.plan as \"ownPlan\",\n coalesce(s.id, s2.id, s3.id) as \"subscriptionsId\",\n coalesce(s.active, s2.active, s3.active, false) as \"pro\",\n coalesce(s.plan, s2.plan, s3.plan) as \"plan\",\n coalesce(s.domain, s2.domain, s3.domain) as \"domain\"\nfrom users u \n\nleft join subscriptions s on s.\"ownerId\" = u.id and s.active is true\nleft join subscriptions s2 on u.email = ANY(s2.members) and s2.active is true\nleft join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true"]);
}

}

0 comments on commit 930d41f

Please sign in to comment.