You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
818 B
26 lines
818 B
class Laboratory < ApplicationRecord
|
|
belongs_to :school, optional: true
|
|
|
|
has_many :laboratory_users, dependent: :destroy
|
|
has_many :users, through: :laboratory_users, source: :user
|
|
|
|
has_one :laboratory_setting, dependent: :destroy
|
|
|
|
validates :identifier, uniqueness: { case_sensitive: false }, allow_nil: true
|
|
|
|
def site
|
|
rails_env = EduSetting.get('rails_env')
|
|
suffix = rails_env && rails_env != 'production' ? ".#{rails_env}.educoder.net" : '.educoder.net'
|
|
|
|
identifier ? "#{identifier}#{suffix}" : ''
|
|
end
|
|
|
|
def self.find_by_subdomain(subdomain)
|
|
return if subdomain.blank?
|
|
|
|
rails_env = EduSetting.get('rails_env')
|
|
subdomain = subdomain.slice(0, subdomain.size - rails_env.size - 1) if subdomain.end_with?(rails_env) # winse.dev => winse
|
|
|
|
find_by_identifier(subdomain)
|
|
end
|
|
end |