diff --git a/CHANGELOG b/CHANGELOG index 63280793343..66d23dcfd4f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,6 +33,7 @@ v 7.12.0 (unreleased) - Move user avatar and logout button to sidebar - You can not remove user if he/she is an only owner of group - User should be able to leave group. If not - show him proper message + - User has ability to leave project v 7.11.4 - Fix missing bullets when creating lists diff --git a/app/controllers/projects/project_members_controller.rb b/app/controllers/projects/project_members_controller.rb index d7fbc979067..b110de11013 100644 --- a/app/controllers/projects/project_members_controller.rb +++ b/app/controllers/projects/project_members_controller.rb @@ -73,10 +73,14 @@ class Projects::ProjectMembersController < Projects::ApplicationController end def leave + if @project.namespace == current_user.namespace + return redirect_to(:back, alert: 'You can not leave your own project. Transfer or delete the project.') + end + @project.project_members.find_by(user_id: current_user).destroy respond_to do |format| - format.html { redirect_to :back } + format.html { redirect_to dashboard_path } format.js { render nothing: true } end end diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index f8df39d236a..94ce6646634 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -294,4 +294,16 @@ module ProjectsHelper nil end end + + def user_max_access_in_project(user, project) + level = project.team.max_member_access(user) + + if level + Gitlab::Access.options_with_owner.key(level) + end + end + + def leave_project_message(project) + "Are you sure you want to leave \"#{project.name}\" project?" + end end diff --git a/app/views/groups/group_members/_group_member.html.haml b/app/views/groups/group_members/_group_member.html.haml index 56b1948a474..ec39a755f0f 100644 --- a/app/views/groups/group_members/_group_member.html.haml +++ b/app/views/groups/group_members/_group_member.html.haml @@ -40,7 +40,8 @@   - 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 + = icon("sign-out") + Leave - else = link_to group_group_member_path(@group, member), data: { confirm: remove_user_from_group_message(@group, member) }, method: :delete, remote: true, class: "btn-xs btn btn-remove", title: 'Remove user from group' do %i.fa.fa-minus.fa-inverse diff --git a/app/views/projects/_aside.html.haml b/app/views/projects/_aside.html.haml index 000a40b466d..9c2ff8f8402 100644 --- a/app/views/projects/_aside.html.haml +++ b/app/views/projects/_aside.html.haml @@ -94,3 +94,15 @@ = icon("exclamation-triangle fw") Archived project! %p Repository is read-only + + - if current_user + - access = user_max_access_in_project(current_user, @project) + - if access + .light-well.light.prepend-top-20 + %small + You have #{access} access to this project. + - if @project.project_member_by_id(current_user) + %br + = link_to leave_namespace_project_project_members_path(@project.namespace, @project), + data: { confirm: leave_project_message(@project) }, method: :delete, title: 'Leave project' do + Leave this project diff --git a/app/views/projects/project_members/_project_member.html.haml b/app/views/projects/project_members/_project_member.html.haml index 635e4d70941..860a997cff8 100644 --- a/app/views/projects/project_members/_project_member.html.haml +++ b/app/views/projects/project_members/_project_member.html.haml @@ -38,8 +38,9 @@   - if current_user == user - = link_to leave_namespace_project_project_members_path(@project.namespace, @project), data: { confirm: "Leave project?"}, method: :delete, class: "btn-xs btn btn-remove", title: 'Leave project' do - %i.fa.fa-minus.fa-inverse + = link_to leave_namespace_project_project_members_path(@project.namespace, @project), data: { confirm: leave_project_message(@project) }, method: :delete, class: "btn-xs btn btn-remove", title: 'Leave project' do + = icon("sign-out") + Leave - else = link_to namespace_project_project_member_path(@project.namespace, @project, member), data: { confirm: remove_from_project_team_message(@project, member) }, method: :delete, remote: true, class: "btn-xs btn btn-remove", title: 'Remove user from team' do %i.fa.fa-minus.fa-inverse