3687: Merge branch 'master' into 3687-grant-permission-on-repo-TC
authorTom Clegg <tom@curoverse.com>
Mon, 6 Oct 2014 15:15:05 +0000 (11:15 -0400)
committerTom Clegg <tom@curoverse.com>
Mon, 6 Oct 2014 15:15:05 +0000 (11:15 -0400)
apps/workbench/app/controllers/actions_controller.rb
apps/workbench/app/views/application/_title_and_buttons.html.erb
apps/workbench/app/views/collections/_show_files.html.erb
apps/workbench/app/views/jobs/show.html.erb
apps/workbench/app/views/pipeline_instances/_show_tab_buttons.html.erb
apps/workbench/app/views/pipeline_templates/show.html.erb
apps/workbench/app/views/projects/_show_tab_contents.html.erb
apps/workbench/app/views/projects/show.html.erb
apps/workbench/test/integration/collections_test.rb
apps/workbench/test/integration/projects_test.rb

index 347644bdbd141092051173315e52afcc3548d03f..62533d81b4ab0a50927379401443dab54f4169e8 100644 (file)
@@ -159,6 +159,18 @@ class ActionsController < ApplicationController
     normalized = arv_normalize combined
     newc = Collection.new({:manifest_text => normalized})
     newc.name = newc.name || "Collection created at #{Time.now.localtime}"
+
+    # set owner_uuid to current project, provided it is writable
+    current_project_writable = false
+    action_data = JSON.parse(params['action_data']) if params['action_data']
+    if action_data && action_data['current_project_uuid']
+      current_project = Group.find(action_data['current_project_uuid']) rescue nil
+      if (current_project && current_project.writable_by.andand.include?(current_user.uuid))
+        newc.owner_uuid = action_data['current_project_uuid']
+        current_project_writable = true
+      end
+    end
+
     newc.save!
 
     chash.each do |k,v|
@@ -171,12 +183,11 @@ class ActionsController < ApplicationController
       l.save!
     end
 
-    action_data = JSON.parse(params['action_data']) if params['action_data']
-    if action_data && action_data['selection_param'].eql?('project')
-      redirect_to :back
-    else
-      redirect_to url_for(controller: 'collections', action: :show, id: newc.uuid)
-    end
+    msg = current_project_writable ?
+              "Created new collection in the project #{current_project.name}." :
+              "Created new collection in your Home project."
+
+    redirect_to newc, flash: {'message' => msg}
   end
 
   def report_issue_popup
index e1ec160ec14bf96aa0701b43898d4d3132cf6d00..822c9048579487366ef2591a7a055454b7dd586e 100644 (file)
@@ -1,3 +1,4 @@
+<% object_class = @object.class_for_display.downcase %>
 <% content_for :page_title do %>
   <%= (@object.respond_to?(:properties) and !@object.properties.nil? ? @object.properties[:page_title] : nil) ||
       @name_link.andand.name ||
@@ -15,7 +16,7 @@
     <% if @object.class.copies_to_projects? %>
       <%= link_to(
           choose_projects_path(
-           title: 'Copy to project...',
+           title: "Copy this #{object_class} to:",
            action_name: 'Copy',
            action_href: actions_path,
            action_method: 'post',
              selection_param: 'uuid',
              success: 'redirect-to-created-object'
            }.to_json),
-          { class: "btn btn-sm btn-primary", remote: true, method: 'get' }) do %>
+          { class: "btn btn-sm btn-primary", remote: true, method: 'get',
+            title: "Make a copy this #{object_class}" }) do %>
         <i class="fa fa-fw fa-copy"></i> Copy to project...
       <% end %>
     <% end %>
     <% if @object.owner_uuid == current_user.uuid or (Group.find(@object.owner_uuid).writable_by.include?(current_user.uuid) rescue nil) %>
       <%= link_to(
           choose_projects_path(
-           title: 'Move to project...',
+           title: "Move this #{object_class} to:",
            action_name: 'Move',
            action_href: actions_path,
            action_method: 'post',
              selection_param: 'uuid',
              success: 'redirect-to-created-object'
            }.to_json),
-          { class: "btn btn-sm btn-primary", remote: true, method: 'get' }) do %>
-        <i class="fa fa-fw fa-truck"></i> Move to project...
+          { class: "btn btn-sm btn-primary", remote: true, method: 'get',
+            title: "Move this #{object_class} to a different project"}) do %>
+        <i class="fa fa-fw fa-truck"></i> Move <%=object_class%>...
       <% end %>
     <% end %>
   <% end %>
 <% end %>
 
