Class: Specify::Model::User

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

Overview

A class that represents a Specify user.

Instance Method Summary collapse

Instance Method Details

#before_updateObject


10
11
12
13
14
# File 'lib/specify/models/user.rb', line 10

def before_update
  self.Version += 1
  self.TimestampModified = Time.now
  super
end

#collection_valid?(collection) ⇒ Boolean

-> true or false Returns true if collection is consistent with the combination of Model::Collection and Model::Disciplin as registered in the databse. collection: a Model::Collection

Returns:

  • (Boolean)

26
27
28
29
30
# File 'lib/specify/models/user.rb', line 26

def collection_valid?(collection)
  c_match = self.LoginCollectionName == collection[:CollectionName]
  d_match = self.LoginDisciplineName == collection.discipline[:Name]
  d_match && c_match
end

#inspectObject

-> String Returns a string containing a human-readable representation of User.


18
19
20
# File 'lib/specify/models/user.rb', line 18

def inspect
  "#{self} user name: #{self.Name}, logged in: #{self.IsLoggedIn}"
end

#log_in(collection) ⇒ Object

-> Hash Logs the user in to collection collection: a Model::Collection


35
36
37
# File 'lib/specify/models/user.rb', line 35

def (collection)
  logged_in?(collection) || (collection)
end

#log_outObject

-> Time Logs the user out of the system.


41
42
43
44
45
46
47
48
49
# File 'lib/specify/models/user.rb', line 41

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

-> Hash or nil Returns the collection and login time if the user is logged in to collection. collection: a Model::Collection

Returns:

  • (Boolean)

Raises:


55
56
57
58
59
# File 'lib/specify/models/user.rb', line 55

def logged_in?(collection)
  return nil unless self.IsLoggedIn
  raise LoginError::INCONSISTENT_LOGIN unless collection_valid? collection
  { collection => self.LoginOutTime }
end

#logged_in_agentObject

-> Specify::Model::Agent Returns the Model::Agent for the division of the collection the user is logged in to.


64
65
66
67
# File 'lib/specify/models/user.rb', line 64

def logged_in_agent
  division = Discipline.first(Name: self.LoginDisciplineName).division
  agents_dataset.first(division: division)
end

#nameObject

Returns a String with the Specify username.


70
71
72
# File 'lib/specify/models/user.rb', line 70

def name
  self.Name
end

#new_login(collection) ⇒ Object

-> Hash Registers a new login in collection with the database. collection: a Model::Collection


77
78
79
80
81
82
83
84
85
# File 'lib/specify/models/user.rb', line 77

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

-> Specify::Model::ViewSetObject Returns the user's ViewSetObject for collection. collection: a Model::Collection


100
101
102
# File 'lib/specify/models/user.rb', line 100

def view_set(collection)
  view_set_dir(collection)&.view_set_object
end

#view_set_dir(collection) ⇒ Object

-> Specify::Model::AppResourceDir Returns the user's AppResourceDir instances for collection. collection: a 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