新增:添加全部或者移除全部团队项目

This commit is contained in:
yystopf 2022-08-30 10:35:43 +08:00
commit 43a41399ac
6 changed files with 258 additions and 3 deletions

View File

@ -21,6 +21,17 @@ class Organizations::TeamProjectsController < Organizations::BaseController
tip_exception(e.message)
end
def create_all
tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project
ActiveRecord::Base.transaction do
@organization.projects.each do |project|
TeamProject.build(@organization.id, @team.id, project.id)
end
Gitea::Organization::TeamProject::CreateAllService.call(@organization.gitea_token, @team.gtid, @organization.login)
render_ok
end
end
def destroy
tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project
ActiveRecord::Base.transaction do
@ -33,6 +44,17 @@ class Organizations::TeamProjectsController < Organizations::BaseController
tip_exception(e.message)
end
def destroy_all
tip_exception("该组织团队项目包括组织所有项目,不允许更改") if @team.includes_all_project
ActiveRecord::Base.transaction do
@team.team_projects.each do |project|
project.destroy!
end
Gitea::Organization::TeamProject::DeleteAllService.call(@organization.gitea_token, @team.gtid, @organization.login)
render_ok
end
end
private
def load_organization
@organization = Organization.find_by(login: params[:organization_id]) || Organization.find_by(id: params[:organization_id])
@ -47,7 +69,7 @@ class Organizations::TeamProjectsController < Organizations::BaseController
end
def load_operate_project
@operate_project = Project.find_by(id: project_mark) || Project.find_by(identifier: project_mark)
@operate_project = @organization.projects.find_by(id: project_mark) || @organization.find_by(identifier: project_mark)
tip_exception("项目不存在") if @operate_project.nil?
end

View File

@ -0,0 +1,78 @@
# Teams
## 团队下新增所有的项目
团队下新增所有的项目
> 示例:
```shell
curl -X POST \
http://localhost:3000/api/organizations/ceshi_org/teams/28/team_projects/create_all
```
```javascript
await octokit.request('POST /api/organizations/ceshi_org/teams/28/team_projects/create_all.json')
```
### HTTP 请求
`POST /api/organizations/:organization/teams/:id/team_projects/create_all.json`
### 请求参数:
参数 | 必选 | 默认 | 类型 | 字段说明
--------- | ------- | ------- | -------- | ----------
|organization |是| | string |组织标识 |
|id |是| | integer|团队 ID|
### 返回字段说明:
> 返回的JSON示例:
```json
{
"status": 0,
"message": "success"
}
```
<aside class="success">
Success Data.
</aside>
## 团队下删除所有的项目
团队下删除所有的项目
> 示例:
```shell
curl -X DELETE \
http://localhost:3000/api/organizations/ceshi_org/teams/28/team_projects/destroy_all
```
```javascript
await octokit.request('DELETE /api/organizations/ceshi_org/teams/28/team_projects/destroy_all.json')
```
### HTTP 请求
`DELETE /api/organizations/:organization/teams/:id/team_projects/destroy_all.json`
### 请求参数:
参数 | 必选 | 默认 | 类型 | 字段说明
--------- | ------- | ------- | -------- | ----------
|organization |是| | string |组织标识 |
|id |是| | integer|团队 ID|
### 返回字段说明:
> 返回的JSON示例:
```json
{
"status": 0,
"message": "success"
}
```
<aside class="success">
Success Data.
</aside>

View File

@ -0,0 +1,23 @@
class Gitea::Organization::TeamProject::CreateAllService < Gitea::ClientService
attr_reader :token, :gtid, :org_name
def initialize(token, gtid, org_name)
@token = token
@gtid = gtid
@org_name = org_name
end
def call
response = put(url, request_params)
render_status(response)
end
private
def request_params
Hash.new.merge(token: token)
end
def url
"/teams/#{gtid}/repos/#{org_name}".freeze
end
end

View File

@ -0,0 +1,23 @@
class Gitea::Organization::TeamProject::DeleteAllService < Gitea::ClientService
attr_reader :token, :gtid, :org_name
def initialize(token, gtid, org_name)
@token = token
@gtid = gtid
@org_name = org_name
end
def call
response = delete(url, params)
render_status(response)
end
private
def params
Hash.new.merge(token: token)
end
def url
"/teams/#{gtid}/repos/#{org_name}".freeze
end
end

View File

@ -139,7 +139,12 @@ Rails.application.routes.draw do
delete :quit
end
end
resources :team_projects, only: [:index, :create, :destroy] do ;end
resources :team_projects, only: [:index, :create, :destroy] do
collection do
post :create_all
delete :destroy_all
end
end
end
resources :projects, only: [:index] do
collection do

View File

