From aaa6483958092ca400a88754c1771aeb7ba03862 Mon Sep 17 00:00:00 2001 From: viletyy Date: Thu, 31 Dec 2020 14:02:37 +0800 Subject: [PATCH 1/6] =?UTF-8?q?[FIX]=E5=87=A0=E5=A4=84bug=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/apply_signatures_controller.rb | 5 ++++- app/models/apply_signature.rb | 2 ++ app/views/admins/apply_signatures/shared/_list.html.erb | 2 +- public/react/build | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) create mode 160000 public/react/build diff --git a/app/controllers/apply_signatures_controller.rb b/app/controllers/apply_signatures_controller.rb index 54f64aa6..19907b11 100644 --- a/app/controllers/apply_signatures_controller.rb +++ b/app/controllers/apply_signatures_controller.rb @@ -11,9 +11,12 @@ class ApplySignaturesController < ApplicationController def create ActiveRecord::Base.transaction do begin - @signature = current_user.apply_signatures.create!(project_id: params[:project_id]) + @signature = current_user.apply_signatures.find_or_create_by!(project_id: params[:project_id]) + @signature.status = 0 + @signature.attachments = Attachment.none @attachment = Attachment.find_by_id(params[:attachment_id]) @attachment.container = @signature + @signature.save! @attachment.save! rescue Exception => e tip_exception("#{e}") diff --git a/app/models/apply_signature.rb b/app/models/apply_signature.rb index f6f7bfc3..d14283f7 100644 --- a/app/models/apply_signature.rb +++ b/app/models/apply_signature.rb @@ -23,5 +23,7 @@ class ApplySignature < ApplicationRecord scope :with_user_id, -> (user_id) {where(user_id: user_id)} + validates :project_id, uniqueness: {scope: :user_id} + enum status: {unpassed: -1, waiting: 0, passed: 1} end diff --git a/app/views/admins/apply_signatures/shared/_list.html.erb b/app/views/admins/apply_signatures/shared/_list.html.erb index ec028b30..36984aa9 100644 --- a/app/views/admins/apply_signatures/shared/_list.html.erb +++ b/app/views/admins/apply_signatures/shared/_list.html.erb @@ -22,7 +22,7 @@ <% if signature.attachments.present? %> <% signature.attachments.each do |attachment|%> - <%= image_tag("/api/attachments/#{attachment.id}", width: 40, height: 40, class: 'preview-image auth-image', data: { toggle: 'tooltip', title: '点击预览' }) %> + <%= link_to "#{attachment.try(:filename)}",attachment_path(attachment), target: "_blank" %> <% end %> <% end %> diff --git a/public/react/build b/public/react/build new file mode 160000 index 00000000..6348a15c --- /dev/null +++ b/public/react/build @@ -0,0 +1 @@ +Subproject commit 6348a15cdb954862dc1b7b5f045a432bcfde7dc4 From a0721623244ac6503b3237e97c037332d323407b Mon Sep 17 00:00:00 2001 From: viletyy Date: Mon, 4 Jan 2021 12:26:58 +0800 Subject: [PATCH 2/6] =?UTF-8?q?[ADD]=E9=A1=B9=E7=9B=AE=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E8=80=85=E5=AE=A1=E6=A0=B8=E7=94=B3=E8=AF=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api_document.md | 100 ++++++++++++++++++ .../apply_signatures_controller.rb | 50 +++++++++ app/models/apply_signature.rb | 1 + .../apply_signatures/index.json.jbuilder | 12 +++ config/routes.rb | 2 +- 5 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 app/views/apply_signatures/index.json.jbuilder diff --git a/api_document.md b/api_document.md index 2cbb2431..a27f9a14 100644 --- a/api_document.md +++ b/api_document.md @@ -4058,6 +4058,70 @@ http://localhost:3000/api/users/Jason/projects.json | jq } ``` --- + +#### 特殊许可证项目申请列表 +``` +GET /api/apply_signatures +``` +*示例* +```bash +curl -X GET \ +-d "project_id=36" \ +-d "page=1" \ +-d "limit=5" \ +-d "search=16895620" \ +-d "status=waiting" \ +http://localhost:3000/api/apply_signatures | jq +``` +*请求参数说明:* + +|参数名|必选|类型|说明| +|-|-|-|-| +|project_id |是|int |项目id | +|page |否|string |页数,第几页 | +|limit |否|string |每页多少条数据,默认15条 | +|search |否|string |用户名、登录名匹配搜索 | +|status |否|string |状态匹配搜索,'unpassed': 审核未通过,'waiting': 等待审核 'passed':审核通过 | + + +*返回参数说明:* + +|参数名|类型|说明| +|-|-|-| +|total_count |int |返回记录总条数 | +|apply_signatures |array|特殊许可证项目申请信息| +|-- id |int|特殊许可证项目申请id| +|-- status |int|特殊许可证项目申请状态,'unpassed': 审核未通过,'waiting': 等待审核 'passed':审核通过| +|user |object|用户| +|-- id |int|用户id| +|-- name |string|用户名称| +|-- login |string|用户登录名/标识| +|-- image_url |string|用户头像| +|-- email |string|用户邮箱| +|-- is_owner |boolean|是否是项目的拥有者,true:是, false:不是| + + +返回值 +```json +{ + "total_count": 1, + "apply_signatures": [ + { + "id": 18, + "status": "waiting", + "user": { + "id": 3, + "name": "16895620", + "login": "16895620", + "image_url": "avatars/User/boy.jpg", + "email": "2456233122@qq.com", + "is_owner": false + } + } + ] +} +``` +--- #### 特殊许可证项目用户创建申请 ``` POST /api/apply_signatures @@ -4095,4 +4159,40 @@ http://localhost:3000/api/apply_signatures.json | jq } } ``` +--- +#### 特殊许可证项目申请修改 +``` +PATCH /api/apply_signatures/:id +``` + +*示例* +```bash +curl -X POST \ +-d "id=18" \ +-d "status=passed" \ +http://localhost:3000/api/apply_signatures/18 | jq +``` + +*请求参数说明:* + +|参数名|必选|类型|说明| +|-|-|-|-| +|id |是|int |特殊许可证项目申请id | +|status |是|string |特殊许可证项目申请状态 ,'unpassed': 审核未通过,'waiting': 等待审核 'passed':审核通过| + +*返回参数说明:* + +|参数名|类型|说明| +|-|-|-| +|status |int |0:添加成功, -1: 更改失败, 1: 表示已经是该状态了 | +|message |string|返回信息说明| + + +返回值 +```json +{ + "status": 0, + "message": "success" +} +``` --- \ No newline at end of file diff --git a/app/controllers/apply_signatures_controller.rb b/app/controllers/apply_signatures_controller.rb index 19907b11..899e7c23 100644 --- a/app/controllers/apply_signatures_controller.rb +++ b/app/controllers/apply_signatures_controller.rb @@ -1,5 +1,14 @@ class ApplySignaturesController < ApplicationController include ApplicationHelper + before_action :find_project, only: [:index, :create, :update] + before_action :require_owner, only: [:update] + before_action :find_apply_signature, only: [:update] + + def index + @apply_signatures = @project.apply_signatures.with_status(status).includes(user: :user_extension) + @apply_signatures = @apply_signatures.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail)) LIKE ?", "%#{search.split(" ").join('|')}%") + @apply_signatures = kaminari_paginate(@apply_signatures) + end def template_file license = License.find_by_name("PHengLEI") @@ -25,4 +34,45 @@ class ApplySignaturesController < ApplicationController render_json end end + + def update + @apply_signature.update_attributes!(apply_signature_params) + if @apply_signature.status == "passed" + Projects::AddMemberInteractor.call(@apply_signature.project.owner, @apply_signature.project, @apply_signature.user, "read", true) + else + Projects::DeleteMemberInteractor.call(@apply_signature.project.owner, @apply_signature.project, @apply_signature.user) + end + render_ok + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + end + + private + def find_project + @project = Project.find_by_id(params[:project_id]) + normal_status(-1, "项目不存在") unless @project.present? + end + + def find_apply_signature + @apply_signature = ApplySignature.find_by_id(params[:id]) + normal_status(-1, "特殊许可申请不存在") unless @apply_signature.present? + normal_status(1, "已经是该状态了") if @apply_signature.status == params[:status] + end + + def apply_signature_params + params.permit(:status) + end + + def search + params.fetch(:search, "").to_s.downcase + end + + def status + params.fetch(:status, "waiting") + end + + def require_owner + normal_status(403, "") unless @project.owner?(current_user) + end end \ No newline at end of file diff --git a/app/models/apply_signature.rb b/app/models/apply_signature.rb index d14283f7..ea748cd4 100644 --- a/app/models/apply_signature.rb +++ b/app/models/apply_signature.rb @@ -22,6 +22,7 @@ class ApplySignature < ApplicationRecord has_many :attachments, as: :container, dependent: :destroy scope :with_user_id, -> (user_id) {where(user_id: user_id)} + scope :with_status, -> (status) {where(status: status) if status.present?} validates :project_id, uniqueness: {scope: :user_id} diff --git a/app/views/apply_signatures/index.json.jbuilder b/app/views/apply_signatures/index.json.jbuilder new file mode 100644 index 00000000..5d12f12b --- /dev/null +++ b/app/views/apply_signatures/index.json.jbuilder @@ -0,0 +1,12 @@ +json.total_count @apply_signatures.total_count +json.apply_signatures @apply_signatures do |signature| + json.id signature.id + json.status signature.status + + if signature.user.present? + json.user do + json.partial! 'members/member', user: signature.user + json.is_owner @project.owner?(signature.user) + end + end +end diff --git a/config/routes.rb b/config/routes.rb index 0bca7da2..97911174 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -59,7 +59,7 @@ Rails.application.routes.draw do delete :destroy_files end end - resources :apply_signatures, only: [:create] do + resources :apply_signatures, only: [:index, :create, :update] do collection do get :template_file end From 9b687f7885f6ecc72a63c701dacec1277609e5aa Mon Sep 17 00:00:00 2001 From: viletyy Date: Mon, 4 Jan 2021 15:22:03 +0800 Subject: [PATCH 3/6] [FIX] --- api_document.md | 3 +++ app/controllers/apply_signatures_controller.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/api_document.md b/api_document.md index a27f9a14..a6f1172c 100644 --- a/api_document.md +++ b/api_document.md @@ -4170,6 +4170,7 @@ PATCH /api/apply_signatures/:id curl -X POST \ -d "id=18" \ -d "status=passed" \ +-d "project_id=36" \ http://localhost:3000/api/apply_signatures/18 | jq ``` @@ -4179,6 +4180,8 @@ http://localhost:3000/api/apply_signatures/18 | jq |-|-|-|-| |id |是|int |特殊许可证项目申请id | |status |是|string |特殊许可证项目申请状态 ,'unpassed': 审核未通过,'waiting': 等待审核 'passed':审核通过| +|project_id |是|int |项目id| + *返回参数说明:* diff --git a/app/controllers/apply_signatures_controller.rb b/app/controllers/apply_signatures_controller.rb index 899e7c23..d2d3c044 100644 --- a/app/controllers/apply_signatures_controller.rb +++ b/app/controllers/apply_signatures_controller.rb @@ -69,7 +69,7 @@ class ApplySignaturesController < ApplicationController end def status - params.fetch(:status, "waiting") + params.fetch(:status, "") end def require_owner From bf91c5e3823aa94efd73ce02dc7a03727a8448bd Mon Sep 17 00:00:00 2001 From: viletyy Date: Mon, 4 Jan 2021 15:32:44 +0800 Subject: [PATCH 4/6] [FIX] --- api_document.md | 9 ++++++++- app/views/apply_signatures/index.json.jbuilder | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/api_document.md b/api_document.md index a6f1172c..e667cb17 100644 --- a/api_document.md +++ b/api_document.md @@ -4099,6 +4099,9 @@ http://localhost:3000/api/apply_signatures | jq |-- image_url |string|用户头像| |-- email |string|用户邮箱| |-- is_owner |boolean|是否是项目的拥有者,true:是, false:不是| +|attachment |object|上传附件| +|--filename |string|附件名称| +|--path |string|附件地址| 返回值 @@ -4108,7 +4111,7 @@ http://localhost:3000/api/apply_signatures | jq "apply_signatures": [ { "id": 18, - "status": "waiting", + "status": "passed", "user": { "id": 3, "name": "16895620", @@ -4116,6 +4119,10 @@ http://localhost:3000/api/apply_signatures | jq "image_url": "avatars/User/boy.jpg", "email": "2456233122@qq.com", "is_owner": false + }, + "attachment": { + "filename": "PHengLEI软件开源协议.docx", + "path": "/api/attachments/23" } } ] diff --git a/app/views/apply_signatures/index.json.jbuilder b/app/views/apply_signatures/index.json.jbuilder index 5d12f12b..b93902a2 100644 --- a/app/views/apply_signatures/index.json.jbuilder +++ b/app/views/apply_signatures/index.json.jbuilder @@ -9,4 +9,11 @@ json.apply_signatures @apply_signatures do |signature| json.is_owner @project.owner?(signature.user) end end + if signature.attachments.present? + attachment = signature.attachments.take + json.attachment do + json.filename attachment.filename + json.path attachment_path(attachment) + end + end end From ef327f2994ce294fb8de489c221a3ca44202cd4b Mon Sep 17 00:00:00 2001 From: viletyy Date: Mon, 4 Jan 2021 16:19:11 +0800 Subject: [PATCH 5/6] [FIX] --- app/controllers/apply_signatures_controller.rb | 2 +- app/controllers/members_controller.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/apply_signatures_controller.rb b/app/controllers/apply_signatures_controller.rb index d2d3c044..81750a27 100644 --- a/app/controllers/apply_signatures_controller.rb +++ b/app/controllers/apply_signatures_controller.rb @@ -6,7 +6,7 @@ class ApplySignaturesController < ApplicationController def index @apply_signatures = @project.apply_signatures.with_status(status).includes(user: :user_extension) - @apply_signatures = @apply_signatures.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail)) LIKE ?", "%#{search.split(" ").join('|')}%") + @apply_signatures = @apply_signatures.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") @apply_signatures = kaminari_paginate(@apply_signatures) end diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 2964eb1a..b8c0ea54 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -18,7 +18,7 @@ class MembersController < ApplicationController scope = @project.members.includes(:roles, user: :user_extension) search = params[:search].to_s.downcase role = params[:role].to_s - scope = scope.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present? + scope = scope.joins(:user).where("LOWER(concat(users.lastname, users.firstname, users.login, users.mail, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") if search.present? scope = scope.joins(:roles).where("roles.name LIKE ?", "%#{role}%") if role.present? @total_count = scope.size From cfa14fff9d1704ab52820fbbb0a3642dbd0571d0 Mon Sep 17 00:00:00 2001 From: viletyy Date: Mon, 4 Jan 2021 17:52:05 +0800 Subject: [PATCH 6/6] [FIX] --- app/controllers/apply_signatures_controller.rb | 2 +- app/models/apply_signature.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/apply_signatures_controller.rb b/app/controllers/apply_signatures_controller.rb index 81750a27..885249cf 100644 --- a/app/controllers/apply_signatures_controller.rb +++ b/app/controllers/apply_signatures_controller.rb @@ -69,7 +69,7 @@ class ApplySignaturesController < ApplicationController end def status - params.fetch(:status, "") + params.fetch(:status, "all") end def require_owner diff --git a/app/models/apply_signature.rb b/app/models/apply_signature.rb index ea748cd4..937b601e 100644 --- a/app/models/apply_signature.rb +++ b/app/models/apply_signature.rb @@ -22,7 +22,7 @@ class ApplySignature < ApplicationRecord has_many :attachments, as: :container, dependent: :destroy scope :with_user_id, -> (user_id) {where(user_id: user_id)} - scope :with_status, -> (status) {where(status: status) if status.present?} + scope :with_status, -> (status) {where(status: status) if status.present? && status != "all"} validates :project_id, uniqueness: {scope: :user_id}