Skip to content

Commit

Permalink
Add excluded requests controller
Browse files Browse the repository at this point in the history
To exclude and unexclude request in the WebUI.

Co-authored-by: David Kang <dkang@suse.com>
Co-authored-by: Saray Cabrera Padrón <scabrerapadron@suse.de>
Co-authored-by: Victor Pereira <vpereira@suse.com>
Co-authored-by: Ana María Martínez Gómez <ammartinez@suse.de>
  • Loading branch information
5 people committed Nov 20, 2018
1 parent 995715e commit 81ff200
Show file tree
Hide file tree
Showing 8 changed files with 151 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
module Webui
module Staging
class ExcludedRequestsController < WebuiController
layout 'webui2/webui'

before_action :require_login, except: [:index]
before_action :switch_to_webui2
before_action :set_staging_workflow
before_action :set_project
before_action :set_request_exclusion, only: [:destroy]
after_action :verify_authorized, except: [:index]

def index
@request_exclusions = @staging_workflow.request_exclusions
@requests = @staging_workflow.unassigned_requests
end

def create
authorize @staging_workflow

staging_request_exclusion = params[:staging_request_exclusion]

request = @staging_workflow.target_of_bs_requests.find_by(number: staging_request_exclusion[:number])
unless request
redirect_back(fallback_location: root_path, error: "Request #{params[:number]} doesn't exist or it doesn't belong to this project")
return
end

request_exclusion = @staging_workflow.request_exclusions.build(bs_request: request, description: staging_request_exclusion[:description])

if request_exclusion.save
flash[:success] = 'The request was successfully excluded'
else
flash[:error] = request_exclusion.errors.full_messages.to_sentence
end
redirect_to staging_workflow_excluded_requests_path(@staging_workflow)
end

def destroy
authorize @staging_workflow

if @request_exclusion.destroy
flash[:success] = 'The request is not excluded anymore'
else
flash[:error] = "Request #{@request_exclusion.number} couldn't be unexcluded"
end
redirect_to staging_workflow_excluded_requests_path(@staging_workflow)
end

private

def switch_to_webui2
prepend_view_path('app/views/webui2')
end

def set_staging_workflow
@staging_workflow = ::Staging::Workflow.find_by(id: params[:staging_workflow_id])
return if @staging_workflow

redirect_back(fallback_location: root_path, error: "Staging Workflow #{params[:staging_workflow_id]} does not exist")
end

def set_project
@project = @staging_workflow.project
return if @project

redirect_back(fallback_location: root_path, error: "Staging Workflow #{params[:staging_workflow_id]} is not assigned to a project")
end

def set_request_exclusion
@request_exclusion = ::Staging::RequestExclusion.find_by(id: params[:id])
return if @request_exclusion

redirect_back(fallback_location: staging_workflow_excluded_requests_path(@staging_workflow), error: "Request doesn't exist")
end
end
end
end
4 changes: 0 additions & 4 deletions src/api/app/models/staging/workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,6 @@ def ready_requests
target_of_bs_requests.ready_to_stage.where.not(id: excluded_requests | staged_requests)
end

def ignored_requests
BsRequest.none # TODO: define this method
end

def write_to_backend
return unless CONFIG['global_write_through']

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
= render partial: 'webui/project/breadcrumb_items'
%li.breadcrumb-item.active{ 'aria-current' => 'page' }
Staging workflow excluded requests
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
.modal.fade#exclude-request-modal{ tabindex: -1, role: 'dialog', aria: { labelledby: 'exclude-request-modal-label', hidden: true } }
.modal-dialog.modal-dialog-centered{ role: 'document' }
.modal-content
.modal-header
%h5.modal-title#exclude-request-modal-label Exclude Request
%a.close{ type: 'button', data: { dismiss: 'modal' }, aria: { label: 'Close' } }
%span{ aria: { hidden: true } } &times;
= form_for Staging::RequestExclusion.new, url: staging_workflow_excluded_requests_path do |f|
.modal-body
.form-group
= f.label :number, 'Request'
= f.number_field :number, required: true, class: 'form-control'
.form-group
= f.label :description
= f.text_area :description,
required: true, placeholder: 'Explain why this request will be excluded', class: 'form-control', maxlength: 255
.modal-footer
= render partial: 'webui2/shared/dialog_action_buttons'
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.modal.fade{ id: "delete-excluded-request-modal-#{request_exclusion.bs_request_id}",
tabindex: -1, role: 'dialog', aria: { labelledby: 'delete-modal-label', hidden: true } }
.modal-dialog.modal-dialog-centered{ role: 'document' }
.modal-content
.modal-header
%h5.modal-title
Stop excluding this request?
.modal-body
%p Please confirm that you want to stop excluding this request
= form_tag staging_workflow_excluded_request_path(staging_workflow, request_exclusion), method: :delete do
.modal-footer
%a.btn.btn-sm.btn-outline-secondary.px-4{ data: { dismiss: 'modal' } }
Cancel
= submit_tag('Accept', class: 'btn btn-sm btn-danger px-4')
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.row
.col-xl-12
.card.mb-3
.card-body
%h3 Excluded Requests
%table.responsive.table.table-striped.table-bordered#excluded-requests-datatable
%thead
%tr.text-center
%th Request
%th Description
%th Actions
%tbody
- @request_exclusions.each do |request_exclusion|
%tr
%td= request_exclusion.bs_request.number
%td= request_exclusion.description
%td
= link_to('#', data: { toggle: 'modal', target: "#delete-excluded-request-modal-#{request_exclusion.bs_request_id}" },
title: 'Stop excluding request') do
%i.fas.fa-times-circle.text-danger
= render(partial: 'delete_dialog',
locals: { staging_workflow: @staging_workflow, request_exclusion: request_exclusion })
= link_to('#', data: { toggle: 'modal', target: '#exclude-request-modal' }) do
%i.fas.fa-plus-circle.text-primary
Exclude request

= render partial: 'create_dialog', locals: { requests: @requests }

= content_for :ready_function do
:plain
$('#excluded-requests-datatable').DataTable({
responsive: true
});
4 changes: 4 additions & 0 deletions src/api/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,7 @@ en:
formats:
only_date: '%Y-%m-%d'
default: '%Y-%m-%d %H:%M UTC'
activerecord:
attributes:
staging/request_exclusion:
bs_request_id: 'Request'
1 change: 1 addition & 0 deletions src/api/config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ def self.public_or_about_path?(request)

resources :staging_workflows, except: :index, controller: 'webui/staging/workflows', constraints: cons do
resources :staging_projects, only: [:create, :destroy], controller: 'webui/staging/projects', param: :project_name, constraints: cons
resources :excluded_requests, controller: 'webui/staging/excluded_requests'
end

constraints(APIMatcher) do
Expand Down

0 comments on commit 81ff200

Please sign in to comment.