@ -666,6 +666,14 @@
</li>
<li>
<a href="#teams" class="toc-h1 toc-link" data-title="Teams">Teams</a>
<ul class="toc-list-h2">
<li>
<a href="#9a2bb9044d" class="toc-h2 toc-link" data-title="团队下新增所有的项目">团队下新增所有的项目</a>
</li>
<li>
<a href="#037098e244" class="toc-h2 toc-link" data-title="团队下删除所有的项目">团队下删除所有的项目</a>
</li>
</ul>
</li>
<li>
<a href="#errors" class="toc-h1 toc-link" data-title="Errors">Errors</a>
@ -15749,7 +15757,103 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals/200.json
<aside class="success">
Success Data.
</aside>
<h1 id='issues'>Issues</h1><h1 id='organizations'>Organizations</h1><h1 id='teams'>Teams</h1><h1 id='errors'>Errors</h1>
<h1 id='issues'>Issues</h1><h1 id='organizations'>Organizations</h1><h1 id='teams'>Teams</h1><h2 id='9a2bb9044d'>团队下新增所有的项目</h2>
<p>团队下新增所有的项目</p>
<blockquote>
<p>示例:</p>
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> POST <span class="se">\</span>
http://localhost:3000/api/organizations/ceshi_org/teams/28/team_projects/create_all
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">POST /api/organizations/ceshi_org/teams/28/team_projects/create_all.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http'>HTTP 请求</h3>
<p><code>POST /api/organizations/:organization/teams/:id/team_projects/create_all.json</code></p>
<h3 id='2eb6f47757'>请求参数:</h3>
<table><thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>默认</th>
<th>类型</th>
<th>字段说明</th>
</tr>
</thead><tbody>
<tr>
<td>organization</td>
<td></td>
<td></td>
<td>string</td>
<td>组织标识</td>
</tr>
<tr>
<td>id</td>
<td></td>
<td></td>
<td>integer</td>
<td>团队 ID</td>
</tr>
</tbody></table>
<h3 id='7447e4874e'>返回字段说明:</h3>
<blockquote>
<p>返回的JSON示例:</p>
</blockquote>
<div class="highlight"><pre class="highlight json tab-json"><code><span class="p">{</span><span class="w">
</span><span class="nl">"status"</span><span class="p">:</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w">
</span><span class="nl">"message"</span><span class="p">:</span><span class="w"> </span><span class="s2">"success"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div>
<aside class="success">
Success Data.
</aside>
<h2 id='037098e244'>团队下删除所有的项目</h2>
<p>团队下删除所有的项目</p>
<blockquote>
<p>示例:</p>
</blockquote>
<div class="highlight"><pre class="highlight shell tab-shell"><code>curl <span class="nt">-X</span> DELETE <span class="se">\</span>
http://localhost:3000/api/organizations/ceshi_org/teams/28/team_projects/destroy_all
</code></pre></div><div class="highlight"><pre class="highlight javascript tab-javascript"><code><span class="k">await</span> <span class="nx">octokit</span><span class="p">.</span><span class="nx">request</span><span class="p">(</span><span class="dl">'</span><span class="s1">DELETE /api/organizations/ceshi_org/teams/28/team_projects/destroy_all.json</span><span class="dl">'</span><span class="p">)</span>
</code></pre></div><h3 id='http-2'>HTTP 请求</h3>
<p><code>DELETE /api/organizations/:organization/teams/:id/team_projects/destroy_all.json</code></p>
<h3 id='2eb6f47757-2'>请求参数:</h3>
<table><thead>
<tr>
<th>参数</th>
<th>必选</th>
<th>默认</th>
<th>类型</th>
<th>字段说明</th>
</tr>
</thead><tbody>
<tr>
<td>organization</td>
<td></td>
<td></td>
<td>string</td>
<td>组织标识</td>
</tr>
<tr>
<td>id</td>
<td></td>
<td></td>
<td>integer</td>
<td>团队 ID</td>
</tr>
</tbody></table>
<h3 id='7447e4874e-2'>返回字段说明:</h3>
<blockquote>
<p>返回的JSON示例:</p>
</blockquote>
<div class="highlight"><pre class="highlight json tab-json"><code><span class="p">{</span><span class="w">
</span><span class="nl">"status"</span><span class="p">:</span><span class="w"> </span><span class="mi">0</span><span class="p">,</span><span class="w">
</span><span class="nl">"message"</span><span class="p">:</span><span class="w"> </span><span class="s2">"success"</span><span class="w">
</span><span class="p">}</span><span class="w">
</span></code></pre></div>
<aside class="success">
Success Data.
</aside>
<h1 id='errors'>Errors</h1>
<aside class="notice">
This error section is stored in a separate file in <code>includes/_errors.md</code>. Slate allows you to optionally separate out your docs into many files...just save them to the <code>includes</code> folder and add them to the top of your <code>index.md</code>'s frontmatter. Files are included in the order listed.
</aside>