Skip to content

Commit

Permalink
Merge pull request #983 from hiberis/ghi#914
Browse files Browse the repository at this point in the history
[webui] Improve supersede requests
  • Loading branch information
hennevogel committed Jul 22, 2015
2 parents c79bf1b + c6516fa commit a8c725a
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 41 deletions.
6 changes: 3 additions & 3 deletions src/api/app/assets/javascripts/webui/application/request.js
Expand Up @@ -11,18 +11,18 @@ function updateSupersedeAndDevelPackageDisplay() {
url: $('#targetproject').data('requests-url'),
data: {
project: $('#targetproject')[0].value,
source_project: $('#project')[0].value,
package: $('#package')[0].value,
types: 'submit',
states: ['new', 'review', 'declined']
},
success: function (data) {
if (data.indexOf('No requests') == -1) {
$('#supersede_display').show();
$('#supersede').prop('checked', true);
$('#pending_requests').html(data);
$('#supersede_requests').html(data);
} else {
$('#supersede_display').hide();
$('#supersede').prop('checked', false);
$('#supersede_requests').html('');
}
}
});
Expand Down
6 changes: 2 additions & 4 deletions src/api/app/controllers/webui/package_controller.rb
Expand Up @@ -261,10 +261,8 @@ def submit_request

# Supersede logic has to be below addition as we need the new request id
supersede_errors = []
if params[:supersede]
pending_requests = BsRequestCollection.list_ids(project: params[:targetproject], package: params[:package], states: %w(new review declined), types: %w(submit))
pending_requests.each do |request_id|
next if request_id == req.id # ignore newly created request
if params[:supersede_request_ids]
params[:supersede_request_ids].each do |request_id|
r = BsRequest.find_by_id request_id
next if r.nil? # unable to load
begin
Expand Down
5 changes: 5 additions & 0 deletions src/api/app/models/bs_request_collection.rb
Expand Up @@ -6,6 +6,7 @@ def initialize(opts)
types = opts[:types] || []
@review_states = opts[:review_states] || %w(new)
@subprojects = opts[:subprojects]
@source_project = opts[:source_project]
@project = opts[:project]
@rel = BsRequest.joins(:bs_request_actions).distinct.order(priority: :asc, id: :desc)

Expand All @@ -19,6 +20,10 @@ def initialize(opts)
@rel = @rel.where('bs_request_actions.type in (?)', types).references(:bs_request_actions)
end

unless @source_project.blank?
@rel = @rel.where('bs_request_actions.source_project = ?', @source_project).references(:bs_request_actions)
end

unless @project.blank?
@package = opts[:package]
wrapper_for_inner_or { extend_query_for_project }
Expand Down
Expand Up @@ -39,12 +39,10 @@
%br/

%span#supersede_display.hidden
= label_tag(:pending_requests, 'Pending requests:')
%br/
%span#pending_requests
= check_box_tag(:supersede)
Supersede pending requests
= label_tag(:supersede_requests, 'Supersede requests:')
%br/
%span#supersede_requests

%span#sourceupdate_display
= check_box_tag(:sourceupdate, 'cleanup', @cleanup_source)
Remove local package if request is accepted
Expand Down
1 change: 1 addition & 0 deletions src/api/app/views/webui/request/_requests_small.html.haml
Expand Up @@ -6,6 +6,7 @@
- requests.each do |req|
%tr
%td{style: "border: medium none; padding: 0px;"}
= check_box_tag('supersede_request_ids[]', req.id, false, id: "supersede_request_ids_#{req.id}")
= link_to(req.id, controller: :request, action: :show, id: req.id)
by
= user_with_realname_and_icon(req.creator, short: true)
Expand Down
48 changes: 22 additions & 26 deletions src/api/test/functional/webui/package_controller_test.rb
Expand Up @@ -254,7 +254,7 @@ def fill_comment(body = 'Comment Body')
# try to submit unchanged sources
click_link 'Submit package'
page.must_have_field('targetproject', with: 'home:dmayr')
page.wont_have_field('supersede')
page.wont_have_field('supersede_request_ids[]')
check('sourceupdate')
click_button 'Ok'
page.wont_have_selector '.dialog' # wait for the reload
Expand All @@ -264,7 +264,7 @@ def fill_comment(body = 'Comment Body')
Suse::Backend.put( '/source/home:adrian/x11vnc/DUMMY?user=adrian', 'DUMMY')
click_link 'Submit package'
page.must_have_field('targetproject', with: 'home:dmayr')
page.wont_have_field('supersede')
page.wont_have_field('supersede_request_ids[]')
check('sourceupdate')
click_button 'Ok'

