Class: Ibrain::Policies::BasePolicy
- Inherits:
-
Object
- Object
- Ibrain::Policies::BasePolicy
- Defined in:
- app/graphql/ibrain/policies/base_policy.rb
Direct Known Subclasses
Class Method Summary collapse
- .guard(type, field) ⇒ Object
- .has_permission?(current_user, resource) ⇒ Boolean
- .mutation_rules ⇒ Object
- .not_authorized_handler(type, field) ⇒ Object
- .query_rules ⇒ Object
- .roles ⇒ Object
- .rules ⇒ Object
Class Method Details
.guard(type, field) ⇒ Object
41 42 43 |
# File 'app/graphql/ibrain/policies/base_policy.rb', line 41 def guard(type, field) rules.dig(type.name, field, :guard) end |
.has_permission?(current_user, resource) ⇒ Boolean
34 35 36 37 38 39 |
# File 'app/graphql/ibrain/policies/base_policy.rb', line 34 def (current_user, resource) return false if current_user.blank? return true if current_user.super_admin? current_user.try(:scope).to_s.split(',').include?(resource) end |
.mutation_rules ⇒ Object
15 16 17 18 19 20 21 |
# File 'app/graphql/ibrain/policies/base_policy.rb', line 15 def mutation_rules { '*': { guard: ->(_obj, _args, _ctx) { false } } } end |
.not_authorized_handler(type, field) ⇒ Object
45 46 47 |
# File 'app/graphql/ibrain/policies/base_policy.rb', line 45 def (type, field) rules.dig(type, field, :not_authorized) || rules.dig(type, :*, :not_authorized) end |
.query_rules ⇒ Object
7 8 9 10 11 12 13 |
# File 'app/graphql/ibrain/policies/base_policy.rb', line 7 def query_rules { '*': { guard: ->(_obj, _args, _ctx) { false } } } end |
.roles ⇒ Object
30 31 32 |
# File 'app/graphql/ibrain/policies/base_policy.rb', line 30 def roles Ibrain.user_class.roles.keys end |
.rules ⇒ Object
23 24 25 26 27 28 |
# File 'app/graphql/ibrain/policies/base_policy.rb', line 23 def rules { 'Types::QueryType' => query_rules, 'Types::MutationType' => mutation_rules }.freeze end |