Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove unverified role from discord on /verify #2156

Closed
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f8fd064
Fix username character limit (#2113) (#2115)
vinit717 Aug 30, 2024
0d51a6d
Merge pull request #2120 from Real-Dev-Squad/develop
iamitprakash Sep 1, 2024
5a7f583
Merge pull request #2121 from Real-Dev-Squad/develop
iamitprakash Sep 9, 2024
a2876c0
remove unverified role on /verify
shobhan-sundar-goutam Sep 14, 2024
a8358bf
fix: username generation for new user and modify format format func f…
vinit717 Sep 15, 2024
d4d40b1
[Feat] Extends Toggle privilege feature allowing other roles to be To…
shubhdevelop Sep 15, 2024
1c3a1a6
Revert "Mavens getting listed in idle,idle7d+ (#2127)" (#2158)
vinit717 Sep 16, 2024
0c3153b
Put the toggle feature behind the dev feature flag (#2161)
shubhdevelop Sep 16, 2024
20e40e5
Merge branch 'main' into develop
iamitprakash Sep 16, 2024
5259304
Merge pull request #2157 from Real-Dev-Squad/develop
iamitprakash Sep 16, 2024
524bc4c
chore: fix users firstname and lastname in lower case (#2162)
vinit717 Sep 17, 2024
54cb4bc
Merge pull request #2164 from Real-Dev-Squad/develop
iamitprakash Sep 17, 2024
02b2e9b
Revert "Dev to Main Sync"
vinit717 Sep 17, 2024
4997d90
Merge pull request #2165 from Real-Dev-Squad/revert-2164-develop
iamitprakash Sep 17, 2024
ac2eb4b
Revert "Dev to Main Sync" (#2166)
iamitprakash Sep 17, 2024
29a0d0b
Make firstname and lastname to lowercase (#2168)
vinit717 Sep 17, 2024
14ca890
Merge branch 'main' into develop
iamitprakash Sep 17, 2024
0244dcd
Merge pull request #2169 from Real-Dev-Squad/develop
iamitprakash Sep 17, 2024
0d6d058
Adding FF to Maven getting listed in idle,idle-7d+ (#2171)
fakhruddinkw Sep 20, 2024
7066ff7
Merge branch 'main' into develop
iamitprakash Sep 21, 2024
59d4720
Merge pull request #2172 from Real-Dev-Squad/develop
iamitprakash Sep 21, 2024
e789945
chore: remove feature flag for POST /extension-requests API (#2150)
samarpan1738 Sep 21, 2024
9af8127
chore: remove feature flag for /discord-actions/nicknames/sync API (#…
samarpan1738 Sep 21, 2024
63e945c
Remove dev feature flag for GET /logs API (#2149)
samarpan1738 Sep 21, 2024
edadf41
Remove dev feature flag for GET /requests API (#2151)
samarpan1738 Sep 21, 2024
a6814b6
Remove dev feature flag for POST /requests and PUT /requests/:id APIs…
samarpan1738 Sep 21, 2024
a19b0b3
chore: remove feature flag for GET /extension-requests/self API (#2152)
samarpan1738 Sep 22, 2024
4443293
Merge branch 'main' into develop
iamitprakash Sep 23, 2024
3bf6f1b
Added pagination in profile diffs API
lakshayman Sep 22, 2024
6970bff
Tests added
lakshayman Sep 23, 2024
3b68c3e
Return empty data if no userId found
lakshayman Sep 23, 2024
3c183c2
Comments removed
lakshayman Sep 23, 2024
2251597
Behind feature flag
lakshayman Sep 23, 2024
349df01
Next link should have feature flag
lakshayman Sep 23, 2024
eeafaaa
enhancement: adding filtered applications count (#2178)
rishirishhh Sep 25, 2024
7be7be2
Merge branch 'develop' into feat/paginationInProfileDiffsAPI
lakshayman Sep 28, 2024
29122bb
Merge pull request #2179 from Real-Dev-Squad/feat/paginationInProfile…
lakshayman Sep 28, 2024
41c136d
fix: Replace the deprecated function for sending notification (#2185)
divyansh0908 Sep 28, 2024
b7f61c7
remove unverified role on /verify
shobhan-sundar-goutam Sep 14, 2024
7522435
modified code and added tests
shobhan-sundar-goutam Oct 1, 2024
65e3f65
Merge branch 'update-/verify-functionality' of https://github.com/sho…
shobhan-sundar-goutam Oct 1, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions controllers/external-accounts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const externalAccountsModel = require("../models/external-accounts");
const { SOMETHING_WENT_WRONG, INTERNAL_SERVER_ERROR } = require("../constants/errorMessages");
const { getDiscordMembers } = require("../services/discordService");
const discordRolesModel = require("../models/discordactions");
const discordServices = require("../services/discordService");
const { fetchUser } = require("../models/users");
const { addOrUpdate, getUsersByRole, updateUsersInBatch } = require("../models/users");
const { retrieveDiscordUsers, fetchUsersForKeyValues } = require("../services/dataAccessLayer");
const { EXTERNAL_ACCOUNTS_POST_ACTIONS } = require("../constants/external-accounts");
Expand Down Expand Up @@ -40,6 +43,38 @@ const getExternalAccountData = async (req, res) => {
return res.boom.unauthorized("Token Expired. Please generate it again");
}

const { id: userId, roles } = req.userData;

if (!roles.in_discord) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • can we move this inside a function and return the data required here? it will make it easy to test the logic that's written here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay I'll do that

const roleExistsPromise = discordRolesModel.isGroupRoleExists({
rolename: "unverified",
});
const userDataPromise = fetchUser({ discordId: attributes.discordId });
const [role, userData] = await Promise.all([roleExistsPromise, userDataPromise]);

if (!role.roleExists || req.userData.id !== userData.user.id) {
return res.boom.forbidden("Permission denied. Cannot delete the role.");
}

await addOrUpdate(
{
roles: { ...roles, in_discord: true, archived: false },
discordId: attributes.discordId,
discordJoinedAt: attributes.discordJoinedAt,
},
userId
);

const roleData = role.existingRoles.docs[0].data();

await discordServices.removeRoleFromUser(roleData.roleid, attributes.discordId, req.userData);

const { wasSuccess } = await discordRolesModel.removeMemberGroup(roleData.roleid, attributes.discordId);
if (!wasSuccess) {
return res.status(400).json({ message: "Role deletion failed" });
}
}

return res.status(200).json({ message: "Data returned successfully", attributes: attributes });
} catch (error) {
logger.error(`Error getting external account data: ${error}`);
Expand Down