1 # Copyright (C) The Arvados Authors. All rights reserved.
3 # SPDX-License-Identifier: AGPL-3.0
5 module ShareObjectHelper
6 def show_object_using(auth_key, type, key, expect)
7 obj_uuid = api_fixture(type)[key]['uuid']
8 visit(page_with_token(auth_key, "/#{type}/#{obj_uuid}"))
9 assert(page.has_text?(expect), "expected string not found: #{expect}")
13 find('#object_sharing').all('tr')
16 def add_share_and_check(share_type, name, obj=nil)
17 assert(page.has_no_text?(name), "project is already shared with #{name}")
18 start_share_count = share_rows.size
19 click_on("Share with #{share_type}")
20 within(".modal-container") do
21 # Order is important here: we should find something that appears in the
22 # modal before we make any assertions about what's not in the modal.
23 # Otherwise, the not-included assertions might falsely pass because
24 # the modal hasn't loaded yet.
25 find(".selectable", text: name).click
26 assert_text "Only #{share_type} you are allowed to access are shown"
27 assert(has_no_selector?(".modal-dialog-preview-pane"),
28 "preview pane available in sharing dialog")
29 if share_type == 'users' and obj and obj['email']
30 assert(page.has_text?(obj['email']), "Did not find user's email")
32 assert_raises(Capybara::ElementNotFound,
33 "Projects pulldown available from sharing dialog") do
34 click_on "All projects"
38 # Admin case takes many times longer than normal user, but not sure why
39 using_wait_time(30) do
40 assert(page.has_link?(name),
41 "new share #{name} was not added to sharing table")
42 assert_equal(start_share_count + 1, share_rows.size,
43 "new share did not add row to sharing table")
47 def modify_share_and_check(name)
48 start_rows = share_rows
49 # We assume rows have already been rendered and can be checked quickly
50 link_row = start_rows.select { |row| row.has_text?(name, wait:(0.1) ) }
51 assert_equal(1, link_row.size, "row with new permission not found")
52 within(link_row.first) do
54 select("Write", from: "share_change_level")
55 click_on("editable-submit")
56 assert(has_link?("Write"),
57 "failed to change access level on new share")
59 if Capybara.current_driver == :selenium
60 page.driver.browser.switch_to.alert.accept
62 # poltergeist returns true for confirm(), so we don't need to accept.
65 # Ensure revoked permission disappears from page.
66 using_wait_time(Capybara.default_max_wait_time * 3) do
68 assert_equal(start_rows.size - 1, share_rows.size,
69 "revoking share did not remove row from sharing table")
73 def user_can_manage(user_sym, fixture)
74 get(:show, params: {id: fixture["uuid"]}, session: session_for(user_sym))
75 is_manager = assigns(:user_is_manager)
76 assert_not_nil(is_manager, "user_is_manager flag not set")
78 assert_empty(assigns(:share_links),
79 "non-manager has share links set")