team_members_controller.rb 1.82 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
    @project_members = @project.project_members.order('access_level DESC')
10
  end
gitlabhq's avatar
gitlabhq committed
11
12

  def new
13
    @user_project_relation = project.project_members.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[:access_level]]
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
29
    @user_project_relation = project.project_members.find_by(user_id: member)
30
    @user_project_relation.update_attributes(member_params)
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
Robert Speicher's avatar
Robert Speicher committed
35
    redirect_to project_team_index_path(@project)
gitlabhq's avatar
gitlabhq committed
36
37
38
  end

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

    respond_to do |format|
Robert Speicher's avatar
Robert Speicher committed
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
49
    project.project_members.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
70
71

  def member_params
72
    params.require(:team_member).permit(:user_id, :access_level)
73
  end
gitlabhq's avatar
gitlabhq committed
74
end