Class: Locomotive::Ability
- Inherits:
-
Object
- Object
- Locomotive::Ability
- Includes:
- CanCan::Ability
- Defined in:
- app/models/locomotive/ability.rb
Constant Summary collapse
- ROLES =
%w(admin designer author)
Instance Method Summary collapse
-
#initialize(account, site) ⇒ Ability
constructor
A new instance of Ability.
- #setup_admin_permissions! ⇒ Object
- #setup_author_permissions! ⇒ Object
- #setup_default_permissions! ⇒ Object
- #setup_designer_permissions! ⇒ Object
Constructor Details
#initialize(account, site) ⇒ Ability
Returns a new instance of Ability.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'app/models/locomotive/ability.rb', line 7 def initialize(account, site) @account, @site = account, site alias_action :index, :show, :edit, :update, :to => :touch if @site @membership = @site.memberships.where(:account_id => @account.id).first elsif @account.admin? @membership = Membership.new(:account => @account, :role => 'admin') end return false if @membership.nil? if @membership.admin? else if @membership.designer? if @membership. end end |
Instance Method Details
#setup_admin_permissions! ⇒ Object
81 82 83 84 85 86 87 |
# File 'app/models/locomotive/ability.rb', line 81 def can :manage, :all cannot [:update, :destroy], Membership do |membership| @membership.account_id == membership.account_id # can not edit myself end end |
#setup_author_permissions! ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/models/locomotive/ability.rb', line 35 def can :touch, [Page, ThemeAsset] can :sort, Page can :manage, [ContentEntry, ContentAsset, Translation] can :touch, Site do |site| site == @site end can :read, ContentType end |
#setup_default_permissions! ⇒ Object
31 32 33 |
# File 'app/models/locomotive/ability.rb', line 31 def cannot :manage, :all end |
#setup_designer_permissions! ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'app/models/locomotive/ability.rb', line 48 def can :manage, Page can :manage, ContentEntry can :manage, ContentType can :manage, Snippet can :manage, ThemeAsset can :manage, ContentAsset can :manage, Translation can :manage, Site do |site| site == @site end can :point, Site cannot :create, Site can :manage, Membership cannot :grant_admin, Membership cannot [:update, :destroy], Membership do |membership| @membership.account_id == membership.account_id || # can not edit myself membership.admin? # can not modify an administrator end end |