Slide 18
Slide 18 text
class User < ActiveRecord::Base
include User::Exceptions
include SentientUser
include Immortal
include Digests
include EmailBounces
include Teambox::TestDeliveryEmail if Rails.env.development?
include Teambox::Metadata
metadata_store :settings
metadata_store :metadata
metadata_store :salesforce_contacts
include User::Geoip
include User::OutgoingEmail
include User::Stats
include User::FeatureTracking
include User::ApiV2Mappings
include Subscriptionable::User
include Rails.application.routes.url_helpers
include User::Ghost
include OrganizationAdmins
include User::Activation
include User::Avatar
include User::Calendars
include User::Contacts
include User::NewFromEmail
include User::Roles
include User::Rss
include User::TaskReminders
include User::Tokens
include User::UserAuthentication
include User::UserCallbacks
include User::UserDeletion
include User::UserFreezing
include User::UserEmailers
include User::UserFinders
include User::UserNetwork
include User::UserOauth
include User::UserRelations
include User::UserScopes
include User::UserStats
include User::UserTimeZones
include User::UserValidations
include User::UserApps
include User::Invitations
include User::DeprecatedColumns
include Audited::User
include Authentication
include Authentication::ByPassword
include Authentication::ByCookieToken
include Chat::Concerns::UserChat
# TODO: Please remove those
accepts_nested_attributes_for :card
attr_accessible :login,
:username,
:email,
:first_name,
:last_name,
:biography,
:password,
:password_confirmation,
:old_password,
:time_zone,
:locale,
:first_day_of_week,
:card_attributes,
:notify_conversations,
:notify_tasks,
:notify_pages,
:wants_task_reminder,
:source,
:newsletter,
:project_activity_digest,
:last_digest_delivery,
:default_watch_new_task, :default_watch_new_conversation, :default_watch_new_page,
:people_attributes,
:google_calendar_url_token,
:needs_profile,
:settings,
:metadata,
:utm_source,
:utm_medium,
:utm_campaign,
:utm_term,
:bouncing_email,
:phone_number_accessor, :country_accessor, :state_accessor,
:wants_email_chat_notifications,
:wants_chat_push_notifications,
:job_title,
:use_gravatar,
:onboarding_tour_shown,
:desktop_notifications_enabled
attr_accessor :activate, :old_password, :invitation_token,
:phone_number_accessor, :country_accessor, :state_accessor
def to_s
name
end
def to_param
# in case it changes but is not yet saved
login_was.match('.') ? id.to_s : login_was
# Fix so user_path doesn't b0rk on dots in username
end
def locale
if I18n.available_locales.map(&:to_s).include? self[:locale]
self[:locale]
else
I18n.default_locale.to_s
end
end
# TODO: Remove after APIv2
def person_for(project)
self.people.find_by_project_id(project.id)
end
# TODO: Remove after APIv2
def member_for(organization)
self.memberships.find_by_organization_id(organization.id)
end
def watching?(object)
object.has_watcher? self
end
def in_project(project)
project.people.find_by_user_id(self)
end
# Forces a password change
#
# @param [String] pass
def change_password!(pass)
self.password = pass
self.password_confirmation = pass
self.performing_reset = true
save
end
# Checks if the user belongs to an org with enabled videoconference
#
# @return [Boolean]
def can_use_videoconference?
organizations.any? do |o|
o.settings[:is_videoconference_banned] != true
end
end
# Split a text in two parts and assign
# to first_name and last_name
#
# @param [String] full_name
def split_full_name(full_name)
parts = full_name.strip.split(' ')
return if parts.empty?
self.first_name = parts.delete_at(0)
self.last_name = parts.join(' ') if parts.present?
end
def crypted_password?
self.crypted_password.present?
end
def short_name
I18n.t 'common.format_name_short', first_name: first_name, last_name: last_name,
first_name_first_character: first_name.chars.first,
last_name_first_character: last_name.chars.first
end
end