Sha256: db14eff587003b2779566b7f6115931e13ee3116f566d968a706d5d8da2e7633

Contents?: true

Size: 1.06 KB

Versions: 50

Compression:

Stored size: 1.06 KB

Contents

class Term < ApplicationRecord
  attribute :locale, :string, default: 'es'
  markdown_on :content

  GENERAL = %w(legal privacy student)
  ROLE_SPECIFIC = %w(headmaster janitor teacher moderator)
  FORUM_RELATED = %w(forum)

  validates :locale, uniqueness: { scope: :scope }
  validates :content, :scope, :header, presence: true

  def self.terms_for(scope, locale)
    where(scope: scope, locale: locale)
  end

  def self.profile_terms_for(user, locale = I18n.locale)
    general_terms(locale) + role_specific_terms_for(user, locale)
  end

  def self.role_specific_terms_for(user, locale = I18n.locale)
    terms_for(current_role_terms_for(user), locale)
  end

  def self.general_terms(locale = I18n.locale)
    terms_for(GENERAL, locale)
  end

  def self.forum_related_terms(locale = I18n.locale)
    terms_for(FORUM_RELATED, locale)
  end

  def self.current_role_terms_for(user)
    return [] unless user.present?
    (user.any_granted_roles & ROLE_SPECIFIC).to_a
  end

  def accepted_by?(user)
    user.term_accepted_at_for(scope).try { |it| it > updated_at }.present?
  end
end

Version data entries

50 entries across 50 versions & 1 rubygems

Version Path
mumuki-domain-9.23.0 app/models/term.rb
mumuki-domain-9.22.1 app/models/term.rb
mumuki-domain-9.22.0 app/models/term.rb
mumuki-domain-9.21.0 app/models/term.rb
mumuki-domain-9.20.0 app/models/term.rb
mumuki-domain-9.19.0 app/models/term.rb
mumuki-domain-9.18.0 app/models/term.rb
mumuki-domain-9.17.0 app/models/term.rb
mumuki-domain-9.16.0 app/models/term.rb
mumuki-domain-9.15.0 app/models/term.rb
mumuki-domain-9.14.1 app/models/term.rb
mumuki-domain-9.14.0 app/models/term.rb
mumuki-domain-9.13.1 app/models/term.rb
mumuki-domain-9.13.0 app/models/term.rb
mumuki-domain-9.12.0 app/models/term.rb
mumuki-domain-9.11.0 app/models/term.rb
mumuki-domain-9.10.0 app/models/term.rb
mumuki-domain-9.9.0 app/models/term.rb
mumuki-domain-9.8.1 app/models/term.rb
mumuki-domain-9.8.0 app/models/term.rb