Commit d78b6ce4 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

New feature: Ability to leave project

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent f9b66aec
class Projects::TeamMembersController < Projects::ApplicationController
# Authorize
before_filter :authorize_admin_project!
before_filter :authorize_admin_project!, except: :leave
layout "project_settings"
......@@ -45,6 +45,15 @@ class Projects::TeamMembersController < Projects::ApplicationController
end
end
def leave
project.users_projects.find_by_user_id(current_user).destroy
respond_to do |format|
format.html { redirect_to :back }
format.js { render nothing: true }
end
end
def apply_import
giver = Project.find(params[:source_project_id])
status = @project.team.import(giver)
......
......@@ -317,7 +317,7 @@ class Project < ActiveRecord::Base
mrs = self.merge_requests.opened.by_branch(branch_name).all
# Update code for merge requests between project and project fork
mrs += self.fork_merge_requests.opened.by_branch(branch_name).all
mrs.each { |merge_request| merge_request.reload_code; merge_request.mark_as_unchecked }
# Close merge requests
......@@ -447,4 +447,8 @@ class Project < ActiveRecord::Base
order('id DESC').limit(100).
update_all(updated_at: Time.now)
end
def project_member(user)
users_projects.where(user_id: user).first
end
end
......@@ -394,4 +394,9 @@ class User < ActiveRecord::Base
self
end
def can_leave_project?(project)
project.namespace != namespace &&
project.project_member(self)
end
end
......@@ -54,7 +54,7 @@
.span9
%ul.bordered-list.my-projects.top-list
- @projects.each do |project|
%li
%li.my-project-row
%h4.project-title
= link_to project_path(project), class: dom_class(project) do
= project.name_with_namespace
......@@ -63,6 +63,12 @@
= public_icon
Public
- if current_user.can_leave_project?(project)
.pull-right
= link_to leave_project_team_members_path(project), confirm: "Leave project?", method: :delete, remote: true, class: "btn-tiny btn remove-row", title: 'Leave project' do
%i.icon-signout
Leave
- if project.forked_from_project
%small.pull-right
%i.icon-code-fork
......@@ -80,6 +86,7 @@
%span.light Last activity:
%span.date= project_last_activity(project)
- if @projects.blank?
%li
%h3.nothing_here_message There are no projects here.
......
......@@ -288,6 +288,7 @@ Gitlab::Application.routes.draw do
resources :team_members, except: [:index, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ } do
collection do
delete :leave
# Used for import team
# from another 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