Skip to content

Commit

Permalink
fix: group duplication on invite
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihai Nicolae committed Dec 13, 2023
1 parent 5cf6966 commit e80099e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 44 deletions.
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "eionet2-user-management",
"version": "1.2.2",
"version": "1.2.3",
"description": "",
"author": "",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion tabs/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions tabs/package.json
@@ -1,6 +1,6 @@
{
"name": "@eeacms/eionet2-user-management",
"version": "1.2.2",
"version": "1.2.3",
"license": "MIT",
"description": "Teams app for managing Eionet users.",
"dependencies": {
Expand Down Expand Up @@ -88,4 +88,4 @@
"@azure/core-rest-pipeline": "1.12.1"
},
"homepage": "."
}
}
71 changes: 31 additions & 40 deletions tabs/src/data/provider.js
Expand Up @@ -306,12 +306,10 @@ export async function inviteUser(user, mappings) {
config = await getConfiguration();
let userId = undefined,
invitationResponse = undefined,
sendMail = false,
onlyNFP = false;
sendMail = false;

if (user.NFP && !firstMapping) {
firstMapping = mappings.find((m) => m.O365GroupId === config.MainEionetGroupId);
onlyNFP = true;
}

if (!user.ADProfile) {
Expand Down Expand Up @@ -367,48 +365,41 @@ export async function inviteUser(user, mappings) {

try {
await addTag(config.MainEionetGroupId, constants.NFP_TAG, userId);
onlyNFP &&
(await addTag(config.MainEionetGroupId, getCountryName(user.Country), userId));
await addTag(config.MainEionetGroupId, getCountryName(user.Country), userId);
} catch (err) {
return wrapError(err, messages.UserInvite.Errors.TagsCreation);
}
}

mappings
.filter(
(m) =>
(user.Membership && user.Membership.includes(m.Membership)) ||
(user.OtherMemberships && user.OtherMemberships.includes(m.Membership)),
)
.forEach(async (mapping) => {
//Set groups and tags
try {
const groupIds = [
...new Set(
[mapping.O365GroupId, mapping.MailingGroupId, mapping.AdditionalGroupId].filter(
(g) => !!g,
),
),
];

const existingGroups = await getExistingGroups(userId, groupIds);

for (const groupId of groupIds.filter((id) => !existingGroups?.includes(id))) {
await postUserGroup(groupId, userId);
}
} catch (err) {
return wrapError(err, messages.UserInvite.Errors.JoiningTeam);
}
try {
if (mapping.Tag) {
//TeamId is the same as O365GroupId
await addTag(mapping.O365GroupId, mapping.Tag, userId);
await addTag(mapping.O365GroupId, getCountryName(user.Country), userId);
}
} catch (err) {
return wrapError(err, messages.UserInvite.Errors.TagsCreation);
}
});
const userMappings = mappings.filter(
(m) =>
(user.Membership && user.Membership.includes(m.Membership)) ||
(user.OtherMemberships && user.OtherMemberships.includes(m.Membership)),
);

//apply user membership and country tag
const userGroupIds = getDistinctGroupsIds(userMappings);
const existingGroups = await getExistingGroups(userId, userGroupIds);
try {
for (const groupId of userGroupIds.filter((id) => !existingGroups?.includes(id))) {
await postUserGroup(groupId, userId);

const groupMapping = userMappings.filter((m) => m.O365GroupId === groupId);
groupMapping[0]?.Tag && addTag(groupId, getCountryName(user.Country), userId);
}
} catch (err) {
return wrapError(err, messages.UserInvite.Errors.JoiningTeam);
}

//apply membership tags
try {
const tags = [...new Set(userMappings.filter((m) => m.Tag))];
for (const m of tags) {
addTag(m.O365GroupId, m.Tag, userId);
}
} catch (err) {
return wrapError(err, messages.UserInvite.Errors.TagsCreation);
}

if (sendMail) {
try {
Expand Down

0 comments on commit e80099e

Please sign in to comment.