Skip to content

Commit 35c2a2f

Browse files
committed
fix: eslint issue
2 parents 99f78ed + 5cf9f12 commit 35c2a2f

File tree

7 files changed

+114
-4
lines changed

7 files changed

+114
-4
lines changed

config/custom-environment-variables.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ module.exports = {
8888
__name: "USER_TOKEN_REFRESH_TTL",
8989
__format: "number",
9090
},
91+
impersonationTtl: {
92+
__name: "USER_TOKEN_IMPERSONATION_TTL",
93+
__format: "number",
94+
},
9195
publicKey: "PUBLIC_KEY",
9296
privateKey: "PRIVATE_KEY",
9397
},

config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ module.exports = {
8686
cookieV2Name: `rds-session-v2-${NODE_ENV}`,
8787
ttl: 30 * 24 * 60 * 60, // in seconds
8888
refreshTtl: 180 * 24 * 60 * 60, // in seconds
89+
impersonationTtl: 15 * 60, // in seconds
8990
publicKey: "<publicKey>",
9091
privateKey: "<privateKey>",
9192
},

constants/requests.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,3 +68,9 @@ export const INVALID_REQUEST_TYPE = "Invalid request type";
6868
export const INVALID_REQUEST_DEADLINE = "New deadline of the request must be greater than old deadline";
6969
export const REQUEST_UPDATED_SUCCESSFULLY = "Request updated successfully";
7070
export const UNAUTHORIZED_TO_UPDATE_REQUEST = "Unauthorized to update request";
71+
72+
export const FEATURE_NOT_IMPLEMENTED = "Feature not implemented";
73+
74+
export const IMPERSONATION_NOT_COMPLETED = "Please complete impersonation before creating a new request";
75+
export const IMPERSONATION_ALREADY_ATTEMPTED = "No active request is available for impersonation";
76+
export const IMPERSONATION_REQUEST_NOT_APPROVED = "Awaiting approval for impersonation request";

middlewares/shortCircuit.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { NextFunction } from "express";
2+
import { CustomRequest, CustomResponse } from "../types/global";
3+
4+
export const disableRoute = (_req: CustomRequest, res: CustomResponse, _next: NextFunction) => {
5+
return res.boom.serverUnavailable(
6+
"This route has been temporarily disabled. If you need assistance, please reach out to the team."
7+
);
8+
};

routes/discordactions.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,24 @@ const ROLES = require("../constants/roles");
3131
const { Services } = require("../constants/bot");
3232
const { verifyCronJob } = require("../middlewares/authorizeBot");
3333
const { authorizeAndAuthenticate } = require("../middlewares/authorizeUsersAndService");
34+
const { disableRoute } = require("../middlewares/shortCircuit");
3435
const router = express.Router();
3536

3637
router.post("/groups", authenticate, checkIsVerifiedDiscord, validateGroupRoleBody, createGroupRole);
3738
router.get("/groups", authenticate, checkIsVerifiedDiscord, validateLazyLoadingParams, getPaginatedAllGroupRoles);
3839
router.delete("/groups/:groupId", authenticate, checkIsVerifiedDiscord, authorizeRoles([SUPERUSER]), deleteGroupRole);
3940
router.post("/roles", authenticate, checkIsVerifiedDiscord, validateMemberRoleBody, addGroupRoleToMember);
40-
router.get("/invite", authenticate, getUserDiscordInvite);
41-
router.post("/invite", authenticate, checkCanGenerateDiscordLink, generateInviteForUser);
41+
/**
42+
* Short-circuit the GET method for this endpoint
43+
* Refer https://github.com/Real-Dev-Squad/todo-action-items/issues/269 for more details.
44+
*/
45+
router.get("/invite", disableRoute, authenticate, getUserDiscordInvite);
46+
/**
47+
* Short-circuit this POST method for this endpoint
48+
* Refer https://github.com/Real-Dev-Squad/todo-action-items/issues/269 for more details.
49+
*/
50+
router.post("/invite", disableRoute, authenticate, checkCanGenerateDiscordLink, generateInviteForUser);
51+
4252
router.delete("/roles", authenticate, checkIsVerifiedDiscord, deleteRole);
4353
router.get("/roles", authenticate, checkIsVerifiedDiscord, getGroupsRoleId);
4454
router.patch(

test/integration/discordactions.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,7 @@ describe("Discord actions", function () {
952952
});
953953
});
954954

