From 0827cf5100224a3a779d8979bfa047c1f4577920 Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Tue, 3 Jul 2012 18:34:07 +0400 Subject: [PATCH] [refs #442] Add other mass builds action to mass_builds controller. Rename cancel_mass_builds action --- app/controllers/mass_builds_controller.rb | 37 ++++++++++++++++++- .../platforms/platforms_controller.rb | 24 ------------ app/models/ability.rb | 12 +++--- .../index.html.haml} | 8 ++-- app/views/platforms/base/_sidebar.html.haml | 6 +-- config/routes.rb | 6 +-- 6 files changed, 50 insertions(+), 43 deletions(-) rename app/views/{platforms/platforms/build_all.html.haml => mass_builds/index.html.haml} (88%) diff --git a/app/controllers/mass_builds_controller.rb b/app/controllers/mass_builds_controller.rb index 441b04503..8f2ec3770 100644 --- a/app/controllers/mass_builds_controller.rb +++ b/app/controllers/mass_builds_controller.rb @@ -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 diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 09dde90c3..5a948d06e 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -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 diff --git a/app/models/ability.rb b/app/models/ability.rb index 6a4642878..f087ce699 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -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) diff --git a/app/views/platforms/platforms/build_all.html.haml b/app/views/mass_builds/index.html.haml similarity index 88% rename from app/views/platforms/platforms/build_all.html.haml rename to app/views/mass_builds/index.html.haml index a02cff527..15ba91f7a 100644 --- a/app/views/platforms/platforms/build_all.html.haml +++ b/app/views/mass_builds/index.html.haml @@ -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 }"} diff --git a/app/views/platforms/base/_sidebar.html.haml b/app/views/platforms/base/_sidebar.html.haml index 2ba6c1279..434e2ad43 100644 --- a/app/views/platforms/base/_sidebar.html.haml +++ b/app/views/platforms/base/_sidebar.html.haml @@ -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) diff --git a/config/routes.rb b/config/routes.rb index c777392b3..4370d907e 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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