Sha256: 53e08711b931b265825207aca233a8c4cf3ba4ed98084c8abbeeb77abb74c580
Contents?: true
Size: 1.9 KB
Versions: 1
Compression:
Stored size: 1.9 KB
Contents
module OpenStax::Accounts class Account < ActiveRecord::Base USERNAME_DISCARDED_CHAR_REGEX = /[^A-Za-z\d_]/ USERNAME_MAX_LENGTH = 50 attr_accessor :syncing has_many :group_owners, dependent: :destroy, class_name: 'OpenStax::Accounts::GroupOwner', primary_key: :openstax_uid, foreign_key: :user_id, inverse_of: :user has_many :groups_as_owner, through: :group_owners, source: :group has_many :group_members, dependent: :destroy, class_name: 'OpenStax::Accounts::GroupMember', primary_key: :openstax_uid, foreign_key: :user_id, inverse_of: :user has_many :groups_as_member, through: :group_members, source: :group enum faculty_status: [:no_faculty_info, :pending_faculty, :confirmed_faculty, :rejected_faculty] after_initialize :set_default_faculty_status validates :faculty_status, presence: true validates :openstax_uid, uniqueness: { allow_nil: true } validates :username, uniqueness: { allow_nil: true } before_update :update_openstax_accounts, if: :should_send_updates_to_accounts? def name (first_name || last_name) ? [first_name, last_name].compact.join(" ") : username end def casual_name first_name || username end def is_anonymous? false end def has_authenticated? !access_token.nil? end def valid_openstax_uid? !openstax_uid.nil? && openstax_uid > 0 end protected def set_default_faculty_status self.faculty_status ||= :no_faculty_info end def syncing_or_stubbing? syncing || OpenStax::Accounts.configuration.enable_stubbing? end def should_send_updates_to_accounts? !syncing_or_stubbing? && valid_openstax_uid? end def update_openstax_accounts OpenStax::Accounts::Api.update_account(self) end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
openstax_accounts-7.3.0 | app/models/openstax/accounts/account.rb |