From d04ed7e00820ce9925f80736652aea7ddb210d15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cxxq250=E2=80=9D?= <“xxq250@qq.com”> Date: Mon, 29 Aug 2022 10:05:56 +0800 Subject: [PATCH 1/3] =?UTF-8?q?fixed=20=E7=BB=84=E7=BB=87=E6=88=90?= =?UTF-8?q?=E5=91=98=E5=88=97=E8=A1=A8=E6=9F=A5=E8=AF=A2=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../organizations/organization_users_controller.rb | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/app/controllers/organizations/organization_users_controller.rb b/app/controllers/organizations/organization_users_controller.rb index 5f358858d..b31ca1e40 100644 --- a/app/controllers/organizations/organization_users_controller.rb +++ b/app/controllers/organizations/organization_users_controller.rb @@ -4,12 +4,14 @@ class Organizations::OrganizationUsersController < Organizations::BaseController def index @organization_users = @organization.organization_users.includes(:user) - search = params[:search].to_s.downcase - user_condition_users = User.like(search).to_sql - team_condition_teams = User.joins(:teams).merge(@organization.teams.like(search)).to_sql - users = User.from("( #{user_condition_users} UNION #{team_condition_teams }) AS users") - - @organization_users = @organization_users.where(user_id: users).distinct + if params[:search].present? + search = params[:search].to_s.downcase + user_condition_users = User.like(search).to_sql + team_condition_teams = User.joins(:teams).merge(@organization.teams.like(search)).to_sql + users = User.from("( #{user_condition_users} UNION #{team_condition_teams }) AS users") + + @organization_users = @organization_users.where(user_id: users).distinct + end @organization_users = kaminari_paginate(@organization_users) end From 0f41cabe71907f9b16df185d318b3eb8b13d5527 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 30 Aug 2022 10:23:35 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=85=A8=E9=83=A8=E6=88=96=E8=80=85=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E5=9B=A2=E9=98=9F=E9=A1=B9=E7=9B=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../organizations/team_projects_controller.rb | 24 ++++++++++++++++++- .../team_project/create_all_service.rb | 23 ++++++++++++++++++ .../team_project/delete_all_service.rb | 23 ++++++++++++++++++ config/routes.rb | 7 +++++- 4 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 app/services/gitea/organization/team_project/create_all_service.rb create mode 100644 app/services/gitea/organization/team_project/delete_all_service.rb diff --git a/app/controllers/organizations/team_projects_controller.rb b/app/controllers/organizations/team_projects_controller.rb index 2badca177..bbf3264f0 100644 --- a/app/controllers/organizations/team_projects_controller.rb +++ b/app/controllers/organizations/team_projects_controller.rb @@ -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 diff --git a/app/services/gitea/organization/team_project/create_all_service.rb b/app/services/gitea/organization/team_project/create_all_service.rb new file mode 100644 index 000000000..5ba6b58b2 --- /dev/null +++ b/app/services/gitea/organization/team_project/create_all_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/gitea/organization/team_project/delete_all_service.rb b/app/services/gitea/organization/team_project/delete_all_service.rb new file mode 100644 index 000000000..e7b9f932f --- /dev/null +++ b/app/services/gitea/organization/team_project/delete_all_service.rb @@ -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 \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 5f8f9f74d..01cfe2b7d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -135,7 +135,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 From 60b3c7925d71ba4f6cb92d4167d446b54efba501 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 30 Aug 2022 10:34:37 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E5=85=A8=E9=83=A8=E6=88=96=E8=80=85=E7=A7=BB=E9=99=A4?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E5=9B=A2=E9=98=9F=E9=A1=B9=E7=9B=AE[?= =?UTF-8?q?=E6=96=87=E6=A1=A3]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/docs/slate/source/includes/_teams.md | 77 ++++++++++++++++ public/docs/api.html | 106 ++++++++++++++++++++++- 2 files changed, 182 insertions(+), 1 deletion(-) diff --git a/app/docs/slate/source/includes/_teams.md b/app/docs/slate/source/includes/_teams.md index c50f6973a..eaaf6bf63 100644 --- a/app/docs/slate/source/includes/_teams.md +++ b/app/docs/slate/source/includes/_teams.md @@ -1 +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" +} +``` + + + +## 团队下删除所有的项目 +团队下删除所有的项目 + +> 示例: + +```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" +} +``` + \ No newline at end of file diff --git a/public/docs/api.html b/public/docs/api.html index c43f7c403..b41272321 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -646,6 +646,14 @@
  • Teams +
  • Errors @@ -15446,7 +15454,103 @@ http://localhost:3000/api/v1/yystopf/ceshi/pulls/1/journals/200.json -

    Issues

    Organizations

    Teams

    Errors

    +

    Issues

    Organizations

    Teams

    团队下新增所有的项目

    +

    团队下新增所有的项目

    + +
    +

    示例:

    +
    +
    curl -X POST \
    +http://localhost:3000/api/organizations/ceshi_org/teams/28/team_projects/create_all
    +
    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

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    organizationstring组织标识
    idinteger团队 ID
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +
    + +

    团队下删除所有的项目

    +

    团队下删除所有的项目

    + +
    +

    示例:

    +
    +
    curl -X DELETE \
    +http://localhost:3000/api/organizations/ceshi_org/teams/28/team_projects/destroy_all
    +
    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

    +

    请求参数:

    + + + + + + + + + + + + + + + + + + + + + + + +
    参数必选默认类型字段说明
    organizationstring组织标识
    idinteger团队 ID
    +

    返回字段说明:

    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +
    + +

    Errors