Module: EquitracUtilities::UserActions

Included in:
Connection
Defined in:
lib/equitrac_utilities/user_actions.rb

Overview

Instance Method Summary collapse

Instance Method Details

#check_atrribs(attrs, command = nil) ⇒ String

Be sure Actions have correct user_id data

Parameters:

  • action (Symbol)

    the action to be formatted

Returns:

  • (String)

    this attribute MUST include: { user_id: “userid” }

Raises:

  • (ArgumentError)


25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/equitrac_utilities/user_actions.rb', line 25

def check_atrribs(attrs, command=nil)
  raise ArgumentError, "user_id missing"   if attrs[:user_id].nil?
  # attribs[:uid] = attribs[:uid].to_s.strip
  attribs = {}
  attrs.each do |k,v|
    attribs[k] = v&.strip     if v.is_a? String
    attribs[k] = v        unless v.is_a? String
  end
  # attribs[:user_id] = attribs[:user_id]&.strip
  # attribs[:user_name] = attribs[:user_name]&.strip
  # attribs[:email] = attribs[:email]&.strip
  raise ArgumentError, "user_id empty"     if attribs[:user_id].empty?
  raise ArgumentError, "user_id has space" if attribs[:user_id].include?(' ')
  if command.eql? :user_add
    raise ArgumentError, " missing user_name" if attribs[:user_name].nil?
    raise ArgumentError, " missing email"     if attribs[:email].nil?
    raise ArgumentError, " missing dept_name" if attribs[:dept_name].nil?
  end
  return attribs
end

#process_user_exists?(test) ⇒ Boolean

Process to test if user exists in Equitrac System

Parameters:

  • test (Hash)

    this attribute MUST include: { user_id: “userid” }

Returns:

  • (Boolean)

    True or False depending on if the user was found or not



70
71
72
73
74
# File 'lib/equitrac_utilities/user_actions.rb', line 70

def process_user_exists?(test)
  return false if test.include?("Can't find")
  return true  if test.include?("User_ID")
  raise
end

#user_add(attribs) ⇒ String

Note:

user_id, initial_balance, user_name, department_name, and primary_pin required

Add a user to the system

Parameters:

  • attributes (Hash)

    this attribute MUST include { user_id: “userid”, init_bal: 0, username: “Test USER”, dept_name: “Testdept”, primary_pin: “99999”}

Returns:

  • (String)

    Formatted for EQCmd.exe command execution



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/equitrac_utilities/user_actions.rb', line 81

def user_add(attribs)
  defaults   = {init_bal: 50.0, min_bal: 0.0, secondary_pin: '""',quota: 0,
                alternate_pin: '""', home_server: '""', locked: 0,
                location: '""', additional_info: 0, home_folder: '""'}
  attribs = defaults.merge( attribs )

  attribs = check_atrribs(attribs, :user_add)

  "add ur #{attribs[:user_id]} #{attribs[:init_bal]}" +
  " \"#{attribs[:user_name]}\" #{attribs[:min_bal]}" +
  " #{attribs[:email]} #{attribs[:dept_name]}" +
  " #{attribs[:primary_pin]} #{attribs[:secondary_pin]}" +
  " #{attribs[:quota]} #{attribs[:alternate_pin]}" +
  " #{attribs[:home_server]} #{attribs[:locked]}" +
  " #{attribs[:location]} #{attribs[:additional_info]}" +
  " #{attribs[:home_folder]}"
end

#user_adjust_set(attribs) ⇒ String

Note:

attr new_bal defaults to 0, if not included in the attributes

Process to set a new balance for a user in the Equitrac System

Parameters:

  • attr (Hash)

    this attribute MUST include: { user_id: “userid” }

Returns:

  • (String)

    Formatted for EQCmd.exe command execution



152
153
154
155
156
157
# File 'lib/equitrac_utilities/user_actions.rb', line 152

