Class: Specify::Model::User

Inherits:
Object
  • Object
show all
Includes:
Updateable
Defined in:
lib/specify/models/user.rb

Overview

Users represent Specify users.

Instance Method Summary collapse

Methods included from Updateable

#before_update

Instance Method Details

#collection_valid?(collection) ⇒ Boolean

Returns true if collection (a Specify::Model::Collection) is the same #login_collection.

Returns:

  • (Boolean)


16
17
18
# File 'lib/specify/models/user.rb', line 16

def collection_valid?(collection)
   == collection
end

#inspectObject

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 (collection)
  logged_in?(collection) || (collection)
end

#log_outObject

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.

Returns:

  • (Boolean)

Raises:



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_agentObject

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: .division)
end

#login_collectionObject

Returns the Specify::Model::Collection that self is logged in to.



62
63
64
65
# File 'lib/specify/models/user.rb', line 62

def 
  .collections_dataset
                  .first CollectionName: self[:LoginCollectionName]
end

#login_disciplineObject

Returns the Specify::Model::Discipline that self is logged in to.



68
69
70
# File 'lib/specify/models/user.rb', line 68

def 
  Discipline.first Name: self[:LoginDisciplineName]
end

#nameObject

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 (collection)
   = Time.now
  self[:LoginOutTime] = 
  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