ActiveAdmin + CanCan + AASM event switcher with AJAX

你离开我真会死。 提交于 2019-12-08 12:37:07

问题


As an admin I have a specific role
I want to see and switch event for object
Depends on my role

Inspired by activeadmin_addons and its Enum Integration I want to make similar functionality for AASM by letting diffent admin users change events depending on their abilities/roles for specific events/statuses in model.


回答1:


Taken from here, please see this link for additional files you need

Prequestites:

Gem: ActiveAdmin, Gem 'active_admin_role', both are installed and working AdminUser model with current_admin_user setup (or similar to your app).

Tested with Rails 5.1.3.

After you finish and deploy/run server you must "Reload" Permissions in admin and enable "event_update" for manager or other than "super_admin" roles.

Smaller addons you'll need to do: (in addition to below attached files)

In your AdminUser model add:

include CanCan::Ability
include ActiveAdminRole::CanCan::Ability

In your table_for (is where you render columns of data):

column 'Our Status' do |auction|
  render 'admin/auctions/event_change', auction: auction
end

In initializers/active_admin.rb or whenever you want

ActiveAdmin::ResourceController.class_eval do
  protected

  def current_ability
    # Match to your current admin user
    @current_ability ||= Ability.new(current_admin_user)
  end
end

also make sure your config:

config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.authorization_adapter = ActiveAdmin::CanCanAdapter
config.cancan_ability_class = 'Ability'

Pardon me if I forgot something, let me know if you have any question or problem !



来源:https://stackoverflow.com/questions/50619383/activeadmin-cancan-aasm-event-switcher-with-ajax

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!