Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[webui][ci] CRUD actions for Download on Demand repos and tests added
- Loading branch information
mdeniz
committed
Jan 20, 2016
1 parent
ee7c5ed
commit 6fbbc0b
Showing
15 changed files
with
337 additions
and
44 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/api/app/controllers/webui/download_on_demand_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
class Webui::DownloadOnDemandController < Webui::WebuiController | ||
before_filter :set_project | ||
|
||
def create | ||
@download_on_demand = DownloadRepository.new(permitted_params) | ||
authorize @download_on_demand | ||
if @download_on_demand.save | ||
@project.store | ||
redirect_to project_repositories_path(@project), notice: "Successfully created Download on Demand" | ||
else | ||
redirect_to :back, error: "Download on Demand can't be created: #{@download_on_demand.errors.full_messages.to_sentence}" | ||
end | ||
end | ||
|
||
def update | ||
@download_on_demand = DownloadRepository.find(params[:id]) | ||
authorize @download_on_demand | ||
if @download_on_demand.update_attributes(permitted_params) | ||
@project.store | ||
redirect_to project_repositories_path(@project), notice: "Successfully updated Download on Demand" | ||
else | ||
redirect_to :back, error: "Download on Demand can't be created: #{@download_on_demand.errors.full_messages.to_sentence}" | ||
end | ||
end | ||
|
||
def destroy | ||
@download_on_demand = DownloadRepository.find(params[:id]) | ||
authorize @download_on_demand | ||
if @download_on_demand.destroy | ||
@project.store | ||
redirect_to project_repositories_path(@project), notice: "Successfully removed Download on Demand" | ||
else | ||
redirect_to :back, error: "Download on Demand can't be removed: #{@download_on_demand.errors.full_messages.to_sentence}" | ||
end | ||
end | ||
|
||
private | ||
|
||
def permitted_params | ||
params.require(:download_repository).permit(:arch, :repotype, :url, :repository_id, :archfilter, :masterurl, :mastersslfingerprint, :pubkey) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
class DownloadRepository < ActiveRecord::Base | ||
belongs_to :repository | ||
|
||
validates :repository, presence: true | ||
validates :arch, presence: true | ||
validates :repository_id, presence: true | ||
validates :arch, uniqueness: { scope: :repository_id}, presence: true | ||
validates :url, presence: true | ||
validates :repotype, presence: true | ||
|
||
# def self._sync_keys | ||
# [ :arch, :url ] | ||
# end | ||
REPOTYPES = ["rpmmd", "susetags", "deb", "arch", "mdk"] | ||
|
||
delegate :to_s, to: :id | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class DownloadRepositoryPolicy < ApplicationPolicy | ||
def create? | ||
@user.is_admin? | ||
end | ||
|
||
def update? | ||
@user.is_admin? | ||
end | ||
|
||
def destroy? | ||
@user.is_admin? | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="box" style="margin: 1em"> | ||
<h2 class="box-header"> | ||
Add Download on Demand for <%= repository.name %> | ||
</h2> | ||
<%= render partial: 'webui/download_on_demand/form', locals: { project: project, repository: repository, download_on_demand: download_on_demand } %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="box" style="margin: 1em"> | ||
<h2 class="box-header"> | ||
Edit Download on Demand for <%= repository.name %> / <%= download_on_demand.arch %> | ||
</h2> | ||
<%= render partial: 'webui/download_on_demand/form', locals: { project: project, repository: repository, download_on_demand: download_on_demand } %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<%= form_for(download_on_demand) do |form| %> | ||
<div style="margin-bottom: 1.2em; margin-left: 2em" > | ||
<%= form.label :arch, 'Architecture', style: "display:inline-block;width:100px;" %> | ||
<%= form.select :arch, options_for_select(repository.architectures, download_on_demand.try(:arch)) %> | ||
<br/><br/> | ||
<%= form.label :repotype, 'Type', style: "display:inline-block;width:100px;" %> | ||
<%= form.select :repotype, options_for_select(DownloadRepository::REPOTYPES, download_on_demand.try(:repotype)) %> | ||
<br/><br/> | ||
<%= form.label :url, style: "display:inline-block;width:100px;" %> | ||
<%= form.text_field :url %> | ||
<br/><br/> | ||
<%= form.label :archfilter, 'Arch. Filter' , style: "display:inline-block;width:100px;"%> | ||
<%= form.text_field :archfilter %> | ||
<br/><br/> | ||
<%= form.label :masterurl, 'Master Url', style: "display:inline-block;width:100px;" %> | ||
<%= form.text_field :masterurl %> | ||
<br/><br/> | ||
<%= form.label :mastersslfingerprint, 'SSL Fingerprint', style: "display:inline-block;width:100px;" %> | ||
<%= form.text_field :mastersslfingerprint %> | ||
<br/><br/> | ||
<%= form.label :pubkey, 'Public Key', style: "display:inline-block;width:100px;" %> | ||
<%= form.text_area :pubkey %> | ||
<%= form.hidden_field :repository_id %> | ||
<%= hidden_field_tag :project, project %> | ||
<% if form.object.new_record? %> | ||
<p><%= form.submit "Add Download on Demand", id: "add_dod_button" %></p> | ||
<% else %> | ||
<p><%= form.submit "Update Download on Demand", id: "update_dod_button-#{download_on_demand}"%></p> | ||
<% end %> | ||
</div> | ||
<% end %> |
44 changes: 44 additions & 0 deletions
44
src/api/app/views/webui/download_on_demand/_index.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<div style="margin-top: 1em"><%= repository.download_repositories.empty? ? "No d" : "D" %>ownload on demand repositories | ||
<% if User.current.is_admin? && repository.download_repositories.count != repository.architectures.count%> | ||
| ||
<span id="<%= "add_dod_repository_link_container_#{repository_id}" %>"> | ||
<%= sprite_tag('drive_add') %> | ||
<%= link_to('Add', '#', id: "add_dod_repository_link_#{repository_id}") %> | ||
</span> | ||
<div class="hidden" id="<%= "add_dod_repository_form_#{repository_id}" %>"> | ||
<%= render partial: 'webui/download_on_demand/add', locals: { project: project, repository: repository, download_on_demand: new_download_on_demand } %> | ||
</div> | ||
<% content_for :ready_function do %> | ||
$("#<%= "add_dod_repository_link_#{repository_id}" %>").click(function() { | ||
$("#<%= "add_dod_repository_form_#{repository_id}" %>").show(); | ||
$("#<%= "add_dod_repository_link_container_#{repository_id}" %>").hide(); | ||
}); | ||
<% end -%> | ||
<% end -%> | ||
<ul style="list-style-type: none;"> | ||
<% repository.download_repositories.each do |dod_element| %> | ||
<li> | ||
<b><%= dod_element.arch %></b>: <a href="<%= dod_element.url %>" target="_blank" title="Go to the repository"><%= dod_element.url %></a> (<%= dod_element.repotype %>) | ||
<% if User.current.is_admin? %> | ||
| ||
<span id="<%= "edit_dod_repository_link_container_#{dod_element}" %>" class="edit_dod_repository_link_container"> | ||
<%= sprite_tag('drive_edit') %> | ||
<%= link_to('Edit', '#', id: "edit_dod_repository_link_#{dod_element}") %> | ||
<%= sprite_tag('drive_delete', title: 'Delete repository') %> | ||
<%= link_to "Delete", download_repository_path(dod_element, project: project), | ||
{data: {confirm: "Really remove Download on Demand for '#{repository.name} / #{dod_element.arch}'?"}, class: 'x', method: :delete} %> | ||
</span> | ||
<div class="hidden" id="<%= "edit_dod_repository_form_#{dod_element}" %>"> | ||
<%= render partial: 'webui/download_on_demand/edit', locals: { project: project, repository: repository, download_on_demand: dod_element } %> | ||
</div> | ||
<% content_for :ready_function do %> | ||
$("#<%= "edit_dod_repository_link_#{dod_element}" %>").click(function() { | ||
$("#<%= "edit_dod_repository_form_#{dod_element}" %>").show(); | ||
$("#<%= "edit_dod_repository_link_container_#{dod_element}" %>").hide(); | ||
}); | ||
<% end -%> | ||
<% end -%> | ||
</li> | ||
<% end -%> | ||
</ul> | ||
</div> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/api/test/fixtures/backend/download_on_demand/project_with_dod.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<project name='home:user5'> | ||
<title>User5 Home Project</title> | ||
<description/> | ||
<person userid='user5' role='maintainer'/> | ||
<repository name='standard'> | ||
<download arch='i586' url='http://mola.org2' repotype='rpmmd'> | ||
<archfilter>i586, noarch</archfilter> | ||
<master url='http://opensuse.org' sslfingerprint='asdfasd'/> | ||
<pubkey>3jnlkdsjfoisdjf0932juro2ikjfdslñkfj</pubkey> | ||
</download> | ||
<arch>i586</arch> | ||
<arch>x86_64</arch> | ||
</repository> | ||
</project> |
9 changes: 9 additions & 0 deletions
9
src/api/test/fixtures/backend/download_on_demand/project_without_dod.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<project name='home:user5'> | ||
<title>User5 Home Project</title> | ||
<description/> | ||
<person userid='user5' role='maintainer'/> | ||
<repository name='standard'> | ||
<arch>i586</arch> | ||
<arch>x86_64</arch> | ||
</repository> | ||
</project> |
152 changes: 152 additions & 0 deletions
152
src/api/test/functional/webui/download_on_demand_controller_test.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# encoding: utf-8 | ||
require_relative '../../test_helper' | ||
|
||
class Webui::DownloadOnDemandControllerTest < Webui::IntegrationTest | ||
PROJECT_WITH_DOWNLOAD_ON_DEMAND = load_backend_file("download_on_demand/project_with_dod.xml") | ||
PROJECT_WITHOUT_DOWNLOAD_ON_DEMAND = load_backend_file("download_on_demand/project_without_dod.xml") | ||
|
||
def test_listing_download_on_demand | ||
use_js | ||
|
||
# Login as admin | ||
login_king | ||
visit(project_show_path(project: "home:user5")) | ||
|
||
# Updating via meta | ||
click_link("Advanced") | ||
click_link("Meta") | ||
page.evaluate_script("editors[0].setValue(\"#{PROJECT_WITH_DOWNLOAD_ON_DEMAND.gsub("\n", '\n')}\");") | ||
click_button("Save") | ||
find(:id, 'flash-messages').must_have_text('Config successfully saved!') | ||
|
||
click_link("Repositories") | ||
page.must_have_link 'http://mola.org2' | ||
page.must_have_text 'rpmmd' | ||
|
||
find(:xpath, "//span[@class='edit_dod_repository_link_container']").must_have_link('Edit') | ||
find(:xpath, "//span[@class='edit_dod_repository_link_container']").must_have_link('Delete') | ||
|
||
# Login as normal user, can't change DoDs | ||
login_tom | ||
visit(project_show_path(project: "home:user5")) | ||
|
||
click_link("Repositories") | ||
page.must_have_text 'Download on demand repositories' | ||
page.must_have_link 'http://mola.org2' | ||
page.must_have_text 'rpmmd' | ||
end | ||
|
||
def test_adding_download_on_demand | ||
use_js | ||
|
||
# Login as admin | ||
login_king | ||
visit(project_show_path(project: "home:user5")) | ||
|
||
# Updating via meta | ||
click_link("Advanced") | ||
click_link("Meta") | ||
page.evaluate_script("editors[0].setValue(\"#{PROJECT_WITHOUT_DOWNLOAD_ON_DEMAND.gsub("\n", '\n')}\");") | ||
click_button("Save") | ||
find(:id, 'flash-messages').must_have_text('Config successfully saved!') | ||
|
||
click_link("Repositories") | ||
click_link("add_dod_repository_link_standard") | ||
|
||
# Fill in the form and send a working dod data | ||
select('i586', from: 'Architecture') | ||
select('rpmmd', from: 'Type') | ||
fill_in('Url', with: 'http://somerandomurl.es') | ||
fill_in('Arch. Filter', with: 'i586, noarch') | ||
fill_in('Master Url', with: 'http://somerandomurl2.es') | ||
fill_in('SSL Fingerprint', with: '293470239742093') | ||
fill_in('Public Key', with: 'JLKSDJFSJ83U4902RKLJSDFLJF2J9IJ23OJFKJFSDF') | ||
click_button('Add Download on Demand') | ||
find(:id, 'flash-messages').must_have_text('Successfully created Download on Demand') | ||
find(:id, "add_dod_repository_link_container_standard").must_have_link('Add') | ||
find(:xpath, "//span[@class='edit_dod_repository_link_container']").must_have_link('Edit') | ||
find(:xpath, "//span[@class='edit_dod_repository_link_container']").must_have_link('Delete') | ||
page.must_have_text 'Download on demand repositories' | ||
page.must_have_link 'http://somerandomurl.es' | ||
page.must_have_text 'rpmmd' | ||
|
||
click_link("Repositories") | ||
click_link("add_dod_repository_link_standard") | ||
|
||
# Fill in the form and send a not working dod data | ||
select('x86_64', from: 'Architecture') | ||
select('rpmmd', from: 'Type') | ||
fill_in('Url', with: '') | ||
click_button('Add Download on Demand') | ||
find(:id, 'flash-messages').must_have_text("Download on Demand can't be created: Url can't be blank") | ||
end | ||
|
||
def test_editing_download_on_demand | ||
use_js | ||
|
||
# Login as admin | ||
login_king | ||
visit(project_show_path(project: "home:user5")) | ||
|
||
# Updating via meta | ||
click_link("Advanced") | ||
click_link("Meta") | ||
page.evaluate_script("editors[0].setValue(\"#{PROJECT_WITH_DOWNLOAD_ON_DEMAND.gsub("\n", '\n')}\");") | ||
click_button("Save") | ||
find(:id, 'flash-messages').must_have_text('Config successfully saved!') | ||
|
||
click_link("Repositories") | ||
within(:css, "span.edit_dod_repository_link_container") do | ||
click_link("Edit") | ||
end | ||
|
||
# Fill in the form and send a working dod data | ||
select('i586', from: 'Architecture') | ||
select('deb', from: 'Type') | ||
fill_in('Url', with: 'http://somerandomurl_2.es') | ||
fill_in('Arch. Filter', with: 'i586, noarch') | ||
fill_in('Master Url', with: 'http://somerandomurl__2.es') | ||
fill_in('SSL Fingerprint', with: '33333333444444') | ||
fill_in('Public Key', with: '902RKLJSDFLJF902RKLJSDFLJF902RKLJSDFLJF') | ||
click_button('Update Download on Demand') | ||
find(:id, 'flash-messages').must_have_text('Successfully updated Download on Demand') | ||
page.must_have_text 'Download on demand repositories' | ||
page.must_have_link 'http://somerandomurl_2.es' | ||
page.must_have_text 'deb' | ||
|
||
click_link("Repositories") | ||
within(:css, "span.edit_dod_repository_link_container") do | ||
click_link("Edit") | ||
end | ||
|
||
# Fill in the form and send a not working dod data | ||
fill_in('Url', with: '') | ||
click_button('Update Download on Demand') | ||
find(:id, 'flash-messages').must_have_text("Download on Demand can't be created: Url can't be blank") | ||
page.must_have_link 'http://somerandomurl_2.es' | ||
end | ||
|
||
def test_destroying_download_on_demand | ||
use_js | ||
|
||
# Login as admin | ||
login_king | ||
visit(project_show_path(project: "home:user5")) | ||
|
||
# Updating via meta | ||
click_link("Advanced") | ||
click_link("Meta") | ||
page.evaluate_script("editors[0].setValue(\"#{PROJECT_WITH_DOWNLOAD_ON_DEMAND.gsub("\n", '\n')}\");") | ||
click_button("Save") | ||
find(:id, 'flash-messages').must_have_text('Config successfully saved!') | ||
|
||
click_link("Repositories") | ||
within(:css, "span.edit_dod_repository_link_container") do | ||
click_link("Delete") | ||
end | ||
|
||
page.wont_have_text 'Download on demand repositories' | ||
page.wont_have_link 'http://mola.org2' | ||
page.wont_have_text 'rpmmd' | ||
end | ||
end |
Oops, something went wrong.