I'm doing this in preparation for the "Manager" ability, which will require even more refactors of the abilities (for example, manager can not modify their own account)
23 lines
544 B
Ruby
23 lines
544 B
Ruby
class Ability
|
|
include CanCan::Ability
|
|
|
|
def initialize(user)
|
|
# If someone can hide something, he can also hide it
|
|
# from the moderation screen
|
|
alias_action :hide_in_moderation_screen, to: :hide
|
|
|
|
if user # logged-in users
|
|
if user.administrator?
|
|
self.merge Abilities::Administrator.new(user)
|
|
elsif user.moderator?
|
|
self.merge Abilities::Moderator.new(user)
|
|
else
|
|
self.merge Abilities::Common.new(user)
|
|
end
|
|
else
|
|
self.merge Abilities::Everyone.new(user)
|
|
end
|
|
end
|
|
|
|
end
|