Commit 84371de0 authored by Douwe Maan's avatar Douwe Maan

Move group leave action from dashboard/groups to groups/group_members.

parent 224187ff
class Dashboard::GroupsController < ApplicationController
def index
@user_groups = current_user.group_members.page(params[:page]).per(PER_PAGE)
end
def leave
@users_group = group.group_members.where(user_id: current_user.id).first
if can?(current_user, :destroy, @users_group)
@users_group.destroy
redirect_to(dashboard_groups_path, info: "You left #{group.name} group.")
else
return render_403
end
end
private
def group
@group ||= Group.find_by(path: params[:id])
@group_members = current_user.group_members.page(params[:page]).per(PER_PAGE)
end
end
......@@ -46,6 +46,17 @@ class Groups::GroupMembersController < Groups::ApplicationController
end
end
def leave
@group_member = @group.group_members.where(user_id: current_user.id).first
if can?(current_user, :destroy_group_member, @group_member)
@group_member.destroy
redirect_to(dashboard_groups_path, info: "You left #{group.name} group.")
else
return render_403
end
end
protected
def group
......
......@@ -23,7 +23,7 @@
Settings
- if can?(current_user, :destroy_group_member, group_member)
= link_to leave_dashboard_group_path(group), data: { confirm: leave_group_message(group.name) }, method: :delete, class: "btn-sm btn btn-grouped", title: 'Remove user from group' do
= link_to leave_group_group_members_path(group), data: { confirm: leave_group_message(group.name) }, method: :delete, class: "btn-sm btn btn-grouped", title: 'Remove user from group' do
%i.fa.fa-sign-out
Leave
......
- user = member.user
- return unless user
- show_roles = true if show_roles.nil?
%li{class: "#{dom_class(member)} js-toggle-container", id: dom_id(member)}
%span{class: ("list-item-name" if show_controls)}
= image_tag avatar_icon(user.email, 16), class: "avatar s16"
......@@ -21,8 +22,8 @@
title: 'Edit access level', type: 'button' do
%i.fa.fa-pencil-square-o
- if can?(current_user, :destroy_group_member, member)
- if current_user == member.user
= link_to leave_dashboard_group_path(@group), data: { confirm: leave_group_message(@group.name)}, method: :delete, class: "btn-xs btn btn-remove", title: 'Remove user from group' do
- if current_user == user
= link_to leave_group_group_members_path(@group), data: { confirm: leave_group_message(@group.name)}, method: :delete, class: "btn-xs btn btn-remove", title: 'Remove user from group' do
%i.fa.fa-minus.fa-inverse
- else
= link_to group_group_member_path(@group, member), data: { confirm: remove_user_from_group_message(@group, user) }, method: :delete, remote: true, class: "btn-xs btn btn-remove", title: 'Remove user from group' do
......
......@@ -215,11 +215,7 @@ Gitlab::Application.routes.draw do
scope module: :dashboard do
resources :milestones, only: [:index, :show]
resources :groups, only: [:index] do
member do
delete :leave
end
end
resources :groups, only: [:index]
resources :projects, only: [] do
collection do
......@@ -241,6 +237,7 @@ Gitlab::Application.routes.draw do
scope module: :groups do
resources :group_members, only: [:index, :create, :update, :destroy] do
delete :leave, on: :collection
end
resource :avatar, only: [:destroy]
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment