2011-06-25 16:25:31 +00:00
|
|
|
class Ability
|
|
|
|
include CanCan::Ability
|
|
|
|
|
2011-06-27 15:27:07 +00:00
|
|
|
ROLES = %w(admin designer author)
|
2011-06-25 16:25:31 +00:00
|
|
|
|
|
|
|
def initialize(account, site)
|
|
|
|
@account, @site = account, site
|
|
|
|
|
|
|
|
alias_action :index, :show, :edit, :update, :to => :touch
|
|
|
|
|
|
|
|
@membership = @site.memberships.where(:account_id => @account.id).first
|
|
|
|
|
|
|
|
return false if @membership.blank?
|
|
|
|
|
|
|
|
if @membership.admin?
|
|
|
|
setup_admin_permissions!
|
|
|
|
else
|
|
|
|
setup_default_permissions!
|
|
|
|
|
|
|
|
setup_designer_permissions! if @membership.designer?
|
|
|
|
|
|
|
|
setup_author_permissions! if @membership.author?
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_default_permissions!
|
|
|
|
cannot :manage, :all
|
|
|
|
end
|
|
|
|
|
|
|
|
def setup_author_permissions!
|
|
|
|
can :touch, [Page, ThemeAsset]
|
|
|
|
can :sort, Page
|
|
|
|
|
|
|
|
can :manage, [ContentInstance, Asset]
|
2011-06-26 23:02:48 +00:00
|
|
|
|
|
|
|
can :touch, Site do |site|
|
|
|
|
site == @site
|
|
|
|
end
|
2011-06-25 16:25:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def setup_designer_permissions!
|
|
|
|
can :manage, Page
|
|
|
|
|
|
|
|
can :manage, ContentInstance
|
|
|
|
|
|
|
|
can :manage, ContentType
|
|
|
|
|
2011-06-27 15:27:07 +00:00
|
|
|
can :manage, Snippet
|
|
|
|
|
2011-06-25 16:25:31 +00:00
|
|
|
can :manage, ThemeAsset
|
|
|
|
|
2011-07-19 14:20:53 +00:00
|
|
|
can :manage, Asset
|
|
|
|
|
2011-06-26 23:02:48 +00:00
|
|
|
can :manage, Site do |site|
|
|
|
|
site == @site
|
|
|
|
end
|
2011-06-25 16:25:31 +00:00
|
|
|
|
2011-06-27 15:27:07 +00:00
|
|
|
can :import, Site
|
|
|
|
|
2011-07-04 13:25:02 +00:00
|
|
|
can :export, Site
|
|
|
|
|
2011-06-27 15:27:07 +00:00
|
|
|
can :point, Site
|
|
|
|
|
2011-06-25 16:25:31 +00:00
|
|
|
can :manage, Membership
|
2011-07-06 18:48:04 +00:00
|
|
|
|
|
|
|
cannot :change_role, Membership do |membership|
|
|
|
|
@membership.account_id == membership.account_id || # can not edit myself
|
|
|
|
membership.admin? # can not modify an administrator
|
|
|
|
end
|
2011-06-25 16:25:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def setup_admin_permissions!
|
|
|
|
can :manage, :all
|
2011-07-06 18:48:04 +00:00
|
|
|
|
|
|
|
cannot :change_role, Membership do |membership|
|
|
|
|
@membership.account_id == membership.account_id # can not edit myself
|
|
|
|
end
|
2011-06-25 16:25:31 +00:00
|
|
|
end
|
|
|
|
end
|