5
0
Fork 0
mirror of https://0xacab.org/sutty/sutty synced 2024-06-02 12:04:16 +00:00
panel/app/models/rol.rb

39 lines
712 B
Ruby
Raw Permalink Normal View History

# 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'
belongs_to :usuarie
belongs_to :site
has_many :deploys
validates_inclusion_of :rol, in: ROLES
2019-07-08 17:55:19 +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
def self.role?(rol)
ROLES.include? rol
end
private
# Asegurarse que tenga un token
def add_token_if_missing!
self.token ||= SecureRandom.hex(64)
end
end