From 8f0f260a4f9bd345eddcf66ab079da054d9d2a00 Mon Sep 17 00:00:00 2001 From: f Date: Tue, 28 Mar 2023 18:18:53 -0300 Subject: [PATCH] feat: almacenar los campos --- app/models/concerns/usuarie/consent.rb | 26 +++++++++++++++++++ app/models/usuarie.rb | 2 ++ app/views/devise/registrations/new.haml | 2 +- .../20230328200129_add_consent_to_usuaries.rb | 12 +++++++++ 4 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 app/models/concerns/usuarie/consent.rb create mode 100644 db/migrate/20230328200129_add_consent_to_usuaries.rb diff --git a/app/models/concerns/usuarie/consent.rb b/app/models/concerns/usuarie/consent.rb new file mode 100644 index 00000000..14e67fbc --- /dev/null +++ b/app/models/concerns/usuarie/consent.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class Usuarie + # Gestiona los campos de consentimiento + module Consent + extend ActiveSupport::Concern + + included do + CONSENT_FIELDS = %i[privacy_policy_accepted terms_of_service_accepted code_of_conduct_accepted available_for_feedback_accepted] + + CONSENT_FIELDS.each do |field| + attribute field, :boolean + end + + before_save :update_consent_fields! + + private + + def update_consent_fields! + CONSENT_FIELDS.each do |field| + send(:"#{field}_at=", Time.now) if send(field).present? + end + end + end + end +end diff --git a/app/models/usuarie.rb b/app/models/usuarie.rb index 7b83ee75..9b9fd4e6 100644 --- a/app/models/usuarie.rb +++ b/app/models/usuarie.rb @@ -2,6 +2,8 @@ # Usuarie de la plataforma class Usuarie < ApplicationRecord + include Usuarie::Consent + devise :invitable, :database_authenticatable, :recoverable, :rememberable, :validatable, :confirmable, :lockable, :registerable diff --git a/app/views/devise/registrations/new.haml b/app/views/devise/registrations/new.haml index 75015831..04e81917 100644 --- a/app/views/devise/registrations/new.haml +++ b/app/views/devise/registrations/new.haml @@ -42,7 +42,7 @@ - if params[:consent] .form-group - - %i[privacy_policy_accepted terms_of_service_accepted code_of_conduct_accepted available_for_feedback_accepted].each do |field| + - Usuarie::CONSENT_FIELDS.each do |field| - required = t(".#{field}.required", default: '').present? - id = "usuarie_#{field}" - name = "usuarie[#{field}]" diff --git a/db/migrate/20230328200129_add_consent_to_usuaries.rb b/db/migrate/20230328200129_add_consent_to_usuaries.rb new file mode 100644 index 00000000..1e85864d --- /dev/null +++ b/db/migrate/20230328200129_add_consent_to_usuaries.rb @@ -0,0 +1,12 @@ +# frozen_string_literal: true + +# Agrega consentimientos a les usuaries. No usamos un loop de +# Usuarie::CONSENT_FIELDS porque quizás agreguemos campos luego. +class AddConsentToUsuaries < ActiveRecord::Migration[6.1] + def change + add_column :usuaries, :privacy_policy_accepted_at, :datetime + add_column :usuaries, :terms_of_service_accepted_at, :datetime + add_column :usuaries, :code_of_conduct_accepted_at, :datetime + add_column :usuaries, :available_for_feedback_accepted_at, :datetime + end +end