2019-07-06 00:21:49 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# Define el rol que tiene una usuaria en un sitio
|
|
|
|
#
|
|
|
|
# Un rol puede ser temporal, es decir que aun no se ha aceptado y
|
|
|
|
# necesita del consentimiento de le usuarie :)
|
|
|
|
class Rol < ApplicationRecord
|
|
|
|
ROLES = %w[usuarie invitade].freeze
|
2020-05-12 14:58:07 +00:00
|
|
|
USUARIE = 'usuarie'
|
|
|
|
INVITADE = 'invitade'
|
2019-07-06 00:21:49 +00:00
|
|
|
|
|
|
|
belongs_to :usuarie
|
|
|
|
belongs_to :site
|
2024-02-16 17:53:05 +00:00
|
|
|
has_many :deploys
|
2019-07-06 00:21:49 +00:00
|
|
|
|
|
|
|
validates_inclusion_of :rol, in: ROLES
|
2019-07-08 17:55:19 +00:00
|
|
|
|
2023-07-31 20:32:14 +00:00
|
|
|
before_save :add_token_if_missing!
|
|
|
|
|
2019-07-08 17:55:19 +00:00
|
|
|
def invitade?
|
2020-05-12 14:58:07 +00:00
|
|
|
rol == INVITADE
|
2019-07-08 17:55:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def usuarie?
|
2020-05-12 14:58:07 +00:00
|
|
|
rol == USUARIE
|
2019-07-08 17:55:19 +00:00
|
|
|
end
|
2023-03-23 20:21:05 +00:00
|
|
|
|
|
|
|
def self.role?(rol)
|
|
|
|
ROLES.include? rol
|
|
|
|
end
|
2023-07-31 20:32:14 +00:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# Asegurarse que tenga un token
|
|
|
|
def add_token_if_missing!
|
|
|
|
self.token ||= SecureRandom.hex(64)
|
|
|
|
end
|
2019-07-06 00:21:49 +00:00
|
|
|
end
|