class User
Attributes
roles[W]
Public Class Methods
role_to_entitlement(role)
click to toggle source
# File lib/buweb/user.rb, line 150 def self.role_to_entitlement(role) BuwebContentModels.config.urn_namespaces.map do |namespace| "#{namespace}#{role}" end end
Public Instance Methods
admin?()
click to toggle source
# File lib/buweb/user.rb, line 142 def admin? has_role?(:admin) || developer? end
create_or_update_person!()
click to toggle source
POLICY: All CAS users signing into wcms should have trogdir_ids. Which is to say that they have a trogdir account. Elsewise they should get 403
# File lib/buweb/user.rb, line 88 def create_or_update_person! return unless trogdir_id.present? person = find_person if person person.update_attributes(update_person_attributes) else person = Person.create(new_person_attributes) end return if self.person.present? || !person.persisted? self.person = person save end
developer?()
click to toggle source
# File lib/buweb/user.rb, line 146 def developer? has_role?(:developer) end
find_person()
click to toggle source
Person
should always have a trogdir id associated with it from the related user record
# File lib/buweb/user.rb, line 73 def find_person @user_person ||= Person.where(trogdir_id: trogdir_id).first end
grant_auth_over_own_person()
click to toggle source
# File lib/buweb/user.rb, line 104 def grant_auth_over_own_person # TODO: Should we remove this method? # => The PersonPolicy is going to always return true so this method will # never create a permission entry. # => It already allows a user to edit their own person record without need # a permission entry person.authorize! self, :edit unless person.nil? || policy(person).edit? end
has_published_bio?()
click to toggle source
# File lib/buweb/user.rb, line 82 def has_published_bio? BioEdition.published.where(person_id: person.id).count > 1 end
name()
click to toggle source
# File lib/buweb/user.rb, line 113 def name [first_name, last_name].compact.join(' ') end
restricted_roles()
click to toggle source
# File lib/buweb/user.rb, line 156 def restricted_roles return [] if (roles & %i[developer employee faculty]).any? if (roles & %i[accepted_student student student_worker]).any? return [:alumnus] end return %i[alumnus accepted_student student student_worker] if friend? %i[accepted_student student student_worker] end
role?(*roles)
click to toggle source
# File lib/buweb/user.rb, line 128 def role?(*roles) (self.roles & roles).any? end
Also aliased as: has_role?
roles()
click to toggle source
# File lib/buweb/user.rb, line 135 def roles @roles ||= (Array(affiliations) + relevant_entitlements).reject(&:blank?).map do |i| i.parameterize.underscore.to_sym end end
student_worker?()
click to toggle source
Student
worker has a space in it so it needs some special attention
# File lib/buweb/user.rb, line 67 def student_worker? has_role?(:"student worker") || has_role?(:student_worker) end
to_s()
click to toggle source
# File lib/buweb/user.rb, line 117 def to_s name end
tracking_id()
click to toggle source
# File lib/buweb/user.rb, line 77 def tracking_id # Warning: Changing this will cause duplicate records in Intercom Digest::MD5.hexdigest(biola_id.to_s) end
update_login_info!()
click to toggle source
# File lib/buweb/user.rb, line 121 def update_login_info! self.last_login_at = current_login_at self.current_login_at = Time.now self.login_count = login_count.to_i + 1 save end
visible_roles()
click to toggle source
# File lib/buweb/user.rb, line 166 def visible_roles return [:faculty] if roles.blank? Person::ALL_AFFILIATIONS - restricted_roles end
Private Instance Methods
downcase_username()
click to toggle source
# File lib/buweb/user.rb, line 173 def downcase_username username&.downcase! end
new_person_attributes()
click to toggle source
# File lib/buweb/user.rb, line 195 def new_person_attributes { trogdir_id: trogdir_id, biola_id: biola_id, biola_photo_url: photo_url, biola_email: email, department: department, biola_title: title, first_name: first_name, preferred_name: nil, last_name: last_name, affiliations: affiliations } end
relevant_entitlements()
click to toggle source
Find URNs that match the namespaces and remove the namespace See en.wikipedia.org/wiki/Uniform_Resource_Name
# File lib/buweb/user.rb, line 179 def relevant_entitlements urns = Array(entitlements) nids = BuwebContentModels.config.urn_namespaces return [] if urns.blank? clean_urns = urns.map { |e| e.gsub(/^urn:/i, '') } clean_nids = nids.map { |n| n.gsub(/^urn:/i, '') } clean_urns.map do |urn| clean_nids.map do |nid| urn[0...nid.length] == nid ? urn[nid.length..urn.length] : nil end end.flatten.compact end
update_person_attributes()
click to toggle source
# File lib/buweb/user.rb, line 208 def update_person_attributes { biola_photo_url: photo_url, department: department, affiliations: affiliations } end