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

Quick success on permission calculation from allow overwrites #712

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

swarley
Copy link
Contributor

@swarley swarley commented Apr 23, 2020

Closes #700

End calculation early when an allow override is met


Fixed

PermissionCalculator#defined_role_permission?

@GrapeColor
Copy link

What about setting the overwrited flag so that if there is a channel overwrite, that one has priority?

overwrited = false  # add
roles_to_check.sort_by(&:position).reduce(false) do |can_act, role|
  # Get the override defined for the role on the channel
  channel_allow = permission_overwrite(action, channel, role.id)

  # If the channel has an override, check whether it is an allow - if yes,
  # the user can act, if not, it can't
  if channel_allow
    overwrited = true  # add
    return true if channel_allow == :allow

    false
  else
    # Otherwise defer to the role
    !overwrited && role.permissions.instance_variable_get("@#{action}") || can_act  # add
  end
end

@swarley swarley marked this pull request as draft May 2, 2020 23:47
@Daniel-Worrall
Copy link
Contributor

This was merged via shardlab/discordrb@9cc3a26 in the new repo and released in v3.4.0 and can be closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

The calculation result of PermissionCalculator#permission? is incorrect
3 participants