def user_adjust_set(attribs)
  defaults = {new_bal: 0.0, description: nil}
  attribs = defaults.merge(attribs)
  attribs = check_atrribs(attribs)
  "adjust ur #{attribs[:user_id]} set #{attribs[:new_bal]} #{attribs[:description]}"
end

#user_delete(attribs) ⇒ String

Process to delete a user from the Equitrac System

Parameters:

  • attr (Hash)

    this attribute MUST include: { user_id: “userid” }

Returns:

  • (String)

    Formatted for EQCmd.exe command execution



103
104
105
106
# File 'lib/equitrac_utilities/user_actions.rb', line 103

def user_delete(attribs)
  attribs = check_atrribs(attribs)
  "delete ur #{attribs[:user_id]}"
end

#user_exists?(attribs) ⇒ String

Note:

This required post-answer_post_processing

Query to test if user exists in Equitrac System

Parameters:

  • attr (Hash)

    this attribute MUST include: { user_id: “userid” }

Returns:

  • (String)

    Formatted for EQCmd.exe command execution



61
62
63
64
# File 'lib/equitrac_utilities/user_actions.rb', line 61

def user_exists?(attribs)
  attribs = check_atrribs(attribs)
  user_query(attribs)
end

#user_lock(attribs) ⇒ String

Process to lock a user in the Equitrac System

Parameters:

  • attr (Hash)

    this attribute MUST include: { user_id: “userid” }

Returns:

  • (String)

    Formatted for EQCmd.exe command execution



112
113
114
115
# File 'lib/equitrac_utilities/user_actions.rb', line 112

def user_lock(attribs)
  attribs = check_atrribs(attribs)
  "lock ur #{attribs[:user_id]}"
end

#user_modify(attribs) ⇒ String

Process to lock a user in the Equitrac System

Parameters:

  • attr (Hash)

    this attribute MUST include: { user_id: “userid” }

Returns:

  • (String)

    Formatted for EQCmd.exe command execution



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
# File 'lib/equitrac_utilities/user_actions.rb', line 130

def user_modify(attribs)
  defaults = {user_name: "!", min_bal: "!",
              email: "!", dept_name: "!", pimary_pin: "!",
              secondary_pin: "!", quota: "!", alternate_pin: "!",
              home_server: "!", locked: "!", location: "!",
              default_bc: "!", additional_info: "!", home_folder: "!"}
  attribs = defaults.merge(attribs)
  attribs = check_atrribs(attribs)
  "modify ur #{attribs[:user_id]} \"#{attribs[:user_name]}\"" +
  " #{attribs[:min_bal]} #{attribs[:email]} #{attribs[:dept_name]}" +
  " #{attribs[:primary_pin]} #{attribs[:secondary_pin]}" +
  " #{attribs[:quota]} #{attribs[:alternate_pin]}" +
  " #{attribs[:home_server]} #{attribs[:locked]}" +
  " #{attribs[:location]} #{attribs[:default_bc]}" +
  " #{attribs[:additional_info]} #{attribs[:home_folder]}"
end

#user_query(attribs) ⇒ String

Get Equitrac User Info

Parameters:

  • attr (Hash)

    this attribute MUST include: { user_id: “userid” }

Returns:

  • (String)

    Formatted for EQCmd.exe command execution



51
52
53
54
# File 'lib/equitrac_utilities/user_actions.rb', line 51

def user_query(attribs)
  attribs = check_atrribs(attribs)
  "query ur #{attribs[:user_id]}"
end

#user_unlock(attribs) ⇒ String

Process to unlock a user in the Equitrac System

Parameters:

  • attr (Hash)

    this attribute MUST include: { user_id: “userid” }

Returns:

  • (String)

    Formatted for EQCmd.exe command execution



121
122
123
124
# File 'lib/equitrac_utilities/user_actions.rb', line 121

def user_unlock(attribs)
  attribs = check_atrribs(attribs)
  "unlock ur #{attribs[:user_id]}"
end