From 8f9a6ee2d25011952a87cedef3808967fd7ee68a Mon Sep 17 00:00:00 2001 From: "konstantin.grabar" Date: Mon, 2 Jul 2012 18:50:47 +0400 Subject: [PATCH] [refs #442] Change cancel btn. Move some actions to mass_builds controller. Add more ability rights --- app/controllers/mass_builds_controller.rb | 15 +++++++++++++++ app/controllers/platforms/platforms_controller.rb | 12 ------------ app/models/ability.rb | 8 ++++++-- app/models/mass_build.rb | 2 +- app/views/platforms/platforms/build_all.html.haml | 4 ++-- config/routes.rb | 10 +++++++--- 6 files changed, 31 insertions(+), 20 deletions(-) create mode 100644 app/controllers/mass_builds_controller.rb diff --git a/app/controllers/mass_builds_controller.rb b/app/controllers/mass_builds_controller.rb new file mode 100644 index 000000000..441b04503 --- /dev/null +++ b/app/controllers/mass_builds_controller.rb @@ -0,0 +1,15 @@ +class MassBuildsController < ApplicationController + before_filter :authenticate_user! + + load_and_authorize_resource + + def cancel_mass_build + @mass_build.cancel_all + flash[:notice] = t("flash.platform.cancel_mass_build") + redirect_to mass_builds_platform_path(@mass_build.platform) + end + + def failed_builds_list + render :text => @mass_build.generate_failed_builds_list + end +end diff --git a/app/controllers/platforms/platforms_controller.rb b/app/controllers/platforms/platforms_controller.rb index 5f77f09f2..09dde90c3 100644 --- a/app/controllers/platforms/platforms_controller.rb +++ b/app/controllers/platforms/platforms_controller.rb @@ -31,18 +31,6 @@ class Platforms::PlatformsController < Platforms::BaseController render :action => :build_all end - def cancel_mass_build - @mass_build = MassBuild.find params[:mass_build_id] - @mass_build.cancel_all - flash[:notice] = t("flash.platform.cancel_mass_build") - redirect_to mass_builds_platform_path(@mass_build.platform) - end - - def failed_builds_list - @mass_build = MassBuild.find params[:mass_build_id] - render :text => @mass_build.generate_failed_builds_list - 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 68b5d7375..6a4642878 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -83,7 +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, :cancel_mass_build, :failed_builds_list] , Platform) {|platform| owner? 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 [:autocomplete_user_uname, :read_advisories, :advisories], Platform can [:read, :projects_list], Repository, :platform => {:visibility => 'open'} @@ -127,7 +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, :cancel_mass_build, :failed_builds_list], 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 } can :create, Subscribe do |subscribe| !subscribe.subscribeable.subscribes.exists?(:user_id => user.id) diff --git a/app/models/mass_build.rb b/app/models/mass_build.rb index ff3124678..b8a2a8fde 100644 --- a/app/models/mass_build.rb +++ b/app/models/mass_build.rb @@ -57,5 +57,5 @@ class MassBuild < ActiveRecord::Base bl.cancel end end - later :cancel_all, :loner => true, :queue => :clone_build + later :cancel_all, :queue => :clone_build end diff --git a/app/views/platforms/platforms/build_all.html.haml b/app/views/platforms/platforms/build_all.html.haml index 072151269..a02cff527 100644 --- a/app/views/platforms/platforms/build_all.html.haml +++ b/app/views/platforms/platforms/build_all.html.haml @@ -43,8 +43,8 @@ = link_to t("layout.build_lists.statuses.#{status}") + ": ", build_lists_path(:filter => {:mass_build_id => mass_build.id, :ownership => 'index'}.merge(status != :build_lists ? {:status => BuildList.status_by_human(status)} : {})) = mass_build.read_attribute "#{status}_count" .both - %td= link_to t("layout.mass_builds.failed_builds_list"), failed_builds_list_platforms_path(:mass_build_id => mass_build.id), :target => "_blank" - %td= link_to t("layout.mass_builds.cancel_mass_build"), cancel_mass_build_platforms_path(:mass_build_id => mass_build.id), :method => :post, :confirm => t("layout.mass_builds.cancel_confirm") + %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 %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/config/routes.rb b/config/routes.rb index d9186bbd2..c777392b3 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -55,10 +55,14 @@ Rosa::Application.routes.draw do get :mass_builds get :advisories end - collection do - get :failed_builds_list - post :cancel_mass_build + + resources :mass_builds do + member do + get :failed_builds_list + post :cancel_mass_build + end end + get :autocomplete_user_uname, :on => :collection resources :repositories do member do