Class: User

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

Overview

User is model responsible for storing user informations.

Relations

Validations

Before destroy

#abort_destroy

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

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

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

Returns:

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

    Boolean[ true if User is a admin otherwise false



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#created_atDateTime

Returns date when User was created.

Returns:

  • (DateTime)

    date when User was created



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#current_sign_in_atDateTime

Returns date of User current sign in.

Returns:

  • (DateTime)

    date of User current sign in



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#current_sign_in_ipString

Returns ip of User current sign in.

Returns:

  • (String)

    ip of User current sign in



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#forcedObject

Returns the value of attribute forced.



43
44
45
# File 'app/models/user.rb', line 43

def forced
  @forced
end

#labelString

Returns long User name.

Returns:

  • (String)

    long User name



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#last_sign_in_atDateTime

Returns date of User last sign in.

Returns:

  • (DateTime)

    date of User last sign in



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#last_sign_in_ipString

Returns ip of User last sign in.

Returns:

  • (String)

    ip of User last sign in



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#locked_atDatetime

Returns date when User was blocked.

Returns:

  • (Datetime)

    date when User was blocked



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#sign_in_countInteger

Returns Counter of User sign in.

Returns:

  • (Integer)

    Counter of User sign in



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#updated_atDateTime

Returns date when User was updated.

Returns:

  • (DateTime)

    date when User was updated



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#usernameString

Returns unique User name.

Returns:

  • (String)

    unique User name



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

Instance Method Details

#disable!Boolean

update self with #locked_at as Time.zone.now

Returns:

  • (Boolean)

    true if is updated



62
63
64
# File 'app/models/user.rb', line 62

def disable!
  update(locked_at: Time.zone.now)
end

#enable!Boolean

update self with #locked_at as nil

Returns:

  • (Boolean)

    true if is updated



68
69
70
# File 'app/models/user.rb', line 68

def enable!
  update(locked_at: nil)
end

#lockedBool

Returns if User with #locked_at present.

Returns:



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'app/models/user.rb', line 41

class User < ApplicationRecord
  store_accessor :metadata, :matr, :responsabile, :data_aggiornamento
  attr_accessor :forced

  devise Settings.auth.devise, :trackable, :timeoutable, :lockable

  default_scope { order(:label) }
  scope :avaibilities, -> { where(locked_at: nil) }
  scope :locked, -> { where.not(locked_at: nil) }
  scope :admins, -> { where(admin: true) }

  has_many :favorites, class_name: 'UserFaq', inverse_of: :user
  has_many :faqs, through: :favorites, source: :faq

  before_validation :presequisite
  before_destroy :abort_destroy, unless: :forced?
  validates :username, presence: true, uniqueness: true
  after_create_commit {UsersCheckJob.perform_now(username: username) unless forced? || Rails.env.test?}

  # 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

  def locked?
    locked_at?
  end

  private

  def presequisite
    self.label = username if label.blank?
  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

  def forced?
    forced == 'true'
  end
end

#locked?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/user.rb', line 72

def locked?
  locked_at?
end