Skip to content

Commit a6fb7d9

Browse files
coopbrihobbescodes
andauthored
Prerelease (#46)
* refactor(env): rename Polar sandbox switch * chore: update import order * chore: add TODO * chore(cors): set prerelease URL * fix(plugins): allow users to delete their own members records * docs(readme): update README --------- Co-authored-by: hobbescodes <[email protected]>
1 parent c7ab83f commit a6fb7d9

File tree

6 files changed

+33
-30
lines changed

6 files changed

+33
-30
lines changed

.env.development

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ AUTH_BASE_URL="https://localhost:8000/api/auth"
33

44
CHECKOUT_SUCCESS_URL="https://localhost:3000/confirmation"
55

6-
# Define whether to connect to Polar's `sandbox` environment
7-
SANDBOX="true"
6+
# whether to connect to Polar's sandbox environment (https://docs.polar.sh/integrate/sandbox)
7+
ENABLE_POLAR_SANDBOX="true"

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Backfeed is an open-source feedback reporting platform.
66

77
First, create a Postgres database called `backfeed`. Then, `cp .env.local.template .env.local` and fill in the values.
88

9-
### Building and Running (Native)
9+
### Building and Running
1010

1111
Install dependencies:
1212

src/generated/graphql/schema.executable.ts

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ const spec_downvote = {
154154
},
155155
description: undefined,
156156
extensions: {
157-
oid: "216526",
157+
oid: "219066",
158158
isTableLike: true,
159159
pg: {
160160
serviceName: "main",
@@ -237,7 +237,7 @@ const spec_upvote = {
237237
},
238238
description: undefined,
239239
extensions: {
240-
oid: "216439",
240+
oid: "218979",
241241
isTableLike: true,
242242
pg: {
243243
serviceName: "main",
@@ -320,7 +320,7 @@ const spec_invitation = {
320320
},
321321
description: undefined,
322322
extensions: {
323-
oid: "216625",
323+
oid: "219165",
324324
isTableLike: true,
325325
pg: {
326326
serviceName: "main",
@@ -403,7 +403,7 @@ const spec_organization = {
403403
},
404404
description: undefined,
405405
extensions: {
406-
oid: "216401",
406+
oid: "218941",
407407
isTableLike: true,
408408
pg: {
409409
serviceName: "main",
@@ -498,7 +498,7 @@ const spec_comment = {
498498
},
499499
description: undefined,
500500
extensions: {
501-
oid: "216506",
501+
oid: "219046",
502502
isTableLike: true,
503503
pg: {
504504
serviceName: "main",
@@ -617,7 +617,7 @@ const spec_project = {
617617
},
618618
description: undefined,
619619
extensions: {
620-
oid: "216425",
620+
oid: "218965",
621621
isTableLike: true,
622622
pg: {
623623
serviceName: "main",
@@ -638,7 +638,7 @@ const roleCodec = enumCodec({
638638
values: ["owner", "admin", "member"],
639639
description: undefined,
640640
extensions: {
641-
oid: "216545",
641+
oid: "219085",
642642
pg: {
643643
serviceName: "main",
644644
schemaName: "public",
@@ -717,7 +717,7 @@ const spec_member = {
717717
},
718718
description: undefined,
719719
extensions: {
720-
oid: "216461",
720+
oid: "219001",
721721
isTableLike: true,
722722
pg: {
723723
serviceName: "main",
@@ -848,7 +848,7 @@ const spec_post = {
848848
},
849849
description: undefined,
850850
extensions: {
851-
oid: "216415",
851+
oid: "218955",
852852
isTableLike: true,
853853
pg: {
854854
serviceName: "main",
@@ -967,7 +967,7 @@ const spec_postStatus = {
967967
},
968968
description: undefined,
969969
extensions: {
970-
oid: "216599",
970+
oid: "219139",
971971
isTableLike: true,
972972
pg: {
973973
serviceName: "main",
@@ -988,7 +988,7 @@ const tierCodec = enumCodec({
988988
values: ["basic", "team", "enterprise"],
989989
description: undefined,
990990
extensions: {
991-
oid: "216648",
991+
oid: "219188",
992992
pg: {
993993
serviceName: "main",
994994
schemaName: "public",
@@ -1117,7 +1117,7 @@ const spec_user = {
11171117
},
11181118
description: undefined,
11191119
extensions: {
1120-
oid: "216449",
1120+
oid: "218989",
11211121
isTableLike: true,
11221122
pg: {
11231123
serviceName: "main",
@@ -4082,7 +4082,7 @@ const planWrapper3 = (plan, _, fieldArgs) => {
40824082
}).from(members).where(and(eq(members.userId, currentUser.id), eq(members.organizationId, member.organizationId)));
40834083
if (userRole.role !== "owner") throw new Error("Insufficient permissions");
40844084
if (patch.role === "owner") throw new Error("Organizations can only have one owner");
4085-
} else throw new Error("Insufficient permissions");
4085+
} else if ("create" === "update") throw new Error("Insufficient permissions");
40864086
}
40874087
});
40884088
return plan();
@@ -4306,7 +4306,7 @@ const planWrapper10 = (plan, _, fieldArgs) => {
43064306
}).from(members).where(and(eq(members.userId, currentUser.id), eq(members.organizationId, member.organizationId)));
43074307
if (userRole.role !== "owner") throw new Error("Insufficient permissions");
43084308
if (patch.role === "owner") throw new Error("Organizations can only have one owner");
4309-
} else throw new Error("Insufficient permissions");
4309+
} else if ("update" === "update") throw new Error("Insufficient permissions");
43104310
}
43114311
});
43124312
return plan();
@@ -4583,7 +4583,7 @@ const planWrapper19 = (plan, _, fieldArgs) => {
45834583
}).from(members).where(and(eq(members.userId, currentUser.id), eq(members.organizationId, member.organizationId)));
45844584
if (userRole.role !== "owner") throw new Error("Insufficient permissions");
45854585
if (patch.role === "owner") throw new Error("Organizations can only have one owner");
4586-
} else throw new Error("Insufficient permissions");
4586+
} else if ("delete" === "update") throw new Error("Insufficient permissions");
45874587
}
45884588
});
45894589
return plan();

src/lib/config/env.config.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ export const {
1212
POLAR_WEBHOOK_SECRET,
1313
CHECKOUT_SUCCESS_URL,
1414
AUTH_BASE_URL,
15-
SANDBOX,
15+
ENABLE_POLAR_SANDBOX,
1616
} = process.env;
1717

1818
export const isDevEnv = NODE_ENV === "development";
1919
export const isProdEnv = NODE_ENV === "production";
20-
export const isSandbox = SANDBOX === "true";
20+
export const enablePolarSandbox = ENABLE_POLAR_SANDBOX === "true";

src/lib/plugins/postgraphile/MemberRBAC.plugin.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,15 @@ const validatePermissions = (propName: string, scope: MutationScope) =>
8787
throw new Error("Organizations can only have one owner");
8888
}
8989
} else {
90-
// Restrict current users from updating their own role
91-
throw new Error("Insufficient permissions");
90+
if (scope === "update") {
91+
// Restrict current users from updating their own role
92+
throw new Error("Insufficient permissions");
9293

93-
// TODO: replace above with below when ownership transfers are allowed
94-
// if (scope === "update" && member.role !== "owner") {
95-
// throw new Error("Insufficient permissions");
96-
// }
94+
// TODO: replace above with below when ownership transfers are allowed
95+
// if (scope === "update" && member.role !== "owner") {
96+
// throw new Error("Insufficient permissions");
97+
// }
98+
}
9799
}
98100
}
99101
},

src/server.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ import {
1717
POLAR_WEBHOOK_SECRET,
1818
PORT,
1919
SKIP_AUTH,
20+
enablePolarSandbox,
2021
isDevEnv,
2122
isProdEnv,
22-
isSandbox,
2323
} from "lib/config/env.config";
2424
import { dbPool as db } from "lib/db/db";
2525
import { users } from "lib/drizzle/schema";
@@ -82,7 +82,8 @@ app.use(
8282
// enable CORS
8383
cors({
8484
origin: isProdEnv
85-
? [appConfig.url, "https://backfeed-app-prerelease.up.railway.app"]
85+
? // TODO remove prerelease URL once ready
86+
[appConfig.url, "https://backfeed-prerelease.omni.dev"]
8687
: "https://localhost:3000",
8788
credentials: true,
8889
allowMethods: ["GET", "POST"],
@@ -94,7 +95,7 @@ app.get(
9495
Checkout({
9596
accessToken: POLAR_ACCESS_TOKEN,
9697
successUrl: CHECKOUT_SUCCESS_URL,
97-
server: isSandbox ? "sandbox" : "production",
98+
server: enablePolarSandbox ? "sandbox" : "production",
9899
}),
99100
);
100101

@@ -108,7 +109,7 @@ app.get(
108109

109110
return customerId;
110111
},
111-
server: isSandbox ? "sandbox" : "production",
112+
server: enablePolarSandbox ? "sandbox" : "production",
112113
}),
113114
);
114115

0 commit comments

Comments
 (0)