Module: UserExtensions
- Extended by:
- ActiveSupport::Concern
- Included in:
- Lesli::User
- Defined in:
- app/models/concerns/user_extensions.rb
Overview
User extension methods Custom methods that belongs to a instance user
Instance Method Summary collapse
-
#calendar(source_code: :lesli) ⇒ CloudDriver::Calendar
If source_code is provided the method return the specified source calendar.
-
#full_name ⇒ String
The name of this user.
-
#full_name_initials ⇒ String
The name initials of this user.
-
#locale ⇒ String
of the platform will be returned.
-
#mfa_settings ⇒ void
Example user_mfa_settings = User.find(2).mfa_settings puts user_mfa_settings { :mfa_enabled => true, :mfa_method => “email”}.
- #notification(subject, body: nil, url: nil, category: "info") ⇒ void
- #notifications(quantity = 5, category: "info") ⇒ void
- #role_names ⇒ Object
- #set_alias ⇒ nil
Instance Method Details
#calendar(source_code: :lesli) ⇒ CloudDriver::Calendar
If source_code is provided the method return the specified source calendar.
83 84 85 86 |
# File 'app/models/concerns/user_extensions.rb', line 83 def calendar source_code: :lesli return Courier::Driver::Calendar.get_user_calendar(self, source_code: source_code, default: true) if source_code == :lesli Courier::Driver::Calendar.get_user_calendar(self, source_code: source_code) end |
#full_name ⇒ String
Returns The name of this user.
99 100 101 |
# File 'app/models/concerns/user_extensions.rb', line 99 def full_name self.first_name.blank? ? email : self.first_name + " " + self.last_name.to_s end |
#full_name_initials ⇒ String
Returns The name initials of this user.
108 109 110 |
# File 'app/models/concerns/user_extensions.rb', line 108 def full_name_initials self.first_name.blank? ? "" : self.first_name[0].upcase + "" + (self.last_name.blank? ? "" : self.last_name[0].upcase) end |
#locale ⇒ String
of the platform will be returned
119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'app/models/concerns/user_extensions.rb', line 119 def locale user_locale = self.settings.find_by(name: "locale") # return the desire locale by the user return user_locale.value.to_sym if user_locale # create a desire locale if the record does not exist self.settings.create_with(:value => I18n.locale).find_or_create_by(:name => "locale") # reevaluate self.locale() end |
#mfa_settings ⇒ void
This method returns an undefined value.
Example
user_mfa_settings = User.find(2).mfa_settings
puts user_mfa_settings
{ :mfa_enabled => true, :mfa_method => "email"}
144 145 146 147 148 149 150 151 |
# File 'app/models/concerns/user_extensions.rb', line 144 def mfa_settings mfa_enabled = self.settings.create_with(:value => false).find_or_create_by(:name => "mfa_enabled") mfa_method = self.settings.create_with(:value => :email).find_or_create_by(:name => "mfa_method") { :enabled => mfa_enabled.nil? ? false : mfa_enabled.value == 't', :method => mfa_method.nil? ? nil : mfa_method.value.to_sym } end |
#notification(subject, body: nil, url: nil, category: "info") ⇒ void
This method returns an undefined value.
59 60 61 |
# File 'app/models/concerns/user_extensions.rb', line 59 def notification subject, body:nil, url:nil, category:"info" Courier::Bell::Notification.new(self, subject, body:body, url:url, category:category) end |
#notifications(quantity = 5, category: "info") ⇒ void
This method returns an undefined value.
69 70 71 72 73 74 75 76 77 |
# File 'app/models/concerns/user_extensions.rb', line 69 def notifications quantity=5, category:"info" query = { :pagination => { :perPage => quantity, :page => 1 } } Lesli::Courier.new(:lesli_bell, []).from(:notification_service, self, query).call(:index) end |
#role_names ⇒ Object
133 134 135 |
# File 'app/models/concerns/user_extensions.rb', line 133 def role_names user_roles = self.lesliroles.map(&:name).join(", ") end |
#set_alias ⇒ nil
45 46 47 48 49 50 |
# File 'app/models/concerns/user_extensions.rb', line 45 def set_alias if self.alias.blank? self.alias = full_name_initials() self.save end end |