Skip to content

Commit

Permalink
Merge pull request #1396 from bgeuken/issue_1248
Browse files Browse the repository at this point in the history
Fix issue 1248
  • Loading branch information
adrianschroeter committed Nov 23, 2015
2 parents 503bcd0 + 471f5b9 commit d839f3d
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/api/app/controllers/webui/package_controller.rb
Expand Up @@ -247,9 +247,20 @@ def submit_request_dialog

def submit_request
required_parameters :project, :package
if params[:targetproject].blank?

target_project_name = params[:targetproject].strip
package_name = params[:package].strip
project_name = params[:project].strip

if params[:targetpackage].blank?
target_package_name = package_name
else
target_package_name = params[:targetpackage].try(:strip)
end

if target_project_name.blank?
flash[:error] = 'Please provide a target for the submit request'
redirect_to action: :show, project: params[:project], package: params[:package]
redirect_to action: :show, project: project_name, package: package_name
return
end

Expand All @@ -259,12 +270,10 @@ def submit_request
req = BsRequest.new(state: "new")
req.description = params[:description]

tpkg = params[:package]
tpkg = params[:targetpackage] unless params[:targetpackage].blank?
opts = { source_project: params[:project],
source_package: params[:package],
target_project: params[:targetproject],
target_package: tpkg }
opts = { source_project: project_name,
source_package: package_name,
target_project: target_project_name,
target_package: target_package_name }
if params[:sourceupdate]
opts[:sourceupdate] = params[:sourceupdate]
elsif params[:project].include?(':branches:')
Expand All @@ -279,21 +288,18 @@ def submit_request
end
rescue BsRequestAction::DiffError => e
flash[:error] = "Unable to diff sources: #{e.message}"
redirect_to(action: :show, project: params[:project], package: params[:package])
return
rescue BsRequestAction::MissingAction => e
flash[:error] = "Unable to submit, sources are unchanged"
redirect_to(action: 'show', project: params[:project], package: params[:package])
return
rescue Project::UnknownObjectError,
BsRequestAction::UnknownProject,
BsRequestAction::UnknownTargetPackage => e
flash[:error] = "Unable to submit (missing target): #{e.message}"
redirect_to(action: :show, project: params[:project], package: params[:package])
return
rescue APIException
flash[:error] = "Unable to submit"
redirect_to(action: :show, project: params[:project], package: params[:package])
end

if flash[:error]
redirect_to(action: :show, project: project_name, package: package_name)
return
end

Expand Down Expand Up @@ -321,9 +327,9 @@ def submit_request
supersede_notice += supersede_errors.join('. ')
end
flash[:notice] = "Created <a href='#{request_show_path(req.id)}'>submit request #{req.id}</a>\
to <a href='#{project_show_path(params[:targetproject])}'>#{params[:targetproject]}</a>
to <a href='#{project_show_path(target_project_name)}'>#{target_project_name}</a>
#{supersede_notice}"
redirect_to(action: 'show', project: params[:project], package: params[:package])
redirect_to(action: 'show', project: project_name, package: package_name)
end

def set_linkinfo
Expand Down
35 changes: 35 additions & 0 deletions src/api/test/functional/webui/package_controller_test.rb
Expand Up @@ -365,6 +365,41 @@ def test_submit_package
page.wont_have_field('supersede_request_ids[]')
end

def test_submit_request
use_js
login_Iggy

visit(package_show_path(project: "home:Iggy", package: "TestPack"))
click_link("Submit package")
click_button("Ok")
page.must_have_text "Please provide a target for the submit request"
assert_equal package_show_path(project: "home:Iggy", package: "TestPack"),
page.current_path

click_link("Submit package")
fill_in "To target project", with: "nonexistant:project"
click_button("Ok")
page.must_have_text "Unable to submit (missing target): nonexistant:project"
assert_equal package_show_path(project: "home:Iggy", package: "TestPack"),
page.current_path

click_link("Submit package")
fill_in "To target project", with: "home:Iggy"
click_button("Ok")
page.must_have_text "Unable to submit, sources are unchanged"
assert_equal package_show_path(project: "home:Iggy", package: "TestPack"),
page.current_path

click_link("Submit package")
# Note: The whitespaces are part of the test, see issue#1248 for details
fill_in "To target project", with: " home:Iggy "
fill_in "To target package", with: " ToBeDeletedTestPack "
click_button("Ok")
page.must_have_text "Created submit request #{BsRequest.last.id} to home:Iggy"
assert_equal package_show_path(project: "home:Iggy", package: "TestPack"),
page.current_path
end

def test_remove_file
use_js

Expand Down

0 comments on commit d839f3d

Please sign in to comment.