add: quit repo

This commit is contained in:
yystopf 2022-05-05 10:00:02 +08:00
parent f15cd44dff
commit 7c88ea3d67
2 changed files with 21 additions and 1 deletions

View File

@ -13,6 +13,8 @@ class ProjectsController < ApplicationController
def menu_list
menu = []
user_is_admin = current_user.admin? || @project.manager?(current_user)
menu.append(menu_hash_by_name("home"))
menu.append(menu_hash_by_name("code")) if @project.has_menu_permission("code")
menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues")
@ -22,7 +24,8 @@ class ProjectsController < ApplicationController
menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki") && @project.forge?
menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources") && @project.forge?
menu.append(menu_hash_by_name("activity"))
menu.append(menu_hash_by_name("settings")) if (current_user.admin? || @project.manager?(current_user)) && @project.forge?
menu.append(menu_hash_by_name("settings")) if user_is_admin && @project.forge?
menu.append(menu_hash_by_name("quit")) if !user_is_admin && @project.member(current_user.id) && @project.forge?
render json: menu
end
@ -177,6 +180,22 @@ class ProjectsController < ApplicationController
tip_exception(e.message)
end
def quit
user_is_admin = current_user.admin? || @project.manager?(current_user)
if !user_is_admin && @project.member(current_user.id) && @project.forge?
ActiveRecord::Base.transaction do
Projects::DeleteMemberInteractor.call(@project.owner, @project, current_user)
SendTemplateMessageJob.perform_later('ProjectMemberLeft', current_user.id, current_user.id, @project.id) if Site.has_notice_menu?
render_ok
end
else
render_forbidden('你不能退出该仓库')
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
def watch_users
watchers = @project.watchers.includes(:user).order("watchers.created_at desc").distinct
@watchers_count = watchers.size

View File

@ -436,6 +436,7 @@ Rails.application.routes.draw do
get :stargazers, to: 'projects#praise_users'
get :forks, to: 'projects#fork_users'
match :about, :via => [:get, :put, :post]
post :quit
end
end