Commit 94f8b51c authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'feature/leave_project' of /home/git/repositories/gitlab/gitlabhq

parents b813a488 d78b6ce4
class Projects::TeamMembersController < Projects::ApplicationController class Projects::TeamMembersController < Projects::ApplicationController
# Authorize # Authorize
before_filter :authorize_admin_project! before_filter :authorize_admin_project!, except: :leave
layout "project_settings" layout "project_settings"
...@@ -45,6 +45,15 @@ class Projects::TeamMembersController < Projects::ApplicationController ...@@ -45,6 +45,15 @@ class Projects::TeamMembersController < Projects::ApplicationController
end end
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 def apply_import
giver = Project.find(params[:source_project_id]) giver = Project.find(params[:source_project_id])
status = @project.team.import(giver) status = @project.team.import(giver)
......
...@@ -447,4 +447,8 @@ class Project < ActiveRecord::Base ...@@ -447,4 +447,8 @@ class Project < ActiveRecord::Base
order('id DESC').limit(100). order('id DESC').limit(100).
update_all(updated_at: Time.now) update_all(updated_at: Time.now)
end end
def project_member(user)
users_projects.where(user_id: user).first
end
end end
...@@ -395,4 +395,9 @@ class User < ActiveRecord::Base ...@@ -395,4 +395,9 @@ class User < ActiveRecord::Base
self self
end end
def can_leave_project?(project)
project.namespace != namespace &&
project.project_member(self)
end
end end
...@@ -54,7 +54,7 @@ ...@@ -54,7 +54,7 @@
.span9 .span9
%ul.bordered-list.my-projects.top-list %ul.bordered-list.my-projects.top-list
- @projects.each do |project| - @projects.each do |project|
%li %li.my-project-row
%h4.project-title %h4.project-title
= link_to project_path(project), class: dom_class(project) do = link_to project_path(project), class: dom_class(project) do
= project.name_with_namespace = project.name_with_namespace
...@@ -63,6 +63,12 @@ ...@@ -63,6 +63,12 @@
= public_icon = public_icon
Public 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 - if project.forked_from_project
%small.pull-right %small.pull-right
%i.icon-code-fork %i.icon-code-fork
...@@ -80,6 +86,7 @@ ...@@ -80,6 +86,7 @@
%span.light Last activity: %span.light Last activity:
%span.date= project_last_activity(project) %span.date= project_last_activity(project)
- if @projects.blank? - if @projects.blank?
%li %li
%h3.nothing_here_message There are no projects here. %h3.nothing_here_message There are no projects here.
......
...@@ -288,6 +288,7 @@ Gitlab::Application.routes.draw do ...@@ -288,6 +288,7 @@ Gitlab::Application.routes.draw do
resources :team_members, except: [:index, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ } do resources :team_members, except: [:index, :edit], constraints: { id: /[a-zA-Z.\/0-9_\-#%+]+/ } do
collection do collection do
delete :leave
# Used for import team # Used for import team
# from another project # 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