Class: FileAuthorizationHandler
- Inherits:
-
Decidim::AuthorizationHandler
- Object
- Decidim::AuthorizationHandler
- FileAuthorizationHandler
- Defined in:
- app/services/file_authorization_handler.rb
Overview
An AuthorizationHandler that uses information uploaded from a CSV file to authorize against the age of the user
Instance Method Summary collapse
- #authorized? ⇒ Boolean
-
#censed ⇒ Object
Checks if the id_document belongs to the census.
- #census_for_user ⇒ Object
-
#handler_name ⇒ Object
This is required in new 0.8.4 version of decicim however, there’s a bug and this doesn’t work.
-
#initialize(params) ⇒ FileAuthorizationHandler
constructor
Customized constructor to support decidim-initiatives.
- #metadata ⇒ Object
- #organization ⇒ Object
- #unique_id ⇒ Object
Constructor Details
#initialize(params) ⇒ FileAuthorizationHandler
Customized constructor to support decidim-initiatives.
17 18 19 20 |
# File 'app/services/file_authorization_handler.rb', line 17 def initialize(params) params[:id_document] = params.delete(:document_number) unless params.has_key?(:id_document) super(params) end |
Instance Method Details
#authorized? ⇒ Boolean
45 46 47 |
# File 'app/services/file_authorization_handler.rb', line 45 def return true if census_for_user end |
#censed ⇒ Object
Checks if the id_document belongs to the census
39 40 41 42 43 |
# File 'app/services/file_authorization_handler.rb', line 39 def censed return if census_for_user&.birthdate == birthdate errors.add(:id_document, I18n.t("decidim.file_authorization_handler.errors.messages.not_censed")) end |
#census_for_user ⇒ Object
55 56 57 58 59 60 |
# File 'app/services/file_authorization_handler.rb', line 55 def census_for_user return unless organization @census_for_user ||= Decidim::FileAuthorizationHandler::CensusDatum .search_id_document(organization, id_document) end |
#handler_name ⇒ Object
This is required in new 0.8.4 version of decicim however, there’s a bug and this doesn’t work
34 35 36 |
# File 'app/services/file_authorization_handler.rb', line 34 def handler_name +"file_authorization_handler" end |
#metadata ⇒ Object
22 23 24 25 26 27 28 29 30 |
# File 'app/services/file_authorization_handler.rb', line 22 def @metadata ||= begin = { birthdate: census_for_user&.birthdate&.strftime("%Y/%m/%d") } census_for_user&.extras&.each_pair do |key, value| [key.to_sym] = value end end end |
#organization ⇒ Object
62 63 64 |
# File 'app/services/file_authorization_handler.rb', line 62 def organization current_organization || user&.organization end |
#unique_id ⇒ Object
49 50 51 52 53 |
# File 'app/services/file_authorization_handler.rb', line 49 def unique_id return nil unless organization Digest::SHA256.hexdigest("#{census_for_user&.id_document}-#{organization.id}-#{Rails.application.secrets.secret_key_base}") end |