ADD delete project api

dev_forge
Jasder 5 years ago
parent 7301ea98d8
commit 828cd69af7

@ -542,6 +542,40 @@ http://localhost:3000/api/projects/3263.json | jq
```
---
#### 删除项目
```
DELETE api/projects/:id
```
*示例*
```
curl -X DELETE http://localhost:3000/api/projects/3263.json | jq
```
注:只有超级管理员和项目拥有者才能删除仓库
*请求参数说明:*
|参数名|必选|类型|说明|
-|-|-|-
|id |是|int |项目id |
*返回参数说明:*
|参数名|类型|说明|
-|-|-
|status |int|返回状态, 0: 表示操作成功 |
|message |string|返回信息说明|
返回值
```
{
"status": 0,
"message": "success"
}
```
---
#### 项目添加成员
```
POST api/projects/:id/members

@ -2,7 +2,7 @@ class ProjectsController < ApplicationController
include ApplicationHelper
include OperateProjectAbilityAble
before_action :require_login, except: %i[index branches group_type_list]
before_action :find_project_with_id, only: %i[show branches update]
before_action :find_project_with_id, only: %i[show branches update destroy]
before_action :authorizate_user_can_edit_project!, only: %i[update]
def index
@ -58,6 +58,21 @@ class ProjectsController < ApplicationController
def show
end
def destroy
if current_user.admin? || @project.owner?(current_user)
ActiveRecord::Base.transaction do
Gitea::Repository::DeleteService.new(@project.owner, @project.identifier).call
@project.destroy!
render_ok
end
else
render_forbidden('你没有权限操作')
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
end
private
def project_params
params.permit(:user_id, :name, :description, :repository_name,

@ -39,7 +39,7 @@ Rails.application.routes.draw do
resources :ignores, only: [:index, :show]
resources :licenses, only: [:index, :show]
resources :projects, only: [:index, :create, :show, :update] do
resources :projects do
resources :pull_requests, except: [:destroy] do
member do
post :pr_merge

Loading…
Cancel
Save