-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Multiple Admins and Account Page improvements (#433)
- Loading branch information
1 parent
2ebe9cf
commit 08c73ea
Showing
32 changed files
with
787 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class PlanOwner1669661894373 implements MigrationInterface { | ||
name = 'planOwner1669661894373' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`, ["VIEW","user_view","public"]); | ||
await queryRunner.query(`DROP VIEW "user_view"`); | ||
await queryRunner.query(`CREATE VIEW "user_view" AS | ||
select | ||
u.id, | ||
i.id as identity_id, | ||
u.name, | ||
i.account_type, | ||
i.username, | ||
u.currency, | ||
u.stripe_id, | ||
i.photo, | ||
u.language, | ||
u.email, | ||
case when i.account_type = 'anonymous' and i.password is null then false else true end as "can_delete_session", | ||
u.trial, | ||
s1.id as "own_subscriptions_id", | ||
s1.plan as "own_plan", | ||
coalesce(s1.id, s2.id, s3.id) as "subscriptions_id", | ||
coalesce(s1.active, s2.active, s3.active, false) as "pro", | ||
coalesce(s1.plan, s2.plan, s3.plan) as "plan", | ||
coalesce(s1.domain, s2.domain, s3.domain) as "domain", | ||
coalesce(o1.name, o2.name, o2.name) as "plan_owner", | ||
coalesce(o1.email, o2.email, o2.email) as "plan_owner_email" | ||
from users_identities i | ||
join users u on u.id = i.user_id | ||
left join subscriptions s1 on s1.owner_id = u.id and s1.active is true | ||
left join users o1 on o1.id = s1.owner_id | ||
left join subscriptions s2 on lower(u.email) = any(lower(s2.members::text)::text[]) and s2.active is true | ||
left join users o2 on o2.id = s2.owner_id | ||
left join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true | ||
left join users o3 on o3.id = s3.owner_id | ||
`); | ||
await queryRunner.query(`INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`, ["public","VIEW","user_view","select \n u.id,\n i.id as identity_id,\n u.name,\n i.account_type,\n i.username,\n u.currency,\n u.stripe_id,\n i.photo,\n u.language,\n u.email,\n case when i.account_type = 'anonymous' and i.password is null then false else true end as \"can_delete_session\",\n u.trial,\n s1.id as \"own_subscriptions_id\",\n s1.plan as \"own_plan\",\n coalesce(s1.id, s2.id, s3.id) as \"subscriptions_id\",\n coalesce(s1.active, s2.active, s3.active, false) as \"pro\",\n coalesce(s1.plan, s2.plan, s3.plan) as \"plan\",\n coalesce(s1.domain, s2.domain, s3.domain) as \"domain\",\n coalesce(o1.name, o2.name, o2.name) as \"plan_owner\",\n coalesce(o1.email, o2.email, o2.email) as \"plan_owner_email\"\nfrom users_identities i\n\njoin users u on u.id = i.user_id\nleft join subscriptions s1 on s1.owner_id = u.id and s1.active is true\nleft join users o1 on o1.id = s1.owner_id\nleft join subscriptions s2 on lower(u.email) = any(lower(s2.members::text)::text[]) and s2.active is true\nleft join users o2 on o2.id = s2.owner_id\nleft join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true\nleft join users o3 on o3.id = s3.owner_id"]); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`, ["VIEW","user_view","public"]); | ||
await queryRunner.query(`DROP VIEW "user_view"`); | ||
await queryRunner.query(`CREATE VIEW "user_view" AS select | ||
u.id, | ||
i.id as identity_id, | ||
u.name, | ||
i.account_type, | ||
i.username, | ||
u.currency, | ||
u.stripe_id, | ||
i.photo, | ||
u.language, | ||
u.email, | ||
case when i.account_type = 'anonymous' and i.password is null then false else true end as "can_delete_session", | ||
u.trial, | ||
s.id as "own_subscriptions_id", | ||
s.plan as "own_plan", | ||
coalesce(s.id, s2.id, s3.id) as "subscriptions_id", | ||
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_identities i | ||
join users u on u.id = i.user_id | ||
left join subscriptions s on s.owner_id = 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"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`, ["public","VIEW","user_view","select \n u.id,\n i.id as identity_id,\n u.name,\n i.account_type,\n i.username,\n u.currency,\n u.stripe_id,\n i.photo,\n u.language,\n u.email,\n case when i.account_type = 'anonymous' and i.password is null then false else true end as \"can_delete_session\",\n u.trial,\n s.id as \"own_subscriptions_id\",\n s.plan as \"own_plan\",\n coalesce(s.id, s2.id, s3.id) as \"subscriptions_id\",\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_identities i\n\njoin users u on u.id = i.user_id\nleft join subscriptions s on s.owner_id = 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"]); | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
backend/src/db/migrations/1669662836558-SubscriptionAdmins.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { MigrationInterface, QueryRunner } from 'typeorm'; | ||
|
||
export class SubscriptionAdmins1669662836558 implements MigrationInterface { | ||
name = 'SubscriptionAdmins1669662836558'; | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query( | ||
`ALTER TABLE "subscriptions" ADD "admins" text array NOT NULL DEFAULT '{}'` | ||
); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`ALTER TABLE "subscriptions" DROP COLUMN "admins"`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import {MigrationInterface, QueryRunner} from "typeorm"; | ||
|
||
export class AdminsView1669663848592 implements MigrationInterface { | ||
name = 'AdminsView1669663848592' | ||
|
||
public async up(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`, ["VIEW","user_view","public"]); | ||
await queryRunner.query(`DROP VIEW "user_view"`); | ||
await queryRunner.query(`CREATE VIEW "user_view" AS | ||
select | ||
u.id, | ||
i.id as identity_id, | ||
u.name, | ||
i.account_type, | ||
i.username, | ||
u.currency, | ||
u.stripe_id, | ||
i.photo, | ||
u.language, | ||
u.email, | ||
case when i.account_type = 'anonymous' and i.password is null then false else true end as "can_delete_session", | ||
u.trial, | ||
s1.id as "own_subscriptions_id", | ||
s1.plan as "own_plan", | ||
coalesce(s1.id, s2.id, s3.id) as "subscriptions_id", | ||
coalesce(s1.active, s2.active, s3.active, false) as "pro", | ||
coalesce(s1.plan, s2.plan, s3.plan) as "plan", | ||
coalesce(s1.domain, s2.domain, s3.domain) as "domain", | ||
coalesce(o1.name, o2.name, o3.name) as "plan_owner", | ||
coalesce(o1.email, o2.email, o3.email) as "plan_owner_email", | ||
coalesce(s1.admins, s2.admins, s3.admins) as "plan_admins" | ||
from users_identities i | ||
join users u on u.id = i.user_id | ||
left join subscriptions s1 on s1.owner_id = u.id and s1.active is true | ||
left join users o1 on o1.id = s1.owner_id | ||
left join subscriptions s2 on lower(u.email) = any(lower(s2.members::text)::text[]) and s2.active is true | ||
left join users o2 on o2.id = s2.owner_id | ||
left join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true | ||
left join users o3 on o3.id = s3.owner_id | ||
`); | ||
await queryRunner.query(`INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`, ["public","VIEW","user_view","select \n u.id,\n i.id as identity_id,\n u.name,\n i.account_type,\n i.username,\n u.currency,\n u.stripe_id,\n i.photo,\n u.language,\n u.email,\n case when i.account_type = 'anonymous' and i.password is null then false else true end as \"can_delete_session\",\n u.trial,\n s1.id as \"own_subscriptions_id\",\n s1.plan as \"own_plan\",\n coalesce(s1.id, s2.id, s3.id) as \"subscriptions_id\",\n coalesce(s1.active, s2.active, s3.active, false) as \"pro\",\n coalesce(s1.plan, s2.plan, s3.plan) as \"plan\",\n coalesce(s1.domain, s2.domain, s3.domain) as \"domain\",\n coalesce(o1.name, o2.name, o3.name) as \"plan_owner\",\n coalesce(o1.email, o2.email, o3.email) as \"plan_owner_email\",\n coalesce(s1.admins, s2.admins, s3.admins) as \"plan_admins\"\nfrom users_identities i\n\njoin users u on u.id = i.user_id\nleft join subscriptions s1 on s1.owner_id = u.id and s1.active is true\nleft join users o1 on o1.id = s1.owner_id\nleft join subscriptions s2 on lower(u.email) = any(lower(s2.members::text)::text[]) and s2.active is true\nleft join users o2 on o2.id = s2.owner_id\nleft join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true\nleft join users o3 on o3.id = s3.owner_id"]); | ||
} | ||
|
||
public async down(queryRunner: QueryRunner): Promise<void> { | ||
await queryRunner.query(`DELETE FROM "typeorm_metadata" WHERE "type" = $1 AND "name" = $2 AND "schema" = $3`, ["VIEW","user_view","public"]); | ||
await queryRunner.query(`DROP VIEW "user_view"`); | ||
await queryRunner.query(`CREATE VIEW "user_view" AS select | ||
u.id, | ||
i.id as identity_id, | ||
u.name, | ||
i.account_type, | ||
i.username, | ||
u.currency, | ||
u.stripe_id, | ||
i.photo, | ||
u.language, | ||
u.email, | ||
case when i.account_type = 'anonymous' and i.password is null then false else true end as "can_delete_session", | ||
u.trial, | ||
s1.id as "own_subscriptions_id", | ||
s1.plan as "own_plan", | ||
coalesce(s1.id, s2.id, s3.id) as "subscriptions_id", | ||
coalesce(s1.active, s2.active, s3.active, false) as "pro", | ||
coalesce(s1.plan, s2.plan, s3.plan) as "plan", | ||
coalesce(s1.domain, s2.domain, s3.domain) as "domain", | ||
coalesce(o1.name, o2.name, o2.name) as "plan_owner", | ||
coalesce(o1.email, o2.email, o2.email) as "plan_owner_email" | ||
from users_identities i | ||
join users u on u.id = i.user_id | ||
left join subscriptions s1 on s1.owner_id = u.id and s1.active is true | ||
left join users o1 on o1.id = s1.owner_id | ||
left join subscriptions s2 on lower(u.email) = any(lower(s2.members::text)::text[]) and s2.active is true | ||
left join users o2 on o2.id = s2.owner_id | ||
left join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true | ||
left join users o3 on o3.id = s3.owner_id`); | ||
await queryRunner.query(`INSERT INTO "typeorm_metadata"("database", "schema", "table", "type", "name", "value") VALUES (DEFAULT, $1, DEFAULT, $2, $3, $4)`, ["public","VIEW","user_view","select \n u.id,\n i.id as identity_id,\n u.name,\n i.account_type,\n i.username,\n u.currency,\n u.stripe_id,\n i.photo,\n u.language,\n u.email,\n case when i.account_type = 'anonymous' and i.password is null then false else true end as \"can_delete_session\",\n u.trial,\n s1.id as \"own_subscriptions_id\",\n s1.plan as \"own_plan\",\n coalesce(s1.id, s2.id, s3.id) as \"subscriptions_id\",\n coalesce(s1.active, s2.active, s3.active, false) as \"pro\",\n coalesce(s1.plan, s2.plan, s3.plan) as \"plan\",\n coalesce(s1.domain, s2.domain, s3.domain) as \"domain\",\n coalesce(o1.name, o2.name, o2.name) as \"plan_owner\",\n coalesce(o1.email, o2.email, o2.email) as \"plan_owner_email\"\nfrom users_identities i\n\njoin users u on u.id = i.user_id\nleft join subscriptions s1 on s1.owner_id = u.id and s1.active is true\nleft join users o1 on o1.id = s1.owner_id\nleft join subscriptions s2 on lower(u.email) = any(lower(s2.members::text)::text[]) and s2.active is true\nleft join users o2 on o2.id = s2.owner_id\nleft join subscriptions s3 on s3.domain = split_part(u.email, '@', 2) and s3.active is true\nleft join users o3 on o3.id = s3.owner_id"]); | ||
} | ||
|
||
} |
Oops, something went wrong.