#373: added ability to destroy ProductBuildList

This commit is contained in:
Vokhmin Alexey V 2014-04-09 22:44:19 +04:00
parent 63b82433af
commit c65853e072
7 changed files with 37 additions and 21 deletions

View File

@ -28,4 +28,13 @@ RosaABF.controller('ProductBuildListController', ['$scope', '$http', '$timeout',
}
$scope.refresh();
$scope.updateStatus = function() {
$http.put(
Routes.product_build_list_path($scope.id),
{product_build_list: {not_delete: $scope.not_delete}, format: 'json'}
).success(function(results) {
$scope.getProductBuildList();
});
}
}]);

View File

@ -3,7 +3,7 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
before_filter :authenticate_user!
skip_before_filter :authenticate_user!, only: [:index, :show, :log] if APP_CONFIG['anonymous_access']
before_filter :redirect_to_full_path_if_short_url, only: :show
before_filter :redirect_to_full_path_if_short_url, only: [:show, :update]
load_and_authorize_resource :platform, except: :index
load_and_authorize_resource :product, through: :platform, except: :index
load_and_authorize_resource :product_build_list, through: :product, except: :index
@ -25,13 +25,8 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
end
def update
if @product_build_list.update_attributes(not_delete: (params[:product_build_list] || {})[:not_delete])
flash[:notice] = t('flash.product_build_list.updated')
else
flash[:error] = t('flash.product_build_list.update_error')
flash[:warning] = @product_build_list.errors.full_messages.join('. ')
end
redirect_to platform_product_product_build_list_path(@platform, @product, @product_build_list)
@product_build_list.update_attributes(not_delete: (params[:product_build_list] || {})[:not_delete])
render nothing: true
end
def cancel

View File

@ -122,8 +122,12 @@ class ProductBuildList < ActiveRecord::Base
status == BUILD_CANCELING
end
def can_destroy?
![BUILD_STARTED, BUILD_PENDING, BUILD_CANCELING].include?(status)
end
def can_cancel?
[BUILD_STARTED, BUILD_PENDING].include? status
[BUILD_STARTED, BUILD_PENDING].include?(status)
end
def event_log_message

View File

@ -38,17 +38,18 @@
%br
- if can?(:update, pbl)
= form_for pbl,
url: platform_product_product_build_list_path(pbl.product.platform,pbl.product, pbl),
html: {'ng-show' => "pbl.status == #{ProductBuildList::BUILD_COMPLETED}"} do |f|
.leftlist= f.label :not_delete
%div{'ng-show' => "pbl.status == #{ProductBuildList::BUILD_COMPLETED}"}
.leftlist= t('activerecord.attributes.product_build_list.not_delete')
.rightlist
= f.select :not_delete, [false, true].collect{|status| [t("layout.#{status}_"), status]}, {selected: pbl.not_delete}
.both
%br
= submit_tag t('layout.update'), data: {'disable-with' => t('layout.processing')}
= select_tag 'not_delete', options_for_select([false, true].map{|status| [t("layout.#{status}_"), status]}), {'ng-model' => "not_delete", 'ng-change' => 'updateStatus()', 'ng-init' => "not_delete = '#{pbl.not_delete}'"}
.both
- if can?(:destroy, pbl)
= link_to t('layout.product_build_lists.delete'),
platform_product_product_build_list_path(pbl.product.platform, pbl.product, pbl),
method: :delete, data: { confirm: t("layout.confirm") }, class: 'button',
'ng-show' => 'pbl.can_destroy'
.both
%br
.flash_notify{'ng-hide' => 'pbl.not_delete'}
.alert.alert-error
- days = pbl.autostarted? ? ProductBuildList::LIVE_TIME : ProductBuildList::MAX_LIVE_TIME

View File

@ -2,7 +2,8 @@ json.product_build_list do
json.(@product_build_list, :id, :status, :human_status, :not_delete)
json.notified_at l(@product_build_list.updated_at, format: :long)
json.can_cancel @product_build_list.can_cancel?
json.can_cancel @product_build_list.can_cancel?
json.can_destroy @product_build_list.can_destroy?
json.results @product_build_list.results do |result|
json.file_name result['file_name']

View File

@ -231,7 +231,7 @@ Rosa::Application.routes.draw do
resources :maintainers, only: [:index]
end
resources :product_build_lists, only: [:index, :show]
resources :product_build_lists, only: [:index, :show, :update]
end
resources :autocompletes, only: [] do

View File

@ -36,7 +36,7 @@ shared_examples_for 'product build list admin' do
it 'should be able to perform update action' do
put :update, valid_attributes_for_show.merge(product_build_list: {time_living: 100,not_delete: true})
response.should redirect_to(platform_product_product_build_list_path(@product.platform, @product, @pbl))
response.should be_success
end
it "ensures that only not_delete field of product build list has been updated" do
@ -73,6 +73,12 @@ shared_examples_for 'product build list user without admin rights' do
put :cancel, valid_attributes_for_show
response.should_not redirect_to(platform_product_product_build_list_path(@product.platform, @product, @pbl))
end
it 'should not be able to perform update action' do
put :update, valid_attributes_for_show
response.should_not be_success
end
end
shared_examples_for 'product build list user' do