Skip to content

Commit eaf6778

Browse files
committed
Make AEM Permissions email based
1 parent 94369a1 commit eaf6778

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

nx/blocks/permissions/utils/utils.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ function compareRoles(aemUser, daUser) {
133133
export function combineUsers(daUsers, aemUsers) {
134134
// Combine up all the existing AEM users that have new requests
135135
const combined = aemUsers.reduce((acc, aemUser) => {
136-
const foundUser = daUsers.find((daUser) => daUser.id === aemUser.email);
136+
const foundUser = daUsers.find((daUser) => daUser.email === aemUser.email);
137137

138138
// If user wasn't found in DA users, push them to aemUsers.
139139
if (!foundUser) {
@@ -149,8 +149,8 @@ export function combineUsers(daUsers, aemUsers) {
149149
}, { daUsers: [], aemUsers: [] });
150150

151151
const onlyRequests = daUsers.filter((daUser) => {
152-
const inDaCombined = combined.daUsers.find((user) => daUser.id === user.id);
153-
const inAemCombined = combined.aemUsers.find((user) => daUser.id === user.id);
152+
const inDaCombined = combined.daUsers.find((user) => daUser.email === user.email);
153+
const inAemCombined = combined.aemUsers.find((user) => daUser.email === user.email);
154154
return !inDaCombined && !inAemCombined && daUser.requested.length > 0;
155155
});
156156

@@ -201,16 +201,18 @@ async function approveSiteUser(org, site, path, user) {
201201

202202
if (found) {
203203
// If found, check to see if the user is already in the list.
204-
const exists = existingRoleUsers.some((existingUser) => existingUser === user.id);
204+
const exists = existingRoleUsers.some((existingUser) => existingUser === user.email);
205205

206206
// It's possible there's nothing in the role, so set it if the user isn't already there
207-
if (!exists) json.admin.role[role] = [...existingRoleUsers, user.id];
207+
if (!exists) json.admin.role[role] = [...existingRoleUsers, user.email];
208208
} else {
209209
// Check to see if there are existing users in the current role
210210
if (!existingRoleUsers.length) return;
211211

212212
// Ensure this user is removed if they've had the role taken away from them
213-
json.admin.role[role] = existingRoleUsers.filter((existingUser) => existingUser !== user.id);
213+
json.admin.role[role] = existingRoleUsers.filter(
214+
(existingUser) => existingUser !== user.email,
215+
);
214216
}
215217
});
216218

@@ -223,13 +225,13 @@ async function approveSiteUser(org, site, path, user) {
223225
}
224226

225227
async function approveOrgUser(org, path, user) {
226-
const { id, aemId, requested = [], roles = [] } = user;
228+
const { email, aemId, requested = [], roles = [] } = user;
227229
const approvedRoles = [...new Set([...requested, ...roles])];
228230

229231
const pathBase = `/config/${org}/users`;
230232
const aemPath = aemId ? `${pathBase}/${aemId}.json` : `${pathBase}.json`;
231233

232-
const json = { email: id, roles: approvedRoles };
234+
const json = { email, roles: approvedRoles };
233235
if (aemId) json.id = aemId;
234236

235237
await clearRequests(path, user);

0 commit comments

Comments
 (0)