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
22 changes: 22 additions & 0 deletions apps/meteor/app/statistics/server/lib/statistics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import os from 'os';
import { Analytics, Team, VideoConf, Presence } from '@rocket.chat/core-services';
import type { IRoom, IStats, ISetting } from '@rocket.chat/core-typings';
import { UserStatus } from '@rocket.chat/core-typings';
import { License } from '@rocket.chat/license';
import {
NotificationQueue,
Rooms,
Expand All @@ -25,6 +26,7 @@ import {
Subscriptions,
Users,
LivechatRooms,
AbacAttributes,
} from '@rocket.chat/models';
import { MongoInternals } from 'meteor/mongo';
import moment from 'moment';
Expand Down Expand Up @@ -609,6 +611,26 @@ export const statistics = {
statistics.webRTCEnabledForOmnichannel = settings.get('Omnichannel_call_provider') === 'WebRTC';
statistics.omnichannelWebRTCCalls = await Rooms.findCountOfRoomsWithActiveCalls();

// ABAC stats
if (License.hasModule('abac')) {
statistics.abacEnabled = settings.get('ABAC_Enabled');
statsPms.push(
AbacAttributes.estimatedDocumentCount().then((result) => {
statistics.abacTotalAttributes = result;
}),
);
statsPms.push(
AbacAttributes.countTotalValues().then((result) => {
statistics.abacTotalAttributeValues = result;
}),
);
statsPms.push(
Rooms.countAbacEnabled().then((result) => {
statistics.abacRoomsEnrolled = result;
}),
);
}

await Promise.all(statsPms).catch(log);

return statistics;
Expand Down
4 changes: 4 additions & 0 deletions packages/core-typings/src/IStats.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,4 +271,8 @@ export interface IStats {
totalUpsellViews: number;
totalUpsellClicks: number;
};
abacEnabled?: boolean;
abacTotalAttributes?: number;
abacTotalAttributeValues?: number;
abacRoomsEnrolled?: number;
}
1 change: 1 addition & 0 deletions packages/model-typings/src/models/IAbacAttributesModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ import type { IBaseModel } from './IBaseModel';
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface IAbacAttributesModel extends IBaseModel<IAbacAttribute> {
findOneByKey(key: string, options?: FindOptions<IAbacAttribute>): Promise<IAbacAttribute | null>;
countTotalValues(): Promise<number>;
}
2 changes: 2 additions & 0 deletions packages/model-typings/src/models/IRoomsModel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,8 @@ export interface IRoomsModel extends IBaseModel<IRoom> {

findByBroadcast(options?: FindOptions<IRoom>): FindCursor<IRoom>;

countAbacEnabled(): Promise<number>;

setAsFederated(roomId: IRoom['_id'], { mrid, origin }: { mrid: string; origin: string }): Promise<UpdateResult>;

setRoomTypeById(roomId: IRoom['_id'], roomType: IRoom['t']): Promise<UpdateResult>;
Expand Down
21 changes: 21 additions & 0 deletions packages/models/src/models/AbacAttributes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,25 @@ export class AbacAttributesRaw extends BaseRaw<IAbacAttribute> {
findOneByKey(key: string, options: FindOptions<IAbacAttribute> = {}): Promise<IAbacAttribute | null> {
return this.findOne({ key }, options);
}

async countTotalValues(): Promise<number> {
const [result] = await this.col
.aggregate<{ totalValues: number }>([
{
$group: {
_id: null,
totalValues: {
$sum: {
$size: {
$ifNull: ['$values', []],
},
},
},
},
},
])
.toArray();

return result?.totalValues ?? 0;
}
}
4 changes: 4 additions & 0 deletions packages/models/src/models/Rooms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2312,4 +2312,8 @@ export class RoomsRaw extends BaseRaw<IRoom> implements IRoomsModel {
// TODO implement
return [];
}

countAbacEnabled(): Promise<number> {
return this.countDocuments({ abacAttributes: { $exists: true }, archived: { $ne: true } });
}
}
Loading