Commit fd0aca122545bf7e4911f45aaff7bcd960accc7b
1 parent
012d62b1
Exists in
master
and in
4 other branches
Feature implemented
Showing
5 changed files
with
58 additions
and
3 deletions
Show diff stats
app/controllers/team_members_controller.rb
| ... | ... | @@ -43,4 +43,12 @@ class TeamMembersController < ProjectResourceController |
| 43 | 43 | format.js { render nothing: true } |
| 44 | 44 | end |
| 45 | 45 | end |
| 46 | + | |
| 47 | + def apply_import | |
| 48 | + giver = Project.find(params[:source_project_id]) | |
| 49 | + status = UsersProject.import_team(giver, project) | |
| 50 | + notice = status ? "Succesfully imported" : "Import failed" | |
| 51 | + | |
| 52 | + redirect_to project_team_members_path(project), notice: notice | |
| 53 | + end | |
| 46 | 54 | end | ... | ... |
app/models/users_project.rb
| ... | ... | @@ -21,6 +21,22 @@ class UsersProject < ActiveRecord::Base |
| 21 | 21 | delegate :name, :email, to: :user, prefix: true |
| 22 | 22 | |
| 23 | 23 | class << self |
| 24 | + def import_team(source_project, target_project) | |
| 25 | + UsersProject.transaction do | |
| 26 | + team = source_project.users_projects.all | |
| 27 | + | |
| 28 | + team.each do |tm| | |
| 29 | + # Skip if user already present in team | |
| 30 | + next if target_project.users.include?(tm.user) | |
| 31 | + | |
| 32 | + new_tm = tm.dup | |
| 33 | + new_tm.id = nil | |
| 34 | + new_tm.project_id = target_project.id | |
| 35 | + new_tm.save | |
| 36 | + end | |
| 37 | + end | |
| 38 | + end | |
| 39 | + | |
| 24 | 40 | def bulk_delete(project, user_ids) |
| 25 | 41 | UsersProject.transaction do |
| 26 | 42 | UsersProject.where(:user_id => user_ids, :project_id => project.id).each do |users_project| | ... | ... |
| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | += render "projects/project_head" | |
| 2 | + | |
| 3 | +%h3.page_title | |
| 4 | + = "Import team from another project" | |
| 5 | +%hr | |
| 6 | +%p.slead | |
| 7 | + Read more about team import #{link_to "here", '#', class: 'vlink'}. | |
| 8 | += form_tag apply_import_project_team_members_path(@project), method: 'post' do | |
| 9 | + %p.slead Choose project you want to use as team source: | |
| 10 | + .padded | |
| 11 | + = label_tag :source_project_id, "Project" | |
| 12 | + .input= select_tag(:source_project_id, options_from_collection_for_select(current_user.projects, :id, :name), prompt: "Select project", class: "chosen xxlarge", required: true) | |
| 13 | + | |
| 14 | + .actions | |
| 15 | + = submit_tag 'Save', class: "btn save-btn" | |
| 16 | + = link_to "Cancel", project_team_index_path(@project), class: "btn cancel-btn" | |
| 17 | + | ... | ... |
app/views/team_members/index.html.haml
| ... | ... | @@ -5,9 +5,14 @@ |
| 5 | 5 | |
| 6 | 6 | - if can? current_user, :admin_team_member, @project |
| 7 | 7 | %p.slead |
| 8 | - = link_to new_project_team_member_path(@project), class: "btn small right", title: "New Team Member" do | |
| 9 | - New Team Member | |
| 10 | 8 | Read more about project permissions |
| 11 | 9 | %strong= link_to "here", help_permissions_path, class: "vlink" |
| 12 | 10 | |
| 11 | + %span.right | |
| 12 | + = link_to import_project_team_members_path(@project), class: "btn small grouped", title: "Import team from another project" do | |
| 13 | + Import team from another project | |
| 14 | + = link_to new_project_team_member_path(@project), class: "btn success small grouped", title: "New Team Member" do | |
| 15 | + New Team Member | |
| 16 | + | |
| 17 | + .clearfix | |
| 13 | 18 | = render partial: "team_members/team", locals: {project: @project} | ... | ... |
config/routes.rb
| ... | ... | @@ -188,7 +188,6 @@ Gitlab::Application.routes.draw do |
| 188 | 188 | :via => [:get, :post], constraints: {from: /.+/, to: /.+/} |
| 189 | 189 | |
| 190 | 190 | resources :team, controller: 'team_members', only: [:index] |
| 191 | - resources :team_members | |
| 192 | 191 | resources :milestones |
| 193 | 192 | resources :labels, only: [:index] |
| 194 | 193 | resources :issues do |
| ... | ... | @@ -199,6 +198,16 @@ Gitlab::Application.routes.draw do |
| 199 | 198 | end |
| 200 | 199 | end |
| 201 | 200 | |
| 201 | + resources :team_members do | |
| 202 | + collection do | |
| 203 | + | |
| 204 | + # Used for import team | |
| 205 | + # from another project | |
| 206 | + get :import | |
| 207 | + post :apply_import | |
| 208 | + end | |
| 209 | + end | |
| 210 | + | |
| 202 | 211 | resources :notes, only: [:index, :create, :destroy] do |
| 203 | 212 | collection do |
| 204 | 213 | post :preview | ... | ... |