Merge branch 'master' into 1-bluepill

Conflicts:
	app/controllers/platforms_controller.rb
	app/models/platform.rb
This commit is contained in:
Pavel Chipiga 2011-12-14 23:51:31 +02:00
commit f1465f51ca
19 changed files with 211 additions and 48 deletions

View File

@ -30,7 +30,6 @@ class CollaboratorsController < ApplicationController
def update
all_user_ids = []
all_groups_ids = []
puts params.inspect
Relation::ROLES.each { |r|
all_user_ids = all_user_ids | params['user'][r.to_sym].keys if params['user'] && params['user'][r.to_sym]
all_groups_ids = all_groups_ids | params['group'][r.to_sym].keys if params['group'] && params['group'][r.to_sym]
@ -82,6 +81,41 @@ class CollaboratorsController < ApplicationController
def destroy
end
def add
# TODO: Here is used Chelyabinsk method to display Flash messages.
member = User.find(params['member_id']) if params['member_id'] && !params['member_id'].empty?
group = Group.find(params['group_id']) if params['group_id'] && !params['group_id'].empty?
flash[:notice], flash[:error], flash[:warning] = [], [], []
[member, group].compact.each do |mem|
if mem and @project.relations.exists?(:object_id => mem.id, :object_type => mem.class.to_s)
flash[:warning] << [t('flash.collaborators.member_already_added'), mem.uname]
end
unless @project.relations.exists?(:object_id => mem.id, :object_type => mem.class.to_s)
rel = @project.relations.build(:role => 'reader')
rel.object = mem
if rel.save
flash[:notice] << [t('flash.collaborators.successfully_added'), mem.uname]
else
flash[:notice] << [t('flash.collaborators.error_in_adding'), mem.uname]
end
end
end
[:notice, :warning, :error].each do |k|
if flash[k].size > 0
flash[k] = flash[k].map{|i| (i.is_a? Array) ? sprintf(i.first, i.last) : i}.join('; ')
else
flash[k] = nil
end
end
flash.delete_if{|k, v| v.nil?}
redirect_to(edit_project_collaborators_path(@project))
end
protected
def find_project
@ -89,10 +123,10 @@ class CollaboratorsController < ApplicationController
end
def find_users
@users = User.all
@users = @project.collaborators#User.all
end
def find_groups
@groups = Group.all
@groups = @project.groups#Group.all
end
end

View File

@ -8,6 +8,7 @@ class GroupsController < ApplicationController
before_filter :find_group, :only => [:show, :edit, :update, :destroy]
load_and_authorize_resource
autocomplete :group, :uname
def index
puts parent.inspect

View File

@ -45,15 +45,20 @@ class PlatformsController < ApplicationController
def new
@platform = Platform.new
@admin_uname = current_user.uname
@admin_id = current_user.id
end
def edit
@admin_id = @platform.owner.id
@admin_uname = @platform.owner.uname
end
def create
@platform = Platform.new params[:platform]
@platform.owner = (params[:admin_uname]) ? User.find_by_uname(params[:admin_uname]) : nil
@platform.owner ||= get_owner
@admin_id = params[:admin_id]
@admin_uname = params[:admin_uname]
@platform.owner = @admin_id.blank? ? get_owner : User.find(@admin_id)
if @platform.save
flash[:notice] = I18n.t("flash.platform.saved")
@ -64,6 +69,27 @@ class PlatformsController < ApplicationController
end
end
def update
@admin_id = params[:admin_id]
@admin_uname = params[:admin_uname]
#@platform.owner = @admin_id.blank? ? get_owner : User.find(@admin_id)
#if @platform.save!
if @platform.update_attributes(
:owner => @admin_id.blank? ? get_owner : User.find(@admin_id),
:description => params[:platform][:description],
:released => params[:platform][:released]
)
#@platform.make_admin_relation(@admin_id)
>>>>>>> master
flash[:notice] = I18n.t("flash.platform.saved")
redirect_to @platform
else
flash[:error] = I18n.t("flash.platform.saved_error")
render :action => :new
end
end
def freeze
@platform.released = true
if @platform.save

View File

@ -52,7 +52,7 @@ class BuildList < ActiveRecord::Base
BuildServer::BINARY_TEST_FAILED => :binary_test_failed
}
scope :recent, order("updated_at DESC")
scope :recent, order("#{table_name}.updated_at DESC")
scope :current, lambda {
outdatable_statuses = [BuildServer::SUCCESS, BuildServer::ERROR, BuildServer::PLATFORM_NOT_FOUND, BuildServer::PLATFORM_PENDING, BuildServer::PROJECT_NOT_FOUND, BuildServer::PROJECT_VERSION_NOT_FOUND]
where(["status in (?) OR (status in (?) AND notified_at >= ?)", [WAITING_FOR_RESPONSE, BUILD_PENDING, BuildServer::BUILD_STARTED], outdatable_statuses, Time.now - 2.days])
@ -63,11 +63,11 @@ class BuildList < ActiveRecord::Base
scope :scoped_to_is_circle, lambda {|is_circle| where(:is_circle => is_circle) }
scope :for_creation_date_period, lambda{|start_date, end_date|
if start_date && end_date
where(["created_at BETWEEN ? AND ?", start_date, end_date])
where(["#{table_name}.created_at BETWEEN ? AND ?", start_date, end_date])
elsif start_date && !end_date
where(["created_at >= ?", start_date])
where(["#{table_name}.created_at >= ?", start_date])
elsif !start_date && end_date
where(["created_at <= ?", end_date])
where(["#{table_name}.created_at <= ?", end_date])
end
}
scope :for_notified_date_period, lambda{|start_date, end_date|

View File

@ -12,7 +12,7 @@ class Download < ActiveRecord::Base
def parse_nginx_log
File.open(PREV_LOG_FILE) do |log|
while (line = log.gets)
if package = line.match( /GET \/.+\/([\w\d]+)-([\d.]+)-((\d+mdv[\d.]+)|([\d\w]+-mdv[\d.]+))\.([\w\d]+)\.rpm/ )
if package = line.match( /GET \/.+\/([\w\d-]+)-([\d.]+)-((\d+mdv[\d.]+)|([\d\w]+-mdv[\d.]+))\.([\w\d]+)\.rpm/ )
increase(
:name => package[1],
:version => package[2],

View File

@ -14,7 +14,9 @@ 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_]+$/ }
if !Rails.env.development?
validates :name, :uniqueness => true, :presence => true, :format => { :with => /^[a-zA-Z0-9_]+$/ }
end
validates :distrib_type, :presence => true, :inclusion => {:in => APP_CONFIG['distr_types']}
before_create :xml_rpc_create, :unless => lambda {Thread.current[:skip]}
@ -22,6 +24,7 @@ class Platform < ActiveRecord::Base
# before_update :check_freezing
after_create lambda { mount_directory_for_rsync unless hidden? }
after_destroy lambda { umount_directory_for_rsync unless hidden? }
after_update :update_owner_relation
scope :by_visibilities, lambda {|v| {:conditions => ['visibility in (?)', v.join(',')]}}
scope :open, where(:visibility => 'open')

View File

@ -21,28 +21,28 @@
.columns.wat-cf
.column.left
.group
= f.label :status, t("layout.build_lists.created_at_start"), :class => :label
= f.label :created_at_start, t("layout.build_lists.created_at_start"), :class => :label
= f.date_select(:created_at_start, :include_blank => true, :selected => @filter.created_at_start)
.group
= f.label :status, t("layout.build_lists.notified_at_start"), :class => :label
= f.label :notified_at_start, t("layout.build_lists.notified_at_start"), :class => :label
= f.date_select(:notified_at_start, :include_blank => true, :selected => @filter.notified_at_start)
.column.right
.group
= f.label :status, t("layout.build_lists.created_at_end"), :class => :label
= f.label :created_at_end, t("layout.build_lists.created_at_end"), :class => :label
= f.date_select(:created_at_end, :include_blank => true, :selected => @filter.created_at_end)
.group
= f.label :status, t("layout.build_lists.notified_at_end"), :class => :label
= f.label :notified_at_end, t("layout.build_lists.notified_at_end"), :class => :label
= f.date_select(:notified_at_end, :include_blank => true, :selected => @filter.notified_at_end)
.columns.wat-cf
.column.left
.group
= f.label :status, t("layout.build_lists.bs_id_search"), :class => :label
= f.text_field :bs_id, :class => :text_field
= f.label :project_name, t("layout.build_lists.project_name_search"), :class => :label
= f.text_field :project_name, :class => :text_field
.column.right
.group
= f.label :status, t("layout.build_lists.project_name"), :class => :label
= f.text_field :project_name, :class => :text_field
= f.label :bs_id, t("layout.build_lists.bs_id_search"), :class => :label
= f.text_field :bs_id, :class => :text_field
.group.navform.wat-cf
%button.button{ :type => "submit" }

View File

@ -5,6 +5,26 @@
%li.active= link_to t("layout.collaborators.edit"), edit_project_collaborators_path(@project)
.content
.inner
= form_tag add_project_collaborators_path(@project) do
= javascript_include_tag 'autocomplete-rails.js'
.group
%h2.title= t("layout.collaborators.add")
= label_tag "member_uname", t("layout.collaborators.input_username")
= autocomplete_field_tag 'member_id', params[:member_id], autocomplete_user_uname_users_path, :id_element => '#member_id_field'
&nbsp;
= t('layout.or')
&nbsp;
= label_tag "group_uname", t("layout.collaborators.input_groupname")
= autocomplete_field_tag 'group_id', params[:group_id], autocomplete_group_uname_groups_path, :id_element => '#group_id_field'
= hidden_field_tag 'member_id', nil, :id => 'member_id_field'
= hidden_field_tag 'group_id', nil, :id => 'group_id_field'
%br
.group.navform.wat-cf
%button.button{:type => "submit"}
= image_tag("web-app-theme/icons/tick.png", :alt => t("layout.add"))
= t("layout.add")
= form_tag project_collaborators_path(@project) do
%h2.title= t("layout.users.list_header")
%table.table
@ -31,8 +51,8 @@
%tr
%th.first ID
%th= t("activerecord.attributes.group.name")
%th= t("activerecord.attributes.group.roles")
%th= t("activerecord.attributes.group.uname")
%th.last= t("layout.collaborators.add")
- @groups.each do |group|
%tr{:class => cycle("odd", "even")}
%td

View File

@ -1,29 +1,31 @@
= javascript_include_tag "autocomplete-rails.js"
.group
= f.label :name, :class => :label
= f.text_field :name, :class => 'text_field'
- unless ['edit', 'update'].include? controller.action_name
.group
= f.label :name, :class => :label
= f.text_field :name, :class => 'text_field'
.group
= f.label :description, :class => :label
= f.text_field :description, :class => 'text_field'
.group
= f.label :distrib_type, :class => :label
= f.select :distrib_type, options_for_select(APP_CONFIG['distr_types'])
- unless ['edit', 'update'].include? controller.action_name
.group
= f.label :distrib_type, :class => :label
= f.select :distrib_type, options_for_select(APP_CONFIG['distr_types'])
.group
= f.label :parent, :class => :label
= f.collection_select :parent_platform_id, Platform.all, :id, :description, :include_blank => true
.group
= f.label :parent, :class => :label
= f.collection_select :parent_platform_id, Platform.all, :id, :description, :include_blank => true
.group
= f.label :released, :class => :label
= f.check_box :released, :class => 'check_box'
.group
= label_tag "admin_uname", t("layout.platforms.admin_uname"), :class => :label
= autocomplete_field_tag 'admin_uname', params[:admin_uname], autocomplete_user_uname_platforms_path
=# text_field_tag 'admin_id', '', :id => 'admin_id_field'
= label_tag "", t("layout.platforms.admin_id"), :class => :label
= autocomplete_field_tag 'admin_id', @admin_uname, autocomplete_user_uname_platforms_path, :id_element => '#admin_id_field'
= hidden_field_tag 'admin_id', @admin_id, :id => 'admin_id_field'
.group.navform.wat-cf
%button.button{:type => "submit"}

View File

@ -64,6 +64,7 @@
= link_to t("layout.platforms.freeze"), freeze_platform_path(@platform), :confirm => I18n.t("layout.platforms.confirm_freeze"), :method => :post, :class => "button" if can? :freeze, @platform
= link_to "Клонировать", clone_platform_path(@platform), :class => "button" if can? :clone, @platform
= link_to t("layout.platforms.build_all"), build_all_platform_path(@platform), :confirm => I18n.t("layout.confirm"), :method => :post, :class => "button" if can? :build_all, @platform
= link_to t("layout.platforms.edit"), edit_platform_path(@platform), :class => "button" if can? :edit, @platform
%a{ :name => "repositories" }
.block

View File

@ -25,3 +25,7 @@ Rosa::Application.configure do
end
require 'stub_xml_rpc'
Rails.application.config.to_prepare {
Platform.send :include, Modules::Models::RsyncStub
}

View File

@ -94,10 +94,11 @@ ru:
confirm_delete: Вы уверены, что хотите удалить эту категорию?
platforms:
admin_uname: Владелец
admin_id: Владелец
build_all: Собрать все
list: Список
new: Создать
edit: Редактировать
new_header: Новая платформа
edit_header: Редактировать
list_header: Платформы
@ -222,6 +223,8 @@ ru:
edit_roles: Редактировать роли
roles_header: Роли для
add_role: Добавить/Удалить роль
input_username: Введите псевдоним пользователя
input_groupname: Введите псевдоним группы
members:
back_to_group: Вернуться к группе
@ -282,7 +285,7 @@ ru:
notified_at_start: "Время последнего обновления от BS с:"
notified_at_end: "Время последнего обновления от BS по:"
bs_id_search: 'Поиск по Id'
project_name: 'Название проекта'
project_name_search: Поиск по названию проекта
bs_id_not_set: Id еще не присвоен
items_header: Элементы сборки
no_items_data: Данных нет
@ -332,6 +335,10 @@ ru:
collaborators:
successfully_changed: Список коллабораторов успешно изменен
error_in_changing: Ошибка изменения списка коллабораторов
member_already_added: Участник %s уже добавлен
group_already_added: Группа уже добавлена
successfully_added: Участник %s успешно добавлен
error_in_adding: Ошибка при добавлении участника %s
members:
successfully_changed: Список участников успешно изменен

View File

@ -8,9 +8,7 @@ Rosa::Application.routes.draw do
resources :users do
resources :groups, :only => [:new, :create, :index]
collection do
get :autocomplete_user_uname
end
get :autocomplete_user_uname, :on => :collection
end
resources :event_logs, :only => :index
@ -81,10 +79,11 @@ Rosa::Application.routes.draw do
end
end
resources :collaborators, :only => [:index, :edit, :update] do
resources :collaborators, :only => [:index, :edit, :update, :add] do
collection do
get :edit
post :update
post :add
end
member do
post :update
@ -111,6 +110,7 @@ Rosa::Application.routes.draw do
end
resources :groups do
get :autocomplete_group_uname, :on => :collection
resources :members, :only => [:index, :edit, :update, :add] do
collection do
get :edit

View File

@ -0,0 +1,23 @@
module Modules
module Models
module RsyncStub
extend ActiveSupport::Concern
included do
def mount_directory_for_rsync
true
end
def umount_directory_for_rsync
true
end
end
module InstanceMethods
end
module ClassMethods
end
end
end
end

View File

@ -44,7 +44,16 @@ describe BuildListsController do
let(:build_list1) { Factory(:build_list_core) }
let(:build_list2) { Factory(:build_list_core) }
let(:build_list3) { Factory(:build_list_core) }
let(:build_list4) do
b = Factory(:build_list_core)
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
before(:each) { set_session_for Factory(:admin); stub_rsync_methods; }
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'}
@ -60,6 +69,18 @@ describe BuildListsController do
assigns[:build_lists].should include(build_list2)
assigns[:build_lists].should_not include(build_list3)
end
it 'should filter by project_name and start_date' do
get :all, :filter => {:project_name => build_list3.project.name,
"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(3i)"=>build_list3.created_at.day.to_s}
assigns[:build_lists].should_not include(build_list1)
assigns[:build_lists].should_not include(build_list2)
assigns[:build_lists].should include(build_list3)
assigns[:build_lists].should_not include(build_list4)
# response.should be_success
end
end
context 'callbacks' do

View File

@ -36,12 +36,30 @@ describe CollaboratorsController do
@user = Factory(:user)
@user.relations
set_session_for(@user)
@group = Factory(:group)
@project.relations.create!(:object_type => 'User', :object_id => @user.id, :role => 'reader')
end
it_should_behave_like 'show collaborators list'
it_should_behave_like 'update collaborators'
it_should_behave_like 'update collaborator relation'
it 'should add new collaborator with reader role' do
@params = {:member_id => @another_user.id.to_s, :project_id => @project.id.to_s}
post :add, @params
@project.relations.exists?(:object_type => 'User', :object_id => @another_user.id, :role => 'reader').should be_true
end
it 'should add new group with reader role' do
@params = {:group_id => @group.id.to_s, :project_id => @project.id.to_s}
post :add, @params
@project.relations.exists?(:object_type => 'Group', :object_id => @group.id, :role => 'reader').should be_true
end
it_should_behave_like 'show collaborators list'
it_should_behave_like 'update collaborators'
it_should_behave_like 'update collaborator relation'
end
context 'for owner user' do

View File

@ -4,6 +4,7 @@ describe MembersController do
before(:each) do
@group = Factory(:group)
@user = @group.owner
set_session_for @user
@another_user = Factory(:user)
@add_params = {:group_id => @group.id, :user_id => @another_user.uname}
end
@ -11,13 +12,13 @@ describe MembersController do
context 'for owner user' do
it 'should add member to group' do
post :add, @add_params
response.should redirect_to(:edit)
response.should redirect_to(edit_group_members_path(@group))
Relation.by_target(@group).by_object(@another_user).count.should eql(1)
end
it 'should add reader member to group' do
post :add, @add_params
Relation.by_target(@group).by_object(@another_user).role.should eql('reader')
Relation.by_target(@group).by_object(@another_user).first.role.should eql('reader')
end
end
end

View File

@ -64,13 +64,15 @@ describe PlatformsController do
it_should_behave_like 'change_objects_count_on_destroy_success'
it_should_behave_like 'not_be_able_to_destroy_personal_platform'
context 'when owner uname present' do
it 'should create platform with mentioned owner' do
post :create, @create_params.merge({:admin_uname => @user.uname})
Platform.last.owner.id.should eql(@user.id)
end
it 'should create platform with mentioned owner if owner id present' do
post :create, @create_params.merge({:admin_id => @user.id})
Platform.last.owner.id.should eql(@user.id)
end
it 'should create platform with current user as owner if owner id not present' do
post :create, @create_params
Platform.last.owner.id.should eql(@admin.id)
end
end

View File

@ -213,7 +213,7 @@ describe CanCan do
end
[:manage, :add_project, :remove_project, :change_visibility, :settings].each do |action|
it 'should be able to #{ action } repository' do
it "should be able to #{ action } repository" do
@ability.should be_able_to(action, @repository)
end
end