Commit 2e848f56 authored by Antonio Terceiro's avatar Antonio Terceiro

Merge branch 'self-service-history' into 'master'

self_service: add user history page with filters

See merge request !95
parents 59e766e8 55c18388
Pipeline #63828 canceled with stage
......@@ -15,7 +15,7 @@
</a>
</div>
<div class="col-xs-12 col-md-6">
<a class="well self-service-card text-center" href="#">
<a class="well self-service-card text-center" href="/selfservice/history">
<div class="self-service-card-icon">
<span class="glyphicon glyphicon-search" aria-hidden="true"></span>
</div>
......
<ol class="breadcrumb">
<li><a href="/selfservice">Welcome <%= @user %>!</a></li>
<li class="active">Request Test History</li>
</ol>
<header class="well">
<h1>Request Test History</h1>
</header>
<form action="/selfservice/history">
<div class="row">
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label for="package">Package</label>
<input class="form-control" id="package" name="package" value="<%= package_filter %>">
</div>
</div>
<div class="col-xs-12 col-sm-6">
<div class="form-group">
<label for="trigger">Trigger</label>
<input class="form-control" id="trigger" name="trigger" value="<%= trigger_filter %>">
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label for="suite">Suite</label>
<% settings.suites.each do |suite| %>
<label class="checkbox-inline">
<input name="suite[]" type="checkbox" value="<%= suite %>" <%= suite_filter.is_a?(Array) && suite_filter.include?(suite) ? "checked" : nil %>><%= suite %>
</label>
<% end %>
</div>
</div>
<div class="col-xs-6">
<div class="form-group">
<label for="arch">Architecture</label>
<% settings.archs.each do |arch| %>
<label class="checkbox-inline">
<input name="arch[]" type="checkbox" value="<%= arch %>"<%= arch_filter.is_a?(Array) && arch_filter.include?(arch) ? "checked" : nil %>><%= arch %>
</label>
<% end %>
</div>
</div>
</div>
<div class="form-group">
<button type="submit" class="btn btn-default" autocomplete="off">
Apply Filters
</button>
</div>
</form>
<table class="table">
<tr>
<td>Date</td>
<td>Package</td>
<td>Suite</td>
<td>Architecture</td>
<td>Trigger</td>
<td>Pin-Packages</td>
<td>Actions</td>
</tr>
<% Array(@history).each do |test| %>
<tr>
<td><%= test[:date] %></td>
<td><%= test[:package] %></td>
<td><%= test[:suite] %></td>
<td><%= test[:arch] %></td>
<td><%= test[:trigger] %></td>
<td><%= test[:pin_packages] %></td>
<td><a
href="/packages/<%= test[:package].match(/^((lib)?.)/) %>/<%= test[:package] %>/<%= test[:suite] %>/<%= test[:arch] %>">Details</a>
</td>
</tr>
<% end %>
</table>
\ No newline at end of file
......@@ -115,5 +115,28 @@ module Debci
end
raise errors.join('<br>') unless errors.empty?
end
get '/history' do
arch_filter = params[:arch]
suite_filter = params[:suite]
package_filter = params[:package] || ''
trigger_filter = params[:trigger] || ''
query = {
requestor: @user
}
query[:arch] = arch_filter if arch_filter
query[:suite] = suite_filter if suite_filter
@history = Debci::Job.where(query)
unless package_filter.empty?
@history = @history.where("package LIKE :query", query: "%#{package_filter}%") unless package_filter.nil?
end
unless trigger_filter.empty?
@history = @history.where("trigger LIKE :query", query: "%#{trigger_filter}%") unless trigger_filter.nil?
end
erb :self_service_history, locals: { arch_filter: arch_filter, suite_filter: suite_filter, package_filter: package_filter, trigger_filter: trigger_filter }
end
end
end
......@@ -2,6 +2,7 @@ require 'spec_mock_server'
require 'debci'
require 'debci/self_service'
require 'rack/test'
require 'json'
describe Debci::SelfService do
include Rack::Test::Methods
......@@ -157,4 +158,69 @@ describe Debci::SelfService do
expect(Debci::Job.count).to eq(job_count)
end
end
context 'history' do
before do
history_jobs = [
{
suite: "unstable",
arch: "amd64",
trigger: "mypackage/0.0.1",
package: "mypackage",
pin_packages: ["src:mypackage", "unstable"],
requestor: "foo@bar.com"
},
{
suite: "unstable",
arch: "amd64",
trigger: "testpackage/0.0.1",
package: "testpackage",
pin_packages: ["src:mypackage", "unstable"],
requestor: "foo@bar.com"
},
{
suite: "unstable",
arch: "arm64",
trigger: "testpackage/0.0.2",
package: "testpackage",
pin_packages: ["src:mypackage", "unstable"],
requestor: "foo@bar.com"
}
]
history_jobs.each do |job|
Debci::Job.create(job)
end
end
it 'displays correct results with package filter' do
get '/selfservice/history', { package: 'package', trigger: '' }, 'SSL_CLIENT_S_DN_CN' => 'foo@bar.com'
expect(last_response.status).to eq(200)
expect(last_response.body).to match('mypackage/0.0.1')
expect(last_response.body).to match('testpackage/0.0.1')
expect(last_response.body).to match('testpackage/0.0.2')
end
it 'displays correct results with trigger and arch filters' do
get '/selfservice/history', { package: '', trigger: 'mypackage/0.0.1', arch: [arch] }, 'SSL_CLIENT_S_DN_CN' => 'foo@bar.com'
expect(last_response.status).to eq(200)
expect(last_response.body).to match('mypackage/0.0.1')
end
it 'displays correct results with arch filter' do
get '/selfservice/history', { package: '', trigger: '', arch: [arch] }, 'SSL_CLIENT_S_DN_CN' => 'foo@bar.com'
expect(last_response.status).to eq(200)
expect(last_response.body).to match('mypackage/0.0.1')
expect(last_response.body).to match('testpackage/0.0.1')
expect(last_response.body).to_not match('testpackage/0.0.2')
end
it 'displays correct results with all filters' do
get '/selfservice/history', { package: 'package', trigger: 'package/0.0.1', arch: [arch], suite: [suite] }, 'SSL_CLIENT_S_DN_CN' => 'foo@bar.com'
expect(last_response.status).to eq(200)
expect(last_response.body).to match('mypackage/0.0.1')
expect(last_response.body).to match('testpackage/0.0.1')
expect(last_response.body).to_not match('testpackage/0.0.2')
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment