Class: UserObject

Inherits:
Object
  • Object
show all
Includes:
DataFactory, Foundry, Navigation
Defined in:
lib/kuality-coeus/data_objects/user.rb

Constant Summary collapse

USERS =
UserCollection[YAML.load_file("#{File.dirname(__FILE__)}/users.yml")]
ROLES =
{
    # Add roles here as needed for testing...
    'Aggregator'                      => '110',
    'approver'                        => '103',
    'Award Budget Aggregator'         => '113',
    'Award Budget Approver'           => '112',
    'Award Budget Modifier'           => '102',
    'Award Budget Viewer'             => '101',
    'Award Viewer'                    => '123',
    'Budget Creator'                  => '108',
    'Create Proposal Log'             => '140',
    'Departments Awards Viewer'       => '121',
    'IACUC Protocol Aggregator'       => '1421',
    'IACUC Protocol Approver'         => '1638',
    'Institutional Proposal Viewer'   => '118',
    'IRB Administrator'               => '128',
    'IRB Approver'                    => '99',
    'IRB Reviewer'                    => '127',
    'KC Super User'                   => '177',
    'Maintain IRB Questionnaire'      => '161',
    'Maintain Proposal Questionnaire' => '162',
    'Manager'                         =>  '98',
    'Narrative Writer'                => '109',
    'Negotiation Creator'             => '1382',
    'OSP Administrator'               => '131',
    'OSPApprover'                     => '100',
    'Protocol Aggregator'             => '105',
    'Proposal Creator'                => '111',
    'System User'                     => '90',
    'Unassigned'                      => '106',
    'Viewer'                          => '107',
    'View Subaward'                   => '1409',
    'View Proposal Log'               => '142'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Navigation

#doc_search, #fill_out, #fill_out_item, #on_document?, #on_page?, #open_document

Methods included from Utilities

#get, #make_user, #random_percentage, #set, #snake_case

Constructor Details

#initialize(browser, opts = {}) ⇒ UserObject

Returns a new instance of UserObject.



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/kuality-coeus/data_objects/user.rb', line 94

def initialize(browser, opts={})
  @browser = browser
  @user_name=case
             when opts.empty?
               'admin'
             when opts.key?(:user)
               opts[:user]
             when opts.key?(:role)
               USERS.have_role(ROLES[opts[:role]])[0][0]
             else
               :nil
             end
  options = USERS[@user_name].nil? ? opts : USERS[@user_name].merge(opts)
  set_options options
end

Instance Attribute Details

#addressesObject

Returns the value of attribute addresses.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def addresses
  @addresses
end

#affiliation_typeObject

Returns the value of attribute affiliation_type.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def affiliation_type
  @affiliation_type
end

#base_salaryObject

Returns the value of attribute base_salary.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def base_salary
  @base_salary
end

#billing_elementObject

Returns the value of attribute billing_element.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def billing_element
  @billing_element
end

#campus_codeObject

Returns the value of attribute campus_code.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def campus_code
  @campus_code
end

#citizenship_typeObject

Returns the value of attribute citizenship_type.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def citizenship_type
  @citizenship_type
end

#descriptionObject

Returns the value of attribute description.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def description
  @description
end

#directory_departmentObject

Returns the value of attribute directory_department.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def directory_department
  @directory_department
end

#directory_titleObject

Returns the value of attribute directory_title.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def directory_title
  @directory_title
end

#emailsObject

Returns the value of attribute emails.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def emails
  @emails
end

#employee_idObject

Returns the value of attribute employee_id.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def employee_id
  @employee_id
end

#employee_statusObject

Returns the value of attribute employee_status.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def employee_status
  @employee_status
end

#employee_typeObject

Returns the value of attribute employee_type.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def employee_type
  @employee_type
end

#era_commons_user_nameObject

Returns the value of attribute era_commons_user_name.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def era_commons_user_name
  @era_commons_user_name
end

#first_nameObject

Returns the value of attribute first_name.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def first_name
  @first_name
end

#graduate_student_countObject

Returns the value of attribute graduate_student_count.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def graduate_student_count
  @graduate_student_count
end

#groupsObject

Returns the value of attribute groups.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def groups
  @groups
end

#last_nameObject

Returns the value of attribute last_name.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def last_name
  @last_name
end

#phonesObject

Returns the value of attribute phones.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def phones
  @phones
end

#primary_dept_codeObject

Returns the value of attribute primary_dept_code.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def primary_dept_code
  @primary_dept_code
end

#primary_titleObject

Returns the value of attribute primary_title.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def primary_title
  @primary_title
end

#principal_idObject

Returns the value of attribute principal_id.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def principal_id
  @principal_id
end

#role_qualifiersObject

Returns the value of attribute role_qualifiers.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def role_qualifiers
  @role_qualifiers
end

#rolesObject

Returns the value of attribute roles.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def roles
  @roles
end

#user_nameObject

Returns the value of attribute user_name.



48
49
50
# File 'lib/kuality-coeus/data_objects/user.rb', line 48

def user_name
  @user_name
end

Instance Method Details

#createObject



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/kuality-coeus/data_objects/user.rb', line 110

def create
  # First we have to make sure we're logged in with
  # a user that has permissions to create other users...
  @browser.windows[0].use
  visit SystemAdmin do |page|
    page.close_children
    if @logged_in_user_name=='admin'
      page.person
    else
      s_o.click
      visit Login do ||
        .username.set 'admin'
        .
      end
      visit(SystemAdmin).person
    end
  end
  # Now we're certain the create button will be there, so...
  on(PersonLookup).create
  on Person do |add|
    add.expand_all
    add.principal_name.set @user_name
    fill_out add, :description, :affiliation_type, :campus_code, :first_name, :last_name
    # TODO: These "default" checkboxes will need to be reworked if and when
    # a test is going to require multiple affiliations, names, addresses, etc.
    # Until then, there's no need to do anything other than set the necessary single values
    # as "default"...
    add.affiliation_default.set
    add.name_default.set
    add.add_name
    add.add_affiliation
    # TODO: Another thing that will need to be changed if ever there's a need to test multiple
    # lines of employment:
    unless @employee_id.nil?
      fill_out add, :employee_id, :employee_status, :employee_type, :base_salary, :primary_dept_code
      add.primary_employment.set
      add.add_employment_information
    end
    unless @roles.nil?
      @roles.each do |role|
        add.role_id.set role
        add.add_role
      end
    end
    unless @role_qualifiers.nil?
      @role_qualifiers.each do |role, unit|
        add.unit_number(role).set unit
        add.add_role_qualifier role
      end
    end
    unless @groups.nil?
      @groups.each do |group|
        add.group_id.set group
        add.add_group
      end
    end
    unless @addresses.nil?
      @addresses.each do |address|
        add.address_type.fit address[:type]
        add.line_1.fit address[:line_1]
        add.city.fit address[:city]
        add.state.pick! address[:state]
        add.country.pick! address[:country]
        add.zip.fit address[:zip]
        add.address_default.fit address[:default]
        add.add_address
      end
    end
    unless @phones.nil?
      @phones.each do |phone|
        add.phone_type.fit phone[:type]
        add.phone_number.fit phone[:number]
        add.phone_default.fit phone[:default]
        add.add_phone
      end
    end
    unless @emails.nil?
      @emails.each do |email|
        add.email.fit email[:email]
        add.email_type.pick! email[:type]
        add.email_default.fit email[:default]
        add.add_email
      end
    end
    # A breaking of the design pattern, but there's no other
    # way to obtain this number:
    @principal_id = add.principal_id
    add.blanket_approve
  end
  visit(SystemAdmin).person_extended_attributes
  on(PersonExtendedAttributesLookup).create
  on PersonExtendedAttributes do |page|
    page.expand_all
    fill_out page, :description, :primary_title, :directory_title, :citizenship_type,
             :era_commons_user_name, :graduate_student_count, :billing_element,
             :principal_id, :directory_department
    page.blanket_approve
  end
  # Now that we're done with the user creation, we can log back in
  # with the other user, if necessary...
  unless @logged_in_user_name.nil?
    s_o.click
    on Login do ||
      .username.set @logged_in_user_name
      .
    end
    @logged_in_user_name=nil
  end
end

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
# File 'lib/kuality-coeus/data_objects/user.rb', line 270

def exist?
  visit SystemAdmin do |page|
    if username_field.present?
      UserObject.new(@browser).
    else
      @logged_in_user_name=.text[/\w+$/]
    end
    page.person
  end
  on PersonLookup do |search|
    search.principal_name.set @user_name
    search.search
    begin
      if search.item_row(@user_name).present?
        # FIXME!
        # This is a coding abomination to include
        # this here, but it's here until I can come
        # up with a better solution...
        @principal_id = search.item_row(@user_name).link(title: /^Person Principal ID=\d+/).text
        return true
      else
        return false
      end
    rescue
      return false
    end
  end
end

#logged_in?Boolean

Returns:

  • (Boolean)


300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/kuality-coeus/data_objects/user.rb', line 300

def logged_in?
  # Are we on the login page already?
  if username_field.present?
    # Yes! So, we're not logged in...
    false
  # No, the Kuali header is showing...
  elsif .present?
    # So, is the user currently listed as logged in?
    return .text.include? @user_name
  else # We're on some page that has no Kuali header, so...
    begin
      # We'll assume that the portal window exists, and go to it.
      on(Researcher).return_to_portal
    # Oops. Apparently there's no portal window, so...
    rescue
      # We'll close any extra tabs/windows
      visit(Login).close_children if @browser.windows.size > 1
      # And make sure that we're using the "parent" window
      @browser.windows[0].use
    end
    # Now that things are hopefully in a clean state, we'll start
    # the process again...
    logged_in?
  end
end

#logged_out?Boolean

Returns:

  • (Boolean)


326
327
328
# File 'lib/kuality-coeus/data_objects/user.rb', line 326

def logged_out?
  !logged_in?
end

#sign_inObject Also known as: log_in

Keep in mind…

  • This method does nothing if the user is already logged in

  • If some other user is logged in, they will be automatically logged out

  • This method will close all child tabs/windows and return to the window with the header frame, so it can see who is currently logged in



229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
# File 'lib/kuality-coeus/data_objects/user.rb', line 229

def 
  unless logged_in?
    if username_field.present?
      # Do nothing because we're already there
    else
      visit Researcher do |page|
        page.return_to_portal
        page.close_children
        page.logout
      end
    end
    on Login do ||
      .username.set @user_name
      .
    end
    on(Researcher).logout_button.wait_until_present
  end
end

#sign_outObject Also known as: log_out



249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
# File 'lib/kuality-coeus/data_objects/user.rb', line 249

def sign_out
# This _might_ cause an infinite loop, but I'm
# hoping not...
  on(Researcher) do |page|
    page.return_to_portal
    page.close_children
  end
  if s_o.present?
    s_o.click
  else
    visit Login do |page|
      if page.username.present?
        # do nothing because we're already logged out...
      else
        sign_out
      end
    end
  end
end