[#135] add publish & reject publish action

This commit is contained in:
Alexander Machehin 2013-06-10 17:26:12 +06:00
parent 1db7955e0c
commit 28b12b8c96
6 changed files with 41 additions and 46 deletions

View File

@ -2035,3 +2035,7 @@ article .activity .top {
-moz-box-shadow: 0;
box-shadow: 0;
}
a.button.reject_publish, a.button.create_container {
height: 15px;
}

View File

@ -79,46 +79,6 @@ class Projects::BuildListsController < Projects::BaseController
@item_groups = @build_list.items.group_by_level
end
def update
if params[:publish].present? and can?(:publish, @build_list)
publish
elsif params[:reject_publish].present? and can?(:reject_publish, @build_list)
reject_publish
else
# King Arthur, we are under attack!
redirect_to :forbidden and return
end
end
def create_container
if @build_list.publish_container
redirect_to :back, :notice => t('layout.build_lists.create_container_success')
else
redirect_to :back, :notice => t('layout.build_lists.create_container_fail')
end
end
def cancel
if @build_list.cancel
redirect_to :back, :notice => t('layout.build_lists.will_be_canceled')
else
redirect_to :back, :notice => t('layout.build_lists.cancel_fail')
end
end
def log
render :json => {
:log => @build_list.log(params[:load_lines]),
:building => @build_list.build_started?
}
end
protected
def find_build_list
@build_list = BuildList.find(params[:id])
end
def publish
@build_list.update_type = params[:build_list][:update_type] if params[:build_list][:update_type].present?
@ -158,4 +118,33 @@ class Projects::BuildListsController < Projects::BaseController
redirect_to :back, :notice => t('layout.build_lists.reject_publish_fail')
end
end
def create_container
if @build_list.publish_container
redirect_to :back, :notice => t('layout.build_lists.create_container_success')
else
redirect_to :back, :notice => t('layout.build_lists.create_container_fail')
end
end
def cancel
if @build_list.cancel
redirect_to :back, :notice => t('layout.build_lists.will_be_canceled')
else
redirect_to :back, :notice => t('layout.build_lists.cancel_fail')
end
end
def log
render :json => {
:log => @build_list.log(params[:load_lines]),
:building => @build_list.build_started?
}
end
protected
def find_build_list
@build_list = BuildList.find(params[:id])
end
end

View File

@ -83,7 +83,6 @@ class Ability
can [:read, :log, :related, :everything], BuildList, :project => {:owner_type => 'Group', :owner_id => user.group_ids}
can([:read, :log, :everything], BuildList, read_relations_for('build_lists', 'projects')) {|build_list| can? :read, build_list.project}
can(:create, BuildList) {|build_list| build_list.project.is_package && can?(:write, build_list.project)}
can :update, BuildList
can(:publish, BuildList) do |build_list|
if build_list.build_published?

View File

@ -157,11 +157,12 @@
- elsif can_publish_in_future?(@build_list) && @build_list.extra_build_lists_published?
- confirm = @build_list.tests_failed? ? t('layout.build_lists.tests_failed') : t('layout.confirm')
= submit_tag t("layout.publish"), :confirm => confirm, :name => 'publish'
- if @build_list.can_reject_publish? && can?(:reject_publish, @build_list)
= submit_tag t("layout.reject_publish"), :confirm => t("layout.confirm"), :name => 'reject_publish'
- if @build_list.can_reject_publish? && can?(:reject_publish, @build_list)
= link_to t('layout.reject_publish'), reject_publish_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"), :class => 'button reject_publish'
- if @build_list.can_create_container? && can?(:create_container, @build_list)
= link_to t("layout.build_lists.create_container"), create_container_build_list_path(@build_list),
:method => :put, :confirm => t("layout.confirm"), :class => 'button'
:method => :put, :confirm => t("layout.confirm"), :class => 'button create_container'
.hr
%h3= t("layout.build_lists.items_header")

View File

@ -232,11 +232,13 @@ Rosa::Application.routes.draw do
end
scope :module => 'projects' do
resources :build_lists, :only => [:index, :show, :update] do
resources :build_lists, :only => [:index, :show] do
member do
put :cancel
put :create_container
get :log
put :publish
put :reject_publish
end
collection {
post :search

View File

@ -131,7 +131,7 @@ describe Projects::BuildListsController do
before(:each) {@build_list.save_to_repository.update_column(:publish_without_qa, true)}
def do_reject_publish
put :update, :id => @build_list, :reject_publish => true
put :reject_publish, :id => @build_list
end
context 'if user is project owner' do