team_members_controller.rb 1.74 KB
Newer Older
1
class Projects::TeamMembersController < Projects::ApplicationController
gitlabhq's avatar
gitlabhq committed
2
  # Authorize
3
  before_filter :authorize_admin_project!, except: :leave
4

5 6
  layout "project_settings"

7
  def index
8
    @group = @project.group
9
    @users_projects = @project.users_projects.order('project_access DESC')
10
  end
gitlabhq's avatar
gitlabhq committed
11 12

  def new
13
    @user_project_relation = project.users_projects.new
gitlabhq's avatar
gitlabhq committed
14 15 16
  end

  def create
17
    users = User.where(id: params[:user_ids].split(','))
18 19

    @project.team << [users, params[:project_access]]
20

21 22 23 24 25
    if params[:redirect_to]
      redirect_to params[:redirect_to]
    else
      redirect_to project_team_index_path(@project)
    end
gitlabhq's avatar
gitlabhq committed
26 27 28
  end

  def update
skv's avatar
skv committed
29
    @user_project_relation = project.users_projects.find_by(user_id: member)
30
    @user_project_relation.update_attributes(params[:team_member])
gitlabhq's avatar
gitlabhq committed
31

32
    unless @user_project_relation.valid?
33
      flash[:alert] = "User should have at least one role"
gitlabhq's avatar
gitlabhq committed
34
    end
35
    redirect_to project_team_index_path(@project)
gitlabhq's avatar
gitlabhq committed
36 37 38
  end

  def destroy
skv's avatar
skv committed
39
    @user_project_relation = project.users_projects.find_by(user_id: member)
40
    @user_project_relation.destroy
gitlabhq's avatar
gitlabhq committed
41 42

    respond_to do |format|
43
      format.html { redirect_to project_team_index_path(@project) }
44
      format.js { render nothing: true }
gitlabhq's avatar
gitlabhq committed
45 46
    end
  end
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
47

48
  def leave
skv's avatar
skv committed
49
    project.users_projects.find_by(user_id: current_user).destroy
50 51 52 53 54 55 56

    respond_to do |format|
      format.html { redirect_to :back }
      format.js { render nothing: true }
    end
  end

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
57 58
  def apply_import
    giver = Project.find(params[:source_project_id])
59
    status = @project.team.import(giver)
Johannes Schleifenbaum's avatar
Johannes Schleifenbaum committed
60
    notice = status ? "Successfully imported" : "Import failed"
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
61

62
    redirect_to project_team_index_path(project), notice: notice
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
63
  end
64 65 66 67

  protected

  def member
skv's avatar
skv committed
68
    @member ||= User.find_by(username: params[:id])
69
  end
gitlabhq's avatar
gitlabhq committed
70
end