[#74] Merge branch 'master' into 65-build_repo

Conflicts:
	app/controllers/build_lists_controller.rb
	app/controllers/projects_controller.rb
	db/schema.rb
This commit is contained in:
Pavel Chipiga 2011-12-21 20:13:57 +02:00
commit e588482f32
13 changed files with 215 additions and 85 deletions

View File

@ -3,46 +3,33 @@ class BuildListsController < ApplicationController
before_filter :authenticate_user!, :except => CALLBACK_ACTIONS before_filter :authenticate_user!, :except => CALLBACK_ACTIONS
before_filter :authenticate_build_service!, :only => CALLBACK_ACTIONS before_filter :authenticate_build_service!, :only => CALLBACK_ACTIONS
before_filter :find_project, :only => [:index, :filter, :show, :publish, :new, :create] before_filter :find_project, :only => [:filter, :show, :publish, :new, :create]
before_filter :find_arches, :only => [:index, :filter, :all] before_filter :find_arches, :only => [:index]
before_filter :find_project_versions, :only => [:index, :filter]
before_filter :find_build_list_by_bs, :only => [:status_build, :pre_build, :post_build] before_filter :find_build_list_by_bs, :only => [:status_build, :pre_build, :post_build]
# load_and_authorize_resource :project, :except => CALLBACK_ACTIONS load_and_authorize_resource :project, :only => :index
# load_and_authorize_resource :build_list, :through => :project, :shallow => true, :except => CALLBACK_ACTIONS load_and_authorize_resource :through => :project, :only => :index, :shallow => true
load_and_authorize_resource :except => CALLBACK_ACTIONS load_and_authorize_resource :except => CALLBACK_ACTIONS.concat([:index])
def all def index
if params[:filter] filter_params = params[:filter] || {}
@filter = BuildList::Filter.new(nil, params[:filter]) if params[:project_id]
@build_lists = @filter.find.paginate :page => params[:page] find_project
find_project_versions
@action_url = project_build_lists_path(@project)
else else
@filter = BuildList::Filter.new(nil) @project = nil
@build_lists = BuildList.recent.paginate :page => params[:page] @action_url = build_lists_path
end end
@action_url = all_build_lists_path
@filter = BuildList::Filter.new(@project, filter_params)
@build_lists = @filter.find.accessible_by(current_ability).recent.paginate :page => params[:page]
@build_server_status = begin @build_server_status = begin
BuildServer.get_status BuildServer.get_status
rescue Exception # Timeout::Error rescue Exception # Timeout::Error
{} {}
end end
render :action => 'index'
end
def index
@build_lists = @project.build_lists.recent.paginate :page => params[:page]
@filter = BuildList::Filter.new(@project)
@action_url = project_build_lists_path(@project)
end
def filter
@filter = BuildList::Filter.new(@project, params[:filter])
@build_lists = @filter.find.paginate :page => params[:page]
@action_url = project_build_lists_path(@project)
render :action => "index"
end end
def show def show

View File

@ -10,7 +10,7 @@ class PlatformsController < ApplicationController
def build_all def build_all
@platform.repositories.each do |repository| @platform.repositories.each do |repository|
repository.projects.each do |project| repository.projects.each do |project|
project.delay.build_for(@platform) project.delay.build_for(@platform, current_user)
end end
end end

View File

@ -45,9 +45,13 @@ class Ability
can :publish, BuildList do |build_list| 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_published? && build_list.project.relations.exists?(:object_type => 'User', :object_id => user.id)
end end
can :read, BuildList do |build_list| can [:index, :read], BuildList, ["build_lists.project_id IN (SELECT id FROM projects WHERE visibility = ?)", 'open'] do |build_list|
build_list.project.public? || build_list.project.relations.exists?(:object_type => 'User', :object_id => user.id) build_list.project.public?
end end
can [:index, :read], BuildList, build_lists_in_relations_with(:object_type => 'User', :object_id => user.id) do |build_list|
build_list.project.relations.exists?(:object_type => 'User', :object_id => user.id)
end
can [:read, :create], PrivateUser, :platform => {:owner_type => 'User', :owner_id => user.id} can [:read, :create], PrivateUser, :platform => {:owner_type => 'User', :owner_id => user.id}
# If rule has multiple conditions CanCan joins them by 'AND' sql operator # If rule has multiple conditions CanCan joins them by 'AND' sql operator
@ -104,8 +108,8 @@ class Ability
can :publish, BuildList do |build_list| 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_published? && build_list.project.relations.exists?(:object_type => 'Group', :object_id => user.group_ids)
end end
can :read, BuildList do |build_list| can [:index, :read], BuildList, build_lists_in_relations_with(:object_type => 'Group', :object_id => user.group_ids) do |build_list|
build_list.project.public? || build_list.project.relations.exists?(:object_type => 'Group', :object_id => user.group_ids) build_list.project.relations.exists?(:object_type => 'Group', :object_id => user.group_ids)
end end
can :manage_collaborators, Project, projects_in_relations_with(:role => 'admin', :object_type => 'Group', :object_id => user.group_ids) do |project| can :manage_collaborators, Project, projects_in_relations_with(:role => 'admin', :object_type => 'Group', :object_id => user.group_ids) do |project|
@ -162,6 +166,16 @@ class Ability
end end
end end
def build_lists_in_relations_with(opts)
query = "build_lists.project_id IN (SELECT target_id FROM relations WHERE relations.target_type = 'Project'"
opts.each do |key, value|
query = query + " AND relations.#{ key } #{ value.class == Array ? 'IN (?)' : '= ?' } "
end
query = query + ")"
return opts.values.unshift query
end
## Sub query for project relations ## Sub query for project relations
#def projects_in_relations_with(opts={}) #def projects_in_relations_with(opts={})
# ["projects.id IN (SELECT target_id FROM relations WHERE relations.object_id #{ opts[:object_id].class == Array ? 'IN (?)' : '= ?' } AND relations.object_type = '#{ opts[:object_type] }' AND relations.target_type = 'Platform') AND relations.role", opts[:object_id]] # ["projects.id IN (SELECT target_id FROM relations WHERE relations.object_id #{ opts[:object_id].class == Array ? 'IN (?)' : '= ?' } AND relations.object_type = '#{ opts[:object_type] }' AND relations.target_type = 'Platform') AND relations.role", opts[:object_id]]

View File

@ -3,6 +3,7 @@ class BuildList < ActiveRecord::Base
belongs_to :arch belongs_to :arch
belongs_to :pl, :class_name => 'Platform' belongs_to :pl, :class_name => 'Platform'
belongs_to :bpl, :class_name => 'Platform' belongs_to :bpl, :class_name => 'Platform'
belongs_to :user
has_many :items, :class_name => "BuildList::Item", :dependent => :destroy has_many :items, :class_name => "BuildList::Item", :dependent => :destroy
validates :project_id, :project_version, :arch, :include_repos, :presence => true validates :project_id, :project_version, :arch, :include_repos, :presence => true

View File

@ -48,7 +48,7 @@ class Project < ActiveRecord::Base
end end
end end
def build_for(platform) def build_for(platform, user)
build_lists.create do |bl| build_lists.create do |bl|
bl.pl = platform bl.pl = platform
bl.bpl = platform bl.bpl = platform
@ -56,6 +56,7 @@ class Project < ActiveRecord::Base
bl.arch = Arch.find_by_name('i586') bl.arch = Arch.find_by_name('i586')
bl.project_version = "latest_#{platform.name}" bl.project_version = "latest_#{platform.name}"
bl.build_requires = false # already set as db default bl.build_requires = false # already set as db default
bl.user = user
end end
end end

View File

@ -38,6 +38,9 @@ class User < ActiveRecord::Base
self.id.blank? # persisted? self.id.blank? # persisted?
end end
def fullname
return "#{uname} (#{name})"
end
class << self class << self
def find_for_database_authentication(warden_conditions) def find_for_database_authentication(warden_conditions)
conditions = warden_conditions.dup conditions = warden_conditions.dup

View File

@ -5,6 +5,7 @@
%th= t("activerecord.attributes.build_list.project_version") %th= t("activerecord.attributes.build_list.project_version")
%th= t("activerecord.attributes.build_list.project") %th= t("activerecord.attributes.build_list.project")
%th= t("activerecord.attributes.build_list.arch") %th= t("activerecord.attributes.build_list.arch")
%th= t("activerecord.attributes.build_list.user")
%th= t("activerecord.attributes.build_list.is_circle") %th= t("activerecord.attributes.build_list.is_circle")
- if controller.action_name = 'all' - if controller.action_name = 'all'
%th= t("layout.build_lists.cancel_button_header") %th= t("layout.build_lists.cancel_button_header")
@ -17,9 +18,10 @@
%td= link_to build_list.project_version, "#" %td= link_to build_list.project_version, "#"
%td= link_to build_list.project.name, project_path(build_list.project) %td= link_to build_list.project.name, project_path(build_list.project)
%td= build_list.arch.name %td= build_list.arch.name
%td= build_list.user.fullname
%td= t("layout.#{build_list.is_circle?}_") %td= t("layout.#{build_list.is_circle?}_")
- if controller.action_name = 'all' - if controller.action_name = 'all'
%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"), build_list_cancel_path(build_list) if build_list.can_cancel?
%td.last= build_list.notified_at %td.last= build_list.notified_at
= will_paginate build_lists = will_paginate build_lists

View File

@ -47,4 +47,4 @@
.group.navform.wat-cf .group.navform.wat-cf
%button.button{ :type => "submit" } %button.button{ :type => "submit" }
= image_tag("web-app-theme/icons/tick.png", :alt => "Save") = image_tag("web-app-theme/icons/tick.png", :alt => "Save")
= t("layout.search") = t("layout.search")

View File

@ -69,6 +69,11 @@
= t("activerecord.attributes.build_list.arch") = t("activerecord.attributes.build_list.arch")
\: \:
= @build_list.arch.name = @build_list.arch.name
%p
%b
= t("activerecord.attributes.build_list.user")
\:
= @build_list.user.fullname
%p %p
%b %b
= t("activerecord.attributes.build_list.notified_at") = t("activerecord.attributes.build_list.notified_at")

View File

@ -36,7 +36,7 @@
%a{:href => event_logs_path}= t("layout.menu.event_logs") %a{:href => event_logs_path}= t("layout.menu.event_logs")
-if can? :index, BuildList -if can? :index, BuildList
%li{:class => controller.controller_path == 'build_lists' ? 'active' : '' } %li{:class => controller.controller_path == 'build_lists' ? 'active' : '' }
%a{:href => all_build_lists_path}= t("layout.menu.build_lists") %a{:href => build_lists_path}= t("layout.menu.build_lists")
-if can? :platforms, Category -if can? :platforms, Category
%li{:class => controller.controller_path == 'categories' ? 'active' : '' } %li{:class => controller.controller_path == 'categories' ? 'active' : '' }
%a{:href => catalogs_path}= t("layout.menu.categories") %a{:href => catalogs_path}= t("layout.menu.categories")

View File

@ -599,6 +599,7 @@ ru:
update_type: Критичность обновления update_type: Критичность обновления
build_requires: Пересборка с зависимостями build_requires: Пересборка с зависимостями
project_version: Версия project_version: Версия
user: Пользователь
build_list/item: build_list/item:
name: Название name: Название

View File

@ -24,8 +24,25 @@ Rosa::Application.routes.draw do
match '/private/:platform_name/*file_path' => 'privates#show' match '/private/:platform_name/*file_path' => 'privates#show'
match 'build_lists/' => 'build_lists#all', :as => :all_build_lists # 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/: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"
resources :build_lists, :only => [:index, :cancel, :status_build, :post_build, :pre_build, :circle_build, :new_bbdt] do
member do
get :cancel
get :status_build
get :post_build
get :pre_build
get :circle_build
get :new_bbdt
end
end
resources :auto_build_lists, :only => [:index, :create, :destroy] resources :auto_build_lists, :only => [:index, :create, :destroy]
@ -131,12 +148,6 @@ Rosa::Application.routes.draw do
match '/catalogs', :to => 'categories#platforms', :as => :catalogs match '/catalogs', :to => 'categories#platforms', :as => :catalogs
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 'product_status', :to => 'product_build_lists#status_build' match 'product_status', :to => 'product_build_lists#status_build'
# Tree # Tree

View File

@ -7,6 +7,11 @@ describe BuildListsController do
get :show, @show_params get :show, @show_params
response.should be_success response.should be_success
end end
it 'should be able to perform index action in project scope' do
get :index, :project_id => @project.id
response.should be_success
end
end end
shared_examples_for 'not show build list' do shared_examples_for 'not show build list' do
@ -14,12 +19,17 @@ describe BuildListsController do
get :show, @show_params get :show, @show_params
response.should redirect_to(forbidden_url) response.should redirect_to(forbidden_url)
end end
it 'should not be able to perform index action in project scope' do
get :index, :project_id => @project.id
response.should redirect_to(forbidden_url)
end
end end
context 'crud' do context 'crud' do
context 'for guest' do context 'for guest' do
it 'should not be able to perform all action' do it 'should not be able to perform index action' do
get :all get :index
response.should redirect_to(new_user_session_path) response.should redirect_to(new_user_session_path)
end end
end end
@ -37,11 +47,31 @@ describe BuildListsController do
@user = Factory(:user) @user = Factory(:user)
set_session_for(@user) set_session_for(@user)
@show_params = {:project_id => @project.id, :id => @build_list.id} @show_params = {:project_id => @project.id, :id => @build_list.id}
end end
it 'should not be able to perform all action' do context 'for all build lists' do
get :all before(:each) do
response.should redirect_to(forbidden_url) @build_list1 = Factory(:build_list_core)
@build_list2 = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
@build_list3 = Factory(:build_list_core, :project => Factory(:project, :owner => @user, :visibility => 'hidden'))
b = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
b.project.relations.create :role => 'reader', :object_id => @user.id, :object_type => 'User'
@build_list4 = b
end
it 'should be able to perform index action' do
get :index
response.should be_success
end
it 'should show only accessible build_lists' do
get :index
assigns(:build_lists).should include(@build_list1)
assigns(:build_lists).should_not include(@build_list2)
assigns(:build_lists).should include(@build_list3)
assigns(:build_lists).should include(@build_list4)
end
end end
context 'for open project' do context 'for open project' do
@ -52,7 +82,7 @@ describe BuildListsController do
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
end end
context 'if user is project owner' do context 'if user is project member' do
before(:each) {set_session_for(@member_user)} before(:each) {set_session_for(@member_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
end end
@ -71,7 +101,89 @@ describe BuildListsController do
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
end end
context 'if user is project owner' do context 'if user is project member' do
before(:each) {set_session_for(@member_user)}
it_should_behave_like 'show build list'
end
end
end
context 'for group' do
before(:each) do
stub_rsync_methods
@owner_group = Factory(:group)
@owner_user = Factory(:user)
@owner_group.objects.create :role => 'reader', :object_id => @owner_user.id, :object_type => 'User'
@member_group = Factory(:group)
@member_user = Factory(:user)
@member_group.objects.create :role => 'reader', :object_id => @member_user.id, :object_type => 'User'
@group = Factory(:group)
@user = Factory(:user)
@group.objects.create :role => 'reader', :object_id => @user.id, :object_type => 'User'
@project = Factory(:project, :owner => @owner_group)
@project.relations.create :role => 'reader', :object_id => @member_group.id, :object_type => 'Group'
@build_list = Factory(:build_list_core, :project => @project)
set_session_for(@user)
@show_params = {:project_id => @project.id, :id => @build_list.id}
end
context 'for all build lists' do
before(:each) do
@build_list1 = Factory(:build_list_core)
@build_list2 = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
@build_list3 = Factory(:build_list_core, :project => Factory(:project, :owner => @group, :visibility => 'hidden'))
b = Factory(:build_list_core, :project => Factory(:project, :visibility => 'hidden'))
b.project.relations.create :role => 'reader', :object_id => @group.id, :object_type => 'Group'
@build_list4 = b
end
it 'should be able to perform index action' do
get :index
response.should be_success
end
it 'should show only accessible build_lists' do
get :index
assigns(:build_lists).should include(@build_list1)
assigns(:build_lists).should_not include(@build_list2)
assigns(:build_lists).should include(@build_list3)
assigns(:build_lists).should include(@build_list4)
end
end
context 'for open project' do
it_should_behave_like 'show build list'
context 'if user is group owner' do
before(:each) {set_session_for(@owner_user)}
it_should_behave_like 'show build list'
end
context 'if user is group member' do
before(:each) {set_session_for(@member_user)}
it_should_behave_like 'show build list'
end
end
context 'for hidden project' do
before(:each) do
@project.visibility = 'hidden'
@project.save
end
it_should_behave_like 'not show build list'
context 'if user is group owner' do
before(:each) {set_session_for(@owner_user)}
it_should_behave_like 'show build list'
end
context 'if user is group member' do
before(:each) {set_session_for(@member_user)} before(:each) {set_session_for(@member_user)}
it_should_behave_like 'show build list' it_should_behave_like 'show build list'
end end
@ -82,13 +194,13 @@ describe BuildListsController do
context 'for admin' do context 'for admin' do
before(:each) { set_session_for Factory(:admin) } before(:each) { set_session_for Factory(:admin) }
it "should be able to perform all action without exception" do it "should be able to perform index action without exception" do
any_instance_of(XMLRPC::Client) do |xml_rpc| any_instance_of(XMLRPC::Client) do |xml_rpc|
stub(xml_rpc).call do |args| stub(xml_rpc).call do |args|
raise Timeout::Error raise Timeout::Error
end end
end end
get :all get :index
assigns[:build_server_status].should == {} assigns[:build_server_status].should == {}
response.should be_success response.should be_success
end end
@ -100,46 +212,39 @@ describe BuildListsController do
before(:each) do before(:each) do
stub_rsync_methods stub_rsync_methods
set_session_for Factory(:admin) set_session_for Factory(:admin)
end
@build_list1 = Factory(:build_list_core)
let(:build_list1) { Factory(:build_list_core) } @build_list2 = Factory(:build_list_core)
let(:build_list2) { Factory(:build_list_core) } @build_list3 = Factory(:build_list_core)
let(:build_list3) { Factory(:build_list_core) } @build_list4 = Factory(:build_list_core, :created_at => (Time.now - 1.day),
let(:build_list4) do :project => @build_list3.project, :pl => @build_list3.pl,
b = Factory(:build_list_core) :arch => @build_list3.arch)
b.created_at = b.created_at - 1.day
b.project = build_list3.project
b.pl = build_list3.pl
b.arch = build_list3.arch
b.save
b
end end
before(:each) { set_session_for Factory(:admin); stub_rsync_methods; }
it 'should filter by bs_id' do it 'should filter by bs_id' do
get :all, :filter => {:bs_id => build_list1.bs_id, :project_name => 'fdsfdf', :any_other_field => 'do not matter'} get :index, :filter => {:bs_id => @build_list1.bs_id, :project_name => 'fdsfdf', :any_other_field => 'do not matter'}
assigns[:build_lists].should include(build_list1) assigns[:build_lists].should include(@build_list1)
assigns[:build_lists].should_not include(build_list2) assigns[:build_lists].should_not include(@build_list2)
assigns[:build_lists].should_not include(build_list3) assigns[:build_lists].should_not include(@build_list3)
end end
it 'should filter by project_name' do it 'should filter by project_name' do
# Project.where(:id => build_list2.project.id).update_all(:name => 'project_name') # Project.where(:id => build_list2.project.id).update_all(:name => 'project_name')
get :all, :filter => {:project_name => build_list2.project.name} get :index, :filter => {:project_name => @build_list2.project.name}
assigns[:build_lists].should_not include(build_list1) assigns[:build_lists].should_not include(@build_list1)
assigns[:build_lists].should include(build_list2) assigns[:build_lists].should include(@build_list2)
assigns[:build_lists].should_not include(build_list3) assigns[:build_lists].should_not include(@build_list3)
end end
it 'should filter by project_name and start_date' do it 'should filter by project_name and start_date' do
get :all, :filter => {:project_name => build_list3.project.name, get :index, :filter => {:project_name => @build_list3.project.name,
"created_at_start(1i)"=>build_list3.created_at.year.to_s, "created_at_start(1i)" => @build_list3.created_at.year.to_s,
"created_at_start(2i)"=>build_list3.created_at.month.to_s, "created_at_start(2i)" => @build_list3.created_at.month.to_s,
"created_at_start(3i)"=>build_list3.created_at.day.to_s} "created_at_start(3i)" => @build_list3.created_at.day.to_s}
assigns[:build_lists].should_not include(build_list1) assigns[:build_lists].should_not include(@build_list1)
assigns[:build_lists].should_not include(build_list2) assigns[:build_lists].should_not include(@build_list2)
assigns[:build_lists].should include(build_list3) assigns[:build_lists].should include(@build_list3)
assigns[:build_lists].should_not include(build_list4) assigns[:build_lists].should_not include(@build_list4)
# response.should be_success # response.should be_success
end end
end end