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|
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
<% 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 %>
<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',
<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[]',
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
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', '/'