Class: User

Inherits:
ApplicationRecord show all
Defined in:
app/models/user.rb

Overview

Relations

Validations

Afteer update

#check_disabled

Before destroy

#abort_destroy

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

#div

Instance Attribute Details

#adminBoolean[ true if {User} is a admin otherwise false

Returns Boolean[ true if User is a admin otherwise false.

Returns:

  • (Boolean[ true if {User} is a admin otherwise false)

    Boolean[ true if User is a admin otherwise false



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#authorObject

Returns instance of User as #secretary thats update current instance. Is an attr_accessor.

Returns:

  • (Object)

    instance of User as #secretary thats update current instance. Is an attr_accessor



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#bodyString

Returns note for User.

Returns:

  • (String)

    note for User



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#cfStrint[ {User}'s tax code

Returns Strint[ User‘s tax code.

Returns:

  • (Strint[ {User}'s tax code)

    Strint[ User‘s tax code



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#citta_nascString

Returns User‘s born city, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s born city, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#cityObject

Enum of cities



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#created_atDateTime[ date when {User} was created

Returns DateTime[ date when User was created.

Returns:

  • (DateTime[ date when {User} was created)

    DateTime[ date when User was created



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#current_sign_in_atDateTime

Returns date of User current sign in.

Returns:

  • (DateTime)

    date of User current sign in



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#current_sign_in_ipString

Returns ip of User current sign in.

Returns:

  • (String)

    ip of User current sign in



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#dataHash

Returns data for update metadata.

Returns:

  • (Hash)

    data for update metadata



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#data_aggiornamentoString

Returns data of last metadata update, is a store accessor of [metadata].

Returns:

  • (String)

    data of last metadata update, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#data_nascString

Returns User‘s born date, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s born date, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#deletedBoolean[ true if {User} was blocked from {secretary}

Returns Boolean[ true if User was blocked from #secretary.

Returns:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#denominazione_contrattoString

Returns User‘s extended work type, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s extended work type, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#doctorBoolean[ true if {User} is a doctor otherwise false

Returns Boolean[ true if User is a doctor otherwise false.

Returns:

  • (Boolean[ true if {User} is a doctor otherwise false)

    Boolean[ true if User is a doctor otherwise false



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#email,String

Returns User‘s emails, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s emails, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#emergenzeString

Returns User‘s phone number for emergency, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s phone number for emergency, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#externalObject

Relations

Validations

Afteer update

#check_disabled

Before destroy

#abort_destroy



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#floorString

Returns User‘s work floor, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s work floor, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#labelString

Returns long User name.

Returns:

  • (String)

    long User name



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#last_sign_in_atDateTime

Returns date of User last sign in.

Returns:

  • (DateTime)

    date of User last sign in



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#last_sign_in_ipString

Returns ip of User last sign in.

Returns:

  • (String)

    ip of User last sign in



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#lastnameString

Returns User‘s lastname, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s lastname, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#locationString

Returns User‘s work city, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s work city, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#locked_atDatetime

Returns date when User was blocked.

Returns:

  • (Datetime)

    date when User was blocked



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#matrString

Returns User‘s work code, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s work code, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#metadataHash[ is a jsonb field for archive {User}'s details

Returns Hash[ is a jsonb field for archive User‘s details.

Returns:

  • (Hash[ is a jsonb field for archive {User}'s details)

    Hash[ is a jsonb field for archive User‘s details



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#nameString

Returns User‘s name, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s name, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#naz_nascString

Returns User‘s born nation, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s born nation, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#postazioneString

Returns enum of sites type.

Returns:

  • (String)

    enum of sites type



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#postazione_created_atString

Returns User‘s when #postazione was created, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s when #postazione was created, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#postazione_fineString

Returns when #postazione end, is a store accessor of [metadata].

Returns:

  • (String)

    when #postazione end, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#postazione_inizioString

Returns when #postazione was set, is a store accessor of [metadata].

Returns:

  • (String)

    when #postazione was set, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#postazione_locazioneString

Returns #postazione sites.

Returns:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#postazione_updated_atString

Returns User‘s when #postazione was updated, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s when #postazione was updated, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#prefixString

Returns is a store accessor of [metadata].

Returns:

  • (String)

    is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#responsabileString

Returns User‘s boss, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s boss, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#roomString

Returns User‘s work room, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s work room, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#scadenza_rapportoString

Returns User‘s end of work, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s end of work, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#secretaryBoolean

Returns true if User is a secretary otherwise false.

Returns:

  • (Boolean)

    true if User is a secretary otherwise false



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#sexString

override sex attribute

Returns:

  • (String)

    return ‘n.d.’ if #sex attribute is empty



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#sign_in_countInteger

Returns Counter of User sign in.

Returns:

  • (Integer)

    Counter of User sign in



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#statusString

Returns User‘s status, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s status, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#structureString

Returns User‘s work area, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s work area, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#structure_labelString

Returns User‘s work area extended, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s work area extended, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#telString[ {User}'s phone number

Returns String[ User‘s phone number.

Returns:

  • (String[ {User}'s phone number)

    String[ User‘s phone number



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#telephoneString

Returns User‘s phone number, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s phone number, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#tipo_contrattoString

Returns User‘s work type, is a store accessor of [metadata].

Returns:

  • (String)

    User‘s work type, is a store accessor of [metadata]



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#updated_atDateTime[ date when {User} was updated

Returns DateTime[ date when User was updated.

Returns:

  • (DateTime[ date when {User} was updated)

    DateTime[ date when User was updated



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#usernameString

Returns unique User name.

Returns:

  • (String)

    unique User name



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

Class Method Details

.blockedArray

Returns list of User with locked_at empty and #deleted true.

Returns:

  • (Array)

    list of User with locked_at empty and #deleted true



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

.doctorsArray

Returns list of User with #doctor true.

Returns:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

.femaleArray

Returns list of User with #metadata ->> sex = F.

Returns:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

.lockedArray

Returns list of User with #locked_at present and #deleted false.

Returns:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

.maleArray

Returns list of User with #metadata ->> sex = M.

Returns:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

.syncableArray

Returns list of User with #username present.

Returns:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

.unassignedArray

Returns list of User with no #audits.

Returns:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

Instance Method Details

#assegnazioneObject

Returns is an acchacched PDF.

Returns:

  • is an acchacched PDF



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#auditsArray

Returns list of related Audit.

Returns:

  • (Array)

    list of related Audit



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#categoriesArray

Returns list of related Category.

Returns:



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#contentString

Returns is a rich text with user info.

Returns:

  • (String)

    is a rich text with user info



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#disable!Boolean

update self with #locked_at as Time.zone.now

Returns:

  • (Boolean)

    true if is updated



204
205
206
# File 'app/models/user.rb', line 204

def disable!
  update(locked_at: Time.zone.now)
end

#enable!Boolean

update self with #locked_at as nil

Returns:

  • (Boolean)

    true if is updated



210
211
212
# File 'app/models/user.rb', line 210

def enable!
  update(locked_at: nil)
end

#eventsArray

Returns list of related Event.

Returns:

  • (Array)

    list of related Event



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#historiesArray

Returns list of related History.

Returns:

  • (Array)

    list of related History



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#meetingsArray

Returns list of related Meeting.

Returns:

  • (Array)

    list of related Meeting



158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# File 'app/models/user.rb', line 158

class User < ApplicationRecord
  has_rich_text :content
  has_one_attached :assegnazione

  has_many :audits, dependent: :destroy
  has_many :categories, through: :audits
  has_many :meetings, through: :audits
  has_many :events, through: :meetings
  has_many :histories, through: :audits, source: :histories
  has_many :risks, through: :categories, source: :risks

  store_accessor :metadata, :email, :sex, :lastname, :name, :matr, :status, :postazione_inizio, :postazione_fine, :postazione_locazione, :postazione_created_at, :postazione_updated_at, :data_nasc, :citta_nasc, :naz_nasc, :scadenza_rapporto, :tipo_contratto, :denominazione_contratto, :location, :floor, :room, :telephone, :emergenze, :user_emergenze, :structure, :structure_label, :responsabile, :data_aggiornamento, :prefix
  attr_accessor :author, :external, :data

  enum city: Settings.users.cities.to_h
  enum postazione: Settings.users.positions.to_h

  devise ENV['RAILS_AUTHENTICATOR'] || Settings.auth.authenticator || :database_authenticatable, :trackable, :timeoutable, :lockable, :recoverable

  after_update :check_disabled
  before_destroy :abort_destroy

  accepts_nested_attributes_for :audits, reject_if: :reject_audit

  validates :username, uniqueness: true, allow_blank: true
  validates :label, presence: true
  validates :name, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  # validates :lastname, presence: { message: 'non può essere lasciato in bianco' }, unless: -> { system? }
  validates :cf, presence: { message: 'non può essere lasciato in bianco' }, uniqueness: { message: 'già esistente' }, unless: -> { system? }
  validates :postazione, presence: true
  validates :assegnazione, content_type: { in: 'application/pdf', message: 'non è un file PDF' }
  validates :assegnazione, size: { less_than: 500.kilobytes, message: 'deve avere una dimensione massima di 500kb' }

  default_scope { where(locked_at: nil, deleted: false) }
  scope :locked, -> { unscoped.where.not(locked_at: nil).where.not(deleted: true) }
  scope :unassigned, -> { where.not(id: Audit.select(:user_id).distinct.pluck(:user_id)) }
  scope :blocked, -> { unscoped.where(deleted: true).where(locked_at: nil) }
  scope :doctors, -> { where(doctor: true).order(:label) }
  scope :male, -> { where("users.metadata->>'sex'=?", 'M') }
  scope :female, -> { where("users.metadata->>'sex'=?", 'F') }
  scope :syncable, -> { where.not(username: nil).order(:label) }
  scope :system, -> { where(system: true) }
  scope :unsystem, -> { where(system: false) }

  # update self with {locked_at} as Time.zone.now
  # @return [Boolean] true if is updated
  def disable!
    update(locked_at: Time.zone.now)
  end

  # update self with {locked_at} as nil
  # @return [Boolean] true if is updated
  def enable!
    update(locked_at: nil)
  end

  # override sex attribute
  # @return [String] return 'n.d.' if {sex} attribute is empty
  def sex
    ['sex'].blank? ? 'n.d.' : super
  end

  # check if user have done analisy and require to do the visit
  # @return [Boolean] true if is required
  def require_visit?
    events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
  end

  private

  # this method is called for check data befor make/update {Audit}
  # when return true the audit update is skypped
  # @param [Hash] attributed attributed is an hash with the params for make/update an {Audit}
  # @return [Boolean] true if attributed['title'] is empty
  def reject_audit(attributed)
    attributed['title'].blank?
  end

  # if {User} is locked destroy relative {Audit}
  def check_disabled
    return if locked_at.blank?

    audits.map do |a|
      a.author = author
      a.revision_date = Time.zone.now
      a.delete
    end
  end

  # is executed before destroy, add an error to :base and abort the action
  # @return [False]
  def abort_destroy
    errors.add :base, "Can't be destroyed"
    throw :abort
  end

end

#require_visit?Boolean

check if user have done analisy and require to do the visit

Returns:

  • (Boolean)

    true if is required



222
223
224
# File 'app/models/user.rb', line 222

def require_visit?
  events.confirmed.analisys.between(start_on: (histories.active.order(revision_date: :asc).last.present? ? (histories.active.order(revision_date: :asc).last.revision_date) : Time.zone.now), stop_on: Time.zone.now).present? && events.confirmed.visit.future.blank?
end