Browse Source

Merge branch 'dev_military_license' of http://git.trustie.net/jasder/forgeplus into dev_military_license

pull/278/head
Jasder 5 years ago
parent
commit
43b4907565
30 changed files with 393 additions and 143 deletions
  1. +95
    -13
      api_document.md
  2. +30
    -0
      app/controllers/admins/apply_signatures_controller.rb
  3. +25
    -0
      app/controllers/apply_signatures_controller.rb
  4. +3
    -3
      app/controllers/projects_controller.rb
  5. +10
    -9
      app/interactors/projects/add_member_interactor.rb
  6. +10
    -0
      app/models/apply_signature.rb
  7. +2
    -2
      app/models/concerns/project_operable.rb
  8. +2
    -0
      app/models/license.rb
  9. +74
    -70
      app/models/project.rb
  10. +1
    -0
      app/models/user.rb
  11. +1
    -1
      app/queries/projects/list_query.rb
  12. +6
    -1
      app/services/projects/create_service.rb
  13. +7
    -0
      app/views/admins/apply_signatures/index.html.erb
  14. +42
    -0
      app/views/admins/apply_signatures/shared/_list.html.erb
  15. +3
    -1
      app/views/admins/projects/shared/_list.html.erb
  16. +2
    -0
      app/views/admins/shared/_sidebar.html.erb
  17. +4
    -0
      app/views/apply_signatures/create.json.jbuilder
  18. +1
    -1
      app/views/licenses/index.json.jbuilder
  19. +1
    -0
      app/views/members/index.json.jbuilder
  20. +4
    -17
      app/views/project_categories/group_list.json.jbuilder
  21. +22
    -7
      app/views/projects/_project_detail.json.jbuilder
  22. +6
    -0
      app/views/projects/index.json.jbuilder
  23. +6
    -0
      app/views/projects/show.json.jbuilder
  24. +1
    -0
      app/views/repositories/edit.json.jbuilder
  25. +6
    -0
      app/views/repositories/show.json.jbuilder
  26. +7
    -1
      config/routes.rb
  27. +0
    -17
      db/migrate/20200927023922_reset_versions_count.rb
  28. +11
    -0
      db/migrate/20201225064324_create_apply_signatures.rb
  29. +6
    -0
      db/migrate/20201225065222_add_some_columns_about_apply_signatures.rb
  30. +5
    -0
      spec/models/apply_signature_spec.rb

+ 95
- 13
api_document.md View File

@@ -286,6 +286,7 @@ http://localhost:3000/api/licenses/ | jq
|licenses|array |返回数据|
|-- id |int |id |
|-- name |string|开源许可证名称|
|-- is_secret |string|是否为特殊许可证|


返回值
@@ -294,23 +295,33 @@ http://localhost:3000/api/licenses/ | jq
"licenses": [
{
"id": 57,
"name": "AFL-1.2"
"name": "AFL-1.2",
"is_secret": false
},
{
"id": 76,
"name": "AFL-3.0"
"name": "AFL-3.0",
"is_secret": false
},
{
"id": 214,
"name": "AFL-1.1"
"name": "AFL-1.1",
"is_secret": false
},
{
"id": 326,
"name": "AFL-2.1"
"name": "AFL-2.1",
"is_secret": false
},
{
"id": 350,
"name": "AFL-2.0"
"name": "AFL-2.0",
"is_secret": false
},
{
"id": 359,
"name": "PHengLEI",
"is_secret": true
}
]
}
@@ -555,6 +566,8 @@ curl -X GET http://localhost:3000/api/repositories/:id/edit.json | jq
|project_category_id |int|项目类别id|
|project_language_id |int|项目语言id|
|private |boolean|项目是否私有, true:为私有,false: 公开 |
|is_secret |boolean|项目是否为特殊协议项目, true:是,false: 否 |



