Module: Hyrax::User
- Extended by:
- ActiveSupport::Concern
- Defined in:
- app/models/concerns/hyrax/user.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #ability ⇒ Object
-
#agent_key ⇒ String
A local identifier for this user; for use (e.g.) in ACL data.
- #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 ⇒ String
A name for the user.
-
#normalize_orcid ⇒ Object
Coerce the ORCID into URL format.
- #profile_events(size = -1)) ⇒ Object
- #set_arkivo_token ⇒ Object
-
#to_param ⇒ Object
Redefine this for more intuitive keys in Redis.
-
#to_sipity_agent ⇒ Object
Look for, in order: A cached version of the agent A non-cached version (direct read of the database) A created version.
- #token_algorithm ⇒ Object
- #user_key ⇒ Object
- #zotero_token ⇒ Object
- #zotero_token=(value) ⇒ Object
Instance Method Details
#ability ⇒ Object
144 145 146 |
# File 'app/models/concerns/hyrax/user.rb', line 144 def ability @ability ||= ::Ability.new(self) end |
#agent_key ⇒ String
Returns a local identifier for this user; for use (e.g.) in ACL data.
59 60 61 |
# File 'app/models/concerns/hyrax/user.rb', line 59 def agent_key user_key end |
#all_user_activity(since = DateTime.current.to_i - 1.day) ⇒ Object
148 149 150 151 152 |
# File 'app/models/concerns/hyrax/user.rb', line 148 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
123 124 125 |
# File 'app/models/concerns/hyrax/user.rb', line 123 def as_json(_opts = nil) { id: user_key, text: display_name ? "#{display_name} (#{user_key})" : user_key } end |
#log_profile_event(event_id) ⇒ Object
82 83 84 |
# File 'app/models/concerns/hyrax/user.rb', line 82 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
140 141 142 |
# File 'app/models/concerns/hyrax/user.rb', line 140 def mailboxer_email(_obj = nil) nil end |
#name ⇒ String
Returns a name for the user.
129 130 131 |
# File 'app/models/concerns/hyrax/user.rb', line 129 def name display_name || user_key end |
#normalize_orcid ⇒ Object
Coerce the ORCID into URL format
111 112 113 114 115 116 117 118 119 |
# File 'app/models/concerns/hyrax/user.rb', line 111 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?('https://orcid.org/') = Hyrax::OrcidValidator.(from: orcid) self.orcid = "https://orcid.org/#{}" end |
#profile_events(size = -1)) ⇒ Object
78 79 80 |
# File 'app/models/concerns/hyrax/user.rb', line 78 def profile_events(size = -1) event_store.for(stream[:event][:profile]).fetch(size) end |
#set_arkivo_token ⇒ Object
99 100 101 |
# File 'app/models/concerns/hyrax/user.rb', line 99 def set_arkivo_token self.arkivo_token ||= token_algorithm end |
#to_param ⇒ Object
Redefine this for more intuitive keys in Redis
134 135 136 137 |
# File 'app/models/concerns/hyrax/user.rb', line 134 def to_param # Rails doesn't like periods in urls user_key.gsub(/\./, '-dot-') end |
#to_sipity_agent ⇒ Object
Look for, in order:
A cached version of the agent
A non-cached version (direct read of the database)
A created version.
A version created in another thread before we were able to create it
68 69 70 71 72 73 74 75 76 |
# File 'app/models/concerns/hyrax/user.rb', line 68 def to_sipity_agent sipity_agent || reload_sipity_agent || begin create_sipity_agent! rescue ActiveRecord::RecordNotUnique reload_sipity_agent end end |
#token_algorithm ⇒ Object
103 104 105 106 107 108 |
# File 'app/models/concerns/hyrax/user.rb', line 103 def token_algorithm loop do token = SecureRandom.base64(24) return token if User.find_by(arkivo_token: token).nil? end end |
#user_key ⇒ Object
52 53 54 |
# File 'app/models/concerns/hyrax/user.rb', line 52 def user_key public_send(self.class.user_key_field) end |
#zotero_token ⇒ Object
86 87 88 |
# File 'app/models/concerns/hyrax/user.rb', line 86 def zotero_token self[:zotero_token].blank? ? nil : Marshal.load(self[:zotero_token]) end |
#zotero_token=(value) ⇒ Object
90 91 92 93 94 95 96 97 |
# File 'app/models/concerns/hyrax/user.rb', line 90 def zotero_token=(value) self[:zotero_token] = if value.blank? # Resetting the token value else Marshal.dump(value) end end |