Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.

Commit

Permalink
Fix: Permissions for global roles
Browse files Browse the repository at this point in the history
  • Loading branch information
thedark1337 committed Oct 11, 2017
1 parent 5a5fbb6 commit 4c2c545
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions lib/room.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,6 @@ class Room {
*/
getPermissions(other) {
const me = this.getSelf();

const permissions = {
canModChat: false,
canModMute: false,
Expand All @@ -219,24 +218,15 @@ class Room {
};

if (Object.is(other, null) || Object.is(me, null)) return permissions;
const isAdmin = Object.is(me.gRole, constants.GLOBAL_ROLES.ADMIN);
const isGreaterRole = Math.max(me.role, me.gRole) > Math.max(other.role, other.gRole);

if (Object.is(other.gRole, constants.GLOBAL_ROLES.NONE)) {
if (Object.is(me.gRole, constants.GLOBAL_ROLES.ADMIN)) {
permissions.canModChat = true;
permissions.canModBan = true;
} else {
permissions.canModChat = me.role > constants.ROOM_ROLE.RESIDENTDJ && Math.max(me.role, me.gRole) > other.role;
permissions.canModBan = me.role > other.role;
}
if ((other.gRole < constants.GLOBAL_ROLES.MODERATOR && isGreaterRole) || isAdmin) {
permissions.canModChat = true;
permissions.canModBan = true;
permissions.canModMute = true;
}

if (Object.is(me.gRole, constants.GLOBAL_ROLES.ADMIN)) {
permissions.canModStaff = true;
} else if (!Object.is(other.gRole, constants.GLOBAL_ROLES.ADMIN)) {
permissions.canModStaff = Math.max(me.role, me.gRole) > Math.max(other.role, other.gRole);
}

permissions.canModMute = !(other.role > constants.ROOM_ROLE.NONE || other.gRole > constants.GLOBAL_ROLES.NONE);
permissions.canModStaff = other.gRole < constants.GLOBAL_ROLES.ADMIN && (isGreaterRole || isAdmin);

return permissions;
}
Expand Down

0 comments on commit 4c2c545

Please sign in to comment.