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

inconsistent behaviour with Hash subjects #811

Open
christian-toscano opened this issue Jan 18, 2023 · 0 comments
Open

inconsistent behaviour with Hash subjects #811

christian-toscano opened this issue Jan 18, 2023 · 0 comments

Comments

@christian-toscano
Copy link

christian-toscano commented Jan 18, 2023

Hi everyone, I'm having a few issues using cancancan with graphql-ruby, I've opened a issue on that project too but I'm here to ask if this is the expected behaviour and if you can suggest a way to handle it.

issue on graphql-ruby

When I check permissions this hash:

{
	search: Search.new, # an active record model
	configuration: { my_field: 1 }
}

I receive the hash inside the Ability block that should check permissions on the Search type

can :read, Search do |search|
	# search is a Hash instead of a Search
end

because the code is changing the subject using subject = subject.values.first if subject.class == Hash but it passes the old subject to the validation block

Steps to reproduce

this code shows the issue, it will print Hash since we are receiving a Hash instead of a Search

class Search < ActiveRecord::Base
end

class Ability
  include CanCan::Ability

  attr_accessor :user

  def initialize
    can :read, Search do |search|
      puts search.class
      true
    end
  end
end

Ability.new.can?(:read, { search: Search.new, configuration: {field: 'hello' }})

Expected behavior

I expected the can :read, Search to be called with a Search

Actual behavior

can :read, Search is being called with a Hash

System configuration

Rails version:
6.1.7

Ruby version:
3.0.2

CanCanCan version
cancancan 3.4.0

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

No branches or pull requests

1 participant