Class: UserObject

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

Overview

UserYamlCollection

Constant Summary collapse

USERS =
UserYamlCollection[YAML.load_file("#{File.dirname(__FILE__)}/users.yml")]

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, #window_cleanup

Methods included from Utilities

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

Constructor Details

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

Returns a new instance of UserObject.



103
104
105
106
107
108
109
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
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 103

def initialize(browser, opts={})
  @browser = browser

  defaults={
      user_name:        random_letters(16),
      description:      random_alphanums,
      affiliation_type: 'Student',
      campus_code:      'UN - UNIVERSITY',
      first_name:       random_alphanums,
      last_name:        random_alphanums,
      addresses:        [{type:   'Work',
                          line_1:  '1375 N Scottsdale Rd',
                          city:    'scottsdale',
                          state:   'ARIZONA',
                          country: 'United States',
                          zip:     '85257',
                          default: :set }],
      phones:           [{type:   'Work',
                          number:  '602-840-7300',
                          default: :set }],
      rolez:            [{id: '106', qualifiers: [{:unit=>'000001'}]}],
      groups:           collection('UserGroups')
  }
  defaults.merge!(opts)
  @roles = collection('UserRoles')

  @user_name=case
             when opts.empty?
               'admin'
             when opts.key?(:user)
               opts[:user]
             when opts.key?(:role)
               USERS.have_role(opts[:role])[0][0]
             else
               :not_nil
             end
  options = USERS[@user_name].nil? ? defaults : USERS[@user_name].merge(opts)

  set_options options
  @rolez.each { |role| role[:user_name]=@user_name; @roles << make(UserRoleObject, role) } unless @rolez.nil?
  @rolez=nil

end

Instance Attribute Details

#addressesObject

Returns the value of attribute addresses.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def addresses
  @addresses
end

#affiliation_typeObject

Returns the value of attribute affiliation_type.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def affiliation_type
  @affiliation_type
end

#base_salaryObject

Returns the value of attribute base_salary.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def base_salary
  @base_salary
end

#billing_elementObject

Returns the value of attribute billing_element.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def billing_element
  @billing_element
end

#campus_codeObject

Returns the value of attribute campus_code.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def campus_code
  @campus_code
end

#citizenship_typeObject

Returns the value of attribute citizenship_type.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def citizenship_type
  @citizenship_type
end

#descriptionObject

Returns the value of attribute description.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def description
  @description
end

#directory_departmentObject

Returns the value of attribute directory_department.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def directory_department
  @directory_department
end

#directory_titleObject

Returns the value of attribute directory_title.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def directory_title
  @directory_title
end

#emailsObject

Returns the value of attribute emails.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def emails
  @emails
end

#employee_idObject

Returns the value of attribute employee_id.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def employee_id
  @employee_id
end

#employee_statusObject

Returns the value of attribute employee_status.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def employee_status
  @employee_status
end

#employee_typeObject

Returns the value of attribute employee_type.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def employee_type
  @employee_type
end

#era_commons_user_nameObject

Returns the value of attribute era_commons_user_name.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def era_commons_user_name
  @era_commons_user_name
end

#first_nameObject

Returns the value of attribute first_name.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def first_name
  @first_name
end

#graduate_student_countObject

Returns the value of attribute graduate_student_count.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def graduate_student_count
  @graduate_student_count
end

#groupsObject

Returns the value of attribute groups.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def groups
  @groups
end

#last_nameObject

Returns the value of attribute last_name.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def last_name
  @last_name
end

#phonesObject

Returns the value of attribute phones.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def phones
  @phones
end

#primary_department_codeObject

Returns the value of attribute primary_department_code.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def primary_department_code
  @primary_department_code
end

#primary_titleObject

Returns the value of attribute primary_title.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def primary_title
  @primary_title
end

#principal_idObject

Returns the value of attribute principal_id.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def principal_id
  @principal_id
end

#role_qualifiersObject

Returns the value of attribute role_qualifiers.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def role_qualifiers
  @role_qualifiers
end

#rolesObject

Returns the value of attribute roles.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def roles
  @roles
end

#session_statusObject

Returns the value of attribute session_status.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def session_status
  @session_status
end

#typeObject

Returns the value of attribute type.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def type
  @type
end

#user_nameObject

Returns the value of attribute user_name.



91
92
93
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 91

def user_name
  @user_name
end

Instance Method Details

#add_group(opts = {}) ⇒ Object



239
240
241
242
243
244
245
246
247
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 239

def add_group opts={}
  opts.merge!({user_name: @user_name})
  navigate
  @groups.add opts
  on Person do |add|
    add.description.set random_alphanums
    add.blanket_approve
  end
end

#add_role(opts = {}) ⇒ Object



229
230
231
232
233
234
235
236
237
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 229

def add_role opts={}
  opts.merge!({user_name: @user_name})
  navigate
  @roles.add opts
  on Person do |add|
    add.description.set random_alphanums
    add.blanket_approve
  end
end

#createObject



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/user.rb', line 147

def create
  visit(SystemAdmin).person
  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_department_code
      add.primary_employment.set
      add.add_employment_information
    end
    @roles.each { |role| role.create }
    # TODO: Support groups creation here. For now, use the add_group method.
    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

  unless extended_attributes.compact.length==0
    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
  end

end

#edit(opts = {}) ⇒ Object

create



220
221
222
223
224
225
226
227
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 220

def edit opts={}
  navigate
  on Person do |edit|
    edit.description.set random_alphanums
    # TODO: Add more here, as necessary
  end
  update_options(opts)
end

#exist?Boolean Also known as: exists?

Returns:

  • (Boolean)


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/user.rb', line 276

def exist?
  $users.admin. if $users.current_user==nil
  visit(SystemAdmin).person
  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

TODO: This method needs a logic revamp in order to ensure it does not enter an infinite loop.

Returns:

  • (Boolean)


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

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(BasePage).return_to_portal
    # Oops. Apparently there's no portal window, so...
    rescue
      # We'll close any extra tabs/windows
      on(BasePage).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)


328
329
330
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 328

def logged_out?
  !logged_in?
end

#sign_inObject Also known as: log_in

Keep in mind…

  • 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 original window



255
256
257
258
259
260
261
262
263
264
265
266
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 255

def 
  $users.logged_in_user.sign_out unless $users.current_user==nil
  # This line is required because visiting the login page doesn't
  # actually work when you're currently logged in.
  #s_o.click if s_o.present?
  visit Login do ||
    .username.set @user_name
    .
  end
  on(Researcher).logout_button.wait_until_present
  @session_status='logged in'
end

#sign_outObject Also known as: log_out



269
270
271
272
273
# File 'lib/kuality-coeus/data_objects/user/user.rb', line 269

def sign_out
  visit(Login).close_extra_windows
  s_o.click if s_o.present?
  @session_status='logged out'
end