+<%
+  # Display any flash messages in an alert. If there is any entry with "error" key, alert-danger is used. 
+  flash_msg = ''
+  flash_msg_is_error = false
+  flash.each do |msg|
+    flash_msg_is_error ||= (msg[0]=='error')
+    flash_msg += ('<p class="contain-align-left">' + msg[1] + '</p>')
+  end
+  if flash_msg != ''
+%>
+<div class="flash-message alert <%= flash_msg_is_error ? 'alert-danger' : 'alert-warning' %>"><%=flash_msg.html_safe%></div>
+<% end %>
index 9fdd32b733ce460f57e5e8ea21ded4ea04896052..051fbf4f6244f8ee556ade7cc6dc18199ad1ea45 100644 (file)
@@ -6,7 +6,9 @@
         <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">Selection... <span class="caret"></span></button>
         <ul class="dropdown-menu" role="menu">
           <li><%= link_to "Create new collection with selected files", '#',
-                  'data-href' => combine_selected_path,
+                  'data-href' => combine_selected_path(
+                    action_data: {current_project_uuid: @object.owner_uuid}.to_json
+                  ),
                   'data-selection-param-name' => 'selection[]',
                   'data-selection-action' => 'combine-collections',
                   'method' => 'post',
index 276aec5eb47228a8167d22f54f50eb66d4e4c215..74c53ca157d892244824a918f3d5a446b854573b 100644 (file)
       <% [:script_parameters, :runtime_constraints].each do |d| %>
         <%= hidden_field :job, d, :value => JSON.dump(@object[d]) %>
       <% end %>
-      <%= button_tag "Re-run same version", {class: 'btn btn-sm btn-primary', id: "re-run-same-job-button"} %>
+      <%= button_tag ({class: 'btn btn-sm btn-primary', id: "re-run-same-job-button",
+                       title: 'Re-run job using the same script version as this run'}) do %>
+        <i class="fa fa-fw fa-gear"></i> Re-run same version
+      <% end %>
     <% end %>
   <% if @object.respond_to? :supplied_script_version and !@object.supplied_script_version.nil? and !@object.supplied_script_version.empty? and @object.script_version != @object.supplied_script_version%>
       <%= form_tag '/jobs', style: "display:inline" do |f| %>
       <% [:script_parameters, :runtime_constraints].each do |d| %>
         <%= hidden_field :job, d, :value => JSON.dump(@object[d]) %>
       <% end %>
-      <%= button_tag "Re-run latest version", {class: 'btn btn-sm btn-primary', id: "re-run-latest-job-button"} %>
+      <%= button_tag ({class: 'btn btn-sm btn-primary', id: "re-run-latest-job-button",
+                       title: 'Re-run job using the latest script version'}) do%>
+        <i class="fa fa-fw fa-gear"></i> Re-run latest version
+      <% end %>
     <% end %>
   <% end %>
 <% end %>
index 2e46581a3fda338a13874da8acd4f3d46424a36e..38a7c913d421965de5da099ec9fe5c2b62a64165 100644 (file)
@@ -2,21 +2,24 @@
 
   <%= link_to(copy_pipeline_instance_path('id' => @object.uuid, 'script' => "use_latest", "components" => "use_latest", "pipeline_instance[state]" => "RunningOnServer"),
       class: 'btn btn-primary',
+      title: 'Re-run with latest options',
       #data: {toggle: :tooltip, placement: :top}, title: 'Re-run',
       method: :post,
       ) do %>
     <i class="fa fa-fw fa-play"></i> Re-run with latest
   <% end %>
 
-  <%= link_to raw('<i class="fa fa-fw fa-cogs"></i> Re-run options'),
+  <%= link_to raw('<i class="fa fa-fw fa-cogs"></i> Re-run options...'),
       "#",
       {class: 'btn btn-primary', 'data-toggle' =>  "modal",
-        'data-target' => '#clone-and-edit-modal-window'}  %>
+        'data-target' => '#clone-and-edit-modal-window',
+        title: 'Re-run with options'}  %>
   <% end %>
 
   <% if @object.state.in? ['New', 'Ready'] %>
     <%= link_to(url_for('pipeline_instance[state]' => 'RunningOnServer'),
         class: 'btn btn-primary run-pipeline-button',
+        title: 'Run this pipeline',
         method: :patch
         ) do %>
       <i class="fa fa-fw fa-play"></i> Run
@@ -25,6 +28,7 @@
     <% if @object.state.in? ['RunningOnClient', 'RunningOnServer'] %>
       <%= link_to(url_for('pipeline_instance[state]' => 'Paused'),
           class: 'btn btn-primary run-pipeline-button',
+          title: 'Pause this pipeline',
           method: :patch
           ) do %>
         <i class="fa fa-fw fa-pause"></i> Pause
@@ -32,6 +36,7 @@
     <% elsif @object.state == 'Paused' %>
       <%= link_to(url_for('pipeline_instance[state]' => 'RunningOnServer'),
           class: 'btn btn-primary run-pipeline-button',
+          title: 'Resume this pipeline',
           method: :patch
           ) do %>
         <i class="fa fa-fw fa-play"></i> Resume
index 57129dfe96def27894c2a8c3b3c3e800ced6badc..02ebd6d9cd09d5aecdd59338714932e8d8f16067 100644 (file)
@@ -10,9 +10,9 @@
                                                    'pipeline_instance[description]' => "Created at #{Time.now.localtime}" + (@object.name.andand.size.andand>0 ? " using the pipeline template *#{@object.name}*" : ""),
                                                    'success' => 'redirect-to-created-object'
                                                   }.to_json),
-                { class: "btn btn-primary btn-sm", remote: true, method: 'get' }
+                { class: "btn btn-primary btn-sm", remote: true, method: 'get', title: 'Run this pipeline' }
                ) do %>
-                   Run this pipeline
+                   <i class="fa fa-gear"></i> Run this pipeline
                  <% end %>
 <% end %>
 
index f185abe69e7bddbda805c137fbed8aec6ceb0280..0f9901aa0ad417356dd27b63a5d9b82ccfcec321 100644 (file)
@@ -6,7 +6,7 @@
         <ul class="dropdown-menu" role="menu">
           <li><%= link_to "Create new collection with selected collections", '#',
                   'data-href' => combine_selected_path(
-                    action_data: {selection_param: 'project'}.to_json
+                    action_data: {current_project_uuid: @object.uuid}.to_json
                   ),
                   'id' => 'combine_selections_button',
                   'data-selection-param-name' => 'selection[]',
index cff8bbd9b0de079755d644d505ce6030c0401422..0429f33b4102920ab424f13a887321af9dd4f7f7 100644 (file)
@@ -14,7 +14,7 @@
            action_href: actions_path(id: @object.uuid),
            action_method: 'post',
            action_data: {selection_param: 'selection[]', copy_selections_into_project: @object.uuid, success: 'page-refresh'}.to_json),
-         { class: "btn btn-primary btn-sm", remote: true, method: 'get', data: {'event-after-select' => 'page-refresh'} }) do %>
+         { class: "btn btn-primary btn-sm", remote: true, method: 'get', title: "Add data to this project", data: {'event-after-select' => 'page-refresh'} }) do %>
       <i class="fa fa-fw fa-plus"></i> Add data...
     <% end %>
     <%= link_to(
            action_href: pipeline_instances_path,
            action_method: 'post',
            action_data: {'selection_param' => 'pipeline_instance[pipeline_template_uuid]', 'pipeline_instance[owner_uuid]' => @object.uuid, 'success' => 'redirect-to-created-object'}.to_json),
-         { class: "btn btn-primary btn-sm", remote: true, method: 'get' }) do %>
+         { class: "btn btn-primary btn-sm", remote: true, method: 'get', title: "Run a pipeline in this project" }) do %>
       <i class="fa fa-fw fa-gear"></i> Run a pipeline...
     <% end %>
-    <%= link_to projects_path({'project[owner_uuid]' => @object.uuid, 'options' => {'ensure_unique_name' => true}}), method: 'post', class: 'btn btn-sm btn-primary' do %>
+    <%= link_to projects_path({'project[owner_uuid]' => @object.uuid, 'options' => {'ensure_unique_name' => true}}), method: 'post', title: "Add a subproject to this project", class: 'btn btn-sm btn-primary' do %>
       <i class="fa fa-fw fa-plus"></i>
       Add a subproject
     <% end %>
index fae29699166333f9302248fdac13551adcc178c4..f62f28534bcd2b21f8d2215b81bdf099019fceec 100644 (file)
@@ -98,37 +98,53 @@ class CollectionsTest < ActionDispatch::IntegrationTest
     assert(page.has_text?('foo'), "Collection page did not include foo file")
     assert(page.has_no_text?(bar_collection['name']), "Collection page did not include foo file")
     assert(page.has_text?('bar'), "Collection page did not include bar file")
-
+    assert(page.has_text?('Created new collection in your Home project'),
+                          'Not found flash message that new collection is created in Home project')
     headless.stop
   end
 
-  test "combine selected collection files into new collection" do
-    headless = Headless.new
-    headless.start
-    Capybara.current_driver = :selenium
+  [
+    ['active', 'foo_file', false],
+    ['active', 'foo_collection_in_aproject', true],
+    ['project_viewer', 'foo_file', false],
+    ['project_viewer', 'foo_collection_in_aproject', false], #aproject not writable
+  ].each do |user, collection, expect_collection_in_aproject|
+    test "combine selected collection files into new collection #{user} #{collection} #{expect_collection_in_aproject}" do
+      headless = Headless.new
+      headless.start
+      Capybara.current_driver = :selenium
 
-    foo_collection = api_fixture('collections')['foo_file']
+      my_collection = api_fixture('collections')[collection]
 
-    visit page_with_token('active', "/collections")
+      visit page_with_token(user, "/collections")
 
-    # choose file from foo collection
-    within('tr', text: foo_collection['uuid']) do
-      click_link 'Show'
-    end
+      # choose file from foo collection
+      within('tr', text: my_collection['uuid']) do
+        click_link 'Show'
+      end
 
-    # now in collection page
-    find('input[type=checkbox]').click
+      # now in collection page
+      find('input[type=checkbox]').click
 
-    click_button 'Selection...'
-    within('.selection-action-container') do
-      click_link 'Create new collection with selected files'
-    end
+      click_button 'Selection...'
+      within('.selection-action-container') do
+        click_link 'Create new collection with selected files'
+      end
 
-    # now in the newly created collection page
-    assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
-    assert(page.has_no_text?(foo_collection['name']), "Collection page did not include foo file")
-    assert(page.has_text?('foo'), "Collection page did not include foo file")
+      # now in the newly created collection page
+      assert(page.has_text?('Copy to project'), "Copy to project text not found in new collection page")
+      assert(page.has_no_text?(my_collection['name']), "Collection page did not include foo file")
+      assert(page.has_text?('foo'), "Collection page did not include foo file")
+      if expect_collection_in_aproject
+        aproject = api_fixture('groups')['aproject']
+        assert page.has_text?("Created new collection in the project #{aproject['name']}"),
+                              'Not found flash message that new collection is created in aproject'
+      else
+        assert page.has_text?("Created new collection in your Home project"),
+                              'Not found flash message that new collection is created in Home project'
+      end
 
-    headless.stop
+      headless.stop
+    end
   end
 end
index ae156b8a5329f311a0c0061b69ed3737a855acef..83565f939dbeef6a2ab6afdbea375b286cc77d45 100644 (file)
@@ -161,7 +161,7 @@ class ProjectsTest < ActionDispatch::IntegrationTest
     end
     wait_for_ajax
 
-    click_link 'Move to project...'
+    click_link 'Move project...'
     find('.selectable', text: 'Project 1234').click
     find('.modal-footer a,button', text: 'Move').click
     wait_for_ajax
@@ -439,32 +439,44 @@ class ProjectsTest < ActionDispatch::IntegrationTest
     end
   end
 
-  test "combine selected collections into new collection" do
-    my_project = api_fixture('groups')['aproject']
-    my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
-
-    visit page_with_token 'active', '/'
-    find("#projects-menu").click
-    find(".dropdown-menu a", text: my_project['name']).click
-    assert page.has_text?(my_collection['name']), 'Collection not found in project'
+  [
+    ['active', true],
+    ['project_viewer', false],
+  ].each do |user, expect_collection_in_aproject|
+    test "combine selected collections into new collection #{user} #{expect_collection_in_aproject}" do
+      my_project = api_fixture('groups')['aproject']
+      my_collection = api_fixture('collections')['collection_to_move_around_in_aproject']
+
+      visit page_with_token user, '/'
+      find("#projects-menu").click
+      find(".dropdown-menu a", text: my_project['name']).click
+      assert page.has_text?(my_collection['name']), 'Collection not found in project'
+
+      within('tr', text: my_collection['name']) do
+        find('input[type=checkbox]').click
+      end
 
-    within('tr', text: my_collection['name']) do
-      find('input[type=checkbox]').click
-    end
+      click_button 'Selection...'
+      within('.selection-action-container') do
+        click_link 'Create new collection with selected collections'
+      end
 
-    click_button 'Selection...'
-    within('.selection-action-container') do
-      click_link 'Create new collection with selected collections'
+      # now in the new collection page
+      if expect_collection_in_aproject
+        assert page.has_text?("Created new collection in the project #{my_project['name']}"),
+                              'Not found flash message that new collection is created in aproject'
+      else
+        assert page.has_text?("Created new collection in your Home project"),
+                              'Not found flash message that new collection is created in Home project'
+      end
+      assert page.has_text?('Content hash'), 'Not found content hash in collection page'
     end
-
-    # back in project page
-    assert page.has_text?(my_collection['name']), 'Collection not found in project'
-    assert page.has_link?('Jobs and pipelines'), 'Jobs and pipelines link not found in project'
   end
 
-  [["jobs", "/jobs"],
-   ["pipelines", "/pipeline_instances"],
-   ["collections", "/collections"]
+  [
+    ["jobs", "/jobs"],
+    ["pipelines", "/pipeline_instances"],
+    ["collections", "/collections"]
   ].each do |target,path|
     test "Test dashboard button all #{target}" do
       visit page_with_token 'active', '/'