diff --git a/app/controllers/projects/project_invite_links_controller.rb b/app/controllers/projects/project_invite_links_controller.rb
index 59f618fc0..c177367cd 100644
--- a/app/controllers/projects/project_invite_links_controller.rb
+++ b/app/controllers/projects/project_invite_links_controller.rb
@@ -13,7 +13,6 @@ class Projects::ProjectInviteLinksController < Projects::BaseController
puts params_data
Projects::ProjectInviteLinks::CreateForm.new(params_data).validate!
@project_invite_link = ProjectInviteLink.create!(params_data.merge(sign: ProjectInviteLink.random_hex_sign))
- render_ok
end
rescue Exception => e
uid_logger_error(e.message)
diff --git a/app/docs/slate/source/includes/_projects.md b/app/docs/slate/source/includes/_projects.md
index e133bcdda..7e7004578 100644
--- a/app/docs/slate/source/includes/_projects.md
+++ b/app/docs/slate/source/includes/_projects.md
@@ -1,4 +1,190 @@
# Projects
+## 获取项目邀请链接
+当前登录(管理员)用户获取项目邀请链接的接口(第一次请求会默认生成role类型为developer和is_apply为true的链接)
+
+> 示例:
+
+```shell
+curl -X GET http://localhost:3000/api/yystopf/kellect/project_invite_links/current_link.json
+```
+
+```javascript
+await octokit.request('GET /api/yystopf/kellect/project_invite_links/current_link.json')
+```
+
+### HTTP 请求
+`GET /api/:owner/:repo/project_invite_links/current_link.json`
+
+### 返回字段说明
+参数 | 类型 | 字段说明
+--------- | ----------- | -----------
+|id |int |链接id |
+|role |string |邀请角色|
+|is_apply |boolean |是否需要审核 |
+|sign |string |邀请标识(放在链接后面即可)|
+|user.id |int |链接创建者的id |
+|user.type |string |链接创建者的类型 |
+|user.name |string |链接创建者的名称 |
+|user.login |string |链接创建者的标识 |
+|user.image_url |string |链接创建者头像 |
+|project.id |int |链接关联项目的id |
+|project.identifier |string |链接关联项目的标识 |
+|project.name |string |链接关联项目的名称 |
+|project.description |string |链接关联项目的描述 |
+|project.is_public |bool |链接关联项目是否公开 |
+|project.owner.id |bool |链接关联项目拥有者id |
+|project.owner.type |string |链接关联项目拥有者类型 |
+|project.owner.name |string |链接关联项目拥有者昵称 |
+|project.owner.login |string |链接关联项目拥有者标识 |
+|project.owner.image_url|string |链接关联项目拥有者头像 |
+
+> 返回的JSON示例:
+
+```json
+{
+ "id": 7,
+ "role": "developer",
+ "is_apply": false,
+ "sign": "6b6b454843c291d4e52e60853cb8ad9f",
+ "user": {
+ "id": 2,
+ "type": "User",
+ "name": "heh",
+ "login": "yystopf",
+ "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
+ },
+ "project": {
+ "id": 474,
+ "identifier": "kellect",
+ "name": "kellect",
+ "description": null,
+ "is_public": true,
+ "owner": {
+ "id": 2,
+ "type": "User",
+ "name": "heh",
+ "login": "yystopf",
+ "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
+ }
+ }
+}
+```
+## 生成项目邀请链接
+当前登录(管理员)用户生成的项目邀请链接,可选role和is_apply参数
+
+> 示例:
+
+```shell
+curl -X POST http://localhost:3000/api/yystopf/kellect/project_invite_links/generate_link.json
+```
+
+```javascript
+await octokit.request('POST /api/yystopf/kellect/project_invite_links/generate_link.json')
+```
+
+### HTTP 请求
+`POST /api/:owner/:repo/project_invite_links/generate_link.json`
+
+### 请求参数
+参数 | 必选 | 默认 | 类型 | 字段说明
+--------- | ------- | ------- | -------- | ----------
+|role |是| |string |项目权限,reporter: 报告者, developer: 开发者,manager:管理员 |
+|is_apply |是| |boolean |是否需要审核 |
+
+
+> 请求的JSON示例
+
+```json
+{
+ "role": "developer",
+ "is_apply": false
+}
+```
+
+### 返回字段说明
+参数 | 类型 | 字段说明
+--------- | ----------- | -----------
+|id |int |链接id |
+|role |string |邀请角色|
+|is_apply |boolean |是否需要审核 |
+|sign |string |邀请标识(放在链接后面即可)|
+|user.id |int |链接创建者的id |
+|user.type |string |链接创建者的类型 |
+|user.name |string |链接创建者的名称 |
+|user.login |string |链接创建者的标识 |
+|user.image_url |string |链接创建者头像 |
+|project.id |int |链接关联项目的id |
+|project.identifier |string |链接关联项目的标识 |
+|project.name |string |链接关联项目的名称 |
+|project.description |string |链接关联项目的描述 |
+|project.is_public |bool |链接关联项目是否公开 |
+|project.owner.id |bool |链接关联项目拥有者id |
+|project.owner.type |string |链接关联项目拥有者类型 |
+|project.owner.name |string |链接关联项目拥有者昵称 |
+|project.owner.login |string |链接关联项目拥有者标识 |
+|project.owner.image_url|string |链接关联项目拥有者头像 |
+
+> 返回的JSON示例:
+
+```json
+{
+ "id": 7,
+ "role": "developer",
+ "is_apply": false,
+ "sign": "6b6b454843c291d4e52e60853cb8ad9f",
+ "user": {
+ "id": 2,
+ "type": "User",
+ "name": "heh",
+ "login": "yystopf",
+ "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
+ },
+ "project": {
+ "id": 474,
+ "identifier": "kellect",
+ "name": "kellect",
+ "description": null,
+ "is_public": true,
+ "owner": {
+ "id": 2,
+ "type": "User",
+ "name": "heh",
+ "login": "yystopf",
+ "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
+ }
+ }
+}
+```
+
+## 请求项目邀请链接
+当前登录(非项目)用户加入项目的接口,如果项目链接不需要审核,请求成功后即加入项目,如果需要审核,那么会提交一个申请,需要项目管理员审核
+
+> 示例:
+
+```shell
+curl -X POST http://localhost:3000/api/yystopf/kellect/project_invite_links/redirect_link.json?invite_sign=d612df03aad63760445c187bcf83f2e6
+```
+
+```javascript
+await octokit.request('POST /api/yystopf/kellect/project_invite_links/redirect_link.json?invite_sign=d612df03aad63760445c187bcf83f2e6')
+```
+
+### HTTP 请求
+`POST /api/:owner/:repo/project_invite_links/generate_link.json?invite_sign=xxx`
+
+### 请求参数
+参数 | 必选 | 默认 | 类型 | 字段说明
+--------- | ------- | ------- | -------- | ----------
+|invite_sign |是| |string |项目邀请链接的标识 |
+
+> 返回的JSON示例:
+
+```json
+{
+ "status": 0,
+ "message": "success"
+}
+```
## 申请加入项目
申请加入项目
diff --git a/app/services/projects/link_join_service.rb b/app/services/projects/link_join_service.rb
index c42376ef2..e586933f9 100644
--- a/app/services/projects/link_join_service.rb
+++ b/app/services/projects/link_join_service.rb
@@ -32,7 +32,7 @@ class Projects::LinkJoinService < ApplicationService
end
def create_applied_project!
- user.applied_projects.create!(project: project, role: role_value)
+ user.applied_projects.create!(project: project, role: role_value, project_invite_link_id: invite_link&.id)
end
def create_member!
diff --git a/app/views/projects/project_invite_links/generate_link.json.jbuilder b/app/views/projects/project_invite_links/generate_link.json.jbuilder
new file mode 100644
index 000000000..1903e10a9
--- /dev/null
+++ b/app/views/projects/project_invite_links/generate_link.json.jbuilder
@@ -0,0 +1 @@
+json.partial! 'detail', locals: { project_invite_link: @project_invite_link }
diff --git a/public/docs/api.html b/public/docs/api.html
index 8ef6924b9..bd3f49eb1 100644
--- a/public/docs/api.html
+++ b/public/docs/api.html
@@ -425,6 +425,15 @@
Projects
+ -
+ 获取项目邀请链接
+
+ -
+ 生成项目邀请链接
+
+ -
+ 请求项目邀请链接
+
-
申请加入项目
@@ -4390,7 +4399,366 @@ Success — a happy kitten is an authenticated kitten!
"created_at": "2021-06-09 16:41",
"time_ago": "7分钟前"
}
-Projects
申请加入项目
+Projects
获取项目邀请链接
+当前登录(管理员)用户获取项目邀请链接的接口(第一次请求会默认生成role类型为developer和is_apply为true的链接)
+
+
+示例:
+
+curl -X GET http://localhost:3000/api/yystopf/kellect/project_invite_links/current_link.json
+
await octokit.request('GET /api/yystopf/kellect/project_invite_links/current_link.json')
+
HTTP 请求
+GET /api/:owner/:repo/project_invite_links/current_link.json
+返回字段说明
+
+
+参数 |
+类型 |
+字段说明 |
+
+
+
+id |
+int |
+链接id |
+
+
+role |
+string |
+邀请角色 |
+
+
+is_apply |
+boolean |
+是否需要审核 |
+
+
+sign |
+string |
+邀请标识(放在链接后面即可) |
+
+
+user.id |
+int |
+链接创建者的id |
+
+
+user.type |
+string |
+链接创建者的类型 |
+
+
+user.name |
+string |
+链接创建者的名称 |
+
+
+user.login |
+string |
+链接创建者的标识 |
+
+
+user.image_url |
+string |
+链接创建者头像 |
+
+
+project.id |
+int |
+链接关联项目的id |
+
+
+project.identifier |
+string |
+链接关联项目的标识 |
+
+
+project.name |
+string |
+链接关联项目的名称 |
+
+
+project.description |
+string |
+链接关联项目的描述 |
+
+
+project.is_public |
+bool |
+链接关联项目是否公开 |
+
+
+project.owner.id |
+bool |
+链接关联项目拥有者id |
+
+
+project.owner.type |
+string |
+链接关联项目拥有者类型 |
+
+
+project.owner.name |
+string |
+链接关联项目拥有者昵称 |
+
+
+project.owner.login |
+string |
+链接关联项目拥有者标识 |
+
+
+project.owner.image_url |
+string |
+链接关联项目拥有者头像 |
+
+
+
+
+返回的JSON示例:
+
+{
+ "id": 7,
+ "role": "developer",
+ "is_apply": false,
+ "sign": "6b6b454843c291d4e52e60853cb8ad9f",
+ "user": {
+ "id": 2,
+ "type": "User",
+ "name": "heh",
+ "login": "yystopf",
+ "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
+ },
+ "project": {
+ "id": 474,
+ "identifier": "kellect",
+ "name": "kellect",
+ "description": null,
+ "is_public": true,
+ "owner": {
+ "id": 2,
+ "type": "User",
+ "name": "heh",
+ "login": "yystopf",
+ "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
+ }
+ }
+}
+
生成项目邀请链接
+当前登录(管理员)用户生成的项目邀请链接,可选role和is_apply参数
+
+
+示例:
+
+curl -X POST http://localhost:3000/api/yystopf/kellect/project_invite_links/generate_link.json
+
await octokit.request('POST /api/yystopf/kellect/project_invite_links/generate_link.json')
+
HTTP 请求
+POST /api/:owner/:repo/project_invite_links/generate_link.json
+请求参数
+
+
+参数 |
+必选 |
+默认 |
+类型 |
+字段说明 |
+
+
+
+role |
+是 |
+ |
+string |
+项目权限,reporter: 报告者, developer: 开发者,manager:管理员 |
+
+
+is_apply |
+是 |
+ |
+boolean |
+是否需要审核 |
+
+
+
+
+请求的JSON示例
+
+{
+ "role": "developer",
+ "is_apply": false
+}
+
返回字段说明
+
+
+参数 |
+类型 |
+字段说明 |
+
+
+
+id |
+int |
+链接id |
+
+
+role |
+string |
+邀请角色 |
+
+
+is_apply |
+boolean |
+是否需要审核 |
+
+
+sign |
+string |
+邀请标识(放在链接后面即可) |
+
+
+user.id |
+int |
+链接创建者的id |
+
+
+user.type |
+string |
+链接创建者的类型 |
+
+
+user.name |
+string |
+链接创建者的名称 |
+
+
+user.login |
+string |
+链接创建者的标识 |
+
+
+user.image_url |
+string |
+链接创建者头像 |
+
+
+project.id |
+int |
+链接关联项目的id |
+
+
+project.identifier |
+string |
+链接关联项目的标识 |
+
+
+project.name |
+string |
+链接关联项目的名称 |
+
+
+project.description |
+string |
+链接关联项目的描述 |
+
+
+project.is_public |
+bool |
+链接关联项目是否公开 |
+
+
+project.owner.id |
+bool |
+链接关联项目拥有者id |
+
+
+project.owner.type |
+string |
+链接关联项目拥有者类型 |
+
+
+project.owner.name |
+string |
+链接关联项目拥有者昵称 |
+
+
+project.owner.login |
+string |
+链接关联项目拥有者标识 |
+
+
+project.owner.image_url |
+string |
+链接关联项目拥有者头像 |
+
+
+
+
+返回的JSON示例:
+
+{
+ "id": 7,
+ "role": "developer",
+ "is_apply": false,
+ "sign": "6b6b454843c291d4e52e60853cb8ad9f",
+ "user": {
+ "id": 2,
+ "type": "User",
+ "name": "heh",
+ "login": "yystopf",
+ "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
+ },
+ "project": {
+ "id": 474,
+ "identifier": "kellect",
+ "name": "kellect",
+ "description": null,
+ "is_public": true,
+ "owner": {
+ "id": 2,
+ "type": "User",
+ "name": "heh",
+ "login": "yystopf",
+ "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
+ }
+ }
+}
+
请求项目邀请链接
+当前登录(非项目)用户加入项目的接口,如果项目链接不需要审核,请求成功后即加入项目,如果需要审核,那么会提交一个申请,需要项目管理员审核
+
+
+示例:
+
+curl -X POST http://localhost:3000/api/yystopf/kellect/project_invite_links/redirect_link.json?invite_sign=d612df03aad63760445c187bcf83f2e6
+
await octokit.request('POST /api/yystopf/kellect/project_invite_links/redirect_link.json?invite_sign=d612df03aad63760445c187bcf83f2e6')
+
HTTP 请求
+POST /api/:owner/:repo/project_invite_links/generate_link.json?invite_sign=xxx
+请求参数
+
+
+参数 |
+必选 |
+默认 |
+类型 |
+字段说明 |
+
+
+
+invite_sign |
+是 |
+ |
+string |
+项目邀请链接的标识 |
+
+
+
+
+返回的JSON示例:
+
+{
+ "status": 0,
+ "message": "success"
+}
+
申请加入项目
申请加入项目
@@ -4398,9 +4766,9 @@ Success — a happy kitten is an authenticated kitten!
curl -X POST http://localhost:3000/api/applied_projects.json
await octokit.request('POST /api/appliedr_projects.json')
-
HTTP 请求
+HTTP 请求
POST /api/applied_projects.json
-请求参数
+请求参数
参数 |
@@ -4435,7 +4803,7 @@ Success — a happy kitten is an authenticated kitten!
"role": "developer"
}
}
-返回字段说明
+返回字段说明
参数 |
@@ -4576,9 +4944,9 @@ Success — a happy kitten is an authenticated kitten!
-d "limit=5" \
http://localhost:3000/api/projects | jq
await octokit.request('GET /api/projects')
-
HTTP 请求
+HTTP 请求
GET api/projects
-请求参数
+请求参数
参数 |
@@ -4645,7 +5013,7 @@ http://localhost:3000/api/projects | jq
项目类型, 取值为:common、mirror; common:开源托管项目, mirror:开源镜像项目 |
-返回字段说明
+返回字段说明
参数 |
@@ -4797,9 +5165,9 @@ Remember — a happy kitten is an authenticated kitten!
curl -X GET \
http://localhost:3000/api/projects/recommend | jq
await octokit.request('GET /api/projects/recommend.json')
-
HTTP 请求
+HTTP 请求
GET api/projects/recommend
-返回字段说明
+返回字段说明
参数 |
@@ -4933,9 +5301,9 @@ Remember — a happy kitten is an authenticated kitten!
curl -X GET \
http://localhost:3000/api/yystopf/ceshi/menu_list | jq
await octokit.request('GET /api/yystopf/ceshi/menu_list')
-
HTTP 请求
+HTTP 请求
GET api/:owner/:repo/menu_list
-请求参数
+请求参数
参数 |
@@ -4960,7 +5328,7 @@ http://localhost:3000/api/yystopf/ceshi/menu_list | jq
项目标识identifier |
-返回字段说明
+返回字段说明
参数 |
@@ -5001,9 +5369,9 @@ http://localhost:3000/api/yystopf/ceshi/menu_list | jq
curl -X GET \
http://localhost:3000/api/jasder/forgeplus/about | jq
await octokit.request('GET /api/jasder/forgeplus/about')
-
HTTP 请求
+HTTP 请求
GET api/:owner/:repo/about
-请求参数
+请求参数
参数 |
@@ -5028,7 +5396,7 @@ http://localhost:3000/api/jasder/forgeplus/about | jq
项目标识identifier |
-返回字段说明
+返回字段说明
参数 |
@@ -5074,7 +5442,7 @@ Remember — a happy kitten is an authenticated kitten!
curl -X GET \
http://localhost:3000/api/yystopf/ceshi/project_units.json
await octokit.request('GET /api/yystopf/ceshi/project_units')
-
HTTP 请求
+HTTP 请求
GET /api/yystopf/ceshi/project_units
返回字段说明:
@@ -5117,9 +5485,9 @@ http://localhost:3000/api/yystopf/ceshi/project_units.json
-d "{ \"unit_typs\": [\"code\", \"pulls\"]}" \
http://localhost:3000/api/yystopf/ceshi/project_units.json
await octokit.request('POST /api/yystopf/ceshi/project_units')
-
HTTP 请求
+HTTP 请求
POST /api/yystopf/ceshi/project_units
-请求参数
+请求参数
参数 |
@@ -5181,9 +5549,9 @@ http://localhost:3000/api/yystopf/ceshi/project_units.json
-d "license_id=1" \
http://localhost:3000/api/projects.json
await octokit.request('GET /api/projects.json')
-
HTTP 请求
+HTTP 请求
POST api/projects
-请求参数
+请求参数
参数 |
@@ -5257,7 +5625,7 @@ http://localhost:3000/api/projects.json
项目是否私有, true:为私有,false: 公开,默认为公开 |
-返回字段说明
+返回字段说明
参数 |
@@ -5299,9 +5667,9 @@ http://localhost:3000/api/projects.json
-d "project_language_id=2" \
http://localhost:3000/api/projects/migrate.json
await octokit.request('GET /api/projects/migrate.json')
-
HTTP 请求
+HTTP 请求
POST api/projects/migrate.json
-请求参数
+请求参数
参数 |
@@ -5389,7 +5757,7 @@ http://localhost:3000/api/projects/migrate.json
项目是否私有, true:为私有,false: 非私有,默认为公开 |
-返回字段说明
+返回字段说明
参数 |
@@ -5424,9 +5792,9 @@ http://localhost:3000/api/projects/migrate.json
curl -X POST http://localhost:3000/api/repositories/1244/sync_mirror.json
await octokit.request('POST /api/repositories/1244/sync_mirror.json')
-
HTTP 请求
+HTTP 请求
POST api/repositories/:id/sync_mirror.json
-请求参数
+请求参数
参数 |
@@ -5444,7 +5812,7 @@ http://localhost:3000/api/projects/migrate.json
仓库id |
-返回字段说明
+返回字段说明
参数 |
@@ -5479,9 +5847,9 @@ http://localhost:3000/api/projects/migrate.json
curl -X POST http://localhost:3000/api/jasder/forgeplus/forks.json
await octokit.request('POST /api/jaser/jasder_test/forks.json')
-
HTTP 请求
+HTTP 请求
POST api/:owner/:repo/forks.json
-请求参数
+请求参数
参数 |
@@ -5506,7 +5874,7 @@ http://localhost:3000/api/projects/migrate.json
项目标识identifier |
-返回字段说明
+返回字段说明
参数 |
@@ -5542,9 +5910,9 @@ http://localhost:3000/api/projects/migrate.json
curl -X GET \
http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizations.json | jq
await octokit.request('GET /api/:owner/:repo/applied_transfer_projects/organizations')
-
HTTP 请求
+HTTP 请求
GET api/:owner/:repo/applied_transfer_projects/organizations
-请求参数
+请求参数
参数 |
@@ -5569,7 +5937,7 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
项目标识identifier |
-返回字段说明
+返回字段说明
参数 |
@@ -5636,9 +6004,9 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
curl -X POST http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects.json
await octokit.request('POST /api/:owner/:repo/applied_transfer_projects.json')
-
HTTP 请求
+HTTP 请求
POST /api/:owner/:repo/applied_transfer_projects.json
-请求参数
+请求参数
参数 |
@@ -5670,7 +6038,7 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
迁移对象标识 |
-返回字段说明
+返回字段说明
参数 |
@@ -5840,9 +6208,9 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
curl -X POST http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/cancel.json
await octokit.request('POST /api/:owner/:repo/applied_transfer_projects/cancel.json')
-
HTTP 请求
+HTTP 请求
POST /api/:owner/:repo/applied_transfer_projects/cancel.json
-请求参数
+请求参数
参数 |
@@ -5867,7 +6235,7 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
项目标识identifier |
-返回字段说明
+返回字段说明
参数 |
@@ -6037,9 +6405,9 @@ http://localhost:3000/api/ceshi1/ceshi_repo1/applied_transfer_projects/organizat
curl -X POST http://localhost:3000/api/ceshi1/ceshi_repo1/quit.json
await octokit.request('POST /api/:owner/:repo/quit.json')
-
HTTP 请求
+HTTP 请求
POST /api/:owner/:repo/quit.json
-请求参数
+请求参数