Class: Decidim::DecidimAwesome::AccessAuthorizationService
- Inherits:
-
Object
- Object
- Decidim::DecidimAwesome::AccessAuthorizationService
- Defined in:
- app/services/decidim/decidim_awesome/access_authorization_service.rb
Instance Attribute Summary collapse
-
#authorization_groups ⇒ Object
readonly
Returns the value of attribute authorization_groups.
-
#organization ⇒ Object
readonly
Returns the value of attribute organization.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
- #adapters ⇒ Object
- #authorization_handlers ⇒ Object
- #authorization_status(method) ⇒ Object
- #granted? ⇒ Boolean
-
#initialize(user, organization, authorization_groups = []) ⇒ AccessAuthorizationService
constructor
A new instance of AccessAuthorizationService.
Constructor Details
#initialize(user, organization, authorization_groups = []) ⇒ AccessAuthorizationService
Returns a new instance of AccessAuthorizationService.
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'app/services/decidim/decidim_awesome/access_authorization_service.rb', line 6 def initialize(user, organization, = []) @user = user @organization = organization @available_handlers = organization. & Decidim..map(&:name) @authorization_groups = .filter_map do |group| group.filter_map do |handler, | next unless @available_handlers.include?(handler) [handler, ] end.to_h end.compact_blank end |
Instance Attribute Details
#authorization_groups ⇒ Object (readonly)
Returns the value of attribute authorization_groups.
19 20 21 |
# File 'app/services/decidim/decidim_awesome/access_authorization_service.rb', line 19 def @authorization_groups end |
#organization ⇒ Object (readonly)
Returns the value of attribute organization.
19 20 21 |
# File 'app/services/decidim/decidim_awesome/access_authorization_service.rb', line 19 def organization @organization end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
19 20 21 |
# File 'app/services/decidim/decidim_awesome/access_authorization_service.rb', line 19 def user @user end |
Instance Method Details
#adapters ⇒ Object
43 44 45 |
# File 'app/services/decidim/decidim_awesome/access_authorization_service.rb', line 43 def adapters @authorizations ||= adapters_for() end |
#authorization_handlers ⇒ Object
35 36 37 38 39 40 41 |
# File 'app/services/decidim/decidim_awesome/access_authorization_service.rb', line 35 def @authorization_handlers ||= .flat_map do |group| next unless group.is_a?(Hash) group.keys end.uniq end |
#authorization_status(method) ⇒ Object
47 48 49 |
# File 'app/services/decidim/decidim_awesome/access_authorization_service.rb', line 47 def (method) ({ method => .flat_map { |group| group[method] } }).first end |
#granted? ⇒ Boolean
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/services/decidim/decidim_awesome/access_authorization_service.rb', line 21 def granted? return false unless user return true if .blank? # if one group is authorized that's ok # inside a group, all adapters must be authorized .detect do |group| statuses = (group) next if statuses.blank? statuses.all? { |status| status == :ok } end end |