diff --git a/app/controllers/collaborators_controller.rb b/app/controllers/collaborators_controller.rb index ba9ecf53f..2c11b6172 100644 --- a/app/controllers/collaborators_controller.rb +++ b/app/controllers/collaborators_controller.rb @@ -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 diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index a624b423b..37b95ac33 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -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 diff --git a/app/controllers/platforms_controller.rb b/app/controllers/platforms_controller.rb index 6cd21c217..34b51eb83 100644 --- a/app/controllers/platforms_controller.rb +++ b/app/controllers/platforms_controller.rb @@ -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 diff --git a/app/models/build_list.rb b/app/models/build_list.rb index 863364f32..1cab5a9f8 100644 --- a/app/models/build_list.rb +++ b/app/models/build_list.rb @@ -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| diff --git a/app/models/download.rb b/app/models/download.rb index 3623ad8b3..6d0630bbf 100644 --- a/app/models/download.rb +++ b/app/models/download.rb @@ -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], diff --git a/app/models/platform.rb b/app/models/platform.rb index e54d85280..a7e214821 100644 --- a/app/models/platform.rb +++ b/app/models/platform.rb @@ -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') diff --git a/app/views/build_lists/_filter.html.haml b/app/views/build_lists/_filter.html.haml index 3b6994cfe..db92e055c 100644 --- a/app/views/build_lists/_filter.html.haml +++ b/app/views/build_lists/_filter.html.haml @@ -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" } diff --git a/app/views/collaborators/edit.html.haml b/app/views/collaborators/edit.html.haml index 1edcff67c..ff80e07aa 100644 --- a/app/views/collaborators/edit.html.haml +++ b/app/views/collaborators/edit.html.haml @@ -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' +   + = t('layout.or') +   + = 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 diff --git a/app/views/platforms/_form.html.haml b/app/views/platforms/_form.html.haml index 00b9e65a1..71e3ac2c5 100644 --- a/app/views/platforms/_form.html.haml +++ b/app/views/platforms/_form.html.haml @@ -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"} diff --git a/app/views/platforms/show.html.haml b/app/views/platforms/show.html.haml index 28acb9d7a..baf917e62 100644 --- a/app/views/platforms/show.html.haml +++ b/app/views/platforms/show.html.haml @@ -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 diff --git a/config/environments/development.rb b/config/environments/development.rb index c3cc4ae1e..6a687d647 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -25,3 +25,7 @@ Rosa::Application.configure do end require 'stub_xml_rpc' + +Rails.application.config.to_prepare { + Platform.send :include, Modules::Models::RsyncStub +} diff --git a/config/locales/ru.yml b/config/locales/ru.yml index a22921e1f..7fc2838ef 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -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: Список участников успешно изменен diff --git a/config/routes.rb b/config/routes.rb index 48b068631..5d22a7cfe 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/lib/modules/models/rsync_stub.rb b/lib/modules/models/rsync_stub.rb new file mode 100644 index 000000000..94c4153de --- /dev/null +++ b/lib/modules/models/rsync_stub.rb @@ -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 diff --git a/spec/controllers/build_lists_controller_spec.rb b/spec/controllers/build_lists_controller_spec.rb index ddc4e3ef3..5f64659d2 100644 --- a/spec/controllers/build_lists_controller_spec.rb +++ b/spec/controllers/build_lists_controller_spec.rb @@ -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 diff --git a/spec/controllers/collaborators_controller_spec.rb b/spec/controllers/collaborators_controller_spec.rb index 4fece56ed..653cae5b3 100644 --- a/spec/controllers/collaborators_controller_spec.rb +++ b/spec/controllers/collaborators_controller_spec.rb @@ -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 diff --git a/spec/controllers/members_controller_spec.rb b/spec/controllers/members_controller_spec.rb index 086c07702..651036b2d 100644 --- a/spec/controllers/members_controller_spec.rb +++ b/spec/controllers/members_controller_spec.rb @@ -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 diff --git a/spec/controllers/platforms_controller_spec.rb b/spec/controllers/platforms_controller_spec.rb index d00f5a65d..1351fed4d 100644 --- a/spec/controllers/platforms_controller_spec.rb +++ b/spec/controllers/platforms_controller_spec.rb @@ -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 diff --git a/spec/models/cancan_spec.rb b/spec/models/cancan_spec.rb index fa34d7845..97362bb66 100644 --- a/spec/models/cancan_spec.rb +++ b/spec/models/cancan_spec.rb @@ -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