move permission stuff to the resolver (#1185)

This commit is contained in:
Gus Caplan
2017-02-22 14:11:11 -06:00
committed by Amish Shah
parent f01b3f922d
commit 566135d25b
2 changed files with 17 additions and 9 deletions

View File

@@ -217,6 +217,20 @@ class ClientDataResolver {
return bitfield; return bitfield;
} }
hasPermission(bitfield, name, explicit = false) {
const permission = this.resolvePermission(name);
if (!explicit && (bitfield & Constants.PermissionFlags.ADMINISTRATOR) > 0) return true;
return (bitfield & permission) > 0;
}
serializePermissions(bitfield) {
const serializedPermissions = {};
for (const name in Constants.PermissionFlags) {
serializedPermissions[name] = this.hasPermission(bitfield, name);
}
return serializedPermissions;
}
/** /**
* Data that can be resolved to give a string. This can be: * Data that can be resolved to give a string. This can be:
* * A string * * A string

View File

@@ -140,11 +140,7 @@ class Role {
* console.log(role.serialize()); * console.log(role.serialize());
*/ */
serialize() { serialize() {
const serializedPermissions = {}; return this.client.resolver.serializePermissions(this.permissions);
for (const permissionName in Constants.PermissionFlags) {
serializedPermissions[permissionName] = this.hasPermission(permissionName);
}
return serializedPermissions;
} }
/** /**
@@ -160,10 +156,8 @@ class Role {
* console.log('This role can\'t ban members'); * console.log('This role can\'t ban members');
* } * }
*/ */
hasPermission(permission, explicit = false) { hasPermission(permission, explicit) {
permission = this.client.resolver.resolvePermission(permission); return this.client.resolver.hasPermission(this.permissions, permission, explicit);
if (!explicit && (this.permissions & Constants.PermissionFlags.ADMINISTRATOR) > 0) return true;
return (this.permissions & permission) > 0;
} }
/** /**