Skip to content

Commit b9c487c

Browse files
authored
config changeup (#56)
1 parent b7447c8 commit b9c487c

File tree

7 files changed

+60
-25
lines changed

7 files changed

+60
-25
lines changed

AYIM/api/routes/staff/comments.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import Router from "@koa/router";
2-
import { hasRole, isLoggedInDiscord } from "../../../../Server/middleware";
2+
import { isLoggedInDiscord, isMCAStaff } from "../../../../Server/middleware";
33
import { UserComment } from "../../../../Models/MCA_AYIM/userComments";
44
import { currentMCA } from "../../../../MCA-AYIM/api/middleware";
55
import { MCA } from "../../../../Models/MCA_AYIM/mca";
66

77
const commentsReviewRouter = new Router();
88

99
commentsReviewRouter.use(isLoggedInDiscord);
10-
commentsReviewRouter.use(hasRole("mca", "staff"));
10+
commentsReviewRouter.use(isMCAStaff);
1111
commentsReviewRouter.use(currentMCA);
1212

1313
commentsReviewRouter.get("/", async (ctx) => {

Closed/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
# CorsaceInvitational
2-
The repository for Corsace Invitational
1+
# Closed
2+
The repository for Corsace Closed

Server/middleware.ts

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,12 @@ import { config } from "node-config-ts";
22
import { discordGuild } from "./discord";
33
import { ParameterizedContext, Next } from "koa";
44

5-
// General middlewares
5+
interface discordRoleInfo {
6+
section: string;
7+
role: string;
8+
}
69

10+
// General middlewares
711
async function isLoggedIn (ctx: ParameterizedContext, next: Next): Promise<void> {
812
if (!ctx.state.user) {
913
ctx.body = { error: "No user found!" };
@@ -38,9 +42,6 @@ async function isStaff (ctx: ParameterizedContext, next: Next): Promise<void> {
3842
config.discord.roles.corsace.corsace,
3943
config.discord.roles.corsace.headStaff,
4044
config.discord.roles.corsace.staff,
41-
config.discord.roles.open.staff,
42-
config.discord.roles.invitational.staff,
43-
config.discord.roles.mca.staff,
4445
];
4546
for (const role of roles)
4647
if (member.roles.cache.has(role)) {
@@ -73,8 +74,51 @@ function hasRole (section: string, role: string) {
7374
};
7475
}
7576

76-
const isMCAStaff = hasRole("mca", "staff");
77+
function hasRoles(roles: discordRoleInfo[]) {
78+
return async (ctx: ParameterizedContext, next: Next): Promise<void> => {
79+
const member = await (await discordGuild()).members.fetch(ctx.state.user.discord.userID);
80+
if (!member) {
81+
ctx.body = { error: "Could not obtain any discord user!" };
82+
return;
83+
}
84+
85+
if (
86+
member.roles.cache.has(config.discord.roles.corsace.corsace) ||
87+
(roles.some(role => role.section == "corsace" && role.role == "corsace") ? false : member.roles.cache.has(config.discord.roles.corsace.headStaff))
88+
) {
89+
await next();
90+
return;
91+
}
92+
for (const role of roles) {
93+
if (member.roles.cache.has(config.discord.roles[role.section][role.role]))
94+
{
95+
await next();
96+
return;
97+
}
98+
}
99+
100+
ctx.body = { error: "User does not have any of the required roles!" };
101+
return;
102+
};
103+
}
104+
105+
const isMCAStaff = hasRoles([{
106+
section: "mca",
107+
role: "standard",
108+
}, {
109+
section: "mca",
110+
role: "taiko",
111+
}, {
112+
section: "mca",
113+
role: "fruits",
114+
}, {
115+
section: "mca",
116+
role: "mania",
117+
}, {
118+
section: "mca",
119+
role: "storyboard",
120+
}]);
77121
const isHeadStaff = hasRole("corsace", "headStaff");
78122
const isCorsace = hasRole("corsace", "corsace");
79123

80-
export { isLoggedIn, isLoggedInDiscord, isLoggedInOsu, isStaff, isMCAStaff, isHeadStaff, isCorsace, hasRole };
124+
export { isLoggedIn, isLoggedInDiscord, isLoggedInOsu, isStaff, isMCAStaff, isHeadStaff, isCorsace, hasRole, hasRoles };

config/Config.d.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ declare module "node-config-ts" {
2727
open: {
2828
participants: string;
2929
captains: string;
30-
staff: string;
3130
mappooler: string;
3231
testplayer: string;
3332
scheduler: string;
@@ -36,10 +35,9 @@ declare module "node-config-ts" {
3635
commentator: string;
3736
referee: string;
3837
};
39-
invitational: {
38+
closed: {
4039
participants: string;
4140
captains: string;
42-
staff: string;
4341
mappooler: string;
4442
scheduler: string;
4543
streamManager: string;
@@ -48,7 +46,6 @@ declare module "node-config-ts" {
4846
referee: string;
4947
};
5048
mca: {
51-
staff: string;
5249
standard: string;
5350
taiko: string;
5451
fruits: string;
@@ -80,7 +77,7 @@ declare module "node-config-ts" {
8077

8178
ayim: ISubSiteConfig;
8279
corsace: ISubSiteConfig;
83-
invitational: ISubSiteConfig;
80+
closed: ISubSiteConfig;
8481
mca: ISubSiteConfig;
8582
open: ISubSiteConfig;
8683
}

config/default.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"open": {
1919
"participants": "role ID",
2020
"captains": "role ID",
21-
"staff": "role ID",
2221
"mappooler": "role ID",
2322
"testplayer": "role ID",
2423
"scheduler": "role ID",
@@ -27,10 +26,9 @@
2726
"commentator": "role ID",
2827
"referee": "role ID"
2928
},
30-
"invitational": {
29+
"closed": {
3130
"participants": "role ID",
3231
"captains": "role ID",
33-
"staff": "role ID",
3432
"mappooler": "role ID",
3533
"scheduler": "role ID",
3634
"streamManager": "role ID",
@@ -39,7 +37,6 @@
3937
"referee": "role ID"
4038
},
4139
"mca": {
42-
"staff": "role ID",
4340
"standard": "role ID",
4441
"taiko": "role ID",
4542
"fruits": "role ID",
@@ -78,7 +75,7 @@
7875
"publicUrl": "http://localhost:4000",
7976
"spa": true
8077
},
81-
"invitational": {
78+
"closed": {
8279
"host": "localhost",
8380
"port": 5000,
8481
"publicUrl": "http://localhost:5000",

config/deployment/docker-compose.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"corsace": {
99
"host": "0.0.0.0"
1010
},
11-
"invitational": {
11+
"closed": {
1212
"host": "0.0.0.0"
1313
},
1414
"mca": {

config/deployment/production.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"open": {
1919
"participants": "485092513640742913",
2020
"captains": "485092709179326474",
21-
"staff": "461571998963990539",
2221
"mappooler": "461583913287024643",
2322
"testplayer": "565333762586443776",
2423
"scheduler": "461584274404016138",
@@ -27,12 +26,10 @@
2726
"commentator": "461584618643259400",
2827
"referee": "461584657042112543"
2928
},
30-
"invitational": {
31-
"staff": "461571998963990539",
29+
"closed": {
3230
"mappooler": "774795961691406366"
3331
},
3432
"mca": {
35-
"staff": "461571998963990539",
3633
"standard": "461585071053209631",
3734
"taiko": "461585200376184842",
3835
"fruits": "461585112518230018",

0 commit comments

Comments
 (0)