Skip to content

Commit

Permalink
Merge pull request #2118 from Real-Dev-Squad/fix/discord-invite-gener…
Browse files Browse the repository at this point in the history
…ation

Remove discord generation check on date
  • Loading branch information
lakshayman authored Sep 1, 2024
2 parents 9802901 + b7919b3 commit b00831d
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 28 deletions.
8 changes: 1 addition & 7 deletions middlewares/checkCanGenerateDiscordLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ const checkCanGenerateDiscordLink = async (req: CustomRequest, res: CustomRespon
const { id: userId, roles } = req.userData;
const isSuperUser = roles.super_user;
const userIdInQuery = req.query.userId;
const currentTime = Date.now();
const cutoffTime = 1725147849000; // Todo will remove this Hotfix time for 31 August 2024

if (isSuperUser) {
return next();
Expand All @@ -17,10 +15,6 @@ const checkCanGenerateDiscordLink = async (req: CustomRequest, res: CustomRespon
return res.boom.forbidden("User should be super user to generate link for other users");
}

if (currentTime >= cutoffTime) {
return res.boom.forbidden("Discord invite link generation is not allowed after the cutoff time.");
}

try {
const applications = await ApplicationModel.getUserApplications(userId);

Expand All @@ -31,7 +25,7 @@ const checkCanGenerateDiscordLink = async (req: CustomRequest, res: CustomRespon
const approvedApplication = applications.find((application: { status: string; }) => application.status === 'accepted');

if (!approvedApplication) {
return res.boom.forbidden("Only users with an approved application can generate a Discord invite link.");
return res.boom.forbidden("Only users with an accepted application can generate a Discord invite link.");
}

return next();
Expand Down
23 changes: 2 additions & 21 deletions test/integration/discordactions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -781,12 +781,6 @@ describe("Discord actions", function () {

// <------ Will revisit this later https://github.com/Real-Dev-Squad/website-backend/issues/2078 --->
describe("POST /discord-actions/invite", function () {
let clock;

beforeEach(function () {
clock = sinon.useFakeTimers(new Date("2024-08-31").getTime());
});

afterEach(function () {
sinon.restore();
});
Expand Down Expand Up @@ -903,19 +897,6 @@ describe("Discord actions", function () {
expect(res.body.inviteLink).to.be.equal("discord.gg/asdfdsfsd");
});

it("should return 403 if current date is after 25 August 2024", async function () {
clock.tick(2 * 24 * 60 * 60 * 1000); // Move time forward to after 31 August 2024
sinon.stub(ApplicationModel, "getUserApplications").resolves([{ status: "accepted" }]);

const res = await chai
.request(app)
.post("/discord-actions/invite")
.set("cookie", `${cookieName}=${userAuthToken}`);

expect(res).to.have.status(403);
expect(res.body.message).to.be.equal("Discord invite link generation is not allowed after the cutoff time.");
});

it("should return 403 if user has no applications", async function () {
sinon.stub(ApplicationModel, "getUserApplications").resolves([]);

Expand All @@ -938,7 +919,7 @@ describe("Discord actions", function () {

expect(res).to.have.status(403);
expect(res.body.message).to.be.equal(
"Only users with an approved application can generate a Discord invite link."
"Only users with an accepted application can generate a Discord invite link."
);
});

Expand All @@ -952,7 +933,7 @@ describe("Discord actions", function () {

expect(res).to.have.status(403);
expect(res.body.message).to.be.equal(
"Only users with an approved application can generate a Discord invite link."
"Only users with an accepted application can generate a Discord invite link."
);
});

Expand Down

0 comments on commit b00831d

Please sign in to comment.