[refs #442] Add other mass builds action to mass_builds controller. Rename cancel_mass_builds action

This commit is contained in:
konstantin.grabar 2012-07-03 18:34:07 +04:00
parent dbbe4cef1f
commit 0827cf5100
6 changed files with 50 additions and 43 deletions

View File

@ -1,12 +1,45 @@
class MassBuildsController < ApplicationController
before_filter :authenticate_user!
load_and_authorize_resource :platform
load_and_authorize_resource
def cancel_mass_build
skip_load_and_authorize_resource :only => [:index, :create]
skip_load_and_authorize_resource :platform, :only => [:cancel, :failed_builds_list]
skip_authorize_resource :platform, :only => [:create, :index]
def create
mass_build = MassBuild.new(
:platform => @platform,
:user => current_user,
:repositories => params[:repositories],
:arches => params[:arches],
:auto_publish => params[:auto_publish] || false
)
authorize! :create, mass_build
if mass_build.save
redirect_to(platform_mass_builds_path(@platform), :notice => t("flash.platform.build_all_success"))
else
@auto_publish_selected = params[:auto_publish].present?
@mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20)
flash[:warning] = mass_build.errors.full_messages.join('. ')
flash[:error] = t("flash.platform.build_all_error")
render :action => :index
end
end
def index
authorize! :edit, @platform
@mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20)
@auto_publish_selected = true
end
def cancel
@mass_build.cancel_all
flash[:notice] = t("flash.platform.cancel_mass_build")
redirect_to mass_builds_platform_path(@mass_build.platform)
redirect_to platform_mass_builds_path(@mass_build.platform)
end
def failed_builds_list

View File

@ -7,30 +7,6 @@ class Platforms::PlatformsController < Platforms::BaseController
autocomplete :user, :uname
def build_all
mass_build = MassBuild.new(
:platform => @platform,
:user => current_user,
:repositories => params[:repositories],
:arches => params[:arches],
:auto_publish => params[:auto_publish] || false
)
if mass_build.save
redirect_to(mass_builds_platform_path(@platform), :notice => t("flash.platform.build_all_success"))
else
@auto_publish_selected = params[:auto_publish].present?
@mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20)
flash[:warning] = mass_build.errors.full_messages.join('. ')
flash[:error] = t("flash.platform.build_all_error")
end
end
def mass_builds
@mass_builds = MassBuild.by_platform(@platform).order('created_at DESC').paginate(:page => params[:page], :per_page => 20)
@auto_publish_selected = true
render :action => :build_all
end
def index
@platforms = @platforms.accessible_by(current_ability, :related).paginate(:page => params[:page], :per_page => 20)
end

View File

@ -83,9 +83,9 @@ class Ability
can [:read, :related, :members], Platform, :owner_type => 'Group', :owner_id => user.group_ids
can([:read, :related, :members], Platform, read_relations_for('platforms')) {|platform| local_reader? platform}
can([:update, :members], Platform) {|platform| local_admin? platform}
can([:destroy, :members, :add_member, :remove_member, :remove_members, :build_all, :mass_builds] , Platform) {|platform| owner?(platform) || local_admin?(platform) }
can(:failed_builds_list, MassBuild) {|mass_build| owner?(mass_build.platform) || local_admin?(mass_build.platform) }
can(:cancel_mass_build, MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && !mass_build.stop_build }
can([:destroy, :members, :add_member, :remove_member, :remove_members] , Platform) {|platform| owner?(platform) || local_admin?(platform) }
can([:failed_builds_list, :create], MassBuild) {|mass_build| owner?(mass_build.platform) || local_admin?(mass_build.platform) }
can(:cancel, MassBuild) {|mass_build| (owner?(mass_build.platform) || local_admin?(mass_build.platform)) && !mass_build.stop_build }
can [:autocomplete_user_uname, :read_advisories, :advisories], Platform
can [:read, :projects_list], Repository, :platform => {:visibility => 'open'}
@ -129,9 +129,9 @@ class Ability
cannot [:members, :add_member, :remove_member, :remove_members], Platform, :platform_type => 'personal'
cannot [:create, :update, :destroy, :clone], Product, :platform => {:platform_type => 'personal'}
cannot [:clone, :build_all, :mass_builds], Platform, :platform_type => 'personal'
cannot(:failed_builds_list, MassBuild) {|mass_build| mass_build.platform.platform_type == 'personal'}
cannot(:cancel_mass_build, MassBuild) { |mass_build| mass_build.platform.platform_type == 'personal' && mass_build.stop_build }
cannot [:clone], Platform, :platform_type => 'personal'
cannot([:failed_builds_list, :create], MassBuild) {|mass_build| mass_build.platform.platform_type == 'personal'}
cannot(:cancel, MassBuild) { |mass_build| mass_build.platform.platform_type == 'personal' && mass_build.stop_build }
can :create, Subscribe do |subscribe|
!subscribe.subscribeable.subscribes.exists?(:user_id => user.id)

View File

@ -1,7 +1,7 @@
= render 'submenu'
= render 'sidebar'
= render 'platforms/base/submenu'
= render 'platforms/base/sidebar'
= form_for :build, :url => build_all_platform_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f|
= form_for :build, :url => platform_mass_builds_path(@platform), :html => { :class => 'form mass_build', :method => :post } do |f|
%section.left
%h3= t("layout.mass_builds.repositories")
- @platform.repositories.each do |rep|
@ -44,7 +44,7 @@
= mass_build.read_attribute "#{status}_count"
.both
%td= link_to t("layout.mass_builds.failed_builds_list"), failed_builds_list_platform_mass_build_path(@platform, mass_build.id), :target => "_blank" if can?(:failed_builds_list, mass_build)
%td= link_to image_tag('x.png'), cancel_mass_build_platform_mass_build_path(@platform, mass_build.id), :method => :post, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:cancel_mass_build, mass_build)
%td= link_to image_tag('x.png'), cancel_platform_mass_build_path(@platform, mass_build.id), :method => :post, :confirm => t("layout.mass_builds.cancel_confirm") if can?(:cancel, mass_build)
%td
%a.toggle_btn{:href => "#toggle_#{ mass_build.id }", :'data-target' => "#toggle_#{ mass_build.id }"}= t("layout.mass_builds.extended_data")
.toggle{:id => "toggle_#{ mass_build.id }"}

View File

@ -10,9 +10,9 @@
= link_to t("layout.platforms.about"), platform_path(@platform)
%li{:class => (contr == :repositories) ? 'active' : ''}
= link_to t("layout.repositories.list_header"), platform_repositories_path(@platform)
- if can? :mass_builds, @platform
%li{:class => (contr == :platforms && [:mass_builds, :build_all].include?(act)) ? 'active' : ''}
= link_to t("layout.platforms.mass_build"), mass_builds_platform_path(@platform)
- if can? :edit, @platform
%li{:class => (contr == :mass_builds && [:index, :create].include?(act)) ? 'active' : ''}
= link_to t("layout.platforms.mass_build"), platform_mass_builds_path(@platform)
- if can? :read, @platform.products.build
%li{:class => (contr == :products) ? 'active' : ''}
= link_to t("layout.products.list_header"), platform_products_path(@platform)

View File

@ -51,15 +51,13 @@ Rosa::Application.routes.draw do
delete :remove_member
post :add_member
post :make_clone
post :build_all
get :mass_builds
get :advisories
end
resources :mass_builds do
resources :mass_builds, :only => [:create, :index] do
member do
get :failed_builds_list
post :cancel_mass_build
post :cancel
end
end