Skip to content
This repository has been archived by the owner on Dec 12, 2021. It is now read-only.

How to differentiate permissions between admin/users_controller and users_controller #1046

Open
vishaltps opened this issue Feb 8, 2017 · 0 comments

Comments

@vishaltps
Copy link

vishaltps commented Feb 8, 2017

#I applied dynamic role and permissions in my application. For that, i used Abilities-in-Database and dynamic-roles-and-permissions-using-cancan
in base_controller.rb

   `class Admin::BaseController < ApplicationController
 include Admin::InheritAction
   before_action :authenticate_user!

  def current_ability
    @current_ability ||= AdminAbility.new(current_user)
 end
   end`

in admin_ability.rb
`
class AdminAbility
include CanCan::Ability

def initialize(user)
user.roles.each do |role|
role.permissions.each do |permission|
if permission.subject_class == "all"
can permission.action.to_sym, permission.subject_class.to_sym
else
can permission.action.to_sym, permission.subject_class.constantize
end

  end

end

end
end
`

User has many roles and role has many permissions. I created a namespace for admin's controllers, like admin/users_controller , i also have another users controller . The admin will manage permissions from the admin/permissions_controller in which admin can assign permissions to any role.

For admin controllers, I checked this Admin Namespace
from wiki and applied in my application.

But the problem is that this only manage permissions for admin name space controller and i want to manage permissions of both admin/users_controller and users_controller from admin/permissions page.
What will be the subject_class for User::registrations_controller ? How can i manage the same controller name from admin side ?
I am stuck in problem since last 2 days. can't figure out what should i do ?

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

No branches or pull requests

1 participant