From fa8c0c78136c1a3bcff2bff042affcfee973c6e1 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 21 Jan 2012 18:06:14 +0200 Subject: [PATCH] Admin area: add multiple users to project --- app/controllers/admin/projects_controller.rb | 18 ++++++++++++ app/models/users_project.rb | 14 +++++++++ app/views/admin/projects/show.html.haml | 1 + app/views/admin/projects/team.html.haml | 30 ++++++++++++++++++++ config/routes.rb | 7 ++++- 5 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 app/views/admin/projects/team.html.haml diff --git a/app/controllers/admin/projects_controller.rb b/app/controllers/admin/projects_controller.rb index 21b25fc0..676a40ae 100644 --- a/app/controllers/admin/projects_controller.rb +++ b/app/controllers/admin/projects_controller.rb @@ -19,6 +19,24 @@ class Admin::ProjectsController < ApplicationController @admin_project = Project.find_by_code(params[:id]) end + def team + @admin_project = Project.find_by_code(params[:id]) + @users = User.not_in_project(@admin_project).all + end + + def team_update + @admin_project = Project.find_by_code(params[:id]) + + UsersProject.bulk_import( + @admin_project, + params[:user_ids], + params[:project_access], + params[:repo_access] + ) + + redirect_to [:admin, @admin_project], notice: 'Project was successfully updated.' + end + def create @admin_project = Project.new(params[:project]) @admin_project.owner = current_user diff --git a/app/models/users_project.rb b/app/models/users_project.rb index 6fd067c3..b98aa1fd 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -13,6 +13,20 @@ class UsersProject < ActiveRecord::Base delegate :name, :email, :to => :user, :prefix => true + def self.bulk_import(project, user_ids, project_access, repo_access) + UsersProject.transaction do + user_ids.each do |user_id| + users_project = UsersProject.new( + :repo_access => repo_access, + :project_access => project_access, + :user_id => user_id + ) + users_project.project = project + users_project.save + end + end + end + def update_repository Gitlabhq::GitHost.system.new.configure do |c| c.update_project(project.path, project) diff --git a/app/views/admin/projects/show.html.haml b/app/views/admin/projects/show.html.haml index cd7a3a81..74cfbb7d 100644 --- a/app/views/admin/projects/show.html.haml +++ b/app/views/admin/projects/show.html.haml @@ -57,3 +57,4 @@ %td= link_to 'Destroy', admin_team_member_path(tm), :confirm => 'Are you sure?', :method => :delete = link_to 'New Team Member', new_admin_team_member_path(:team_member => {:project_id => @admin_project.id}), :class => "grey-button" + .right= link_to 'Bulk Import', team_admin_project_path(@admin_project), :class => "grey-button" diff --git a/app/views/admin/projects/team.html.haml b/app/views/admin/projects/team.html.haml new file mode 100644 index 00000000..c032d580 --- /dev/null +++ b/app/views/admin/projects/team.html.haml @@ -0,0 +1,30 @@ += form_tag team_update_admin_project_path(@admin_project), :class => "bulk_import", :method => :put do + .span-6 + %b Project Access: + .span-6 + = select_tag :project_access, options_for_select(Project.access_options), :class => "project-access-select" + + .span-6 + %b Repository Access: + .span-6 + = select_tag :repo_access, options_for_select(Repository.access_options), :class => "repo-access-select" + + %br + = select_tag :user_ids, options_from_collection_for_select(@users , :id, :name), :multiple => true + + %br + .clear + %br + .actions + = submit_tag 'Save', :class => "grey-button" + +:css + form select { + width:300px; + } + + +:javascript + $('select#user_ids').chosen(); + $('select#repo_access').chosen(); + $('select#project_access').chosen(); diff --git a/config/routes.rb b/config/routes.rb index 4f0e6fcb..b8149f8f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -10,7 +10,12 @@ Gitlab::Application.routes.draw do namespace :admin do resources :users - resources :projects, :constraints => { :id => /[^\/]+/ } + resources :projects, :constraints => { :id => /[^\/]+/ } do + member do + get :team + put :team_update + end + end resources :team_members get 'emails', :to => 'mailer#preview' get 'mailer/preview_note'