From 23c44c899b783a784bd9c60e3efda63cab2f6cc8 Mon Sep 17 00:00:00 2001 From: Radhika Chippada Date: Thu, 9 Apr 2015 09:37:46 -0400 Subject: [PATCH] 5365: preload editable component inputs --- .../app/controllers/application_controller.rb | 6 +++- .../app/helpers/application_helper.rb | 2 +- .../_show_components_editable.html.erb | 20 +++++++++++ .../test/integration/anonymous_access_test.rb | 36 ++++++++++++++++++- .../api/test/fixtures/pipeline_instances.yml | 34 ++++++++++++++++++ 5 files changed, 95 insertions(+), 3 deletions(-) diff --git a/apps/workbench/app/controllers/application_controller.rb b/apps/workbench/app/controllers/application_controller.rb index 4f89f262b7..69c273c65e 100644 --- a/apps/workbench/app/controllers/application_controller.rb +++ b/apps/workbench/app/controllers/application_controller.rb @@ -1120,10 +1120,14 @@ class ApplicationController < ActionController::Base return @objects_for if uuids.empty? # if already preloaded for all of these uuids, return - if not uuids.select { |x| @objects_for[x].nil? }.any? + if not uuids.select { |x| !@objects_for.include?(x) }.any? return @objects_for end + # preset all uuids to nil + uuids.each do |x| + @objects_for[x] = nil + end dataclass.where(uuid: uuids).each do |obj| @objects_for[obj.uuid] = obj end diff --git a/apps/workbench/app/helpers/application_helper.rb b/apps/workbench/app/helpers/application_helper.rb index b145fddcc9..0dee527205 100644 --- a/apps/workbench/app/helpers/application_helper.rb +++ b/apps/workbench/app/helpers/application_helper.rb @@ -298,7 +298,7 @@ module ApplicationHelper end if not object.andand.attribute_editable?(attr) - return link_to_if_arvados_object attrvalue + return link_to_arvados_object_if_readable(attrvalue, attrvalue, attrvalue, false) end if dataclass diff --git a/apps/workbench/app/views/pipeline_instances/_show_components_editable.html.erb b/apps/workbench/app/views/pipeline_instances/_show_components_editable.html.erb index f6c9e85883..50b2c9e088 100644 --- a/apps/workbench/app/views/pipeline_instances/_show_components_editable.html.erb +++ b/apps/workbench/app/views/pipeline_instances/_show_components_editable.html.erb @@ -1,3 +1,23 @@ +<% + input_uuids = [] + input_pdhs = [] + @object.components.each do |k, component| + next if !component + component[:script_parameters].andand.each do |p, tv| + if tv[:value] and tv[:dataclass].andand.eql?('Collection') + if CollectionsHelper.match(tv[:value]) + input_pdhs << tv[:value] + else + input_uuids << tv[:value] + end + end + end + end + + preload_collections_for_objects input_uuids if input_uuids.any? + preload_for_pdhs input_pdhs if input_pdhs.any? +%> + diff --git a/apps/workbench/test/integration/anonymous_access_test.rb b/apps/workbench/test/integration/anonymous_access_test.rb index 20bb0fd2b1..dedcd4c112 100644 --- a/apps/workbench/test/integration/anonymous_access_test.rb +++ b/apps/workbench/test/integration/anonymous_access_test.rb @@ -215,7 +215,7 @@ class AnonymousAccessTest < ActionDispatch::IntegrationTest if objects_readable if pipeline_page assert_text 'This pipeline was created from' - assert_selector 'a', object['components']['foo']['job']['uuid'] + assert_selector 'a', text: object['components']['foo']['job']['uuid'] end assert_no_text 'Output data not available' assert_selector 'a[href="#Log"]', text: 'Log' @@ -242,6 +242,40 @@ class AnonymousAccessTest < ActionDispatch::IntegrationTest end end + [ + ['new_pipeline_in_publicly_accessible_project', true], + ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false], + ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', false, 'spectator'], + ['new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere', true, 'admin'], + ].each do |fixture, objects_readable, user=nil| + test "access #{fixture} in public project with objects readable=#{objects_readable} with user #{user}" do + object = api_fixture('pipeline_instances')[fixture] + page = "/pipeline_instances/#{object['uuid']}" + if user + visit page_with_token user, page + else + visit page + end + + # click Components tab + click_link 'Components' + + if objects_readable + assert_text 'This pipeline was created from' + if user == 'admin' + assert_text 'input' + assert_selector 'a', text: 'Choose' + else + assert_selector 'a', text: object['components']['foo']['script_parameters']['input']['value'] + end + else + assert_no_text 'This pipeline was created from' # template is not readable + assert_text object['components']['foo']['script_parameters']['input']['value'] + assert_no_selector 'a', text: object['components']['foo']['script_parameters']['input']['value'] + end + end + end + test "anonymous user accesses collection in shared project" do visit "/collections/#{api_fixture('collections')['public_text_file']['uuid']}" diff --git a/services/api/test/fixtures/pipeline_instances.yml b/services/api/test/fixtures/pipeline_instances.yml index bb06dac2db..1f1b128133 100644 --- a/services/api/test/fixtures/pipeline_instances.yml +++ b/services/api/test/fixtures/pipeline_instances.yml @@ -304,6 +304,40 @@ pipeline_in_publicly_accessible_project_but_other_objects_elsewhere: output: zzzzz-4zz18-bv31uwvy3neko21 state: Complete +new_pipeline_in_publicly_accessible_project: + uuid: zzzzz-d1hrv-newpisharedobjs + owner_uuid: zzzzz-j7d0g-zhxawtyetzwc5f0 + name: Pipeline in New state in publicly accessible project + pipeline_template_uuid: zzzzz-p5p6p-tmpltpublicproj + state: New + created_at: 2014-09-15 12:00:00 + components: + foo: + script: foo + script_version: master + script_parameters: + input: + required: true + dataclass: Collection + value: b519d9cb706a29fc7ea24dbea2f05851+93 + +new_pipeline_in_publicly_accessible_project_but_other_objects_elsewhere: + uuid: zzzzz-d1hrv-newsharenotobjs + owner_uuid: zzzzz-j7d0g-zhxawtyetzwc5f0 + name: Pipeline in New state in public project with objects elsewhere + pipeline_template_uuid: zzzzz-p5p6p-aox0k0ofxrystgw + state: New + created_at: 2014-09-15 12:00:00 + components: + foo: + script: foo + script_version: master + script_parameters: + input: + required: true + dataclass: Collection + value: zzzzz-4zz18-bv31uwvy3neko21 + pipeline_in_running_state: name: running_with_job state: Ready -- 2.39.5