Skip to content

Commit a29f2fc

Browse files
Fix: Disable discord-actions/invite routes (#2435)
* feat: Add short-circuit middleware to disable invite routes temporarily * fix: Temporarily skip tests for invite routes in Discord actions * fix: Correct wording in server unavailable message for disabled route
1 parent f1d1739 commit a29f2fc

File tree

3 files changed

+24
-4
lines changed

3 files changed

+24
-4
lines changed

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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -952,7 +952,8 @@ describe("Discord actions", function () {
952952
});
953953
});
954954

955-
describe("GET /discord-actions/invite", function () {
955+
// eslint-disable-next-line mocha/no-skipped-tests
956+
describe.skip("GET /discord-actions/invite", function () {
956957
it("should return the invite for the user if no userId is provided in the params and the invite exists", async function () {
957958
await addInviteToInviteModel({ userId: superUserId, inviteLink: "discord.gg/apQYT7HB" });
958959

@@ -994,7 +995,8 @@ describe("Discord actions", function () {
994995
});
995996

996997
// <------ Will revisit this later https://github.com/Real-Dev-Squad/website-backend/issues/2078 --->
997-
describe("POST /discord-actions/invite", function () {
998+
// eslint-disable-next-line mocha/no-skipped-tests
999+
describe.skip("POST /discord-actions/invite", function () {
9981000
afterEach(function () {
9991001
sinon.restore();
10001002
});

0 commit comments

Comments
 (0)