返回值
@@ -567,7 +580,8 @@ curl -X GET http://localhost:3000/api/repositories/:id/edit.json | jq
"project_description": "my first project mirror_demo",
"project_category_id": 1,
"project_language_id": 2,
"private": false
"private": false,
"is_secret": true
}
```
---
@@ -1146,6 +1160,7 @@ http://localhost:3000/api/projects | jq
|forked_count |int|被fork的数量|
|praises_count |int|star数量|
|is_public |boolean|是否公开, true:公开,false:未公开|
|is_secret |boolean|是否为特殊许可证项目, true:是,false:否|
|mirror_url |string|镜像url|
|last_update_time|int|最后更新时间,为UNIX格式的时间戳|
|author |object|项目创建者|
@@ -1156,6 +1171,10 @@ http://localhost:3000/api/projects | jq
|language |object|项目语言|
|-- id |int|项目语言id|
|-- name |string|项目语言名称|
|user_apply_signatures |object|用户创建的特殊许可申请|
|-- id |int|用户创建的特殊许可申请id|
|-- status |int|用户创建的特殊许可申请审核状态, 'unpassed': 审核未通过,'waiting': 等待审核 'passed':审核通过|



返回值
@@ -1171,6 +1190,7 @@ http://localhost:3000/api/projects | jq
"praises_count": 0,
"forked_count": 0,
"is_public": true,
"is_secret": true,
"mirror_url": null,
"last_update_time": 1577697461,
"author": {
@@ -1184,7 +1204,13 @@ http://localhost:3000/api/projects | jq
"language": {
"id": 2,
"name": "C"
}
},
"user_apply_signatures":[
{
"id": 1,
"status": "waiting"
}
]
},
{
"id": 2,
@@ -1194,6 +1220,7 @@ http://localhost:3000/api/projects | jq
"praises_count": 0,
"forked_count": 0,
"is_public": true,
"is_secret": false,
"mirror_url": null,
"last_update_time": 1577697403,
"author": {
@@ -1207,7 +1234,8 @@ http://localhost:3000/api/projects | jq
"language": {
"id": 2,
"name": "C"
}
},
"user_apply_signatures":[]
},
{
"id": 3,
@@ -1217,6 +1245,7 @@ http://localhost:3000/api/projects | jq
"praises_count": 0,
"forked_count": 0,
"is_public": true,
"is_secret": true,
"mirror_url": null,
"last_update_time": 1577415173,
"author": {
@@ -1230,7 +1259,8 @@ http://localhost:3000/api/projects | jq
"language": {
"id": 2,
"name": "C"
}
},
"user_apply_signatures":[]
},
{
"id": 5,
@@ -1240,6 +1270,7 @@ http://localhost:3000/api/projects | jq
"praises_count": 0,
"forked_count": 0,
"is_public": false,
"is_secret": true,
"mirror_url": "https://gitea.com/CasperVector/slew.git",
"last_update_time": 1577346228,
"author": {
@@ -1253,7 +1284,8 @@ http://localhost:3000/api/projects | jq
"language": {
"id": 2,
"name": "C"
}
},
"user_apply_signatures":[]
},
{
"id": 7,
@@ -1263,6 +1295,7 @@ http://localhost:3000/api/projects | jq
"praises_count": 0,
"forked_count": 0,
"is_public": true,
"is_secret": true,
"mirror_url": null,
"last_update_time": 1577341572,
"author": {
@@ -1276,7 +1309,8 @@ http://localhost:3000/api/projects | jq
"language": {
"id": 2,
"name": "C"
}
},
"user_apply_signatures":[]
}
]
}
@@ -3970,6 +4004,7 @@ http://localhost:3000/api/users/Jason/projects.json | jq
|forked_count |int|被fork的数量|
|praises_count |int|star数量|
|is_public |boolean|是否公开, true:公开,false:未公开|
|is_secret |boolean|是否为特殊许可证项目, true:是,false:否|
|mirror_url |string|镜像url|
|last_update_time|int|最后更新时间,为UNIX格式的时间戳|
|author |object|项目创建者|
@@ -3980,7 +4015,9 @@ http://localhost:3000/api/users/Jason/projects.json | jq
|language |object|项目语言|
|-- id |int|项目语言id|
|-- name |string|项目语言名称|

|user_apply_signatures |object|用户创建的特殊许可申请|
|-- id |int|用户创建的特殊许可申请id|
|-- status |int|用户创建的特殊许可申请审核状态, 'unpassed': 审核未通过,'waiting': 等待审核 'passed':审核通过|

返回值
```json
@@ -3995,6 +4032,7 @@ http://localhost:3000/api/users/Jason/projects.json | jq
"praises_count": 0,
"forked_count": 0,
"is_public": true,
"is_secret": false,
"mirror_url": null,
"last_update_time": 1577697461,
"author": {
@@ -4008,9 +4046,53 @@ http://localhost:3000/api/users/Jason/projects.json | jq
"language": {
"id": 2,
"name": "C"
}
},
"user_apply_signatures":[
{
"id": 1,
"status": "waiting"
}
]
}
]
}
```
---
#### 特殊许可证项目用户创建申请
```
POST /api/apply_signatures
```

*示例*
```bash
curl -X POST \
-d "project_id=8" \
-d "attachment_id=4" \
http://localhost:3000/api/apply_signatures.json | jq
```

*请求参数说明:*

|参数名|必选|类型|说明|
|-|-|-|-|
|project_id |是|int |项目id |
|attachment_id |是|int |上传的文件id |

*返回参数说明:*

|参数名|类型|说明|
|-|-|-|
|id |int|特殊许可证项目用户创建申请的id|
|attachment |object|上传的文件|
|--filename |string|上传的文件的文件名|

返回值
```json
{
"id": 5,
"attachment": {
"filename": "timg.jpeg"
}
}
```
---

+ 30
- 0
app/controllers/admins/apply_signatures_controller.rb View File

@@ -0,0 +1,30 @@
class Admins::ApplySignaturesController < Admins::BaseController

def index
sort_by = params[:sort_by] ||= 'created_on'
sort_direction = params[:sort_direction] ||= 'desc'
@apply_signatures = paginate ApplySignature.waiting.includes(:attachments)
end
def update
ActiveRecord::Base.transaction do
begin
apply_signature = ApplySignature.find_by!(id: params[:id])
apply_signature.update_attributes!(apply_signatures_params)
Projects::AddMemberInteractor.call(apply_signature.project.owner, apply_signature.project, apply_signature.user, "write", true)
redirect_to admins_apply_signatures_path
flash[:success] = "更新成功"
rescue => e
raise ActiveRecord::Rollback
redirect_to admins_apply_signatures_path
flash[:danger] = "更新失败"
end
end
end

private
def apply_signatures_params
params.permit(:status)
end
end

+ 25
- 0
app/controllers/apply_signatures_controller.rb View File

@@ -0,0 +1,25 @@
class ApplySignaturesController < ApplicationController
include ApplicationHelper

def template_file
license = License.find_by_name("PHengLEI")
file = license.attachments.take
normal_status(-1, "文件不存在") if file.blank?
send_file(absolute_path(local_path(file)), filename: file.title,stream:false, type: file.content_type.presence || 'application/octet-stream')
end

def create
ActiveRecord::Base.transaction do
begin
@signature = current_user.apply_signatures.create!(project_id: params[:project_id])
@attachment = Attachment.find_by_id(params[:attachment_id])
@attachment.container = @signature
@attachment.save!
rescue Exception => e
tip_exception("#{e}")
raise ActiveRecord::Rollback
end
render_json
end
end
end

+ 3
- 3
app/controllers/projects_controller.rb View File

@@ -11,7 +11,7 @@ class ProjectsController < ApplicationController
scope = Projects::ListQuery.call(params)

# @projects = kaminari_paginate(scope)
@projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, owner: :user_extension)
@projects = paginate scope.includes(:project_category, :project_language, :repository, :project_educoder, :apply_signatures, owner: :user_extension)

category_id = params[:category_id]
@total_count =
@@ -53,7 +53,7 @@ class ProjectsController < ApplicationController
# else
# projects = Project.visible
# end
projects = Project.no_anomory_projects.visible
projects = Project.no_anomory_projects.secret_and_visible
language_lists = projects.joins(:project_language).group("project_languages.name", "project_languages.id").size.keys.sort.to_h
@project_group_list = language_lists.delete_if { |k, v| k.blank? }
end
@@ -153,7 +153,7 @@ class ProjectsController < ApplicationController
private
def project_params
params.permit(:user_id, :name, :description, :repository_name,
:project_category_id, :project_language_id, :license_id, :ignore_id)
:project_category_id, :project_language_id, :license_id, :ignore_id, :private)
end

def mirror_params


+ 10
- 9
app/interactors/projects/add_member_interactor.rb View File

@@ -1,18 +1,19 @@
module Projects
class AddMemberInteractor
def self.call(owner, project, collaborator, permission="write")
interactor = new(owner, project, collaborator, permission)
def self.call(owner, project, collaborator, permission="write", is_apply_signature=false)
interactor = new(owner, project, collaborator, permission, is_apply_signature)
interactor.run
interactor
end

attr_reader :error, :result

def initialize(owner, project, collaborator, permission)
@owner = owner
@project = project
@collaborator = collaborator
@permission = permission
def initialize(owner, project, collaborator, permission, is_apply_signature)
@owner = owner
@project = project
@collaborator = collaborator
@permission = permission
@is_apply_signature = is_apply_signature
end

def success?
@@ -23,7 +24,7 @@ module Projects
ActiveRecord::Base.transaction do
gitea_result = Gitea::Repository::Members::AddService.new(owner, project.identifier, collaborator.login, permission).call
if gitea_result.status == 204
project.add_member!(collaborator.id)
project.add_member!(collaborator.id, 'Developer', is_apply_signature)
end
fail!(nil)
end
@@ -32,7 +33,7 @@ module Projects
end

private
attr_reader :owner, :project, :collaborator, :permission
attr_reader :owner, :project, :collaborator, :permission, :is_apply_signature

def fail!(error)
@error = error


+ 10
- 0
app/models/apply_signature.rb View File

@@ -0,0 +1,10 @@
class ApplySignature < ApplicationRecord
belongs_to :user
belongs_to :project

has_many :attachments, as: :container, dependent: :destroy

scope :with_user_id, -> (user_id) {where(user_id: user_id)}

enum status: {unpassed: -1, waiting: 0, passed: 1}
end

+ 2
- 2
app/models/concerns/project_operable.rb View File

@@ -10,8 +10,8 @@ module ProjectOperable
has_many :writable_members, -> { joins(:roles).where.not(roles: {name: 'Reporter'}) }, class_name: 'Member'
end

def add_member!(user_id, role_name='Developer')
member = members.create!(user_id: user_id)
def add_member!(user_id, role_name='Developer', is_apply_signature=false)
member = members.create!(user_id: user_id, is_apply_signature: is_apply_signature)
set_developer_role(member)
end



+ 2
- 0
app/models/license.rb View File

@@ -11,4 +11,6 @@

class License < ApplicationRecord
include Projectable
has_many :attachments, as: :container, dependent: :destroy

end

+ 74
- 70
app/models/project.rb View File

@@ -1,73 +1,73 @@
# == Schema Information
#
# Table name: projects
#
# id :integer not null, primary key
# name :string(255) default(""), not null
# description :text(4294967295)
# homepage :string(255) default("")
# is_public :boolean default("1"), not null
# parent_id :integer
# created_on :datetime
# updated_on :datetime
# identifier :string(255)
# status :integer default("1"), not null
# lft :integer
# rgt :integer
# inherit_members :boolean default("0"), not null
# project_type :integer default("0")
# hidden_repo :boolean default("0"), not null
# attachmenttype :integer default("1")
# user_id :integer
# dts_test :integer default("0")
# enterprise_name :string(255)
# organization_id :integer
# project_new_type :integer
# gpid :integer
# forked_from_project_id :integer
# forked_count :integer default("0")
# publish_resource :integer default("0")
# visits :integer default("0")
# hot :integer default("0")
# invite_code :string(255)
# qrcode :string(255)
# qrcode_expiretime :integer default("0")
# script :text(65535)
# training_status :integer default("0")
# rep_identifier :string(255)
# project_category_id :integer
# project_language_id :integer
# license_id :integer
# ignore_id :integer
# praises_count :integer default("0")
# watchers_count :integer default("0")
# issues_count :integer default("0")
# pull_requests_count :integer default("0")
# language :string(255)
# versions_count :integer default("0")
# issue_tags_count :integer default("0")
# closed_issues_count :integer default("0")
# open_devops :boolean default("0")
# gitea_webhook_id :integer
# open_devops_count :integer default("0")
# recommend :boolean default("0")
# platform :integer default("0")
#
# Indexes
#
# index_projects_on_forked_from_project_id (forked_from_project_id)
# index_projects_on_identifier (identifier)
# index_projects_on_is_public (is_public)
# index_projects_on_lft (lft)
# index_projects_on_name (name)
# index_projects_on_platform (platform)
# index_projects_on_project_type (project_type)
# index_projects_on_recommend (recommend)
# index_projects_on_rgt (rgt)
# index_projects_on_status (status)
# index_projects_on_updated_on (updated_on)
#
# == Schema Information
#
# Table name: projects
#
# id :integer not null, primary key
# name :string(255) default(""), not null
# description :text(4294967295)
# homepage :string(255) default("")
# is_public :boolean default("1"), not null
# parent_id :integer
# created_on :datetime
# updated_on :datetime
# identifier :string(255)
# status :integer default("1"), not null
# lft :integer
# rgt :integer
# inherit_members :boolean default("0"), not null
# project_type :integer default("0")
# hidden_repo :boolean default("0"), not null
# attachmenttype :integer default("1")
# user_id :integer
# dts_test :integer default("0")
# enterprise_name :string(255)
# organization_id :integer
# project_new_type :integer
# gpid :integer
# forked_from_project_id :integer
# forked_count :integer default("0")
# publish_resource :integer default("0")
# visits :integer default("0")
# hot :integer default("0")
# invite_code :string(255)
# qrcode :string(255)
# qrcode_expiretime :integer default("0")
# script :text(65535)
# training_status :integer default("0")
# rep_identifier :string(255)
# project_category_id :integer
# project_language_id :integer
# license_id :integer
# ignore_id :integer
# praises_count :integer default("0")
# watchers_count :integer default("0")
# issues_count :integer default("0")
# pull_requests_count :integer default("0")
# language :string(255)
# versions_count :integer default("0")
# issue_tags_count :integer default("0")
# closed_issues_count :integer default("0")
# open_devops :boolean default("0")
# gitea_webhook_id :integer
# open_devops_count :integer default("0")
# recommend :boolean default("0")
# platform :integer default("0")
#
# Indexes
#
# index_projects_on_forked_from_project_id (forked_from_project_id)
# index_projects_on_identifier (identifier)
# index_projects_on_is_public (is_public)
# index_projects_on_lft (lft)
# index_projects_on_name (name)
# index_projects_on_platform (platform)
# index_projects_on_project_type (project_type)
# index_projects_on_recommend (recommend)
# index_projects_on_rgt (rgt)
# index_projects_on_status (status)
# index_projects_on_updated_on (updated_on)
#
class Project < ApplicationRecord
include Matchable
include Publicable
@@ -106,12 +106,16 @@ class Project < ApplicationRecord
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
has_one :project_detail, dependent: :destroy
has_many :apply_signatures, dependent: :destroy
after_save :check_project_members
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
scope :recommend, -> { visible.project_statics_select.where(recommend: true) }
scope :secret_and_visible, -> {joins(:license).where("licenses.is_secret = TRUE OR projects.is_public = TRUE")}
delegate :is_secret, to: :license, allow_nil: true
def self.search_project(search)


+ 1
- 0
app/models/user.rb View File

@@ -161,6 +161,7 @@ class User < ApplicationRecord
# has_many :libraries, dependent: :destroy
has_many :project_trends, dependent: :destroy
has_many :oauths , dependent: :destroy
has_many :apply_signatures, dependent: :destroy

# Groups and active users
scope :active, lambda { where(status: STATUS_ACTIVE) }


+ 1
- 1
app/queries/projects/list_query.rb View File

@@ -10,7 +10,7 @@ class Projects::ListQuery < ApplicationQuery
end

def call
q = Project.visible.by_name_or_identifier(params[:search])
q = Project.secret_and_visible.by_name_or_identifier(params[:search])

scope = q
.with_project_type(params[:project_type])


+ 6
- 1
app/services/projects/create_service.rb View File

@@ -53,6 +53,11 @@ class Projects::CreateService < ApplicationService
# end

def repo_is_public
params[:private].blank? ? true : !params[:private]
license = License.find_by_id(params[:license_id])
if license.is_secret
false
else
params[:private].blank? ? true : !params[:private]
end
end
end

+ 7
- 0
app/views/admins/apply_signatures/index.html.erb View File

@@ -0,0 +1,7 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('特殊许可申请列表') %>
<% end %>

<div class="box admin-list-container apply_signatures-list-container">
<%= render partial: 'admins/apply_signatures/shared/list', locals: { apply_signatures: @apply_signatures } %>
</div>

+ 42
- 0
app/views/admins/apply_signatures/shared/_list.html.erb View File

@@ -0,0 +1,42 @@
<table class="table table-hover text-center subject-list-table">
<thead class="thead-light">
<tr>
<th width="10%">序号</th>
<th width="20%" class="text-left">项目名称</th>
<th width="20%">申请人</th>
<th width="25%">申请材料</th>
<th width="25%">操作</th>
</tr>
</thead>
<tbody>
<% if apply_signatures.present? %>
<% apply_signatures.each_with_index do |signature, index| %>
<tr class="sinature-item-<%= signature.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td class="text-left">
<%= link_to(signature&.project&.name, "/projects/#{signature&.project&.owner.login}/#{signature&.project&.identifier}", target: '_blank') %>
</td>
<td>
<%= link_to(signature&.user&.real_name, "/users/#{signature&.user&.login}", target: '_blank') %>
</td>
<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: '点击预览' }) %>
<% end %>
<% end %>
</td>
<td class="action-container">
<%= link_to "同意", admins_apply_signature_path(signature.id, status: 1), method: :patch, class: "delete-project-action" %>
<%= link_to "拒绝", admins_apply_signature_path(signature.id, status: -1), method: :patch, class: "delete-project-action" %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>

<%= render partial: 'admins/shared/paginate', locals: { objects: apply_signatures } %>

+ 3
- 1
app/views/admins/projects/shared/_list.html.erb View File

@@ -5,6 +5,7 @@
<th width="4%">ID</th>
<th width="15%" class="text-left">项目名称</th>
<th width="6%">公开</th>
<th width="6%">特殊协议</th>
<th width="5%">issue</th>
<th width="5%">资源</th>
<th width="6%">版本库</th>
@@ -23,9 +24,10 @@
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td><%= project.id %></td>
<td class="text-left">
<%= link_to(project.name, "/projects/#{project.owner.login}/#{project.identifier}", target: '_blank') %>
<%= link_to(project.name, "/projects/#{project.owner&.login}/#{project.identifier}", target: '_blank') %>
</td>
<td><%= project.is_public ? '√' : '' %></td>
<td><%= project.is_secret ? '√' : '' %></td>
<td><%= project.issues.size %></td>
<td><%= project.attachments.size %></td>
<td><%= project&.project_score.try(:changeset_num).to_i %></td>


+ 2
- 0
app/views/admins/shared/_sidebar.html.erb View File

@@ -26,6 +26,8 @@
<li><%= sidebar_item(admins_project_categories_path, '分类列表', icon: 'sitemap', controller: 'admins-project_categories') %></li>
<li><%= sidebar_item(admins_project_licenses_path, '开源许可证', icon: 'file-text-o', controller: 'admins-project_licenses') %></li>
<li><%= sidebar_item(admins_project_ignores_path, '忽略文件', icon: 'git', controller: 'admins-project_ignores') %></li>
<li><%= sidebar_item(admins_apply_signatures_path, '特殊许可申请列表', icon: 'git', controller: 'admins-apply_signatures') %></li>

<% end %>
</li>



+ 4
- 0
app/views/apply_signatures/create.json.jbuilder View File

@@ -0,0 +1,4 @@
json.id @signature.id
json.attachment do
json.filename @attachment.filename
end

+ 1
- 1
app/views/licenses/index.json.jbuilder View File

@@ -1 +1 @@
json.licenses @licenses, :id, :name
json.licenses @licenses, :id, :name, :is_secret

+ 1
- 0
app/views/members/index.json.jbuilder View File

@@ -5,5 +5,6 @@ json.members @members do |member|
json.is_owner @project.owner?(member.user)
json.role member.roles.last.name
json.role_name t("roles.#{member.roles.last.name}")
json.is_apply_signature member.is_apply_signature
end
end

+ 4
- 17
app/views/project_categories/group_list.json.jbuilder View File

@@ -1,18 +1,5 @@
# json.array! @category_group_list do |category,v|
# json.id category[0]
# json.name category[1]
# json.projects_count v
# end

json.array! @category_group_list do |k,v|
children_category = @project_children_categories.get_children(v)
json.children do
json.array! children_category do |cate|
json.id cate[0]
json.name cate[1]
json.parent_id v
end
end
json.id v
json.name k.to_s
json.array! @project_categories do |category|
json.id category.id
json.name category.name
json.projects_count category.projects_count
end

+ 22
- 7
app/views/projects/_project_detail.json.jbuilder View File

@@ -7,6 +7,7 @@ json.visits project.visits
json.praises_count project.praises_count.to_i
json.forked_count project.forked_count.to_i
json.is_public project.is_public
json.is_secret project.is_secret
json.mirror_url project.repository&.mirror_url
json.type project&.numerical_for_project_type
json.last_update_time render_unix_time(project.updated_on)
@@ -35,12 +36,26 @@ json.category do
json.id project.project_category.id
json.name project.project_category.name
end
end
json.language do
if project.project_language.blank?
json.nil!
else
json.id project.project_language.id
json.name project.project_language.name
json.category do
if project.project_category.blank?
json.nil!
else
json.id project.project_category.id
json.name project.project_category.name
end
end
json.language do
if project.project_language.blank?
json.nil!
else
json.id project.project_language.id
json.name project.project_language.name
end
end
end

user_apply_signatures = project.apply_signatures.with_user_id(current_user.id)
json.user_apply_signatures user_apply_signatures do |signature|
json.id signature.id
json.status signature.status
end

+ 6
- 0
app/views/projects/index.json.jbuilder View File

@@ -10,6 +10,7 @@ json.projects @projects do |project|
json.praises_count project.praises_count.to_i
json.forked_count project.forked_count.to_i
json.is_public project.is_public
json.is_secret project.is_secret
json.mirror_url project.repository&.mirror_url
json.type project&.numerical_for_project_type
json.last_update_time render_unix_time(project.updated_on)
@@ -47,4 +48,9 @@ json.projects @projects do |project|
json.name project.project_language.name
end
end
user_apply_signatures = project.apply_signatures.with_user_id(current_user.id)
json.user_apply_signatures user_apply_signatures do |signature|
json.id signature.id
json.status signature.status
end
end

+ 6
- 0
app/views/projects/show.json.jbuilder View File

@@ -1,6 +1,12 @@
json.name @project.name
json.identifier @project.identifier
json.is_public @project.is_public
json.is_secret @project.is_secret
json.description @project.description
json.repo_id @project.repository.id
json.repo_identifier @project.repository.identifier
user_apply_signatures = @project.apply_signatures.with_user_id(current_user.id)
json.user_apply_signatures user_apply_signatures do |signature|
json.id signature.id
json.status signature.status
end

+ 1
- 0
app/views/repositories/edit.json.jbuilder View File

@@ -5,3 +5,4 @@ json.project_description @project.description
json.project_category_id @project.project_category_id
json.project_language_id @project.project_language_id
json.private !@project.is_public
json.is_secret @project.is_secret

+ 6
- 0
app/views/repositories/show.json.jbuilder View File

@@ -17,6 +17,12 @@ json.mirror_url @project&.repository.mirror_url
json.mirror @project&.repository.mirror_url.present?
json.type @project.numerical_for_project_type
json.open_devops @project.open_devops?
json.is_secret @project.is_secret
user_apply_signatures = @project.apply_signatures.with_user_id(current_user.id)
json.user_apply_signatures user_apply_signatures do |signature|
json.id signature.id
json.status signature.status
end

unless @project.common?
json.mirror_status @repo.mirror_status


+ 7
- 1
config/routes.rb View File

@@ -1,5 +1,5 @@
Rails.application.routes.draw do
require 'sidekiq/web'
require 'admin_constraint'
@@ -59,6 +59,11 @@ Rails.application.routes.draw do
delete :destroy_files
end
end
resources :apply_signatures, only: [:create] do
collection do
get :template_file
end
end
get 'home/index'
get 'home/search'
get 'main/first_stamp'
@@ -771,6 +776,7 @@ Rails.application.routes.draw do
resources :salesman_customers, only: [:index, :create, :edit, :update, :destroy] do
post :batch_add, on: :collection
end
resources :apply_signatures, only: [:index, :update]
end


+ 0
- 17
db/migrate/20200927023922_reset_versions_count.rb View File

@@ -1,17 +0,0 @@
class ResetVersionsCount < ActiveRecord::Migration[5.2]
def change
execute "ALTER TABLE licenses MODIFY COLUMN id INT AUTO_INCREMENT;"
versions = Version.includes(:issues).select(:id, :closed_issues_count, :percent,:issues_count)
versions.each do |v|
Version.reset_counters v.id, :issues
closed_issues = Issue.select(:id, :fixed_version_id, :status_id).where(fixed_version_id: v.id, status_id: 5).size
unless v.closed_issues_count.to_i == closed_issues
percent = v.issues_count.to_i <=0 ? 0.0 : (closed_issues.to_f / v.issues_count.to_i)
v.closed_issues_count = closed_issues
v.percent = percent
v.save
end
puts v.id
end
end
end

+ 11
- 0
db/migrate/20201225064324_create_apply_signatures.rb View File

@@ -0,0 +1,11 @@
class CreateApplySignatures < ActiveRecord::Migration[5.2]
def change
create_table :apply_signatures do |t|
t.references :user
t.references :project
t.integer :status, default: 0

t.timestamps
end
end
end

+ 6
- 0
db/migrate/20201225065222_add_some_columns_about_apply_signatures.rb View File

@@ -0,0 +1,6 @@
class AddSomeColumnsAboutApplySignatures < ActiveRecord::Migration[5.2]
def change
add_column :licenses, :is_secret, :boolean, default: false
add_column :members, :is_apply_signature, :boolean, default: false
end
end

+ 5
- 0
spec/models/apply_signature_spec.rb View File

@@ -0,0 +1,5 @@
require 'rails_helper'

RSpec.describe ApplySignature, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end

Loading…
Cancel
Save