Class: Projects::ProjectMembersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/projects/project_members_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#redirect_back_or_default

Methods included from PageLayoutHelper

#blank_container, #container_class, #fluid_layout, #header_title, #nav, #page_card_attributes, #page_card_meta_tags, #page_description, #page_image, #page_title, #sidebar

Methods included from GitlabRoutingHelper

#activity_project_path, #edit_project_path, #edit_project_url, #issue_path, #issue_url, #merge_request_path, #merge_request_url, #milestone_path, #project_builds_path, #project_commits_path, #project_files_path, #project_path, #project_pipelines_path, #project_snippet_url, #project_url, #runner_path, #runners_path, #toggle_subscription_path

Methods included from Gitlab::GonHelper

#add_gon_variables

Methods included from Gitlab::CurrentSettings

#current_application_settings, #fake_application_settings

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Projects::ApplicationController

Instance Method Details

#apply_importObject


96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'app/controllers/projects/project_members_controller.rb', line 96

def apply_import
  source_project = Project.find(params[:source_project_id])

  if can?(current_user, :read_project_member, source_project)
    status = @project.team.import(source_project, current_user)
    notice = status ? "Successfully imported" : "Import failed"
  else
    return render_404
  end

  redirect_to(namespace_project_project_members_path(project.namespace, project),
              notice: notice)
end

#createObject


33
34
35
36
37
# File 'app/controllers/projects/project_members_controller.rb', line 33

def create
  @project.team.add_users(params[:user_ids].split(','), params[:access_level], current_user)

  redirect_to namespace_project_project_members_path(@project.namespace, @project)
end

#destroyObject


47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'app/controllers/projects/project_members_controller.rb', line 47

def destroy
  @project_member = @project.project_members.find(params[:id])

  return render_403 unless can?(current_user, :destroy_project_member, @project_member)

  @project_member.destroy

  respond_to do |format|
    format.html do
      redirect_to namespace_project_project_members_path(@project.namespace, @project)
    end
    format.js { render nothing: true }
  end
end

#indexObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/projects/project_members_controller.rb', line 5

def index
  @project_members = @project.project_members
  @project_members = @project_members.non_invite unless can?(current_user, :admin_project, @project)

  if params[:search].present?
    users = @project.users.search(params[:search]).to_a
    @project_members = @project_members.where(user_id: users)
  end

  @project_members = @project_members.order('access_level DESC')

  @group = @project.group
  if @group
    @group_members = @group.group_members
    @group_members = @group_members.non_invite unless can?(current_user, :admin_group, @group)

    if params[:search].present?
      users = @group.users.search(params[:search]).to_a
      @group_members = @group_members.where(user_id: users)
    end

    @group_members = @group_members.order('access_level DESC')
  end

  @project_member = @project.project_members.new
  @project_group_links = @project.project_group_links
end

#leaveObject


76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/controllers/projects/project_members_controller.rb', line 76

def leave
  @project_member = @project.project_members.find_by(user_id: current_user)

  if can?(current_user, :destroy_project_member, @project_member)
    @project_member.destroy

    respond_to do |format|
      format.html { redirect_to dashboard_projects_path, notice: "You left the project." }
      format.js { render nothing: true }
    end
  else
    if current_user == @project.owner
      message = 'You can not leave your own project. Transfer or delete the project.'
      redirect_back_or_default(default: { action: 'index' }, options: { alert: message })
    else
      render_403
    end
  end
end

#resend_inviteObject


62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/controllers/projects/project_members_controller.rb', line 62

def resend_invite
  redirect_path = namespace_project_project_members_path(@project.namespace, @project)

  @project_member = @project.project_members.find(params[:id])

  if @project_member.invite?
    @project_member.resend_invite

    redirect_to redirect_path, notice: 'The invitation was successfully resent.'
  else
    redirect_to redirect_path, alert: 'The invitation has already been accepted.'
  end
end

#updateObject


39
40
41
42
43
44
45
# File 'app/controllers/projects/project_members_controller.rb', line 39

def update
  @project_member = @project.project_members.find(params[:id])

  return render_403 unless can?(current_user, :update_project_member, @project_member)

  @project_member.update_attributes(member_params)
end