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

[FIX] LDAP "Sync Roles" option doesn't work for custom roles #26842

Merged
merged 8 commits into from
Nov 19, 2022
16 changes: 12 additions & 4 deletions apps/meteor/ee/server/lib/ldap/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,8 @@ export class LDAPEEManager extends LDAPManager {
{},
{
projection: {
_updatedAt: 0,
_id: 1,
name: 1,
},
},
).toArray()) as Array<IRole>;
Expand All @@ -223,11 +224,18 @@ export class LDAPEEManager extends LDAPManager {
const userFields = ensureArray<string>(fieldMap[ldapField]);

for await (const userField of userFields) {
const [roleId] = userField.split(/\.(.+)/);
allowedRoles.push(roleId);
const [roleIdOrName] = userField.split(/\.(.+)/);

const role = roles.find((role) => role._id === roleIdOrName) ?? roles.find((role) => role.name === roleIdOrName);

if (role) {
allowedRoles.push(role._id);
}

if (await this.isUserInGroup(ldap, syncUserRolesBaseDN, syncUserRolesFilter, { dn, username }, ldapField)) {
roleList.push(roleId);
if (role) {
roleList.push(role._id);
}
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion apps/meteor/server/models/raw/Roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export class RolesRaw extends BaseRaw<IRole> implements IRolesModel {

findInIds<P>(ids: IRole['_id'][], options?: FindOptions<IRole>): P extends Pick<IRole, '_id'> ? FindCursor<P> : FindCursor<IRole> {
const query: Filter<IRole> = {
name: {
_id: {
$in: ids,
},
};
Expand Down