Class: PermissionsObject
- Inherits:
-
Object
- Object
- PermissionsObject
- Includes:
- DataFactory, Foundry, Navigation
- Defined in:
- lib/kuality-coeus/data_objects/proposal_development/permissions.rb
Instance Attribute Summary collapse
-
#aggregators ⇒ Object
Returns the value of attribute aggregators.
-
#approvers ⇒ Object
Returns the value of attribute approvers.
-
#budget_creators ⇒ Object
Returns the value of attribute budget_creators.
-
#delete_proposals ⇒ Object
Returns the value of attribute delete_proposals.
-
#document_id ⇒ Object
Returns the value of attribute document_id.
-
#narrative_writers ⇒ Object
Returns the value of attribute narrative_writers.
-
#viewers ⇒ Object
Returns the value of attribute viewers.
Instance Method Summary collapse
-
#add_roles(username, *roles) ⇒ Object
This method is used when the user is already assigned a role and you need to assign them more roles.
-
#assign ⇒ Object
It’s important to realize that this method assigns users to roles, but does not check who is already assigned.
- #delete(username) ⇒ Object
-
#initialize(browser, opts = {}) ⇒ PermissionsObject
constructor
A new instance of PermissionsObject.
Methods included from Navigation
#doc_search, #fill_out, #on_document?, #on_page?, #open_document
Methods included from Utilities
#get, #make_role, #make_user, #random_percentage, #set, #snake_case
Constructor Details
#initialize(browser, opts = {}) ⇒ PermissionsObject
Returns a new instance of PermissionsObject.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 10 def initialize(browser, opts={}) @browser = browser defaults = { budget_creators: [], # Arrays should contain usernames narrative_writers: [], viewers: [], delete_proposals: [], approvers: [] } (defaults.merge(opts)) requires :document_id, :aggregators end |
Instance Attribute Details
#aggregators ⇒ Object
Returns the value of attribute aggregators.
7 8 9 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 7 def aggregators @aggregators end |
#approvers ⇒ Object
Returns the value of attribute approvers.
7 8 9 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 7 def approvers @approvers end |
#budget_creators ⇒ Object
Returns the value of attribute budget_creators.
7 8 9 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 7 def budget_creators @budget_creators end |
#delete_proposals ⇒ Object
Returns the value of attribute delete_proposals.
7 8 9 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 7 def delete_proposals @delete_proposals end |
#document_id ⇒ Object
Returns the value of attribute document_id.
7 8 9 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 7 def document_id @document_id end |
#narrative_writers ⇒ Object
Returns the value of attribute narrative_writers.
7 8 9 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 7 def narrative_writers @narrative_writers end |
#viewers ⇒ Object
Returns the value of attribute viewers.
7 8 9 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 7 def viewers @viewers end |
Instance Method Details
#add_roles(username, *roles) ⇒ Object
This method is used when the user is already assigned a role and you need to assign them more roles.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 51 def add_roles(username, *roles) # get to the right page... navigate on Permissions do |page| # click the edit role button for the right user... page.edit_role username # This opens a new window, so we have to use it... page.windows.last.use end on Roles do |page| roles.each do |role| # Set the appropriate role checkbox... page.send(snakify(role)).set # Add the username to the correct role # instance variable... get(roles.invert[role]) << username end page.save # Now we're done with the child window so we close it... page.close # Attach to the main window again... page.windows.first.use end end |
#assign ⇒ Object
It’s important to realize that this method assigns users to roles, but does not check who is already assigned. You need to make sure that the values used in the instantiation of the class are an accurate reflection of what exists in the site.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 30 def assign navigate on Permissions do |add| # See the roles method defined below... roles.each do |inst_var, role| get(inst_var).each do |username| unless add.user_row(username).present? && add.assigned_role(username).include?(role) add.user_name.set username add.role.select role add.add add.user_row(username).wait_until_present end end end add.save # TODO: Add some logic here to use in case the user is already added to the list (so use add_roles) end end |
#delete(username) ⇒ Object
76 77 78 79 80 81 82 |
# File 'lib/kuality-coeus/data_objects/proposal_development/permissions.rb', line 76 def delete username navigate on(Permissions).delete username roles.each do |role| get(role).delete_if { |name| name==username } end end |