| @@ -4058,6 +4058,77 @@ 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:不是| | |||
| |attachment |object|上传附件| | |||
| |--filename |string|附件名称| | |||
| |--path |string|附件地址| | |||
| 返回值 | |||
| ```json | |||
| { | |||
| "total_count": 1, | |||
| "apply_signatures": [ | |||
| { | |||
| "id": 18, | |||
| "status": "passed", | |||
| "user": { | |||
| "id": 3, | |||
| "name": "16895620", | |||
| "login": "16895620", | |||
| "image_url": "avatars/User/boy.jpg", | |||
| "email": "2456233122@qq.com", | |||
| "is_owner": false | |||
| }, | |||
| "attachment": { | |||
| "filename": "PHengLEI软件开源协议.docx", | |||
| "path": "/api/attachments/23" | |||
| } | |||
| } | |||
| ] | |||
| } | |||
| ``` | |||
| --- | |||
| #### 特殊许可证项目用户创建申请 | |||
| ``` | |||
| POST /api/apply_signatures | |||
| @@ -4095,4 +4166,43 @@ http://localhost:3000/api/apply_signatures.json | jq | |||
| } | |||
| } | |||
| ``` | |||
| --- | |||
| #### 特殊许可证项目申请修改 | |||
| ``` | |||
| PATCH /api/apply_signatures/:id | |||
| ``` | |||
| *示例* | |||
| ```bash | |||
| curl -X POST \ | |||
| -d "id=18" \ | |||
| -d "status=passed" \ | |||
| -d "project_id=36" \ | |||
| http://localhost:3000/api/apply_signatures/18 | jq | |||
| ``` | |||
| *请求参数说明:* | |||
| |参数名|必选|类型|说明| | |||
| |-|-|-|-| | |||
| |id |是|int |特殊许可证项目申请id | | |||
| |status |是|string |特殊许可证项目申请状态 ,'unpassed': 审核未通过,'waiting': 等待审核 'passed':审核通过| | |||
| |project_id |是|int |项目id| | |||
| *返回参数说明:* | |||
| |参数名|类型|说明| | |||
| |-|-|-| | |||
| |status |int |0:添加成功, -1: 更改失败, 1: 表示已经是该状态了 | | |||
| |message |string|返回信息说明| | |||
| 返回值 | |||
| ```json | |||
| { | |||
| "status": 0, | |||
| "message": "success" | |||
| } | |||
| ``` | |||
| --- | |||
| @@ -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, users.nickname)) LIKE ?", "%#{search.split(" ").join('|')}%") | |||
| @apply_signatures = kaminari_paginate(@apply_signatures) | |||
| end | |||
| def template_file | |||
| license = License.find_by_name("PHengLEI") | |||
| @@ -11,9 +20,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}") | |||
| @@ -22,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, "all") | |||
| end | |||
| def require_owner | |||
| normal_status(403, "") unless @project.owner?(current_user) | |||
| end | |||
| end | |||
| @@ -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 | |||
| @@ -22,6 +22,9 @@ 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? && status != "all"} | |||
| validates :project_id, uniqueness: {scope: :user_id} | |||
| enum status: {unpassed: -1, waiting: 0, passed: 1} | |||
| end | |||
| @@ -22,7 +22,7 @@ | |||
| <td> | |||
| <% 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 %> | |||
| @@ -0,0 +1,19 @@ | |||
| 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 | |||
| if signature.attachments.present? | |||
| attachment = signature.attachments.take | |||
| json.attachment do | |||
| json.filename attachment.filename | |||
| json.path attachment_path(attachment) | |||
| end | |||
| end | |||
| end | |||
| @@ -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 | |||
| @@ -0,0 +1 @@ | |||
| Subproject commit 6348a15cdb954862dc1b7b5f045a432bcfde7dc4 | |||