The communications platform that puts data protection first.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
Rocket.Chat/app/statistics/server/lib/getMostImportantRole.js

47 lines
792 B

const order = [
'admin',
'livechat-manager',
'livechat-monitor',
'livechat-agent',
'custom-role',
'user',
'app',
'bot',
'guest',
'anonymous',
];
const rolesToConsiderAsUser = [
'auditor',
'auditor-log',
];
export function getMostImportantRole(roles = []) {
if (!roles.length) {
return 'no-role';
}
roles = roles.map((r) => (rolesToConsiderAsUser.includes(r) ? 'user' : r));
if (roles.length === 1) {
if (!order.includes(roles[0])) {
return 'custom-role';
}
return roles[0];
}
const newRoles = [];
for (const role of roles) {
if (order.includes(role)) {
newRoles.push(role);
} else if (!newRoles.includes('custom-role')) {
newRoles.push('custom-role');
}
}
for (const item of order) {
if (newRoles.includes(item)) {
return item;
}
}
}