Class: Groups::GroupMembersController

Inherits:
ApplicationController show all
Defined in:
app/controllers/groups/group_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

Instance Method Details

#createObject


20
21
22
23
24
# File 'app/controllers/groups/group_members_controller.rb', line 20

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

  redirect_to group_group_members_path(@group), notice: 'Users were successfully added.'
end

#destroyObject


34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/groups/group_members_controller.rb', line 34

def destroy
  @group_member = @group.group_members.find(params[:id])

  return render_403 unless can?(current_user, :destroy_group_member, @group_member)

  @group_member.destroy

  respond_to do |format|
    format.html { redirect_to group_group_members_path(@group), notice: 'User was successfully removed from group.' }
    format.js { render nothing: true }
  end
end

#indexObject


5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/controllers/groups/group_members_controller.rb', line 5

def index
  @project = @group.projects.find(params[:project_id]) if params[:project_id]
  @members = @group.group_members
  @members = @members.non_invite unless can?(current_user, :admin_group, @group)

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

  @members = @members.order('access_level DESC').page(params[:page]).per(50)

  @group_member = @group.group_members.new
end

#leaveObject


61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'app/controllers/groups/group_members_controller.rb', line 61

def leave
  @group_member = @group.group_members.find_by(user_id: current_user)

  if can?(current_user, :destroy_group_member, @group_member)
    @group_member.destroy

    redirect_to(dashboard_groups_path, notice: "You left #{group.name} group.")
  else
    if @group.last_owner?(current_user)
      redirect_to(dashboard_groups_path, alert: "You can not leave #{group.name} group because you're the last owner. Transfer or delete the group.")
    else
      return render_403
    end
  end
end

#resend_inviteObject


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

def resend_invite
  redirect_path = group_group_members_path(@group)

  @group_member = @group.group_members.find(params[:id])

  if @group_member.invite?
    @group_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


26
27
28
29
30
31
32
# File 'app/controllers/groups/group_members_controller.rb', line 26

def update
  @group_member = @group.group_members.find(params[:id])

  return render_403 unless can?(current_user, :update_group_member, @group_member)

  @group_member.update_attributes(member_params)
end