Class: User
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- User
- Defined in:
- app/models/user.rb
Overview
Relations
-
has many Audit
Validations
-
validate presence of #username
-
validate uniqueness of #username
-
validate presence of #label
-
validate presence of #name
-
validate presence of #lastname
-
validate presence of #cf
-
validate uniqueness of #cf
-
validate presence of #postazione
-
validate content type of #assegnazione should be a pdf
-
validate size of #assegnazione
Afteer update
#check_disabled
Before destroy
#abort_destroy
Instance Attribute Summary collapse
-
#admin ⇒ Boolean[ true if {User} is a admin otherwise false
Boolean[ true if User is a admin otherwise false.
-
#author ⇒ Object
Instance of User as #secretary thats update current instance.
-
#body ⇒ String
Note for User.
-
#cf ⇒ Strint[ {User}'s tax code
Strint[ User‘s tax code.
-
#citta_nasc ⇒ String
User‘s born city, is a store accessor of [metadata].
-
#city ⇒ Object
Enum of cities.
-
#created_at ⇒ DateTime[ date when {User} was created
DateTime[ date when User was created.
-
#current_sign_in_at ⇒ DateTime
Date of User current sign in.
-
#current_sign_in_ip ⇒ String
Ip of User current sign in.
-
#data ⇒ Hash
Data for update metadata.
-
#data_aggiornamento ⇒ String
Data of last metadata update, is a store accessor of [metadata].
-
#data_nasc ⇒ String
User‘s born date, is a store accessor of [metadata].
-
#deleted ⇒ Boolean[ true if {User} was blocked from {secretary}
Boolean[ true if User was blocked from #secretary.
-
#denominazione_contratto ⇒ String
User‘s extended work type, is a store accessor of [metadata].
-
#doctor ⇒ Boolean[ true if {User} is a doctor otherwise false
Boolean[ true if User is a doctor otherwise false.
-
#email, ⇒ String
User‘s emails, is a store accessor of [metadata].
-
#emergenze ⇒ String
User‘s phone number for emergency, is a store accessor of [metadata].
-
#external ⇒ Object
Relations.
-
#floor ⇒ String
User‘s work floor, is a store accessor of [metadata].
-
#label ⇒ String
Long User name.
-
#last_sign_in_at ⇒ DateTime
Date of User last sign in.
-
#last_sign_in_ip ⇒ String
Ip of User last sign in.
-
#lastname ⇒ String
User‘s lastname, is a store accessor of [metadata].
-
#location ⇒ String
User‘s work city, is a store accessor of [metadata].
-
#locked_at ⇒ Datetime
Date when User was blocked.
-
#matr ⇒ String
User‘s work code, is a store accessor of [metadata].
-
#metadata ⇒ Hash[ is a jsonb field for archive {User}'s details
Hash[ is a jsonb field for archive User‘s details.
-
#name ⇒ String
User‘s name, is a store accessor of [metadata].
-
#naz_nasc ⇒ String
User‘s born nation, is a store accessor of [metadata].
-
#postazione ⇒ String
Enum of sites type.
-
#postazione_created_at ⇒ String
User‘s when #postazione was created, is a store accessor of [metadata].
-
#postazione_fine ⇒ String
When #postazione end, is a store accessor of [metadata].
-
#postazione_inizio ⇒ String
When #postazione was set, is a store accessor of [metadata].
-
#postazione_locazione ⇒ String
#postazione sites.
-
#postazione_updated_at ⇒ String
User‘s when #postazione was updated, is a store accessor of [metadata].
-
#prefix ⇒ String
Is a store accessor of [metadata].
-
#responsabile ⇒ String
User‘s boss, is a store accessor of [metadata].
-
#room ⇒ String
User‘s work room, is a store accessor of [metadata].
-
#scadenza_rapporto ⇒ String
User‘s end of work, is a store accessor of [metadata].
-
#secretary ⇒ Boolean
True if User is a secretary otherwise false.
-
#sex ⇒ String
override sex attribute.
-
#sign_in_count ⇒ Integer
Counter of User sign in.
-
#status ⇒ String
User‘s status, is a store accessor of [metadata].
-
#structure ⇒ String
User‘s work area, is a store accessor of [metadata].
-
#structure_label ⇒ String
User‘s work area extended, is a store accessor of [metadata].
-
#tel ⇒ String[ {User}'s phone number
String[ User‘s phone number.
-
#telephone ⇒ String
User‘s phone number, is a store accessor of [metadata].
-
#tipo_contratto ⇒ String
User‘s work type, is a store accessor of [metadata].
-
#updated_at ⇒ DateTime[ date when {User} was updated
DateTime[ date when User was updated.
-
#username ⇒ String
Unique User name.
Class Method Summary collapse
- .blocked ⇒ Array
- .doctors ⇒ Array
- .female ⇒ Array
-
.locked ⇒ Array
List of User with #locked_at present and #deleted false.
- .male ⇒ Array
- .syncable ⇒ Array
- .unassigned ⇒ Array
Instance Method Summary collapse
-
#assegnazione ⇒ Object
Is an acchacched PDF.
-
#audits ⇒ Array
List of related Audit.
-
#categories ⇒ Array
List of related Category.
-
#content ⇒ String
Is a rich text with user info.
-
#disable! ⇒ Boolean
update self with #locked_at as Time.zone.now.
-
#enable! ⇒ Boolean
update self with #locked_at as nil.
-
#events ⇒ Array
List of related Event.
-
#histories ⇒ Array
List of related History.
-
#meetings ⇒ Array
List of related Meeting.
-
#require_visit? ⇒ Boolean
check if user have done analisy and require to do the visit.
Methods inherited from ApplicationRecord
Instance Attribute Details
#admin ⇒ Boolean[ true if {User} is a admin otherwise false
Returns 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. = 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 |
#author ⇒ Object
Returns 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. = 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 |
#body ⇒ String
Returns 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. = 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 |
#cf ⇒ Strint[ {User}'s tax code
Returns 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. = 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_nasc ⇒ String
Returns 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. = 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 |
#city ⇒ Object
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. = 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_at ⇒ DateTime[ date when {User} was created
Returns 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. = 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_at ⇒ DateTime
Returns 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. = 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_ip ⇒ String
Returns 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. = 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 ⇒ Hash
Returns 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. = 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_aggiornamento ⇒ String
Returns 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. = 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_nasc ⇒ String
Returns 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. = 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 |
#deleted ⇒ Boolean[ true if {User} was blocked from {secretary}
Returns Boolean[ true if User was blocked from #secretary.
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. = 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_contratto ⇒ String
Returns 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. = 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 |
#doctor ⇒ Boolean[ true if {User} is a doctor otherwise false
Returns 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. = 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].
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. = 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 |
#emergenze ⇒ String
Returns 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. = 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 |
#external ⇒ Object
Relations
-
has many Audit
Validations
-
validate presence of #username
-
validate uniqueness of #username
-
validate presence of #label
-
validate presence of #name
-
validate presence of #lastname
-
validate presence of #cf
-
validate uniqueness of #cf
-
validate presence of #postazione
-
validate content type of #assegnazione should be a pdf
-
validate size of #assegnazione
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. = 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 |
#floor ⇒ String
Returns 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. = 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 |
#label ⇒ String
Returns 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. = 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_at ⇒ DateTime
Returns 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. = 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_ip ⇒ String
Returns 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. = 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 |
#lastname ⇒ String
Returns 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. = 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 |
#location ⇒ String
Returns 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. = 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_at ⇒ Datetime
Returns 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. = 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 |
#matr ⇒ String
Returns 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. = 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 |
#metadata ⇒ Hash[ is a jsonb field for archive {User}'s details
Returns 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. = 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 |
#name ⇒ String
Returns 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. = 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_nasc ⇒ String
Returns 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. = 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 ⇒ String
Returns 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. = 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_at ⇒ String
Returns 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. = 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_fine ⇒ String
Returns 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. = 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_inizio ⇒ String
Returns 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. = 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_locazione ⇒ String
Returns #postazione sites.
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. = 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_at ⇒ String
Returns 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. = 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 |
#prefix ⇒ String
Returns 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. = 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 |
#responsabile ⇒ String
Returns 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. = 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 |
#room ⇒ String
Returns 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. = 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_rapporto ⇒ String
Returns 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. = 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 |
#secretary ⇒ Boolean
Returns 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. = 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 |
#sex ⇒ String
override sex attribute
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. = 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_count ⇒ Integer
Returns 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. = 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 |
#status ⇒ String
Returns 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. = 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 ⇒ String
Returns 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. = 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_label ⇒ String
Returns 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. = 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 |
#tel ⇒ String[ {User}'s phone number
Returns 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. = 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 |
#telephone ⇒ String
Returns 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. = 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_contratto ⇒ String
Returns 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. = 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_at ⇒ DateTime[ date when {User} was updated
Returns 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. = 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 |
#username ⇒ String
Returns 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. = 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
.blocked ⇒ Array
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. = 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 |
.doctors ⇒ Array
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. = 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 |
.female ⇒ Array
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. = 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 ⇒ Array
Returns list of User with #locked_at present and #deleted 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. = 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 |
.male ⇒ Array
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. = 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 |
.syncable ⇒ Array
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. = 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 |
.unassigned ⇒ Array
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. = 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
#assegnazione ⇒ Object
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. = 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 |
#audits ⇒ Array
Returns 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. = 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 |
#categories ⇒ Array
Returns list of related Category.
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. = 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 |
#content ⇒ String
Returns 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. = 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
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
210 211 212 |
# File 'app/models/user.rb', line 210 def enable! update(locked_at: nil) end |
#events ⇒ Array
Returns 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. = 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 |
#histories ⇒ Array
Returns 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. = 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 |
#meetings ⇒ Array
Returns 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. = 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
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 |