Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
23 changes: 22 additions & 1 deletion apps/meteor/ee/server/lib/ldap/Manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,6 +358,11 @@ export class LDAPEEManager extends LDAPManager {
return;
}

if (settings.get('ABAC_Enabled') && room?.abacAttributes?.length) {
logger.error({ msg: 'Cannot add user to channel. Channel is ABAC managed', userChannelName });
continue;
}

if (room.teamMain) {
logger.error(`Can't add user to channel ${userChannelName} because it is a team.`);
} else {
Expand Down Expand Up @@ -430,7 +435,23 @@ export class LDAPEEManager extends LDAPManager {
});
const currentTeamIds = currentTeams?.map(({ teamId }) => teamId);
const teamsToRemove = currentTeamIds?.filter((teamId) => notInTeamIds.includes(teamId));
const teamsToAdd = inTeamIds.filter((teamId) => !currentTeamIds?.includes(teamId));
let teamsToAdd = inTeamIds.filter((teamId) => !currentTeamIds?.includes(teamId));

if (settings.get('ABAC_Enabled')) {
const roomsWithAbacAttributes = await Rooms.findPrivateRoomsByIdsWithAbacAttributes(
allTeams.filter((t) => teamsToAdd.includes(t._id)).map((t) => t.roomId),
{ projection: { teamId: 1 } },
)
.map((r) => r.teamId)
.toArray();

logger.debug({ msg: 'Some teams will be ignored from sync because they are abac managed', roomsWithAbacAttributes });

teamsToAdd = teamsToAdd.filter((teamId) => !roomsWithAbacAttributes.includes(teamId));
if (!teamsToAdd.length) {
return;
}
}

await Team.insertMemberOnTeams(user._id, teamsToAdd);
if (teamsToRemove) {
Expand Down
1 change: 1 addition & 0 deletions packages/model-typings/src/models/IRoomsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export interface IRoomsModel extends IBaseModel<IRoom> {
findByIds(rids: string[], options?: FindOptions<IRoom>): FindCursor<IRoom>;
findByType(type: IRoom['t'], options?: FindOptions<IRoom>): FindCursor<IRoom>;
findByTypeInIds(type: IRoom['t'], ids: string[], options?: FindOptions<IRoom>): FindCursor<IRoom>;
findPrivateRoomsByIdsWithAbacAttributes(ids: string[], options?: FindOptions<IRoom>): FindCursor<IRoom>;
findBySubscriptionUserId(userId: string, options?: FindOptions<IRoom>): Promise<FindCursor<IRoom>>;
findBySubscriptionUserIdUpdatedAfter(userId: string, updatedAfter: Date, options?: FindOptions<IRoom>): Promise<FindCursor<IRoom>>;
findByNameAndTypeNotDefault(
Expand Down
10 changes: 10 additions & 0 deletions packages/models/src/models/Rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1268,6 +1268,16 @@ export class RoomsRaw extends BaseRaw<IRoom> implements IRoomsModel {
return this.find(query, options);
}

findPrivateRoomsByIdsWithAbacAttributes(ids: Array<IRoom['_id']>, options: FindOptions<IRoom> = {}): FindCursor<IRoom> {
const query: Filter<IRoom> = {
_id: { $in: ids },
t: 'p',
abacAttributes: { $exists: true, $ne: [] },
};

return this.find(query, options);
}

async findBySubscriptionUserId(userId: IUser['_id'], options: FindOptions<IRoom> = {}): Promise<FindCursor<IRoom>> {
const data = (await Subscriptions.findByUserId(userId, { projection: { rid: 1 } }).toArray()).map((item) => item.rid);

Expand Down
Loading