From ddda2b92abf6ef2ccbe97ea1e5ab8f73f1c90174 Mon Sep 17 00:00:00 2001 From: Vladimir Sharshov Date: Tue, 28 Feb 2012 00:00:33 +0400 Subject: [PATCH] [Refs #221] Delete product build lists (only in web) --- app/controllers/product_build_lists_controller.rb | 12 +++++++++--- app/models/ability.rb | 3 ++- .../_product_build_list.html.haml | 1 + app/views/products/show.html.haml | 3 ++- config/locales/en.yml | 3 +++ config/locales/ru.yml | 3 +++ config/routes.rb | 2 +- 7 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/controllers/product_build_lists_controller.rb b/app/controllers/product_build_lists_controller.rb index fac839015..6936b1d11 100644 --- a/app/controllers/product_build_lists_controller.rb +++ b/app/controllers/product_build_lists_controller.rb @@ -1,9 +1,9 @@ # -*- encoding : utf-8 -*- class ProductBuildListsController < ApplicationController before_filter :authenticate_user!, :except => [:status_build] - load_and_authorize_resource :platform, :only => [:create] - load_and_authorize_resource :product, :through => :platform, :only => [:create] - load_and_authorize_resource :product_build_list, :through => :product, :only => [:create] + load_and_authorize_resource :platform, :only => [:create, :destroy] + load_and_authorize_resource :product, :through => :platform, :only => [:create, :destroy] + load_and_authorize_resource :product_build_list, :through => :product, :only => [:create, :destroy] before_filter :authenticate_product_builder!, :only => [:status_build] before_filter :find_product_build_list, :only => [:status_build] @@ -20,6 +20,12 @@ class ProductBuildListsController < ApplicationController @product_build_list.save! render :nothing => true end + + def destroy + @product_build_list.destroy + flash[:notice] = t('flash.product.build_list_delete') + redirect_to [@platform, @product] + end protected diff --git a/app/models/ability.rb b/app/models/ability.rb index bbbb6fd9d..bca5689a6 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -81,7 +81,8 @@ class Ability can :read, Product, :platform => {:owner_type => 'Group', :owner_id => user.group_ids} can(:manage, Product, read_relations_for('products', 'platforms')) {|product| local_admin? product.platform} can(:create, ProductBuildList) {|pbl| pbl.product.can_build? and can?(:update, pbl.product)} - + can(:destroy, ProductBuildList) {|pbl| can?(:destroy, pbl.product)} + can [:read, :platforms], Category can [:read, :create], PrivateUser, :platform => {:owner_type => 'User', :owner_id => user.id} diff --git a/app/views/product_build_lists/_product_build_list.html.haml b/app/views/product_build_lists/_product_build_list.html.haml index d1464dc3a..38a70580e 100644 --- a/app/views/product_build_lists/_product_build_list.html.haml +++ b/app/views/product_build_lists/_product_build_list.html.haml @@ -3,4 +3,5 @@ %td= link_to product_build_list.product.name, [product_build_list.product.platform, product_build_list.product] %td= link_to nil, product_build_list.container_path %td= product_build_list.human_status + %td= link_to t("layout.product_build_lists.delete"), platform_product_product_build_list_path(product_build_list.product.platform, product_build_list.product, product_build_list), :method => "delete", :confirm => t("layout.confirm") if can? :delete, product_build_list %td= product_build_list.notified_at \ No newline at end of file diff --git a/app/views/products/show.html.haml b/app/views/products/show.html.haml index 3372317e6..f9c3f5bea 100644 --- a/app/views/products/show.html.haml +++ b/app/views/products/show.html.haml @@ -43,7 +43,8 @@ %th.first= t("activerecord.attributes.product_build_list.id") %th= t("activerecord.attributes.product_build_list.product") %th= t("activerecord.attributes.product_build_list.container_path") - %th= t("activerecord.attributes.product_build_list.status") + %th= t("activerecord.attributes.product_build_list.status") + %th= t("layout.product_build_lists.action") %th.last= t("activerecord.attributes.product_build_list.notified_at") = render @product.product_build_lists.default_order / = will_paginate build_lists diff --git a/config/locales/en.yml b/config/locales/en.yml index deb26de54..56519f0e7 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -519,6 +519,8 @@ en: project_versions: Versions product_build_lists: + delete: Delete + action: Action statuses: '0': 'build' '1': 'build error' @@ -662,6 +664,7 @@ en: save_error: Product saves error build_started: Product build started destroyed: Product deleted + build_list_delete: Product build list deleted platform: saved: Platform saved diff --git a/config/locales/ru.yml b/config/locales/ru.yml index f5eac73ae..299ab82e3 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -371,6 +371,8 @@ ru: project_versions: Версии product_build_lists: + delete: Удалить + action: Действие statuses: '0': 'собран' '1': 'ошибка сборки' @@ -519,6 +521,7 @@ ru: save_error: Не удалось сохранить изменения build_started: Запущена сборка продукта destroyed: Продукт удален + build_list_delete: Сборочный лист продукта удален platform: saved: Платформа успешно добавлена diff --git a/config/routes.rb b/config/routes.rb index 947f2b27a..05ebfd548 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -85,7 +85,7 @@ Rosa::Application.routes.draw do # get :clone # get :build # end - resources :product_build_lists, :only => [:create] + resources :product_build_lists, :only => [:create, :destroy] end resources :repositories