если вы просто сделаете это, у вас возникнут проблемы?
# ability.db
def initialize(user)
case
# ...
when user.super_admin?
can :manage, :all
when user.admin?
can :manage, Profile, :institution_id => user.institution.id
#
# ...
end
это позволит: Profile.accessible_by(current_user)
, что здесь совпадает с current_user.profiles
class AdminUser
has_one :institution
has_many :profiles, :through => :institution
end
ActiveAdmin.register Profile do
scope_to :current_user #here comes the variable which set in initializer
end
если вы хотите, чтобы суперадмин имел доступ ко всем сообщениям, вы можете использовать опцию :association_method
ActiveAdmin.register Profile do
scope_to :current_user, :association_method => :admin_profiles
end
# in class User
def admin_profiles
if super_admin?
Profile.unscoped
else
profiles
end
end
Хитрое решение может обобщить это и использовать класс делегатора в качестве прокси, чтобы отменить все модели для суперадминистраторов. могу расписать по запросу.
person
Viktor Trón
schedule
30.05.2012