Expand Down Expand Up @@ -301,46 +301,42 @@ def fill_comment(body = 'Comment Body')
page.must_have_field('targetproject', with: 'home:dmayr')
page.must_have_field('targetpackage', with: 'x11vnc')

# TODO: actually it does not make sense to display requests that we can't supersede
# but that's for later
within '#supersede_display' do
page.must_have_text "#{requestid} by adrian"
end

check('supersede')
page.must_have_field('supersede_request_ids[]')
all('input[name="supersede_request_ids[]"]').each {|input| check(input[:id]) }
click_button 'Ok'
page.wont_have_selector '.dialog' # wait for the reload
flash_message.must_match %r{Created submit request .* to home:dmayr}
new_requestid = flash_message.gsub(%r{Created submit request (\d*) to home:dmayr}, '\1').to_i
visit request_show_path(id: requestid)
page.must_have_text "Request #{requestid} (superseded)"
page.must_have_content "Superseded by #{new_requestid}"
end

test 'supersede foreign request' do
use_js
# You are not allowed to supersede requests you have no role in.
#
# TODO: actually it does not make sense to display requests that we can't supersede
# but that's for later
Suse::Backend.put( '/source/home:adrian/x11vnc/DUMMY2?user=adrian', 'DUMMY2')
login_tom to: package_show_path(project: 'home:adrian', package: 'x11vnc')
click_link 'Submit package'
page.must_have_field('supersede_request_ids[]')
all('input[name="supersede_request_ids[]"]').each {|input| check(input[:id]) }
click_button 'Ok'
page.wont_have_selector '.dialog' # wait for the reload
flash_message.must_match %r{Created submit request \d* to home:dmayr}
flash_message.must_match %r{Superseding failed: You have no role in request \d*}

login_adrian to: project_show_path(project: 'home:adrian')
# You will not be given the option to supersede requests from other source projects
login_tom to: project_show_path(project: 'home:tom')
click_link 'Branch existing package'
fill_in 'linked_project', with: 'Apache'
fill_in 'linked_package', with: 'apache2'
fill_in 'linked_project', with: 'home:dmayr'
fill_in 'linked_package', with: 'x11vnc'
click_button 'Create Branch'

page.must_have_link 'Submit package'
page.wont_have_link 'link diff'

# modify and resubmit
Suse::Backend.put( '/source/home:adrian/apache2/DUMMY?user=adrian', 'DUMMY')
click_link 'Submit package'
page.must_have_field('targetproject', with: 'Apache')
check('supersede')
check('sourceupdate')
click_button 'Ok'

# got a request
page.wont_have_selector '.dialog' # wait for the reload
flash_message.must_match %r{Created submit request \d* to Apache}
flash_message.must_match %r{Superseding failed: You have no role in request.*set state to superseded from a final state is not allowed}
page.wont_have_field('supersede_request_ids[]')
end

test 'remove file' do
Expand Down
6 changes: 3 additions & 3 deletions src/api/test/functional/webui/request_controller_test.rb
Expand Up @@ -88,21 +88,22 @@ def test_my_involved_requests
click_link 'Submit package'
fill_in 'targetproject', with: 'kde4'
fill_in 'description', with: 'I want to see his reaction'
uncheck('supersede')
click_button 'Ok'
within '#flash-messages' do
click_link 'submit request'
end
oldrequest = current_path.gsub(%r{\/request\/show\/(\d*)}, '\1').to_i
# verify it is not superseding anything
page.wont_have_text('Superseding')
page.wont_have_field('supersede_request_ids[]')

# create submission that is superseding the former one
visit package_show_path(project: 'Apache', package: 'apache2')
click_link 'Submit package'
fill_in 'targetproject', with: 'kde4'
fill_in 'description', with: 'I want to see his reaction'
check('supersede')
page.must_have_field('supersede_request_ids[]')
all('input[name="supersede_request_ids[]"]').each {|input| check(input[:id]) }
click_button 'Ok'
within '#flash-messages' do
click_link 'submit request'
Expand Down Expand Up @@ -284,7 +285,6 @@ def visit_requests
click_link 'Submit package'
fill_in 'targetproject', with: 'kde4'
fill_in 'description', with: 'I want to see his reaction'
uncheck('supersede')
click_button 'Ok'

within '#flash-messages' do
Expand Down

0 comments on commit a8c725a

Please sign in to comment.