5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-11-16 12:21:43 +00:00

feat: almacenar los campos

This commit is contained in:
f 2023-03-28 18:18:53 -03:00
parent 87d51e8856
commit 8f0f260a4f
4 changed files with 41 additions and 1 deletions

View file

@ -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

View file

@ -2,6 +2,8 @@
# Usuarie de la plataforma # Usuarie de la plataforma
class Usuarie < ApplicationRecord class Usuarie < ApplicationRecord
include Usuarie::Consent
devise :invitable, :database_authenticatable, devise :invitable, :database_authenticatable,
:recoverable, :rememberable, :validatable, :recoverable, :rememberable, :validatable,
:confirmable, :lockable, :registerable :confirmable, :lockable, :registerable

View file

@ -42,7 +42,7 @@
- if params[:consent] - if params[:consent]
.form-group .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? - required = t(".#{field}.required", default: '').present?
- id = "usuarie_#{field}" - id = "usuarie_#{field}"
- name = "usuarie[#{field}]" - name = "usuarie[#{field}]"

View file

@ -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