Module: MnoEnterprise::Concerns::Models::Ability
- Extended by:
- ActiveSupport::Concern
- Included in:
- Ability
- Defined in:
- lib/mno_enterprise/concerns/models/ability.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
-
#admin_abilities(user) ⇒ Object
Abilities for admin user.
-
#impac_abilities(orgs_with_acl) ⇒ Object
Enables / disables Impac! Angular capabilities.
-
#initialize(user, session) ⇒ Object
Instance methods ==================================================================.
Instance Method Details
#admin_abilities(user) ⇒ Object
Abilities for admin user
174 175 176 177 178 179 |
# File 'lib/mno_enterprise/concerns/models/ability.rb', line 174 def admin_abilities(user) if user.admin_role.to_s.casecmp('admin').zero? || user.admin_role.to_s.casecmp('staff').zero? can :manage_app_instances, MnoEnterprise::Organization can :manage_sub_tenant, MnoEnterprise::SubTenant end end |
#impac_abilities(orgs_with_acl) ⇒ Object
Enables / disables Impac! Angular capabilities
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 |
# File 'lib/mno_enterprise/concerns/models/ability.rb', line 108 def impac_abilities(orgs_with_acl) can :create_impac_dashboards, MnoEnterprise::Impac::Dashboard do |d| orgs = d.organizations(orgs_with_acl) orgs.present? && orgs.all? do |org| org.acl[:related] && org.acl[:related][:dashboards] && org.acl[:related][:dashboards][:create] end end can :update_impac_dashboards, MnoEnterprise::Impac::Dashboard do |d| orgs = d.organizations(orgs_with_acl) orgs.present? && orgs.all? do |org| org.acl[:related] && org.acl[:related][:dashboards] && org.acl[:related][:dashboards][:update] end end can :destroy_impac_dashboards, MnoEnterprise::Impac::Dashboard do |d| orgs = d.organizations(orgs_with_acl) orgs.present? && orgs.all? do |org| org.acl[:related] && org.acl[:related][:dashboards] && org.acl[:related][:dashboards][:destroy] end end can :create_impac_widgets, MnoEnterprise::Impac::Widget do |w| orgs = w.organizations(orgs_with_acl) orgs.present? && orgs.all? do |org| org.acl[:related] && org.acl[:related][:widgets] && org.acl[:related][:widgets][:create] end end can :update_impac_widgets, MnoEnterprise::Impac::Widget do |w| orgs = w.organizations(orgs_with_acl) orgs.present? && orgs.all? do |org| org.acl[:related] && org.acl[:related][:widgets] && org.acl[:related][:widgets][:update] end end can :destroy_impac_widgets, MnoEnterprise::Impac::Widget do |w| orgs = w.organizations(orgs_with_acl) orgs.present? && orgs.all? do |org| org.acl[:related] && org.acl[:related][:widgets] && org.acl[:related][:widgets][:destroy] end end can :create_impac_kpis, MnoEnterprise::Impac::Kpi do |k| orgs = k.organizations(orgs_with_acl) orgs.present? && orgs.all? do |org| org.acl[:related] && org.acl[:related][:kpis] && org.acl[:related][:kpis][:create] end end can :update_impac_kpis, MnoEnterprise::Impac::Kpi do |k| orgs = k.organizations(orgs_with_acl) orgs.present? && orgs.all? do |org| org.acl[:related] && org.acl[:related][:kpis] && org.acl[:related][:kpis][:update] end end can :destroy_impac_kpis, MnoEnterprise::Impac::Kpi do |k| orgs = k.organizations(orgs_with_acl) orgs.present? && orgs.all? do |org| org.acl[:related] && org.acl[:related][:kpis] && org.acl[:related][:kpis][:destroy] end end end |
#initialize(user, session) ⇒ Object
Instance methods
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/mno_enterprise/concerns/models/ability.rb', line 22 def initialize(user, session) user ||= MnoEnterprise::User.new #=================================================== # Organization #=================================================== can :create, MnoEnterprise::Organization can :read, MnoEnterprise::Organization do |organization| !!user.role(organization) end can [:update, :destroy, :manage_billing], MnoEnterprise::Organization do |organization| user.role(organization) == 'Super Admin' end can [:upload, :purchase, :invite_member, :administrate, :manage_app_instances, :manage_teams], MnoEnterprise::Organization do |organization| ['Super Admin','Admin'].include? user.role(organization) end # To be updated can :sync_apps, MnoEnterprise::Organization do |organization| user.role(organization) end # To be updated can :check_apps_sync, MnoEnterprise::Organization do |organization| user.role(organization) end #=================================================== # AppInstance #=================================================== can :access, MnoEnterprise::AppInstance do |app_instance| !!user.role(app_instance.owner) && ( ['Super Admin','Admin'].include?(user.role(app_instance.owner)) || user.teams.empty? || user.teams.map(&:app_instances).compact.flatten.map(&:id).include?(app_instance.id) ) end #=================================================== # Impac #=================================================== orgs_with_acl = user.organizations.active.include_acl(session[:impersonator_user_id]).to_a impac_abilities(orgs_with_acl) #=================================================== # Admin abilities #=================================================== admin_abilities(user) # Define abilities for the passed in user here. For example: # # user ||= User.new # guest user (not logged in) # if user.admin? # can :manage, :all # else # can :read, :all # end # # The first argument to `can` is the action you are giving the user # permission to do. # If you pass :manage it will apply to every action. Other common actions # here are :read, :create, :update and :destroy. # # The second argument is the resource the user can perform the action on. # If you pass :all it will apply to every resource. Otherwise pass a Ruby # class of the resource. # # The third argument is an optional hash of conditions to further filter the # objects. # For example, here the user can only update published articles. # # can :update, Article, :published => true # # See the wiki for details: # https://github.com/CanCanCommunity/cancancan/wiki/Defining-Abilities end |