Merge pull request #75 from warpc/65-build_repo
Refactor and cleanup build_lists. Minor fixes * Refactor and cleanup build_lists controller and routes * Rename methods * Allow deffis in platform and repository name * Add missing relation and migration to force work user assign in build_lists * Fix and simplify links * Abstract sidebar
This commit is contained in:
commit
71da0a51d8
|
@ -1,24 +1,22 @@
|
|||
class BuildListsController < ApplicationController
|
||||
CALLBACK_ACTIONS = [:status_build, :pre_build, :post_build, :circle_build, :new_bbdt]
|
||||
NESTED_ACTIONS = [:index, :new, :create]
|
||||
|
||||
before_filter :authenticate_user!, :except => CALLBACK_ACTIONS
|
||||
before_filter :authenticate_build_service!, :only => CALLBACK_ACTIONS
|
||||
before_filter :find_project, :only => [:filter, :show, :publish, :new, :create]
|
||||
before_filter :find_arches, :only => [:index]
|
||||
before_filter :find_project, :only => NESTED_ACTIONS
|
||||
before_filter :find_build_list, :only => [:show, :publish, :cancel]
|
||||
before_filter :find_build_list_by_bs, :only => [:status_build, :pre_build, :post_build]
|
||||
|
||||
load_and_authorize_resource :project, :only => :index
|
||||
load_and_authorize_resource :through => :project, :only => :index, :shallow => true
|
||||
load_and_authorize_resource :except => CALLBACK_ACTIONS.concat([:index])
|
||||
load_and_authorize_resource :project, :only => NESTED_ACTIONS
|
||||
load_and_authorize_resource :through => :project, :only => NESTED_ACTIONS, :shallow => true
|
||||
load_and_authorize_resource :except => CALLBACK_ACTIONS.concat(NESTED_ACTIONS)
|
||||
|
||||
def index
|
||||
filter_params = params[:filter] || {}
|
||||
if params[:project_id]
|
||||
find_project
|
||||
find_project_versions
|
||||
if @project
|
||||
@action_url = project_build_lists_path(@project)
|
||||
else
|
||||
@project = nil
|
||||
@action_url = build_lists_path
|
||||
end
|
||||
|
||||
|
@ -32,11 +30,6 @@ class BuildListsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@build_list = @project.build_lists.find(params[:id])
|
||||
@item_groups = @build_list.items.group_by_level
|
||||
end
|
||||
|
||||
def new
|
||||
@build_list = BuildList.new
|
||||
end
|
||||
|
@ -65,20 +58,24 @@ class BuildListsController < ApplicationController
|
|||
redirect_to @project
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def show
|
||||
@item_groups = @build_list.items.group_by_level
|
||||
end
|
||||
|
||||
def publish
|
||||
@build_list = @project.build_lists.find(params[:id])
|
||||
@build_list.publish
|
||||
|
||||
redirect_to project_build_lists_path(@project)
|
||||
if @build_list.publish
|
||||
redirect_to :back, :notice => t('layout.build_lists.publish_success')
|
||||
else
|
||||
redirect_to :back, :notice => t('layout.build_lists.publish_fail')
|
||||
end
|
||||
end
|
||||
|
||||
def cancel
|
||||
build_list = BuildList.find(params[:id])
|
||||
if build_list.cancel_build_list
|
||||
redirect_to :back, :notice => t('layout.build_lists.cancel_successed')
|
||||
if @build_list.cancel
|
||||
redirect_to :back, :notice => t('layout.build_lists.cancel_success')
|
||||
else
|
||||
redirect_to :back, :notice => t('layout.build_lists.cancel_failed')
|
||||
redirect_to :back, :notice => t('layout.build_lists.cancel_fail')
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -86,10 +83,9 @@ class BuildListsController < ApplicationController
|
|||
@item = @build_list.items.find_by_name!(params[:package_name])
|
||||
@item.status = params[:status]
|
||||
@item.save
|
||||
|
||||
|
||||
@build_list.container_path = params[:container_path]
|
||||
@build_list.notified_at = Time.current
|
||||
|
||||
@build_list.save
|
||||
|
||||
render :nothing => true, :status => 200
|
||||
|
@ -98,7 +94,6 @@ class BuildListsController < ApplicationController
|
|||
def pre_build
|
||||
@build_list.status = BuildServer::BUILD_STARTED
|
||||
@build_list.notified_at = Time.current
|
||||
|
||||
@build_list.save
|
||||
|
||||
render :nothing => true, :status => 200
|
||||
|
@ -108,7 +103,6 @@ class BuildListsController < ApplicationController
|
|||
@build_list.status = params[:status]
|
||||
@build_list.container_path = params[:container_path]
|
||||
@build_list.notified_at = Time.current
|
||||
|
||||
@build_list.save
|
||||
|
||||
render :nothing => true, :status => 200
|
||||
|
@ -118,7 +112,6 @@ class BuildListsController < ApplicationController
|
|||
@build_list.is_circle = true
|
||||
@build_list.container_path = params[:container_path]
|
||||
@build_list.notified_at = Time.current
|
||||
|
||||
@build_list.save
|
||||
|
||||
render :nothing => true, :status => 200
|
||||
|
@ -139,27 +132,22 @@ class BuildListsController < ApplicationController
|
|||
end
|
||||
|
||||
protected
|
||||
|
||||
def find_project
|
||||
@project = Project.find params[:project_id]
|
||||
end
|
||||
|
||||
def find_arches
|
||||
@arches = Arch.recent
|
||||
end
|
||||
def find_project
|
||||
@project = Project.find_by_id params[:project_id]
|
||||
end
|
||||
|
||||
def find_project_versions
|
||||
@git_repository = @project.git_repository
|
||||
@project_versions = @project.versions
|
||||
end
|
||||
def find_build_list
|
||||
@build_list = BuildList.find(params[:id])
|
||||
end
|
||||
|
||||
def find_build_list_by_bs
|
||||
@build_list = BuildList.find_by_bs_id!(params[:id])
|
||||
end
|
||||
def find_build_list_by_bs
|
||||
@build_list = BuildList.find_by_bs_id!(params[:id])
|
||||
end
|
||||
|
||||
def authenticate_build_service!
|
||||
if request.remote_ip != APP_CONFIG['build_server_ip']
|
||||
render :nothing => true, :status => 403
|
||||
end
|
||||
def authenticate_build_service!
|
||||
if request.remote_ip != APP_CONFIG['build_server_ip']
|
||||
render :nothing => true, :status => 403
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,7 +43,7 @@ class Ability
|
|||
can :create, Project
|
||||
can :create, Group
|
||||
can :publish, BuildList do |build_list|
|
||||
build_list.can_published? && build_list.project.relations.exists?(:object_type => 'User', :object_id => user.id)
|
||||
build_list.can_publish? && build_list.project.relations.exists?(:object_type => 'User', :object_id => user.id)
|
||||
end
|
||||
can [:index, :read], BuildList, ["build_lists.project_id IN (SELECT id FROM projects WHERE visibility = ?)", 'open'] do |build_list|
|
||||
build_list.project.public?
|
||||
|
@ -106,7 +106,7 @@ class Ability
|
|||
# Same rights for groups:
|
||||
can [:read, :create], PrivateUser, :platform => {:owner_type => 'Group', :owner_id => user.group_ids}
|
||||
can :publish, BuildList do |build_list|
|
||||
build_list.can_published? && build_list.project.relations.exists?(:object_type => 'Group', :object_id => user.group_ids)
|
||||
build_list.can_publish? && build_list.project.relations.exists?(:object_type => 'Group', :object_id => user.group_ids)
|
||||
end
|
||||
can [:index, :read], BuildList, build_lists_in_relations_with(:object_type => 'Group', :object_id => user.group_ids) do |build_list|
|
||||
build_list.project.relations.exists?(:object_type => 'Group', :object_id => user.group_ids)
|
||||
|
|
|
@ -105,18 +105,18 @@ class BuildList < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def publish
|
||||
return false unless can_published?
|
||||
return false unless can_publish?
|
||||
|
||||
BuildServer.publish_container bs_id
|
||||
self.update_attribute(:status, BUILD_PUBLISHED)
|
||||
#self.destroy # self.delete
|
||||
end
|
||||
|
||||
def can_published?
|
||||
def can_publish?
|
||||
self.status == BuildServer::SUCCESS
|
||||
end
|
||||
|
||||
def cancel_build_list
|
||||
def cancel
|
||||
has_canceled = BuildServer.delete_build_list bs_id
|
||||
update_attribute(:status, BUILD_CANCELED) if has_canceled == 0
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ class Platform < ActiveRecord::Base
|
|||
has_many :groups, :through => :objects, :source => :object, :source_type => 'Group'
|
||||
|
||||
validates :description, :presence => true, :uniqueness => true
|
||||
validates :name, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }
|
||||
validates :name, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9_\-]+$/ }
|
||||
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']}
|
||||
|
||||
before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]}
|
||||
|
|
|
@ -11,7 +11,7 @@ class Repository < ActiveRecord::Base
|
|||
has_many :groups, :through => :objects, :source => :object, :source_type => 'Group'
|
||||
|
||||
validates :description, :uniqueness => {:scope => :platform_id}, :presence => true
|
||||
validates :name, :uniqueness => {:scope => :platform_id}, :presence => true, :format => { :with => /^[a-z0-9_]+$/ }
|
||||
validates :name, :uniqueness => {:scope => :platform_id}, :presence => true, :format => { :with => /^[a-z0-9_\-]+$/ }
|
||||
# validates :platform_id, :presence => true # if you uncomment this platform clone will not work
|
||||
|
||||
scope :recent, order("name ASC")
|
||||
|
|
|
@ -5,6 +5,7 @@ class User < ActiveRecord::Base
|
|||
:recoverable, :rememberable, :validatable #, :trackable, :confirmable, :lockable
|
||||
|
||||
has_many :authentications, :dependent => :destroy
|
||||
has_many :build_lists, :dependent => :destroy
|
||||
|
||||
has_many :relations, :as => :object, :dependent => :destroy
|
||||
has_many :targets, :as => :object, :class_name => 'Relation'
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
- build_lists.each do |build_list|
|
||||
%tr{:class => cycle("odd", "even")}
|
||||
%td= link_to (build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")), project_build_list_path(build_list.project, build_list)
|
||||
%td= link_to (build_list.bs_id.present? ? build_list.bs_id : t("layout.build_lists.bs_id_not_set")), build_list
|
||||
%td= build_list.human_status
|
||||
%td= link_to build_list.project_version, "#"
|
||||
%td= link_to build_list.project.name, project_path(build_list.project)
|
||||
|
@ -21,7 +21,7 @@
|
|||
%td= build_list.user.try(:fullname)
|
||||
%td= t("layout.#{build_list.is_circle?}_")
|
||||
- unless @project
|
||||
%td= link_to t("layout.build_lists.cancel_button"), build_list_cancel_path(build_list) if build_list.can_cancel?
|
||||
%td= link_to t("layout.build_lists.cancel_button"), cancel_build_list_path(build_list), :method => "put", :confirm => t("layout.confirm") if build_list.can_cancel?
|
||||
%td.last= build_list.notified_at
|
||||
|
||||
= will_paginate build_lists
|
||||
|
|
|
@ -8,12 +8,12 @@
|
|||
= f.select :status, BuildList::STATUSES.collect{|status| [BuildList.human_status(status), status]}, :include_blank => true, :selected => @filter.status
|
||||
.group
|
||||
= f.label :arch_id, t("activerecord.attributes.build_list.arch"), :class => :label
|
||||
= f.select :arch_id, @arches.collect{|arch| [arch.name, arch.id]}, :include_blank => true, :selected => @filter.arch_id
|
||||
= f.select :arch_id, Arch.recent.collect{|arch| [arch.name, arch.id]}, :include_blank => true, :selected => @filter.arch_id
|
||||
.column.right
|
||||
- if @project_versions
|
||||
- if @project
|
||||
.group
|
||||
= f.label :project_version, t("activerecord.attributes.build_list.project_version"), :class => :label
|
||||
= f.select :project_version, @project_versions, :include_blank => true, :selected => @filter.project_version
|
||||
= f.select :project_version, @project.versions, :include_blank => true, :selected => @filter.project_version
|
||||
.group
|
||||
= f.label :is_circle, t("activerecord.attributes.build_list.is_circle"), :class => :label
|
||||
= f.select :is_circle, [[t("layout.yes_"), 1], [t("layout.no_"), 0]], :include_blank => true, :selected => @filter.is_circle.present? ? (@filter.is_circle ? "1" : "0") : nil
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
.block.notice
|
||||
%h3= t("layout.repositories.current_repository_header")
|
||||
.content
|
||||
- @project.repositories.each do |repository|
|
||||
- project.repositories.each do |repository|
|
||||
%p= link_to "#{repository.name} (#{repository.platform.name})", platform_repository_path(repository.platform, repository)
|
||||
|
||||
.block.notice
|
||||
%h3= t("layout.projects.current_project_header")
|
||||
.content
|
||||
%p= link_to @project.name, project_path(@project)
|
||||
%p= link_to project.name, project
|
|
@ -25,4 +25,4 @@
|
|||
.inner
|
||||
= render :partial => "build_lists/build_lists", :object => @build_lists
|
||||
|
||||
- content_for :sidebar, render(:partial => 'sidebar') if @project
|
||||
- content_for :sidebar, render('sidebar', :project => @project) if @project
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
.block
|
||||
.secondary-navigation
|
||||
%ul.wat-cf
|
||||
%li.first= link_to t("layout.build_lists.current"), project_path(@project) + "#build_lists"
|
||||
%li= link_to t("layout.build_lists.all"), project_build_lists_path(@project)
|
||||
%li.active= link_to t("layout.build_lists.show"), project_build_list_path(@project, @build_list)
|
||||
%li.first= link_to t("layout.build_lists.current"), project_path(@build_list.project) + "#build_lists"
|
||||
%li= link_to t("layout.build_lists.all"), project_build_lists_path(@build_list.project)
|
||||
%li.active= link_to t("layout.build_lists.show"), @build_list
|
||||
|
||||
.content
|
||||
.inner
|
||||
|
@ -85,9 +85,9 @@
|
|||
\:
|
||||
= t("layout.#{@build_list.is_circle?}_")
|
||||
|
||||
- if @build_list.can_published?
|
||||
- if @build_list.can_publish?
|
||||
.wat-cf
|
||||
= link_to image_tag("web-app-theme/icons/tick.png", :alt => t("layout.publish")) + " " + t("layout.publish"), publish_project_build_list_path(@project, @build_list), :method => "post", :class => "button", :confirm => t("layout.build_lists.confirm_publish")
|
||||
= link_to image_tag("web-app-theme/icons/tick.png", :alt => t("layout.publish")) + " " + t("layout.publish"), publish_build_list_path(@build_list), :method => "put", :class => "button", :confirm => t("layout.confirm")
|
||||
|
||||
.block
|
||||
.content
|
||||
|
@ -111,4 +111,4 @@
|
|||
%td= item.version
|
||||
%td.last= item.human_status
|
||||
|
||||
- content_for :sidebar, render(:partial => 'sidebar')
|
||||
- content_for :sidebar, render('sidebar', :project => @build_list.project)
|
||||
|
|
|
@ -280,7 +280,6 @@ ru:
|
|||
build_lists:
|
||||
filter_header: Фильтр
|
||||
current: Текущие
|
||||
all: Все
|
||||
created_at_start: "Время постановки на сборку с:"
|
||||
created_at_end: "Время постановки на сборку по:"
|
||||
notified_at_start: "Время последнего обновления от BS с:"
|
||||
|
@ -291,11 +290,12 @@ ru:
|
|||
items_header: Элементы сборки
|
||||
no_items_data: Данных нет
|
||||
show: Просмотр
|
||||
confirm_publish: Вы уверены, что хотите опубликовать контейнер?
|
||||
cancel_button_header: Действие
|
||||
cancel_button: Отмена
|
||||
cancel_successed: 'Сборка отменена.'
|
||||
cancel_failed: 'При отмене сборки произошла ошибка!'
|
||||
cancel_success: 'Сборка отменена.'
|
||||
cancel_fail: 'При отмене сборки произошла ошибка!'
|
||||
publish_success: 'Сборка опубликована.'
|
||||
publish_fail: 'При публикации сборки произошла ошибка!'
|
||||
|
||||
build_server_status:
|
||||
header: Статус сборочного сервера
|
||||
|
|
|
@ -24,23 +24,16 @@ Rosa::Application.routes.draw do
|
|||
|
||||
match '/private/:platform_name/*file_path' => 'privates#show'
|
||||
|
||||
# match 'build_lists/' => 'build_lists#index', :as => :all_build_lists
|
||||
# match 'build_lists/:id/cancel/' => 'build_lists#cancel', :as => :build_list_cancel
|
||||
# match 'build_lists/status_build', :to => "build_lists#status_build"
|
||||
# match 'build_lists/post_build', :to => "build_lists#post_build"
|
||||
# match 'build_lists/pre_build', :to => "build_lists#pre_build"
|
||||
# match 'build_lists/circle_build', :to => "build_lists#circle_build"
|
||||
# match 'build_lists/new_bbdt', :to => "build_lists#new_bbdt"
|
||||
match 'build_lists/status_build', :to => "build_lists#status_build"
|
||||
match 'build_lists/post_build', :to => "build_lists#post_build"
|
||||
match 'build_lists/pre_build', :to => "build_lists#pre_build"
|
||||
match 'build_lists/circle_build', :to => "build_lists#circle_build"
|
||||
match 'build_lists/new_bbdt', :to => "build_lists#new_bbdt"
|
||||
|
||||
|
||||
resources :build_lists, :only => [:index, :cancel, :status_build, :post_build, :pre_build, :circle_build, :new_bbdt] do
|
||||
resources :build_lists, :only => [:index, :show] do
|
||||
member do
|
||||
get :cancel
|
||||
get :status_build
|
||||
get :post_build
|
||||
get :pre_build
|
||||
get :circle_build
|
||||
get :new_bbdt
|
||||
put :cancel
|
||||
put :publish
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -86,15 +79,7 @@ Rosa::Application.routes.draw do
|
|||
|
||||
resources :projects do
|
||||
resource :repo, :controller => "git/repositories", :only => [:show]
|
||||
resources :build_lists, :only => [:index, :show, :new, :create] do
|
||||
collection do
|
||||
get :recent
|
||||
post :filter
|
||||
end
|
||||
member do
|
||||
post :publish
|
||||
end
|
||||
end
|
||||
resources :build_lists, :only => [:index, :new, :create]
|
||||
|
||||
resources :collaborators, :only => [:index, :edit, :update, :add] do
|
||||
collection do
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
class AddUserIdToBuildLists < ActiveRecord::Migration
|
||||
def self.up
|
||||
add_column :build_lists, :user_id, :integer
|
||||
end
|
||||
|
||||
def self.down
|
||||
remove_column :build_lists, :user_id
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20111220152347) do
|
||||
ActiveRecord::Schema.define(:version => 20111221194422) do
|
||||
|
||||
create_table "arches", :force => true do |t|
|
||||
t.string "name", :null => false
|
||||
|
@ -70,6 +70,7 @@ ActiveRecord::Schema.define(:version => 20111220152347) do
|
|||
t.integer "bpl_id"
|
||||
t.integer "pl_id"
|
||||
t.text "include_repos"
|
||||
t.integer "user_id"
|
||||
end
|
||||
|
||||
add_index "build_lists", ["arch_id"], :name => "index_build_lists_on_arch_id"
|
||||
|
|
Loading…
Reference in New Issue