Module: Sufia::User
- Extended by:
- ActiveSupport::Concern, Deprecation
- Defined in:
- app/models/concerns/sufia/user.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #ability ⇒ Object
- #all_user_activity(since = DateTime.current.to_i - 1.day) ⇒ Object
-
#as_json(_opts = nil) ⇒ Object
Format the json for select2 which requires just an id and a field called text.
- #log_profile_event(event_id) ⇒ Object
-
#mailboxer_email(_obj = nil) ⇒ Object
method needed for messaging.
- #name ⇒ Object
-
#normalize_orcid ⇒ Object
Coerce the ORCID into URL format.
-
#populate_attributes ⇒ Object
Populate user instance with attributes from remote system (e.g., LDAP) There is no default implementation – override this in your application.
- #profile_events(size = -1)) ⇒ Object
- #set_arkivo_token ⇒ Object
-
#to_param ⇒ Object
Redefine this for more intuitive keys in Redis.
- #token_algorithm ⇒ Object
- #zotero_token ⇒ Object
- #zotero_token=(value) ⇒ Object
Instance Method Details
#ability ⇒ Object
118 119 120 |
# File 'app/models/concerns/sufia/user.rb', line 118 def ability @ability ||= ::Ability.new(self) end |
#all_user_activity(since = DateTime.current.to_i - 1.day) ⇒ Object
122 123 124 125 126 |
# File 'app/models/concerns/sufia/user.rb', line 122 def all_user_activity(since = DateTime.current.to_i - 1.day) events = self.events.reverse.collect { |event| event if event[:timestamp].to_i > since }.compact profile_events = self.profile_events.reverse.collect { |event| event if event[:timestamp].to_i > since }.compact events.concat(profile_events).sort { |a, b| b[:timestamp].to_i <=> a[:timestamp].to_i } end |
#as_json(_opts = nil) ⇒ Object
Format the json for select2 which requires just an id and a field called text. If we need an alternate format we should probably look at a json template gem
92 93 94 |
# File 'app/models/concerns/sufia/user.rb', line 92 def as_json(_opts = nil) { id: user_key, text: display_name ? "#{display_name} (#{user_key})" : user_key } end |
#log_profile_event(event_id) ⇒ Object
51 52 53 |
# File 'app/models/concerns/sufia/user.rb', line 51 def log_profile_event(event_id) event_store.for(stream[:event][:profile]).push(event_id) end |
#mailboxer_email(_obj = nil) ⇒ Object
method needed for messaging
114 115 116 |
# File 'app/models/concerns/sufia/user.rb', line 114 def mailboxer_email(_obj = nil) nil end |
#name ⇒ Object
101 102 103 104 105 |
# File 'app/models/concerns/sufia/user.rb', line 101 def name display_name.titleize || raise rescue user_key end |
#normalize_orcid ⇒ Object
Coerce the ORCID into URL format
80 81 82 83 84 85 86 87 88 |
# File 'app/models/concerns/sufia/user.rb', line 80 def normalize_orcid # Skip normalization if: # 1. validation has already flagged the ORCID as invalid # 2. the orcid field is blank # 3. the orcid is already in its normalized form return if errors[:orcid].first.present? || orcid.blank? || orcid.starts_with?('http://orcid.org/') = Sufia::OrcidValidator.match(orcid).string self.orcid = "http://orcid.org/#{bare_orcid}" end |
#populate_attributes ⇒ Object
Populate user instance with attributes from remote system (e.g., LDAP) There is no default implementation – override this in your application
98 99 |
# File 'app/models/concerns/sufia/user.rb', line 98 def populate_attributes end |
#profile_events(size = -1)) ⇒ Object
47 48 49 |
# File 'app/models/concerns/sufia/user.rb', line 47 def profile_events(size = -1) event_store.for(stream[:event][:profile]).fetch(size) end |
#set_arkivo_token ⇒ Object
68 69 70 |
# File 'app/models/concerns/sufia/user.rb', line 68 def set_arkivo_token self.arkivo_token ||= token_algorithm end |
#to_param ⇒ Object
Redefine this for more intuitive keys in Redis
108 109 110 111 |
# File 'app/models/concerns/sufia/user.rb', line 108 def to_param # HACK: because rails doesn't like periods in urls. user_key.gsub(/\./, '-dot-') end |
#token_algorithm ⇒ Object
72 73 74 75 76 77 |
# File 'app/models/concerns/sufia/user.rb', line 72 def token_algorithm loop do token = SecureRandom.base64(24) return token if User.find_by(arkivo_token: token).nil? end end |
#zotero_token ⇒ Object
55 56 57 |
# File 'app/models/concerns/sufia/user.rb', line 55 def zotero_token self[:zotero_token].blank? ? nil : Marshal.load(self[:zotero_token]) end |
#zotero_token=(value) ⇒ Object
59 60 61 62 63 64 65 66 |
# File 'app/models/concerns/sufia/user.rb', line 59 def zotero_token=(value) self[:zotero_token] = if value.blank? # Resetting the token value else Marshal.dump(value) end end |