Class: Specify::Model::User
- Inherits:
-
Object
- Object
- Specify::Model::User
- Includes:
- Updateable
- Defined in:
- lib/specify/models/user.rb
Overview
Users represent Specify users.
Instance Method Summary collapse
-
#collection_valid?(collection) ⇒ Boolean
Returns
true
ifcollection
(a Specify::Model::Collection) is the same #login_collection. -
#inspect ⇒ Object
Creates a string representation of
self
. -
#log_in(collection) ⇒ Object
Logs the user in to
collection
(a Specify::Model::Collection). -
#log_out ⇒ Object
Logs the user out.
-
#logged_in?(collection) ⇒ Boolean
Returns a Hash with the Specify::Model::Collection as key, the timestamp for the login as the value if
self
is logged in tocollection
(a Specify::Model::Collection),nil
otherwise. -
#logged_in_agent ⇒ Object
Returns the Specify::Model::Agent for
self
in the Specify::Model::Division division to which the login_discipline belongs. -
#login_collection ⇒ Object
Returns the Specify::Model::Collection that
self
is logged in to. -
#login_discipline ⇒ Object
Returns the Specify::Model::Discipline that
self
is logged in to. -
#name ⇒ Object
Returns a String with the Specify username for
self
. -
#new_login(collection) ⇒ Object
Registers a new login in
collection
(a Specify::Model::Collection). -
#view_set(collection) ⇒ Object
Returns the Specify::Model::ViewSetObject for
self
incollection
(a Specify::Model::Collection). -
#view_set_dir(collection) ⇒ Object
Returns the Specify::Model::AppResourceDir for
self
incollection
(a Specify::Model::Collection).
Methods included from Updateable
Instance Method Details
#collection_valid?(collection) ⇒ Boolean
Returns true
if collection
(a Specify::Model::Collection) is the same #login_collection.
16 17 18 |
# File 'lib/specify/models/user.rb', line 16 def collection_valid?(collection) login_collection == collection end |
#inspect ⇒ Object
Creates a string representation of self
.
21 22 23 |
# File 'lib/specify/models/user.rb', line 21 def inspect "#{self} user name: #{self.Name}, logged in: #{self.IsLoggedIn}" end |
#log_in(collection) ⇒ Object
Logs the user in to collection
(a Specify::Model::Collection).
Returns a Hash with the Specify::Model::Collection as key, the timestamp for the login as the value.
29 30 31 |
# File 'lib/specify/models/user.rb', line 29 def log_in(collection) logged_in?(collection) || new_login(collection) end |
#log_out ⇒ Object
Logs the user out.
Returns the timestamp for the logout.
36 37 38 39 40 41 42 43 44 |
# File 'lib/specify/models/user.rb', line 36 def log_out return true unless self[:IsLoggedIn] self[:LoginOutTime] = Time.now self[:IsLoggedIn] = false self[:LoginCollectionName] = nil self[:LoginDisciplineName] = nil save self[:LoginOutTime] end |
#logged_in?(collection) ⇒ Boolean
Returns a Hash with the Specify::Model::Collection as key, the timestamp for the login as the value if self
is logged in to collection
(a Specify::Model::Collection), nil
otherwise.
49 50 51 52 53 |
# File 'lib/specify/models/user.rb', line 49 def logged_in?(collection) return nil unless self[:IsLoggedIn] raise LoginError::INCONSISTENT_LOGIN unless collection_valid? collection { collection => self[:LoginOutTime] } end |
#logged_in_agent ⇒ Object
Returns the Specify::Model::Agent for self
in the Specify::Model::Division division to which the login_discipline belongs.
57 58 59 |
# File 'lib/specify/models/user.rb', line 57 def logged_in_agent agents_dataset.first(division: login_discipline.division) end |
#login_collection ⇒ Object
Returns the Specify::Model::Collection that self
is logged in to.
62 63 64 65 |
# File 'lib/specify/models/user.rb', line 62 def login_collection login_discipline.collections_dataset .first CollectionName: self[:LoginCollectionName] end |
#login_discipline ⇒ Object
Returns the Specify::Model::Discipline that self
is logged in to.
68 69 70 |
# File 'lib/specify/models/user.rb', line 68 def login_discipline Discipline.first Name: self[:LoginDisciplineName] end |
#name ⇒ Object
Returns a String with the Specify username for self
.
73 74 75 |
# File 'lib/specify/models/user.rb', line 73 def name self[:Name] end |
#new_login(collection) ⇒ Object
Registers a new login in collection
(a Specify::Model::Collection).
78 79 80 81 82 83 84 85 86 |
# File 'lib/specify/models/user.rb', line 78 def new_login(collection) login_time = Time.now self[:LoginOutTime] = login_time self[:IsLoggedIn] = true self[:LoginCollectionName] = collection[:CollectionName] self[:LoginDisciplineName] = collection.discipline[:Name] save { collection => self[:LoginOutTime] } end |
#view_set(collection) ⇒ Object
Returns the Specify::Model::ViewSetObject for self
in collection
(a Specify::Model::Collection)
99 100 101 |
# File 'lib/specify/models/user.rb', line 99 def view_set(collection) view_set_dir(collection)&.view_set_object end |
#view_set_dir(collection) ⇒ Object
Returns the Specify::Model::AppResourceDir for self
in collection
(a Specify::Model::Collection).
90 91 92 93 94 95 |
# File 'lib/specify/models/user.rb', line 90 def view_set_dir(collection) app_resource_dirs_dataset.first(collection: collection, discipline: collection.discipline, UserType: self[:UserType], IsPersonal: true) end |