You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'd love to try for a PR, maybe someone can give me some guidance where to start:
We have a table with a jsonb column, that has a GIN index on it and stores various information. I'd like to define abilities based on fields inside that jsonb column.
How would one implement such a feature in cancancan? I know that I can pass scopes to abilities, but that doesn't solve calls like can?(:index, product) and they are not mergeable. So supporting jsonb columns the same way normale columns are supported would be awesome.
This gist should describe what I want to achieve:
require"bundler/inline"gemfile(true)dosource"https://rubygems.org"gem"rails","= 7.1.5.1"gem"cancancan","= 3.6.1",require: false# require false to force rails to be required firstendrequire"active_record"require"cancancan"require"minitest/autorun"require"logger"ActiveRecord::Base.establish_connection(adapter: "postgresql",database: "test",username: "postgres",password: "password",host: "localhost")ActiveRecord::Base.logger=Logger.new(STDOUT)ActiveRecord::Schema.definedodrop_table:products,if_exists: truecreate_table:products,force: truedo |t|
t.jsonb:dataendendclassProduct < ActiveRecord::Base;endclassAbilityincludeCanCan::Abilitydefinitializecan:index,Product,data: {shop_id: 1}endendclassBugTest < Minitest::Testdeftest_bugproduct=Product.create!(data: {shop_id: 1})ability=Ability.newassert_equal[product],Product.accessible_by(ability,:index).to_aendend
The text was updated successfully, but these errors were encountered:
I'd love to try for a PR, maybe someone can give me some guidance where to start:
We have a table with a jsonb column, that has a GIN index on it and stores various information. I'd like to define abilities based on fields inside that jsonb column.
How would one implement such a feature in cancancan? I know that I can pass scopes to abilities, but that doesn't solve calls like
can?(:index, product)
and they are not mergeable. So supporting jsonb columns the same way normale columns are supported would be awesome.This gist should describe what I want to achieve:
The text was updated successfully, but these errors were encountered: