Merge branch 'master' into 4036-combine-collections-in-project-issue
authorradhika <radhika@curoverse.com>
Fri, 3 Oct 2014 14:05:59 +0000 (10:05 -0400)
committerradhika <radhika@curoverse.com>
Fri, 3 Oct 2014 14:05:59 +0000 (10:05 -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/projects/_show_tab_contents.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..bf2df58dcaf4a160fb9bb8e429689bd1e2c3910c 100644 (file)
   <% end %>
 <% end %>
 
+<%
+  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 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 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..189de02f7cf3ad26957195cfec69d16739a250a1 100644 (file)
@@ -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', '/'