Commit acb402a1c1cfb23613be0f988b60884c352de37c

Authored by Dmitriy Zaporozhets
1 parent 7a42dece

Ability to leave group from profile area

app/assets/stylesheets/common.scss
... ... @@ -420,3 +420,8 @@ img.emoji {
420 420 @extend .light;
421 421 margin-bottom: 10px;
422 422 }
  423 +
  424 +.group-name {
  425 + font-size: 14px;
  426 + line-height: 24px;
  427 +}
... ...
app/controllers/profiles/groups_controller.rb 0 → 100644
... ... @@ -0,0 +1,24 @@
  1 +class Profiles::GroupsController < ApplicationController
  2 + layout "profile"
  3 +
  4 + def index
  5 + @groups = current_user.authorized_groups.all
  6 + end
  7 +
  8 + def leave
  9 + @users_group = group.users_groups.where(user_id: current_user.id).first
  10 +
  11 + if group.owner == current_user
  12 + redirect_to(profile_groups_path, alert: "You can't leave group. You must transfer it to another owner before leaving.")
  13 + else
  14 + @users_group.destroy
  15 + redirect_to(profile_groups_path, info: "You left #{group.name} group.")
  16 + end
  17 + end
  18 +
  19 + private
  20 +
  21 + def group
  22 + @group ||= Group.find_by_path(params[:id])
  23 + end
  24 +end
... ...
app/views/layouts/_flash.html.haml
1 1 .flash-container
2 2 - if alert
3   - .alert
  3 + .alert.alert-error
4 4 %span= alert
5 5  
6 6 - elsif notice
... ...
app/views/layouts/nav/_profile.html.haml
... ... @@ -12,6 +12,8 @@
12 12 %span.count= current_user.keys.count
13 13 = nav_link(path: 'profiles#design') do
14 14 = link_to "Design", design_profile_path
  15 + = nav_link(controller: :groups) do
  16 + = link_to "Groups", profile_groups_path
15 17 = nav_link(path: 'profiles#history') do
16 18 = link_to "History", history_profile_path
17 19  
... ...
app/views/profiles/groups/index.html.haml 0 → 100644
... ... @@ -0,0 +1,17 @@
  1 +.ui-box
  2 + %h5.title Groups
  3 + %ul.well-list
  4 + - @groups.each do |group|
  5 + %li
  6 + .pull-right
  7 + - if can?(current_user, :manage_group, group)
  8 + = link_to edit_group_path(group), class: "btn-small btn grouped" do
  9 + %i.icon-cogs
  10 + Settings
  11 +
  12 + = link_to leave_profile_group_path(group), confirm: "Are you sure you want to leave #{group.name} group?", method: :delete, class: "btn-small btn grouped", title: 'Remove user from group' do
  13 + %i.icon-signout
  14 + Leave
  15 +
  16 + = link_to group, class: 'group-name' do
  17 + = group.name
... ...
app/views/users_groups/_users_group.html.haml
... ... @@ -13,6 +13,7 @@
13 13 - else
14 14 = member.human_access
15 15  
16   - - if show_controls && user != current_user && user != @group.owner
  16 + - if show_controls && user != @group.owner && user != current_user
17 17 = link_to group_users_group_path(@group, member), confirm: remove_user_from_group_message(@group, user), method: :delete, remote: true, class: "btn-tiny btn btn-remove", title: 'Remove user from group' do
18 18 %i.icon-minus.icon-white
  19 +
... ...
config/routes.rb
... ... @@ -116,6 +116,11 @@ Gitlab::Application.routes.draw do
116 116 resource :notifications, only: [:show, :update]
117 117 resource :password, only: [:new, :create]
118 118 resources :keys
  119 + resources :groups, only: [:index] do
  120 + member do
  121 + delete :leave
  122 + end
  123 + end
119 124 end
120 125 end
121 126  
... ...