From 168e110169b55c9245fc8e924d23a270dab0978a Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Sat, 10 Dec 2011 03:40:13 +0400 Subject: [PATCH 1/4] [close #11] Changed adding members to group. --- Gemfile | 6 ++++-- app/controllers/members_controller.rb | 15 ++++++++++++++- app/controllers/users_controller.rb | 1 + app/views/members/edit.html.haml | 14 +++++++++++++- config/locales/ru.yml | 4 ++++ config/routes.rb | 10 +++++++--- spec/controllers/members_controller_spec.rb | 18 ++++++++++++++++++ 7 files changed, 61 insertions(+), 7 deletions(-) diff --git a/Gemfile b/Gemfile index 7beb52395..76b9022e5 100644 --- a/Gemfile +++ b/Gemfile @@ -2,8 +2,10 @@ source 'http://rubygems.org' gem 'rails', '3.0.11' #, :git => 'git://github.com/rails/rails.git' -gem 'pg', '~> 0.11.0' -gem 'silent-postgres', '~> 0.1.1' +group :production do + gem 'pg', '~> 0.11.0' + gem 'silent-postgres', '~> 0.1.1' +end gem 'devise', '~> 1.5.2' gem 'omniauth', '~> 1.0.1' diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 2a4fbdf3e..870d4a56b 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -67,10 +67,23 @@ class MembersController < ApplicationController def destroy end + def add + if params['user_id'] and !params['user_id'].empty? + @user = User.find_by_uname(params['user_id']) + relation = parent.objects.build(:object_id => @user.id, :object_type => 'User', :role => 'reader') + if relation.save + flash[:notice] = t("flash.members.successfully_added") + else + flash[:error] = t("flash.members.error_in_adding") + end + end + redirect_to edit_group_members_path(parent) + end + protected def find_users - @users = User.all + @users = parent.members #User.all end end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index bd2d52e4b..8a33c413a 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -4,6 +4,7 @@ class UsersController < ApplicationController before_filter :find_user, :only => [:show, :edit, :update, :destroy] load_and_authorize_resource + autocomplete :user, :uname def index @users = User.paginate(:page => params[:user_page]) diff --git a/app/views/members/edit.html.haml b/app/views/members/edit.html.haml index 8ea7bfaa6..719ccb8ad 100644 --- a/app/views/members/edit.html.haml +++ b/app/views/members/edit.html.haml @@ -22,7 +22,7 @@ = link_to user.name, user_path(user) %td - Relation::ROLES.each do |role| - = check_box_tag "#{ role }[#{user.id}]", '1', ((parent.relations.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), {:class => "user_role_chbx"} + = check_box_tag "#{ role }[#{user.id}]", '1', ((parent.objects.exists? :object_id => user.id, :object_type => 'User', :role => role) ? :checked : nil), {:class => "user_role_chbx"} = label_tag "#{ role }[#{user.id}]", t("layout.members.roles.#{ role }") %td = user.uname @@ -33,3 +33,15 @@ %span.text_button_padding= t("layout.or") = link_to t("layout.cancel"), group_path(parent), :class => "text_button_padding link_button" + = form_tag add_group_members_path(parent) do + = javascript_include_tag 'autocomplete-rails.js' + .group + %h2.title= t("layout.members.add_member") + = label_tag "", t("layout.members.input_username") + = autocomplete_field_tag 'user_id', params[:user_id], autocomplete_user_uname_users_path + %br + .group.navform.wat-cf + %button.button{:type => "submit"} + = image_tag("web-app-theme/icons/tick.png", :alt => t("layout.add")) + = t("layout.add") + diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 943cfb82a..74982de09 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -227,6 +227,8 @@ ru: back_to_group: Вернуться к группе edit: Редактировать список roles: Роли + add_member: Добавить участника + input_username: Псевдоним пользователя groups: list: Список @@ -331,6 +333,8 @@ ru: members: successfully_changed: Список участников успешно изменен error_in_changing: Ошибка изменения списка участников + successfully_added: Участник успешно добавлен + error_in_adding: Ошибка при добавлении участника auto_build_list: success: Сборка проекта автоматизорована! diff --git a/config/routes.rb b/config/routes.rb index d6d9ed2b6..48b068631 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -8,6 +8,9 @@ Rosa::Application.routes.draw do resources :users do resources :groups, :only => [:new, :create, :index] + collection do + get :autocomplete_user_uname + end end resources :event_logs, :only => :index @@ -25,7 +28,7 @@ Rosa::Application.routes.draw do match 'build_lists/' => 'build_lists#all', :as => :all_build_lists match 'build_lists/:id/cancel/' => 'build_lists#cancel', :as => :build_list_cancel - + resources :auto_build_lists, :only => [:index, :create, :destroy] resources :personal_repositories, :only => [:show] do @@ -108,9 +111,10 @@ Rosa::Application.routes.draw do end resources :groups do - resources :members, :only => [:index, :edit, :update] do + resources :members, :only => [:index, :edit, :update, :add] do collection do - get :edit + get :edit + post :add post :update end member do diff --git a/spec/controllers/members_controller_spec.rb b/spec/controllers/members_controller_spec.rb index 3b886638e..086c07702 100644 --- a/spec/controllers/members_controller_spec.rb +++ b/spec/controllers/members_controller_spec.rb @@ -1,5 +1,23 @@ require 'spec_helper' describe MembersController do + before(:each) do + @group = Factory(:group) + @user = @group.owner + @another_user = Factory(:user) + @add_params = {:group_id => @group.id, :user_id => @another_user.uname} + end + context 'for owner user' do + it 'should add member to group' do + post :add, @add_params + response.should redirect_to(:edit) + 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') + end + end end From d2831da4b8303fb9dbaff1ed420c4b1a4d532f60 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Sat, 10 Dec 2011 21:26:57 +0400 Subject: [PATCH 2/4] Issue #11 updated. Added check if user already added. --- app/controllers/members_controller.rb | 12 ++++++++---- config/locales/ru.yml | 1 + 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 870d4a56b..e139e2234 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -70,11 +70,15 @@ class MembersController < ApplicationController def add if params['user_id'] and !params['user_id'].empty? @user = User.find_by_uname(params['user_id']) - relation = parent.objects.build(:object_id => @user.id, :object_type => 'User', :role => 'reader') - if relation.save - flash[:notice] = t("flash.members.successfully_added") + unless parent.objects.exists? :object_id => @user.id, :object_type => 'User' + relation = parent.objects.build(:object_id => @user.id, :object_type => 'User', :role => 'reader') + if relation.save + flash[:notice] = t("flash.members.successfully_added") + else + flash[:error] = t("flash.members.error_in_adding") + end else - flash[:error] = t("flash.members.error_in_adding") + flash[:error] = t("flash.members.already_added") end end redirect_to edit_group_members_path(parent) diff --git a/config/locales/ru.yml b/config/locales/ru.yml index 74982de09..3c5836f05 100644 --- a/config/locales/ru.yml +++ b/config/locales/ru.yml @@ -335,6 +335,7 @@ ru: error_in_changing: Ошибка изменения списка участников successfully_added: Участник успешно добавлен error_in_adding: Ошибка при добавлении участника + already_added: Пользователь уже добавлен auto_build_list: success: Сборка проекта автоматизорована! From 4d76d8ad904c0e1dc1317ad957b82640e6548406 Mon Sep 17 00:00:00 2001 From: George Vinogradov Date: Sun, 11 Dec 2011 13:36:04 +0400 Subject: [PATCH 3/4] [updated #11] Changed Gemfile, because it was changed mistakely. --- Gemfile | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/Gemfile b/Gemfile index 76b9022e5..7beb52395 100644 --- a/Gemfile +++ b/Gemfile @@ -2,10 +2,8 @@ source 'http://rubygems.org' gem 'rails', '3.0.11' #, :git => 'git://github.com/rails/rails.git' -group :production do - gem 'pg', '~> 0.11.0' - gem 'silent-postgres', '~> 0.1.1' -end +gem 'pg', '~> 0.11.0' +gem 'silent-postgres', '~> 0.1.1' gem 'devise', '~> 1.5.2' gem 'omniauth', '~> 1.0.1' From 572a7b1e9cb3df405ab80015559a12f2655e8e5d Mon Sep 17 00:00:00 2001 From: Pavel Chipiga Date: Tue, 13 Dec 2011 15:09:24 +0200 Subject: [PATCH 4/4] Redo import script. Refs #1 --- lib/tasks/import.rake | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/lib/tasks/import.rake b/lib/tasks/import.rake index 1c2912892..1c24e8e1e 100644 --- a/lib/tasks/import.rake +++ b/lib/tasks/import.rake @@ -1,17 +1,26 @@ +require 'highline/import' require 'open-uri' namespace :import do desc "Load projects" task :projects => :environment do + owner = User.find_by_uname(ENV['OWNER_UNAME']) || Group.find_by_uname(ENV['OWNER_UNAME']) || User.first + platform = Platform.find_by_name(ENV['PLATFORM_NAME']) # 'mandriva2011' + repo = platform.repositories.first rescue nil + say "START import projects for '#{owner.uname}'.#{repo ? " To repo '#{platform.name}/#{repo.name}'." : ''}" + ask 'Press enter to continue' open('http://dl.dropbox.com/u/984976/package_list.txt').readlines.each do |name| name.chomp!; name.strip! #; name.downcase! # name = name.match(/^([a-z\d_\-\+\.]+?)-(\d[a-z\d\-\.]+)\.src\.rpm$/)[1] # parse - print "Import #{name}..." - owner = User.find(1) # I am - # owner = Group.find(1) # Core Team - p = Project.find_or_create_by_name(name) {|p| p.owner = owner} - puts p.persisted? ? "Ok!" : "Fail!" + print "Import '#{name}'..." + p = Project.find_or_create_by_name_and_owner_type_and_owner_id(name, owner.class.to_s, owner.id) + print p.persisted? ? "Ok!" : "Fail!" + if repo + print " Add to repo '#{platform.name}/#{repo.name}'." + repo.projects << p rescue print ' Fail!' + end + puts end - puts 'DONE' + say 'DONE' end end