Commit 2afa5fcb authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add ability to leave project

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 907bbb2b
...@@ -73,10 +73,14 @@ class Projects::ProjectMembersController < Projects::ApplicationController ...@@ -73,10 +73,14 @@ class Projects::ProjectMembersController < Projects::ApplicationController
end end
def leave 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 @project.project_members.find_by(user_id: current_user).destroy
respond_to do |format| respond_to do |format|
format.html { redirect_to :back } format.html { redirect_to dashboard_path }
format.js { render nothing: true } format.js { render nothing: true }
end end
end end
......
...@@ -294,4 +294,16 @@ module ProjectsHelper ...@@ -294,4 +294,16 @@ module ProjectsHelper
nil nil
end end
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 end
...@@ -94,3 +94,15 @@ ...@@ -94,3 +94,15 @@
= icon("exclamation-triangle fw") = icon("exclamation-triangle fw")
Archived project! Archived project!
%p Repository is read-only %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
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