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