955-
describe("GET /discord-actions/invite", function () {
955+
describe.skip("GET /discord-actions/invite", function () {
956956
it("should return the invite for the user if no userId is provided in the params and the invite exists", async function () {
957957
await addInviteToInviteModel({ userId: superUserId, inviteLink: "discord.gg/apQYT7HB" });
958958

@@ -994,7 +994,7 @@ describe("Discord actions", function () {
994994
});
995995

996996
// <------ Will revisit this later https://github.com/Real-Dev-Squad/website-backend/issues/2078 --->
997-
describe("POST /discord-actions/invite", function () {
997+
describe.skip("POST /discord-actions/invite", function () {
998998
afterEach(function () {
999999
sinon.restore();
10001000
});

types/impersonationRequest.d.ts

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
import { Request, Response } from "express";
2+
import { REQUEST_STATE } from "../constants/requests";
3+
import { Boom } from "express-boom";
4+
import {RequestQuery } from "./requests";
5+
import { userData } from "./global";
6+
import { Timestamp } from "firebase-admin/firestore";
7+
8+
export type ImpersonationRequest = {
9+
id: string;
10+
status: REQUEST_STATE;
11+
isImpersonationFinished: boolean;
12+
createdBy: string;
13+
createdFor: string;
14+
userId: string;
15+
reason: string;
16+
message?: string;
17+
impersonatedUserId: string;
18+
createdAt: Timestamp;
19+
updatedAt: Timestamp;
20+
startedAt?: Timestamp;
21+
endedAt?: Timestamp;
22+
}
23+
24+
export type CreateImpersonationRequestBody = {
25+
impersonatedUserId: string;
26+
reason: string;
27+
};
28+
29+
export type CreateImpersonationRequestModelBody = {
30+
status: REQUEST_STATE;
31+
isImpersonationFinished: boolean;
32+
createdBy: string;
33+
createdFor: string;
34+
userId: string;
35+
reason: string;
36+
impersonatedUserId: string;
37+
}
38+
39+
export type UpdateImpersonationRequestDataBody = {
40+
startedAt?: Timestamp;
41+
endedAt: Timestamp;
42+
isImpersonationFinished?: boolean;
43+
}
44+
45+
export type UpdateImpersonationRequestStatusBody = {
46+
status: REQUEST_STATE.APPROVED | REQUEST_STATE.REJECTED;
47+
message?: string;
48+
}
49+
50+
export type ImpersonationRequestQuery = RequestQuery & {
51+
dev?: string;
52+
};
53+
54+
export type ImpersonationRequestResponse = Response & {
55+
boom: Boom;
56+
};
57+
58+
export type RequestParams = {
59+
id: string;
60+
}
61+
62+
export type CreateImpersonationRequest = Request & {
63+
userData: userData;
64+
body: CreateImpersonationRequestBody;
65+
query: ImpersonationRequestQuery;
66+
};
67+
68+
export type UpdateImpersonationRequestStatus = Request & {
69+
userData: userData;
70+
body: UpdateImpersonationRequestStatusBody;
71+
query: ImpersonationRequestQuery;
72+
params: RequestParams;
73+
}
74+
75+
export type PaginatedImpersonationRequests = {
76+
allRequests: ImpersonationRequest[];
77+
next: string;
78+
prev: string;
79+
page: number;
80+
count: number;
81+
}

0 commit comments

Comments
 (0)