mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-16 08:51:42 +00:00
feat: almacenar los campos
This commit is contained in:
parent
87d51e8856
commit
8f0f260a4f
4 changed files with 41 additions and 1 deletions
26
app/models/concerns/usuarie/consent.rb
Normal file
26
app/models/concerns/usuarie/consent.rb
Normal 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
|
|
@ -2,6 +2,8 @@
|
|||
|
||||
# Usuarie de la plataforma
|
||||
class Usuarie < ApplicationRecord
|
||||
include Usuarie::Consent
|
||||
|
||||
devise :invitable, :database_authenticatable,
|
||||
:recoverable, :rememberable, :validatable,
|
||||
:confirmable, :lockable, :registerable
|
||||
|
|
|
@ -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}]"
|
||||
|
|
12
db/migrate/20230328200129_add_consent_to_usuaries.rb
Normal file
12
db/migrate/20230328200129_add_consent_to_usuaries.rb
Normal 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
|
Loading…
Reference in a new issue