I have 2 of my models , users & company
configured to ActiveAdmin
gem in my ROR 3 app. I want to restrict one of my admin users to have access to only users
model (like he can change password
, username
etc ) but he should not be able to change any data in company
model (like add company, or change no of licenses
for a company etc)
How can I achieve this different access levels based on models?? For now I want one admin user to access all models and one to access only users model
Code snippets:
I have created two admin users.. one tagged as type-super and other as normal. The following code works fine for super admin with full access but for normal admin , it gives error as : This web page has redirect loops
app/admin/companies.rb:
ActiveAdmin.register Company do
index do
column "Company", :name
column :address
column "No. of Subscriptions", :no_of_licenses
column "License Period(Days)", :no_of_days
if authorized?(:update, companies)
default_actions
end
end
filter :name
form do |f|
f.inputs "Company Details" do
f.input :name
f.input :address
f.input :no_of_licenses, :label => 'No of Subscriptions'
f.input :no_of_days, :label => 'License Period(Days)'
end
f.buttons
end
end
app/models/OnlyUser.rb:
class OnlyUser < ActiveAdmin::AuthorizationAdapter
def authorized?(action, subject = nil)
user.super?
end
end
config/initializers/activeadmin.rb:
config.authorization_adapter = "OnlyUser"
app/models/admin_user.rb:
as_enum :admin_type, :normal => 0, :super => 1