Newer
Older
# == Schema Information
#
# Table name: communication_extranets
#
# id :uuid not null, primary key
# about_type :string indexed => [about_id]
# color :string
# css :text
# feature_alumni :boolean default(FALSE)
# feature_contacts :boolean default(FALSE)
# feature_documents :boolean default(FALSE)
# feature_jobs :boolean default(FALSE)
# feature_posts :boolean default(FALSE)
# has_sso :boolean default(FALSE)
# host :string
# sass :text
# sso_cert :text
# sso_mapping :jsonb
# sso_name_identifier_format :string
# sso_provider :integer default("saml")
# sso_target_url :string
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid indexed => [about_type]
# university_id :uuid not null, indexed
# index_communication_extranets_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_c2268c7ebd (university_id => universities.id)
#
class Communication::Extranet < ApplicationRecord
Sébastien Gaya
committed
# We don't include Sanitizable because too many complex attributes. We handle it below.
include Filterable
include Localizable
include LocalizableOrderByNameScope
has_many :languages, through: :localizations
has_many :post_localizations, class_name: 'Communication::Extranet::Post::Localization'
has_many :post_categories, class_name: 'Communication::Extranet::Post::Category'
has_many :post_category_localizations, class_name: 'Communication::Extranet::Post::Category::Localization'
has_many :document_categories, class_name: 'Communication::Extranet::Document::Category'
has_many :document_kinds, class_name: 'Communication::Extranet::Document::Kind'
validates :host, presence: true
validates :about_type, :about_id, presence: true, if: :feature_alumni
Sébastien Gaya
committed
before_validation :sanitize_fields
scope :for_search_term, -> (term, language) {
joins(:localizations)
.where("
unaccent(communication_extranets.host) ILIKE unaccent(:term) OR
unaccent(communication_extranet_localizations.name) ILIKE unaccent(:term)
find_by host: host
if feature_alumni?
university.users.where(person: alumni)
elsif feature_contacts?
university.users.where(person: connected_people)
else
university.users.none
end
def cohorts
about&.cohorts
end
def years
about&.academic_years
end
alias :academic_years :years
if about.present? && about.respond_to?(:alumni_organizations)
about.alumni_organizations
else
connected_organizations
end
if about.present? && about.respond_to?(:alumni_experiences)
about.alumni_experiences
else
experiences_through_connections
end
@url ||= Rails.env.development? ? "http://#{host}:3000" : "https://#{host}"
Sébastien Gaya
committed
def sanitize_fields
self.color = Osuny::Sanitizer.sanitize(self.color, 'string')
self.host = Osuny::Sanitizer.sanitize(self.host, 'string')
end