Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(GuildChannel): improve empty overwrite handling for permissionsLocked #5821

Merged
merged 3 commits into from Jun 11, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 26 additions & 6 deletions src/structures/GuildChannel.js
Expand Up @@ -95,13 +95,33 @@ class GuildChannel extends Channel {
*/
get permissionsLocked() {
if (!this.parent) return null;
if (this.permissionOverwrites.size !== this.parent.permissionOverwrites.size) return false;
return this.permissionOverwrites.every((value, key) => {
const testVal = this.parent.permissionOverwrites.get(key);

// Get all overwrites
const overwriteIds = new Set([...this.permissionOverwrites.keys(), ...this.parent.permissionOverwrites.keys()]);

// Compare all overwrites
return [...overwriteIds].every(key => {
const channelVal = this.permissionOverwrites.get(key);
const parentVal = this.parent.permissionOverwrites.get(key);

// Handle empty overwrite
if (
(channelVal === undefined &&
parentVal.deny.bitfield === Permissions.defaultBit &&
parentVal.allow.bitfield === Permissions.defaultBit) ||
(parentVal === undefined &&
channelVal.deny.bitfield === Permissions.defaultBit &&
channelVal.allow.bitfield === Permissions.defaultBit)
) {
return true;
}

// Compare overwrites
return (
testVal !== undefined &&
testVal.deny.bitfield === value.deny.bitfield &&
testVal.allow.bitfield === value.allow.bitfield
channelVal !== undefined &&
parentVal !== undefined &&
channelVal.deny.bitfield === parentVal.deny.bitfield &&
channelVal.allow.bitfield === parentVal.allow.bitfield
);
});
}
Expand Down