forked from Trustie/forgeplus
合并sonar #1
|
@ -10,6 +10,7 @@
|
|||
|
||||
# Ignore lock config file
|
||||
*.log
|
||||
.rubocop.yml
|
||||
.env
|
||||
# mac
|
||||
*.DS_Store
|
||||
|
|
5
Gemfile
5
Gemfile
|
@ -26,7 +26,7 @@ gem 'roo-xls'
|
|||
gem 'simple_xlsx_reader', '~>1.0.4'
|
||||
|
||||
gem 'rubyzip'
|
||||
|
||||
gem 'sonarqube', :git => 'https://gitlink.org.cn/KingChan/sonarqube.git'
|
||||
gem 'spreadsheet'
|
||||
gem 'ruby-ole'
|
||||
# 导出为xlsx
|
||||
|
@ -70,6 +70,7 @@ group :development do
|
|||
gem 'web-console', '>= 3.3.0'
|
||||
gem 'listen', '>= 3.0.5', '< 3.2'
|
||||
gem 'spring'
|
||||
gem 'pry-rails'
|
||||
gem 'spring-watcher-listen', '~> 2.0.0'
|
||||
gem "annotate", "~> 2.6.0"
|
||||
end
|
||||
|
@ -141,4 +142,4 @@ gem 'doorkeeper'
|
|||
|
||||
gem 'doorkeeper-jwt'
|
||||
|
||||
gem 'gitea-client', '~> 1.4.3'
|
||||
gem 'gitea-client', '~> 1.5.7'
|
||||
|
|
41
Gemfile.lock
41
Gemfile.lock
|
@ -1,3 +1,11 @@
|
|||
GIT
|
||||
remote: https://gitlink.org.cn/KingChan/sonarqube.git
|
||||
revision: 80f07d427322ef02c0714c77a382e87aed0bef81
|
||||
specs:
|
||||
sonarqube (1.3.0)
|
||||
httparty (~> 0.14, >= 0.14.0)
|
||||
terminal-table (~> 1.5, >= 1.5.1)
|
||||
|
||||
GEM
|
||||
remote: https://mirrors.cloud.tencent.com/rubygems/
|
||||
specs:
|
||||
|
@ -99,6 +107,7 @@ GEM
|
|||
archive-zip (~> 0.10)
|
||||
nokogiri (~> 1.8)
|
||||
chunky_png (1.3.11)
|
||||
coderay (1.1.3)
|
||||
concurrent-ruby (1.1.6)
|
||||
connection_pool (2.2.2)
|
||||
crass (1.0.6)
|
||||
|
@ -135,7 +144,7 @@ GEM
|
|||
fugit (1.4.1)
|
||||
et-orbi (~> 1.1, >= 1.1.8)
|
||||
raabro (~> 1.4)
|
||||
gitea-client (1.4.2)
|
||||
gitea-client (1.5.7)
|
||||
rest-client (~> 2.1.0)
|
||||
globalid (0.4.2)
|
||||
activesupport (>= 4.2.0)
|
||||
|
@ -150,6 +159,9 @@ GEM
|
|||
http-accept (1.7.0)
|
||||
http-cookie (1.0.5)
|
||||
domain_name (~> 0.5)
|
||||
httparty (0.21.0)
|
||||
mini_mime (>= 1.0.0)
|
||||
multi_xml (>= 0.5.2)
|
||||
i18n (1.8.2)
|
||||
concurrent-ruby (~> 1.0)
|
||||
io-like (0.3.1)
|
||||
|
@ -187,9 +199,9 @@ GEM
|
|||
mimemagic (~> 0.3.2)
|
||||
maruku (0.7.3)
|
||||
method_source (0.9.2)
|
||||
mime-types (3.4.1)
|
||||
mime-types (3.5.2)
|
||||
mime-types-data (~> 3.2015)
|
||||
mime-types-data (3.2023.0218.1)
|
||||
mime-types-data (3.2024.0507)
|
||||
mimemagic (0.3.10)
|
||||
nokogiri (~> 1)
|
||||
rake
|
||||
|
@ -244,14 +256,18 @@ GEM
|
|||
popper_js (1.16.0)
|
||||
powerpack (0.1.2)
|
||||
prettier (0.18.2)
|
||||
pry (0.12.2)
|
||||
coderay (~> 1.1.0)
|
||||
method_source (~> 0.9.0)
|
||||
pry-rails (0.3.9)
|
||||
pry (>= 0.10.4)
|
||||
public_suffix (4.0.3)
|
||||
puma (3.12.2)
|
||||
puma (5.6.8)
|
||||
nio4r (~> 2.0)
|
||||
raabro (1.4.0)
|
||||
rack (2.0.9)
|
||||
rack-cors (1.1.1)
|
||||
rack (>= 2.0.0)
|
||||
rack-mini-profiler (2.0.1)
|
||||
rack (>= 1.2.0)
|
||||
rack-protection (2.0.8.1)
|
||||
rack
|
||||
rack-test (1.1.0)
|
||||
|
@ -438,6 +454,8 @@ GEM
|
|||
actionpack (>= 4.0)
|
||||
activesupport (>= 4.0)
|
||||
sprockets (>= 3.0.0)
|
||||
terminal-table (1.8.0)
|
||||
unicode-display_width (~> 1.1, >= 1.1.1)
|
||||
thor (1.0.1)
|
||||
thread_safe (0.3.6)
|
||||
tilt (2.0.10)
|
||||
|
@ -450,7 +468,7 @@ GEM
|
|||
execjs (>= 0.3.0, < 3)
|
||||
unf (0.1.4)
|
||||
unf_ext
|
||||
unf_ext (0.0.8.2)
|
||||
unf_ext (0.0.9.1)
|
||||
unicode-display_width (1.6.1)
|
||||
web-console (3.7.0)
|
||||
actionview (>= 5.0)
|
||||
|
@ -492,7 +510,7 @@ DEPENDENCIES
|
|||
enumerize
|
||||
faraday (~> 0.15.4)
|
||||
font-awesome-sass (= 4.7.0)
|
||||
gitea-client (~> 1.4.2)
|
||||
gitea-client (~> 1.5.7)
|
||||
grape-entity (~> 0.7.1)
|
||||
groupdate (~> 4.1.0)
|
||||
harmonious_dictionary (~> 0.0.1)
|
||||
|
@ -514,9 +532,9 @@ DEPENDENCIES
|
|||
parallel (~> 1.19, >= 1.19.1)
|
||||
pdfkit
|
||||
prettier
|
||||
puma (~> 3.11)
|
||||
pry-rails
|
||||
puma (~> 5.6.5)
|
||||
rack-cors
|
||||
rack-mini-profiler
|
||||
rails (~> 5.2.0)
|
||||
rails-i18n (~> 5.1)
|
||||
ransack
|
||||
|
@ -538,9 +556,10 @@ DEPENDENCIES
|
|||
sidekiq-cron (= 1.2.0)
|
||||
sidekiq-failures
|
||||
simple_form
|
||||
simple_xlsx_reader
|
||||
simple_xlsx_reader (~> 1.0.4)
|
||||
sinatra
|
||||
solargraph (~> 0.38.0)
|
||||
sonarqube!
|
||||
spreadsheet
|
||||
spring
|
||||
spring-watcher-listen (~> 2.0.0)
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,2 @@
|
|||
// Place all the behaviors and hooks related to the matching controller here.
|
||||
// All this logic will automatically be available in application.js.
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the api/pm/issue_links controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the api/pm/projects controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the api/v1/pm_issues controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the api/v1/sonarqubes controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the pm/journals controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,75 @@
|
|||
class Action::NodeInputsController < ApplicationController
|
||||
before_action :require_admin, except: [:index]
|
||||
before_action :find_action_node
|
||||
|
||||
def index
|
||||
@node_inputs = @node.action_node_inputs
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@node_input = Action::NodeInput.new(node_input_params)
|
||||
@node_input.action_node = @node
|
||||
respond_to do |format|
|
||||
if @node_input.save
|
||||
format.html { redirect_to action_node_node_inputs_path(@node), notice: '创建成功.' }
|
||||
format.json { render_ok(data: @node_input.as_json) }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @node_input.errors, status: -1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
@node_input.update(node_input_params)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to action_node_node_inputs_path(@node), notice: '更新成功.' }
|
||||
format.json { render_ok(data: @node_input.as_json) }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @node_input.destroy!
|
||||
flash[:success] = '删除成功'
|
||||
else
|
||||
flash[:danger] = '删除失败'
|
||||
end
|
||||
redirect_to "api/actions/nodes"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_action_node
|
||||
@node = Action::Node.find(params[:node_id])
|
||||
if params[:id].present?
|
||||
@node_input = @node.action_node_inputs.find(params[:id])
|
||||
else
|
||||
@node_input = Action::NodeInput.new
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def node_input_params
|
||||
if params.require(:action_node_input)
|
||||
params.require(:action_node_input).permit(:name, :input_type, :description, :is_required, :sort_no)
|
||||
else
|
||||
params.permit(:name, :input_type, :description, :is_required, :sort_no)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,76 @@
|
|||
class Action::NodeSelectsController < ApplicationController
|
||||
|
||||
before_action :require_admin, except: [:index]
|
||||
before_action :find_action_node
|
||||
|
||||
def index
|
||||
@node_selects = @node.action_node_selects
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@node_select = Action::NodeSelect.new(node_select_params)
|
||||
@node_select.action_node = @node
|
||||
respond_to do |format|
|
||||
if @node_select.save
|
||||
format.html { redirect_to action_node_node_selects_path(@node), notice: '创建成功.' }
|
||||
format.json { render_ok(data: @node_select.as_json) }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @node_select.errors, status: -1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
@node_select.update(node_select_params)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to action_node_node_selects_path(@node), notice: '更新成功.' }
|
||||
format.json { render_ok(data: @node_select.as_json) }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @node_select.destroy!
|
||||
flash[:success] = '删除成功'
|
||||
else
|
||||
flash[:danger] = '删除失败'
|
||||
end
|
||||
redirect_to "api/actions/nodes"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_action_node
|
||||
@node = Action::Node.find(params[:node_id])
|
||||
if params[:id].present?
|
||||
@node_select = @node.action_node_selects.find(params[:id])
|
||||
else
|
||||
@node_select = Action::NodeSelect.new
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def node_select_params
|
||||
if params.require(:action_node_select)
|
||||
params.require(:action_node_select).permit(:name, :val, :val_ext, :description, :sort_no)
|
||||
else
|
||||
params.permit(:name, :val, :val_ext, :description, :sort_no)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,64 @@
|
|||
class Action::NodeTypesController < ApplicationController
|
||||
before_action :require_admin, except: [:index]
|
||||
before_action :find_node_type, except: [:index, :create, :new]
|
||||
|
||||
def index
|
||||
@node_types = Action::NodeType.all
|
||||
end
|
||||
|
||||
def create
|
||||
@node_type = Action::NodeType.new(node_types_params)
|
||||
respond_to do |format|
|
||||
if @node_type.save
|
||||
format.html { redirect_to action_node_types_path, notice: '创建成功.' }
|
||||
format.json { render_ok(data: @node_type.as_json) }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @node_type.errors, status: -1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
end
|
||||
|
||||
def new
|
||||
@node_type = Action::NodeType.new
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
@node_type.update(node_types_params)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to action_node_types_path, notice: '更新成功.' }
|
||||
format.json { render_ok(data: @node_type.as_json) }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @node_type.destroy!
|
||||
flash[:success] = '删除成功'
|
||||
else
|
||||
flash[:danger] = '删除失败'
|
||||
end
|
||||
redirect_to action_node_types_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_node_type
|
||||
@node_type = Action::NodeType.find(params[:id])
|
||||
end
|
||||
|
||||
def node_types_params
|
||||
if params.require(:action_node_type)
|
||||
params.require(:action_node_type).permit(:name, :description, :sort_no)
|
||||
else
|
||||
params.permit(:name, :description, :sort_no)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,69 @@
|
|||
class Action::NodesController < ApplicationController
|
||||
before_action :require_admin, except: [:index]
|
||||
before_action :find_action_node, except: [:index, :create, :new]
|
||||
|
||||
def index
|
||||
@node_types = Action::NodeType.all
|
||||
@no_type_nodes = Action::Node.where(action_node_types_id: nil)
|
||||
respond_to do |format|
|
||||
format.html { @nodes = Action::Node.all }
|
||||
format.json
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@node = Action::Node.new(node_params)
|
||||
respond_to do |format|
|
||||
if @node.save
|
||||
format.html { redirect_to action_nodes_path, notice: '创建成功.' }
|
||||
format.json { render_ok(data: @node.as_json) }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @node.errors, status: -1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@node = Action::Node.new
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
@node.update(node_params)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to action_nodes_path, notice: '更新成功.' }
|
||||
format.json { render_ok(data: @node.as_json) }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @node.destroy!
|
||||
flash[:success] = '删除成功'
|
||||
else
|
||||
flash[:danger] = '删除失败'
|
||||
end
|
||||
redirect_to action_nodes_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_action_node
|
||||
@node = Action::Node.find(params[:id])
|
||||
end
|
||||
|
||||
def node_params
|
||||
if params.require(:action_node)
|
||||
params.require(:action_node).permit(:name, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no)
|
||||
else
|
||||
params.permit(:name, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url, :yaml, :sort_no)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,68 @@
|
|||
class Action::TemplatesController < ApplicationController
|
||||
before_action :require_admin, except: [:index]
|
||||
before_action :find_action_template, except: [:index, :create, :new]
|
||||
|
||||
def index
|
||||
@templates = Action::Template.all
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.json
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@template = Action::Template.new(templates_params)
|
||||
respond_to do |format|
|
||||
if @template.save
|
||||
format.html { redirect_to action_templates_path, notice: '创建成功.' }
|
||||
format.json { render_ok(data: @template.as_json) }
|
||||
else
|
||||
format.html { render :new }
|
||||
format.json { render json: @template.errors, status: -1 }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
|
||||
end
|
||||
|
||||
def new
|
||||
@template = Action::Template.new
|
||||
end
|
||||
|
||||
def edit
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
@template.update(templates_params)
|
||||
respond_to do |format|
|
||||
format.html { redirect_to action_templates_path, notice: '更新成功.' }
|
||||
format.json { render_ok(data: @template.as_json) }
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @template.destroy!
|
||||
flash[:success] = '删除成功'
|
||||
else
|
||||
flash[:danger] = '删除失败'
|
||||
end
|
||||
redirect_to action_templates_path
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_action_template
|
||||
@template = Action::Template.find(params[:id])
|
||||
end
|
||||
|
||||
def templates_params
|
||||
if params.require(:action_template)
|
||||
params.require(:action_template).permit(:name, :description, :img, :sort_no, :json, :yaml)
|
||||
else
|
||||
params.permit(:name, :description, :img, :sort_no, :json, :yaml)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -21,13 +21,75 @@ class Admins::DashboardsController < Admins::BaseController
|
|||
weekly_project_ids = (CommitLog.where(created_at: current_week).pluck(:project_id).uniq + Issue.where(created_on: current_week).pluck(:project_id).uniq).uniq
|
||||
month_project_ids = (CommitLog.where(created_at: current_month).pluck(:project_id).uniq + Issue.where(created_on: current_month).pluck(:project_id).uniq).uniq
|
||||
@day_active_project_count = Project.where(updated_on: today).or(Project.where(id: day_project_ids)).count
|
||||
@weekly_active_project_count = Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count
|
||||
@month_active_project_count = Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count
|
||||
|
||||
@weekly_active_project_count = Rails.cache.fetch("dashboardscontroller:weekly_active_project_count", expires_in: 10.minutes) do
|
||||
Project.where(updated_on: current_week).or(Project.where(id: weekly_project_ids)).count
|
||||
end
|
||||
@month_active_project_count = Rails.cache.fetch("dashboardscontroller:month_active_project_count", expires_in: 1.hours) do
|
||||
Project.where(updated_on: current_month).or(Project.where(id: month_project_ids)).count
|
||||
end
|
||||
# 新增项目数
|
||||
@day_new_project_count = Project.where(created_on: today).count
|
||||
@weekly_new_project_count = Project.where(created_on: current_week).count
|
||||
@month_new_project_count = Project.where(created_on: current_month).count
|
||||
@day_new_project_count = Rails.cache.fetch("dashboardscontroller:day_new_project_count", expires_in: 10.minutes) do
|
||||
Project.where(created_on: today).count
|
||||
end
|
||||
@weekly_new_project_count = Rails.cache.fetch("dashboardscontroller:weekly_new_project_count", expires_in: 10.minutes) do
|
||||
Project.where(created_on: current_week).count
|
||||
end
|
||||
@month_new_project_count = Rails.cache.fetch("dashboardscontroller:month_new_project_count", expires_in: 1.hours) do
|
||||
Project.where(created_on: current_month).count
|
||||
end
|
||||
|
||||
|
||||
# 总的平台用户数
|
||||
# 总的平台项目数
|
||||
# 总的平台组织数
|
||||
# 总的平台Issue数、评论数、PR数、Commit数
|
||||
@user_count = Rails.cache.fetch("dashboardscontroller:platform:user_count", expires_in: 1.days) do
|
||||
User.count
|
||||
end
|
||||
@project_count = Rails.cache.fetch("dashboardscontroller:platform:project_count", expires_in: 1.days) do
|
||||
Project.count
|
||||
end
|
||||
@organization_count = Rails.cache.fetch("dashboardscontroller:platform:organization_count", expires_in: 1.days) do
|
||||
Organization.count
|
||||
end
|
||||
@issue_count = Rails.cache.fetch("dashboardscontroller:platform:issue_count", expires_in: 1.days) do
|
||||
Issue.count
|
||||
end
|
||||
@comment_count = Rails.cache.fetch("dashboardscontroller:platform:comment_count", expires_in: 1.days) do
|
||||
Journal.count
|
||||
end
|
||||
@pr_count = Rails.cache.fetch("dashboardscontroller:platform:pr_count", expires_in: 1.days) do
|
||||
PullRequest.count
|
||||
end
|
||||
@commit_count = Rails.cache.fetch("dashboardscontroller:platform:commit_count", expires_in: 1.days) do
|
||||
CommitLog.count
|
||||
end
|
||||
|
||||
@subject_name = ["用户数", "项目数", "组织数", "Issue数", "Issue评论数", "PR数", "Commit数"]
|
||||
@subject_icon = ["fa-user","fa-git", "fa-sitemap", "fa-warning", "fa-comments", "fa-share-alt", "fa-upload"]
|
||||
@subject_data = [@user_count, @project_count, @organization_count, @issue_count, @comment_count, @pr_count, @commit_count]
|
||||
|
||||
if EduSetting.get("open_baidu_tongji").to_s == "true"
|
||||
tongji_service = Baidu::TongjiService.new
|
||||
@access_token = tongji_service.access_token
|
||||
Rails.logger.info "baidu_tongji_auth access_token ===== #{@access_token}"
|
||||
# @overview_data = tongji_service.api_overview
|
||||
last_date = DailyPlatformStatistic.order(:date).last || Time.now
|
||||
start_date = last_date.date
|
||||
end_date = Time.now
|
||||
if @access_token.present?
|
||||
@overview_data = Rails.cache.fetch("dashboardscontroller:baidu_tongji:overview_data", expires_in: 10.minutes) do
|
||||
tongji_service.source_from_batch_add(start_date, end_date)
|
||||
@overview_data = tongji_service.overview_batch_add(start_date, end_date)
|
||||
@overview_data
|
||||
end
|
||||
end
|
||||
|
||||
@current_week_statistic = DailyPlatformStatistic.where(date: current_week)
|
||||
@pre_week_statistic = DailyPlatformStatistic.where(date: pre_week)
|
||||
end
|
||||
|
||||
|
||||
end
|
||||
|
||||
def month_active_user
|
||||
|
@ -42,6 +104,19 @@ class Admins::DashboardsController < Admins::BaseController
|
|||
render_ok(data: data)
|
||||
end
|
||||
|
||||
def baidu_tongji
|
||||
tongji_service = Baidu::TongjiService.new
|
||||
redirect_to tongji_service.code_url
|
||||
end
|
||||
|
||||
def baidu_tongji_auth
|
||||
if params[:code].present?
|
||||
tongji_service = Baidu::TongjiService.new
|
||||
tongji_service.get_access_token(params[:code])
|
||||
end
|
||||
redirect_to "/admins/"
|
||||
end
|
||||
|
||||
def evaluate
|
||||
names = []
|
||||
data = []
|
||||
|
@ -63,8 +138,12 @@ class Admins::DashboardsController < Admins::BaseController
|
|||
Time.now.beginning_of_day..Time.now.end_of_day
|
||||
end
|
||||
|
||||
def current_week
|
||||
def pre_7_days
|
||||
7.days.ago.end_of_day..Time.now.end_of_day
|
||||
end
|
||||
|
||||
def current_week
|
||||
Time.now.beginning_of_week..Time.now.end_of_day
|
||||
end
|
||||
|
||||
def current_month
|
||||
|
@ -72,6 +151,7 @@ class Admins::DashboardsController < Admins::BaseController
|
|||
end
|
||||
|
||||
def pre_week
|
||||
14.days.ago.end_of_day..7.days.ago.end_of_day
|
||||
# 14.days.ago.end_of_day..7.days.ago.end_of_day
|
||||
Time.now.prev_week..Time.now.prev_week.end_of_week
|
||||
end
|
||||
end
|
|
@ -14,12 +14,14 @@ class Admins::IdentityVerificationsController < Admins::BaseController
|
|||
end
|
||||
|
||||
def update
|
||||
if @identity_verification.update(update_params)
|
||||
if update_params[:state] == "已拒绝" && update_params[:description].blank?
|
||||
flash[:danger] = '拒绝理由不能为空'
|
||||
render 'edit'
|
||||
else
|
||||
UserAction.create(action_id: @identity_verification.id, action_type: "UpdateIdentityVerifications", user_id: current_user.id, :ip => request.remote_ip, data_bank: @identity_verification.attributes.to_json)
|
||||
@identity_verification.update(update_params)
|
||||
redirect_to admins_identity_verifications_path
|
||||
flash[:success] = "更新成功"
|
||||
else
|
||||
redirect_to admins_identity_verifications_path
|
||||
flash[:danger] = "更新失败"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
class Admins::IssuesRankController < Admins::BaseController
|
||||
|
||||
def index
|
||||
@statistics = DailyProjectStatistic.where('date >= ? AND date <= ?', begin_date, end_date)
|
||||
@statistics = @statistics.group(:project_id).joins(:project).select("project_id,
|
||||
sum(issues) as issues,
|
||||
sum(closed_issues) as closed_issues,
|
||||
projects.issues_count as issues_count")
|
||||
@statistics = @statistics.order("#{sort_by} #{sort_direction}").limit(50)
|
||||
end
|
||||
|
||||
private
|
||||
def begin_date
|
||||
params.fetch(:begin_date, (Date.yesterday-7.days).to_s)
|
||||
end
|
||||
|
||||
def end_date
|
||||
params.fetch(:end_date, Date.yesterday.to_s)
|
||||
end
|
||||
|
||||
def sort_by
|
||||
DailyProjectStatistic.column_names.include?(params.fetch(:sort_by, "issues")) ? params.fetch(:sort_by, "issues") : "issues"
|
||||
end
|
||||
|
||||
def sort_direction
|
||||
%w(desc asc).include?(params.fetch(:sort_direction, "desc")) ? params.fetch(:sort_direction, "desc") : "desc"
|
||||
end
|
||||
|
||||
end
|
|
@ -5,7 +5,7 @@ class Admins::ProjectsController < Admins::BaseController
|
|||
sort_by = Project.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_on'
|
||||
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
|
||||
search = params[:search].to_s.strip
|
||||
projects = Project.where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}")
|
||||
projects = Project.where("name like ? OR identifier LIKE ?", "%#{search}%", "%#{search}%").order("#{sort_by} #{sort_direction}")
|
||||
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
|
||||
end
|
||||
|
||||
|
|
|
@ -17,11 +17,11 @@ class Admins::ProjectsRankController < Admins::BaseController
|
|||
private
|
||||
|
||||
def begin_date
|
||||
params.fetch(:begin_date, (Date.today-7.days).to_s)
|
||||
params.fetch(:begin_date, (Date.yesterday-7.days).to_s)
|
||||
end
|
||||
|
||||
def end_date
|
||||
params.fetch(:end_date, Date.today.to_s)
|
||||
params.fetch(:end_date, Date.yesterday.to_s)
|
||||
end
|
||||
|
||||
def sort_by
|
||||
|
|
|
@ -29,8 +29,12 @@ class Admins::SitePagesController < Admins::BaseController
|
|||
end
|
||||
|
||||
def update
|
||||
@site_page.update(update_params)
|
||||
flash[:success] = '保存成功'
|
||||
if update_params[:state] == "false" && update_params[:state_description].blank?
|
||||
flash[:danger] = '关闭站点理由不能为空'
|
||||
else
|
||||
@site_page.update(update_params)
|
||||
flash[:success] = '保存成功'
|
||||
end
|
||||
render 'edit'
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,60 @@
|
|||
class Api::Pm::BaseController < ApplicationController
|
||||
|
||||
include Api::ProjectHelper
|
||||
include Api::UserHelper
|
||||
include Api::PullHelper
|
||||
|
||||
# before_action :doorkeeper_authorize!
|
||||
# skip_before_action :user_setup
|
||||
|
||||
protected
|
||||
|
||||
def kaminary_select_paginate(relation)
|
||||
limit = params[:limit] || params[:per_page]
|
||||
limit = (limit.to_i.zero? || limit.to_i > 200) ? 200 : limit.to_i
|
||||
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
|
||||
|
||||
relation.page(page).per(limit)
|
||||
end
|
||||
|
||||
def limit
|
||||
params.fetch(:limit, 15)
|
||||
end
|
||||
|
||||
def page
|
||||
params.fetch(:page, 1)
|
||||
end
|
||||
|
||||
def load_project
|
||||
@project = Project.find_by_id(params[:project_id]) || Project.new(id: 0, user_id: 0, name: 'pm_mm', identifier: 'pm_mm', is_public:true)
|
||||
end
|
||||
|
||||
def load_issue
|
||||
return render_parameter_missing if params[:pm_project_id].blank?
|
||||
@issue = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:issue_id])
|
||||
render_not_found('疑修不存在!') if @issue.blank?
|
||||
end
|
||||
# 具有对仓库的管理权限
|
||||
def require_manager_above
|
||||
@project = load_project
|
||||
return render_forbidden if !current_user.admin? && !@project.manager?(current_user)
|
||||
end
|
||||
|
||||
# 具有对仓库的操作权限
|
||||
def require_operate_above
|
||||
@project = load_project
|
||||
return render_forbidden if !current_user.admin? && !@project.operator?(current_user)
|
||||
end
|
||||
|
||||
# 具有仓库的操作权限或者fork仓库的操作权限
|
||||
def require_operate_above_or_fork_project
|
||||
@project = load_project
|
||||
return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
|
||||
end
|
||||
|
||||
# 具有对仓库的访问权限
|
||||
def require_public_and_member_above
|
||||
@project = load_project
|
||||
return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,21 @@
|
|||
class Api::Pm::IssueLinksController < Api::Pm::BaseController
|
||||
before_action :load_project
|
||||
before_action :load_issue
|
||||
def index
|
||||
@links = @issue.pm_links.where(be_linkable_type: 'Issue')
|
||||
end
|
||||
|
||||
def create
|
||||
params[:link_ids].map { |e| @issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: e) }
|
||||
render_ok
|
||||
end
|
||||
|
||||
def destroy
|
||||
@link = @issue.pm_links.find_by(be_linkable_type: 'Issue', be_linkable_id: params[:id])
|
||||
if @link.try(:destroy)
|
||||
render_ok
|
||||
else
|
||||
render_error('删除失败!')
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,71 @@
|
|||
class Api::Pm::IssueTagsController < Api::Pm::BaseController
|
||||
|
||||
def index
|
||||
@issue_tags = IssueTag.pm_able
|
||||
if params[:organization_id].present?
|
||||
IssueTag.pm_org_init_data(params[:organization_id]) unless $redis_cache.hget("pm_org_init_issue_tags", params[:organization_id])
|
||||
@issue_tags = @issue_tags.where(organization_id: params[:organization_id])
|
||||
end
|
||||
@issue_tags = @issue_tags.where(pm_project_id: params[:pm_project_id]) if params[:pm_project_id].present?
|
||||
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
|
||||
@issue_tags = @issue_tags.reorder("#{tag_sort_by} #{tag_sort_direction}")
|
||||
@issue_tags = kaminari_paginate(@issue_tags)
|
||||
render "api/v1/issues/issue_tags/index"
|
||||
end
|
||||
|
||||
def create
|
||||
return render_error("请输入正确的OrganizationID") unless Organization.exists?(id: issue_tag_create_params[:organization_id])
|
||||
return render_error("项目标记名称不能为空!") unless issue_tag_create_params[:name].present?
|
||||
@issue_tag = IssueTag.new(issue_tag_create_params.merge!(project_id: 0))
|
||||
if @issue_tag.save!
|
||||
render_ok
|
||||
else
|
||||
render_error("创建标记失败!")
|
||||
end
|
||||
end
|
||||
|
||||
before_action :load_issue_tag, only: [:update, :destroy]
|
||||
|
||||
def update
|
||||
@issue_tag.attributes = issue_tag_update_params
|
||||
if @issue_tag.save!
|
||||
render_ok
|
||||
else
|
||||
render_error("更新标记失败!")
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
if @issue_tag.destroy!
|
||||
render_ok
|
||||
else
|
||||
render_error("删除标记失败!")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def tag_sort_by
|
||||
sort_by = params.fetch(:sort_by, "created_at")
|
||||
sort_by = IssueTag.column_names.include?(sort_by) ? sort_by : "created_at"
|
||||
sort_by
|
||||
end
|
||||
|
||||
def tag_sort_direction
|
||||
sort_direction = params.fetch(:sort_direction, "desc")&.downcase
|
||||
sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc"
|
||||
sort_direction
|
||||
end
|
||||
|
||||
def issue_tag_create_params
|
||||
params.permit(:name, :description, :color, :pm_project_id, :organization_id)
|
||||
end
|
||||
|
||||
def issue_tag_update_params
|
||||
params.permit(:name, :description, :color)
|
||||
end
|
||||
|
||||
def load_issue_tag
|
||||
@issue_tag = IssueTag.pm_able.find_by_id(params[:id])
|
||||
end
|
||||
end
|
|
@ -0,0 +1,215 @@
|
|||
class Api::Pm::IssuesController < Api::Pm::BaseController
|
||||
before_action :require_login, except: [:index]
|
||||
before_action :load_project
|
||||
before_action :load_issue, only: %i[show update destroy link_index link_issues parent_issues]
|
||||
before_action :load_issues, only: %i[batch_update batch_destroy]
|
||||
before_action :check_issue_operate_permission, only: %i[update destroy]
|
||||
|
||||
def index
|
||||
@object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user)
|
||||
@total_issues_count = @object_result[:total_issues_count]
|
||||
@opened_issues_count = @object_result[:opened_issues_count]
|
||||
@closed_issues_count = @object_result[:closed_issues_count]
|
||||
@complete_issues_count = @object_result[:complete_issues_count]
|
||||
if params[:only_name].present?
|
||||
@issues = kaminary_select_paginate(
|
||||
@object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on))
|
||||
else
|
||||
@issues = kaminari_paginate(@object_result[:data])
|
||||
end
|
||||
render 'api/v1/issues/index'
|
||||
end
|
||||
|
||||
def link_index
|
||||
pm_issue_type = params[:pm_issue_type] || [1, 2, 3]
|
||||
not_join_id = case params[:issue_filter_type]
|
||||
when 'leaf_issue'
|
||||
Issue.where(root_id: @issue.id).pluck(:id)
|
||||
when 'link_issue'
|
||||
@issue.pm_links.pluck(:be_linkable_id)
|
||||
end
|
||||
|
||||
not_join_id << @issue.id
|
||||
object_issues = Issue.where(
|
||||
pm_project_id: params[:pm_project_id],
|
||||
pm_issue_type: pm_issue_type
|
||||
).where.not(id: not_join_id).order(updated_on: :desc)
|
||||
|
||||
object_issues = object_issues.where(root_id: nil, child_count: 0) if params[:issue_filter_type] == 'leaf_issue'
|
||||
@issues = kaminari_paginate(object_issues)
|
||||
render 'api/v1/issues/index'
|
||||
end
|
||||
|
||||
def parent_issues
|
||||
@issues = Issue.where(pm_project_id: params[:pm_project_id])
|
||||
.where.not(id: @issue.id)
|
||||
.where.not(id: Issue.full_children_issues(@issue).map{|i|i.id})
|
||||
@issues = @issues.where(pm_issue_type: params[:pm_issue_type]) if params[:pm_issue_type].present?
|
||||
@issues = @issues.ransack(id_or_project_issues_index_eq: params[:keyword]).result.or(@issues.ransack(subject_or_description_cont: params[:keyword]).result) if params[:keyword].present?
|
||||
@issues = @issues.reorder("#{issue_sort_by} #{issue_sort_direction}")
|
||||
if params[:only_name].present?
|
||||
@issues = kaminary_select_paginate(
|
||||
@issues.select(:id, :subject, :project_issues_index, :updated_on, :created_on))
|
||||
else
|
||||
@issues = @issues.includes(:priority, :issue_status, :user, :show_assigners, :show_issue_tags, :version, :comment_journals)
|
||||
@issues = kaminari_paginate(@issues)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
@issue.associate_attachment_container
|
||||
render 'api/v1/issues/show'
|
||||
end
|
||||
|
||||
def create
|
||||
@object_result = Api::V1::Issues::CreateService.call(@project, issue_params, current_user)
|
||||
render 'api/v1/issues/create'
|
||||
end
|
||||
|
||||
def update
|
||||
@object_result = Api::V1::Issues::UpdateService.call(@project, @issue, issue_params, current_user)
|
||||
render 'api/v1/issues/update'
|
||||
end
|
||||
|
||||
def batch_update
|
||||
@object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user)
|
||||
if @object_result
|
||||
render_ok
|
||||
else
|
||||
render_error('批量更新疑修失败!')
|
||||
end
|
||||
end
|
||||
|
||||
def batch_destroy
|
||||
return render_ok if params[:ids].is_a?(Array) && params[:ids].blank?
|
||||
@object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user)
|
||||
if @object_result
|
||||
render_ok
|
||||
else
|
||||
render_error('批量删除疑修失败!')
|
||||
end
|
||||
end
|
||||
|
||||
def priorities
|
||||
@priorities = IssuePriority.order(position: :asc)
|
||||
@priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword]
|
||||
@priorities = kaminary_select_paginate(@priorities)
|
||||
render "api/v1/issues/issue_priorities/index"
|
||||
end
|
||||
|
||||
def tags
|
||||
# IssueTag.pm_init_data(params[:pm_project_id]) unless $redis_cache.hget("pm_project_init_issue_tags", params[:pm_project_id])
|
||||
@issue_tags = IssueTag.where(pm_project_id: params[:pm_project_id]).reorder("#{tag_sort_by} #{tag_sort_direction}")
|
||||
@issue_tags = @issue_tags.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
|
||||
params[:only_name] = true #强制渲染 不走project
|
||||
@issue_tags = kaminary_select_paginate(@issue_tags.select(:id, :name, :color))
|
||||
render "api/v1/issues/issue_tags/index"
|
||||
end
|
||||
|
||||
def statues
|
||||
@statues = IssueStatus.order("position asc")
|
||||
@statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
|
||||
@statues = kaminary_select_paginate(@statues)
|
||||
render "api/v1/issues/statues/index"
|
||||
end
|
||||
|
||||
|
||||
|
||||
def destroy
|
||||
@object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user)
|
||||
if @object_result
|
||||
render_ok
|
||||
else
|
||||
render_error('删除疑修失败!')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def check_issue_operate_permission
|
||||
return if params[:project_id].to_i.zero?
|
||||
render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? || @issue.user == current_user
|
||||
end
|
||||
|
||||
def load_issue
|
||||
return render_parameter_missing if params[:pm_project_id].blank?
|
||||
@issue = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:id])
|
||||
render_not_found('疑修不存在!') if @issue.blank?
|
||||
end
|
||||
|
||||
def load_issues
|
||||
return render_error('请输入正确的ID数组!') unless params[:ids].is_a?(Array)
|
||||
params[:ids].each do |id|
|
||||
@issue = Issue.find_by(id: id, pm_project_id: params[:pm_project_id])
|
||||
return render_not_found("ID为#{id}的疑修不存在!") if @issue.blank?
|
||||
end
|
||||
if params[:ids].blank?
|
||||
@issues = Issue.where(pm_project_id: params[:pm_project_id])
|
||||
else
|
||||
@issues = Issue.where(id: params[:ids], pm_project_id: params[:pm_project_id])
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def query_params
|
||||
params.permit(
|
||||
:only_name,
|
||||
:category,
|
||||
:participant_category,
|
||||
:keyword, :author_id,
|
||||
:milestone_id, :assigner_id,
|
||||
:status_id, :priority_id,
|
||||
:begin_date, :end_date,
|
||||
:update_begin_date, :update_end_date,
|
||||
:sort_by, :sort_direction, :root_id,
|
||||
:issue_tag_ids, :pm_project_id, :pm_sprint_id, :pm_issue_type, :pm_project_ids,
|
||||
:status_ids, :ids, :exclude_ids, :pm_issue_types, :participator_id
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
|
||||
def issue_params
|
||||
params.permit(
|
||||
:status_id, :priority_id, :milestone_id,
|
||||
:branch_name, :start_date, :due_date, :time_scale,
|
||||
:subject, :description, :blockchain_token_num, :root_subject,
|
||||
:pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :link_able_id, :project_id,
|
||||
issue_tag_ids: [],
|
||||
assigner_ids: [],
|
||||
attachment_ids: [],
|
||||
receivers_login: []
|
||||
)
|
||||
end
|
||||
|
||||
def batch_issue_params
|
||||
params.permit(
|
||||
:status_id, :priority_id, :milestone_id, :pm_sprint_id, :due_date, :pm_issue_type, :root_id, :target_pm_project_id, :project_id,
|
||||
:issue_tag_ids => [],
|
||||
:assigner_ids => [] )
|
||||
end
|
||||
|
||||
def issue_sort_by
|
||||
sort_by = params.fetch(:sort_by, "updated_on")
|
||||
sort_by = Issue.column_names.include?(sort_by) ? sort_by : "updated_on"
|
||||
sort_by
|
||||
end
|
||||
|
||||
def issue_sort_direction
|
||||
sort_direction = params.fetch(:sort_direction, "desc").downcase
|
||||
sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc"
|
||||
sort_direction
|
||||
end
|
||||
|
||||
def tag_sort_by
|
||||
sort_by = params.fetch(:sort_by, "created_at")
|
||||
sort_by = IssueTag.column_names.include?(sort_by) ? sort_by : "created_at"
|
||||
sort_by
|
||||
end
|
||||
|
||||
def tag_sort_direction
|
||||
sort_direction = params.fetch(:sort_direction, "desc").downcase
|
||||
sort_direction = %w(desc asc).include?(sort_direction) ? sort_direction : "desc"
|
||||
sort_direction
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,61 @@
|
|||
class Api::Pm::JournalsController < Api::Pm::BaseController
|
||||
before_action :require_login, except: [:index, :children_journals]
|
||||
before_action :load_project
|
||||
before_action :load_issue
|
||||
before_action :load_journal, only: [:children_journals, :update, :destroy]
|
||||
|
||||
def index
|
||||
@object_result = Api::V1::Issues::Journals::ListService.call(@issue, query_params, current_user)
|
||||
@total_journals_count = @object_result[:total_journals_count]
|
||||
@total_operate_journals_count = @object_result[:total_operate_journals_count]
|
||||
@total_comment_journals_count = @object_result[:total_comment_journals_count]
|
||||
@journals = kaminary_select_paginate(@object_result[:data])
|
||||
render 'api/v1/issues/journals/index'
|
||||
end
|
||||
|
||||
def create
|
||||
@object_result = Api::V1::Issues::Journals::CreateService.call(@issue, journal_params, current_user)
|
||||
render 'api/v1/issues/journals/create'
|
||||
end
|
||||
|
||||
def children_journals
|
||||
@object_results = Api::V1::Issues::Journals::ChildrenListService.call(@issue, @journal, query_params, current_user)
|
||||
@journals = kaminari_paginate(@object_results)
|
||||
render 'api/v1/issues/journals/children_journals'
|
||||
end
|
||||
|
||||
def update
|
||||
@object_result = Api::V1::Issues::Journals::UpdateService.call(@issue, @journal, journal_params, current_user)
|
||||
render 'api/v1/issues/journals/update'
|
||||
end
|
||||
|
||||
def destroy
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueComment', @issue&.id, current_user.id, @journal.id, 'deleted', JSON.parse(@journal.to_builder.target!))
|
||||
if @journal.destroy!
|
||||
render_ok
|
||||
else
|
||||
render_error('删除评论失败!')
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def query_params
|
||||
params.permit(:category, :keyword, :sort_by, :sort_direction)
|
||||
end
|
||||
|
||||
def journal_params
|
||||
params.permit(:notes, :parent_id, :reply_id, :attachment_ids => [], :receivers_login => [])
|
||||
end
|
||||
|
||||
def load_issue
|
||||
@issue = Issue.issue_issue.where(pm_project_id: params[:pm_project_id]).find_by_id(params[:issue_id])
|
||||
render_not_found('疑修不存在!') if @issue.blank?
|
||||
end
|
||||
|
||||
def load_journal
|
||||
@journal = Journal.find_by_id(params[:id])
|
||||
render_not_found('评论不存在!') unless @journal.present?
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,145 @@
|
|||
class Api::Pm::ProjectsController < Api::Pm::BaseController
|
||||
before_action :require_login, except: [:convert]
|
||||
before_action :load_project, only: [:convert]
|
||||
def convert
|
||||
data = {
|
||||
owner: @project.owner.try(:login),
|
||||
identifier: @project.identifier,
|
||||
name: @project.name
|
||||
}
|
||||
render_ok(data: data)
|
||||
end
|
||||
|
||||
def issues_count
|
||||
return tip_exception '参数错误' unless params[:pm_project_id].present?
|
||||
@issues = Issue.where(pm_project_id: params[:pm_project_id])
|
||||
case params[:category].to_s
|
||||
when 'closed'
|
||||
@issues = @issues.closed
|
||||
when 'opened'
|
||||
@issues = @issues.opened
|
||||
end
|
||||
@participant_category_count = {}
|
||||
if params[:participant_category].to_s == "authoredme" or params[:participant_category].to_s == "assignedme"
|
||||
issues_category = @issues.joins(:issue_participants).where(pm_issue_type: [1, 2, 3]).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id})
|
||||
@participant_category_count = issues_category.group(:pm_project_id, "issue_participants.participant_type").count
|
||||
end
|
||||
case params[:participant_category].to_s
|
||||
when 'aboutme' # 关于我的
|
||||
@issues = @issues.joins(:issue_participants).where(issue_participants: {participant_type: %w[authored assigned atme], participant_id: current_user&.id})
|
||||
when 'authoredme' # 我创建的
|
||||
@issues = @issues.joins(:issue_participants).where(issue_participants: {participant_type: 'authored', participant_id: current_user&.id})
|
||||
when 'assignedme' # 我负责的
|
||||
@issues = @issues.joins(:issue_participants).where(issue_participants: {participant_type: 'assigned', participant_id: current_user&.id})
|
||||
when 'atme' # @我的
|
||||
@issues = @issues.joins(:issue_participants).where(issue_participants: {participant_type: 'atme', participant_id: current_user&.id})
|
||||
end
|
||||
data = {}
|
||||
@issues_count = @issues.group(:pm_project_id).count
|
||||
# requirement 1 task 2 bug 3
|
||||
@issues_type_count = @issues.group(:pm_project_id, :pm_issue_type).count
|
||||
params[:pm_project_id].map(&:to_i).map do |project_id|
|
||||
data[project_id] = {
|
||||
total: @issues_count[project_id] || 0,
|
||||
requirement: @issues_type_count[[project_id, 1]] || 0,
|
||||
task: @issues_type_count[[project_id, 2]] || 0,
|
||||
bug: @issues_type_count[[project_id, 3]] || 0,
|
||||
authoredme: @participant_category_count[[project_id, 0]] || 0,
|
||||
assignedme: @participant_category_count[[project_id, 1]] || 0,
|
||||
atme: @participant_category_count[[project_id, 4]] || 0,
|
||||
}
|
||||
end
|
||||
render_ok(data: data)
|
||||
end
|
||||
|
||||
|
||||
def statistics
|
||||
return tip_exception '参数错误' if params[:pm_project_id].blank?
|
||||
@issues = Issue.where(pm_project_id: params[:pm_project_id])
|
||||
type_count_data = @issues.group(:pm_issue_type).count
|
||||
type_status = @issues.group(:pm_issue_type,:status_id).count
|
||||
type_status_data = {}
|
||||
IssueStatus.all.map do |e|
|
||||
[1,2,3].map{ |type|
|
||||
type_status_data[type] = {} if type_status_data[type].nil?
|
||||
if type_status[[type,e.id]].nil?
|
||||
type_status_data[type][e.id] = 0
|
||||
else
|
||||
type_status_data[type][e.id] = type_status[[type,e.id]]
|
||||
end
|
||||
}
|
||||
end
|
||||
open_data = {
|
||||
"1": type_status_data[1][1].to_i + type_status_data[1][2].to_i,
|
||||
"2": type_status_data[2][1].to_i + type_status_data[2][2].to_i,
|
||||
"3": type_status_data[3][1].to_i + type_status_data[3][2].to_i,
|
||||
}
|
||||
if type_count_data.keys.size < 3
|
||||
nedd_add = [1,2,3] - type_count_data.keys
|
||||
nedd_add.map{ |e|
|
||||
type_count_data[e] = 0
|
||||
}
|
||||
end
|
||||
data = {
|
||||
pie_chart: type_count_data,
|
||||
bar_chart: type_status_data,
|
||||
open_data: open_data
|
||||
}
|
||||
render_ok(data: data)
|
||||
end
|
||||
|
||||
def polyline
|
||||
return tip_exception '参数错误' if params[:pm_project_id].blank?
|
||||
time_line = (Time.current.beginning_of_day - 6.day) .. Time.current
|
||||
@create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line)
|
||||
@due_issues = Issue.where(pm_project_id: params[:pm_project_id],status_id:[3,5],due_date: time_line)
|
||||
@create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count
|
||||
@due_issues_count = @due_issues.group(:pm_issue_type,"DATE(due_date)").count
|
||||
data = {
|
||||
create_issues: {},
|
||||
due_issues: {}
|
||||
}
|
||||
7.times do |time|
|
||||
current_time = Date.current - time.day
|
||||
if @create_issues_count.present?
|
||||
data[:create_issues][current_time] = {
|
||||
"1": @create_issues_count[[1,current_time]] || 0,
|
||||
"2": @create_issues_count[[2,current_time]] || 0,
|
||||
"3": @create_issues_count[[3,current_time]] || 0
|
||||
}
|
||||
else
|
||||
data[:create_issues][current_time] = {
|
||||
"1": 0,
|
||||
"2": 0,
|
||||
"3": 0
|
||||
}
|
||||
end
|
||||
if @due_issues_count.present?
|
||||
data[:due_issues][current_time] = {
|
||||
"1": @due_issues_count[[1,current_time]] || 0,
|
||||
"2": @due_issues_count[[2,current_time]] || 0,
|
||||
"3": @due_issues_count[[3,current_time]] || 0
|
||||
}
|
||||
else
|
||||
data[:due_issues][current_time] = {
|
||||
"1": 0,
|
||||
"2": 0,
|
||||
"3": 0
|
||||
}
|
||||
end
|
||||
end
|
||||
render_ok(data: data)
|
||||
end
|
||||
|
||||
def bind_project
|
||||
return render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin?
|
||||
Issue.where(pm_project_id: params[:pm_project_id], user_id: current_user).update_all(project_id: params[:project_id])
|
||||
end
|
||||
|
||||
private
|
||||
def load_project
|
||||
@project = Project.joins(:owner).find params[:project_id]
|
||||
end
|
||||
|
||||
|
||||
end
|
|
@ -0,0 +1,108 @@
|
|||
class Api::Pm::SprintIssuesController < Api::Pm::BaseController
|
||||
|
||||
before_action :require_login, except: [:index]
|
||||
|
||||
def index
|
||||
@issues = Api::Pm::SprintIssues::ListService.call(query_params, current_user)
|
||||
@issues = kaminari_paginate(@issues)
|
||||
render 'api/v1/issues/index'
|
||||
end
|
||||
|
||||
def burndown_charts
|
||||
return tip_exception '参数错误' if params[:pm_sprint_id].blank? || params[:start_time].blank? || params[:end_time].blank?
|
||||
@issues = Issue.where(pm_sprint_id: params[:pm_sprint_id])
|
||||
start_time = Date.parse params[:start_time]
|
||||
end_time = Date.parse params[:end_time]
|
||||
time_count = (end_time - start_time).to_i + 1 # 计算间隔时间 加上最后一天
|
||||
data = []
|
||||
curren_issues = @issues.group(:status_id, :due_date).count
|
||||
total_count = @issues.count
|
||||
cardinality = BigDecimal.new(total_count) / BigDecimal.new(time_count)
|
||||
time_count.times do |x|
|
||||
e_time = start_time + x
|
||||
completed = curren_issues[[5, e_time]].to_i + curren_issues[[3, e_time]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size
|
||||
total_count = total_count - completed
|
||||
data << { time: e_time, undone: total_count, completed: completed, base_number: (cardinality * (time_count - x - 1)).to_f.round(2) }
|
||||
end
|
||||
render_ok(data: data)
|
||||
end
|
||||
|
||||
def statistics
|
||||
pm_sprint_ids = params[:pm_sprint_ids].split(",") rescue []
|
||||
return tip_exception '参数错误' if pm_sprint_ids.blank?
|
||||
@issues = Issue.where(pm_sprint_id: pm_sprint_ids)
|
||||
data = {}
|
||||
# requirement 1 task 2 bug 3
|
||||
@issues_count = @issues.group(:pm_sprint_id).count
|
||||
@issues_type_count = @issues.group(:pm_sprint_id, :status_id).count
|
||||
@issues_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).count
|
||||
@issues_hour_count = @issues.group(:pm_sprint_id).sum(:time_scale)
|
||||
@issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale)
|
||||
@issues_hour_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).sum(:time_scale)
|
||||
@issues_status_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type, :status_id).count
|
||||
pm_sprint_ids.map(&:to_i).map do |sprint_id|
|
||||
# count_closed 工作项已完成/已关闭数量,需排除已修复的缺陷数量
|
||||
count_closed = @issues_type_count[[sprint_id, 5]].to_i + @issues_type_count[[sprint_id, 3]].to_i - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).size
|
||||
# hour_closed 已完成/已关闭 预估工时之和,需排除已修复的缺陷预估工时
|
||||
hour_closed = @issues_hour_type_count[[sprint_id, 5]].to_f + @issues_hour_type_count[[sprint_id, 3]].to_f - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).sum(:time_scale).to_f
|
||||
data[sprint_id] = {
|
||||
count_total: @issues_count[sprint_id] || 0,
|
||||
count_closed: count_closed || 0,
|
||||
hour_total: @issues_hour_count[sprint_id].to_f || 0,
|
||||
hour_closed: hour_closed || 0,
|
||||
requirement: @issues_pm_type_count[[sprint_id, 1]] || 0,
|
||||
task: @issues_pm_type_count[[sprint_id, 2]] || 0,
|
||||
bug: @issues_pm_type_count[[sprint_id, 3]] || 0,
|
||||
requirement_hour: @issues_hour_pm_type_count[[sprint_id, 1]].to_i || 0,
|
||||
task_hour: @issues_hour_pm_type_count[[sprint_id, 2]].to_i || 0,
|
||||
bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]].to_i || 0,
|
||||
requirement_open: (@issues_status_pm_type_count[[sprint_id, 1, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 1, 2]].to_i) || 0,
|
||||
task_open: @issues_status_pm_type_count[[sprint_id, 2, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 2, 2]].to_i || 0,
|
||||
bug_open: @issues_status_pm_type_count[[sprint_id, 3, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 3, 2]].to_i || 0
|
||||
}
|
||||
end
|
||||
render_ok(data: data)
|
||||
end
|
||||
|
||||
before_action :load_uncomplete_issues, only: [:complete]
|
||||
|
||||
def complete
|
||||
begin
|
||||
case complete_params[:complete_type].to_i
|
||||
when 1
|
||||
@issues.update_all(status_id: 5)
|
||||
when 2
|
||||
@issues.update_all(pm_sprint_id: 0)
|
||||
when 3
|
||||
@issues.update_all(pm_sprint_id: complete_params[:target_pm_project_sprint_id])
|
||||
end
|
||||
render_ok
|
||||
rescue => e
|
||||
render_error(e.message)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def load_uncomplete_issues
|
||||
@issues = Issue.where(pm_sprint_id: complete_params[:pm_project_sprint_id]).where.not(status_id: 5)
|
||||
end
|
||||
|
||||
def complete_params
|
||||
params.permit(:pm_project_sprint_id, :complete_type, :target_pm_project_sprint_id)
|
||||
end
|
||||
|
||||
def query_params
|
||||
params.permit(
|
||||
:category,
|
||||
:pm_project_id,
|
||||
:pm_issue_type, # 需求1 任务2 缺陷3
|
||||
:assigner_id,
|
||||
:priority_id,
|
||||
:status_id,
|
||||
:keyword, :status_ids, :pm_issue_types,
|
||||
:sort_by, :sort_direction
|
||||
)
|
||||
end
|
||||
|
||||
end
|
|
@ -55,9 +55,14 @@ class Api::V1::BaseController < ApplicationController
|
|||
return render_forbidden if !current_user.admin? && !@project.operator?(current_user) && !(@project.fork_project.present? && @project.fork_project.operator?(current_user))
|
||||
end
|
||||
|
||||
def require_member_above
|
||||
@project = load_project
|
||||
return render_forbidden if !current_user.admin? && !@project.member?(current_user)
|
||||
end
|
||||
|
||||
# 具有对仓库的访问权限
|
||||
def require_public_and_member_above
|
||||
@project = load_project
|
||||
@project = load_project
|
||||
return render_forbidden if !@project.is_public && !current_user.admin? && !@project.member?(current_user)
|
||||
end
|
||||
end
|
|
@ -0,0 +1,37 @@
|
|||
class Api::V1::GitlinkCompetitionAppliesController < Api::V1::BaseController
|
||||
|
||||
def create
|
||||
return render_error("请输入正确的竞赛ID") unless params[:competition_id].present?
|
||||
return render_error("请输入正确的队伍ID") unless params[:team_id].present?
|
||||
return render_error("请输入正确的队伍成员信息") unless params[:team_members].is_a?(Array)
|
||||
params[:team_members].each do |member|
|
||||
apply = GitlinkCompetitionApply.find_or_create_by(competition_id: params[:competition_id], team_id: params[:team_id], educoder_login: member[:login])
|
||||
apply.competition_identifier = params[:competition_identifier]
|
||||
apply.team_name = params[:team_name]
|
||||
apply.school_name = member[:school_name]
|
||||
apply.nickname = member[:nickname]
|
||||
apply.identity = member[:identity]
|
||||
apply.role = member[:role]
|
||||
apply.email = member[:email]
|
||||
user_info = get_user_info_by_educoder_login(member[:login])
|
||||
apply.phone = user_info["phone"]
|
||||
apply.save
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
def get_user_info_by_educoder_login(edu_login)
|
||||
req_params = { "login" => "#{edu_login}", "private_token" => "hriEn3UwXfJs3PmyXnqQ" }
|
||||
api_url= "https://data.educoder.net"
|
||||
client = Faraday.new(url: api_url)
|
||||
response = client.public_send("get", "/api/sources/get_user_info_by_login", req_params)
|
||||
result = JSON.parse(response.body)
|
||||
|
||||
return nil if result["status"].to_s != "0"
|
||||
|
||||
# login 邮箱 手机号 姓名 学校/单位
|
||||
user_info = result["data"]
|
||||
|
||||
return user_info
|
||||
end
|
||||
end
|
|
@ -7,12 +7,4 @@ class Api::V1::Issues::IssuePrioritiesController < Api::V1::BaseController
|
|||
@priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword]
|
||||
@priorities = kaminary_select_paginate(@priorities)
|
||||
end
|
||||
|
||||
def pm_index
|
||||
@priorities = IssuePriority.order(position: :asc)
|
||||
@priorities = @priorities.ransack(name_cont: params[:keyword]).result if params[:keyword]
|
||||
@priorities = kaminary_select_paginate(@priorities)
|
||||
render "index"
|
||||
end
|
||||
|
||||
end
|
|
@ -13,12 +13,7 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController
|
|||
end
|
||||
end
|
||||
|
||||
def pm_index
|
||||
@issue_tags = IssueTag.init_mp_issues_tags
|
||||
render_ok(@issue_tags)
|
||||
end
|
||||
|
||||
def create
|
||||
def create
|
||||
@issue_tag = @project.issue_tags.new(issue_tag_params)
|
||||
if @issue_tag.save!
|
||||
render_ok
|
||||
|
|
|
@ -8,11 +8,4 @@ class Api::V1::Issues::StatuesController < Api::V1::BaseController
|
|||
@statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
|
||||
@statues = kaminary_select_paginate(@statues)
|
||||
end
|
||||
|
||||
def pm_index
|
||||
@statues = IssueStatus.order("position asc")
|
||||
@statues = @statues.ransack(name_cont: params[:keyword]).result if params[:keyword].present?
|
||||
@statues = kaminary_select_paginate(@statues)
|
||||
render "index"
|
||||
end
|
||||
end
|
|
@ -0,0 +1,36 @@
|
|||
class Api::V1::PmIssuesController < ApplicationController
|
||||
before_action :require_login, except: [:index, :show]
|
||||
|
||||
def index
|
||||
project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: 0, name:"pm_mm", identifier:"pm_mm" )
|
||||
object_result = Api::V1::Issues::ListService.call(@project, query_params, current_user)
|
||||
@total_issues_count = @object_result[:total_issues_count]
|
||||
@opened_issues_count = @object_result[:opened_issues_count]
|
||||
@closed_issues_count = @object_result[:closed_issues_count]
|
||||
if params[:only_name].present?
|
||||
@issues = kaminary_select_paginate(@object_result[:data].select(:id, :subject, :project_issues_index, :updated_on, :created_on))
|
||||
else
|
||||
@issues = kaminari_paginate(@object_result[:data])
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
project = Project.find_by_id(params[:project_id]) || Project.new( id: 0, user_id: 0, name:"pm_mm", identifier:"pm_mm" )
|
||||
@object_result = Api::V1::Issues::CreateService.call(project, issue_params, current_user)
|
||||
end
|
||||
|
||||
private
|
||||
def issue_params
|
||||
params.permit(
|
||||
:status_id, :priority_id, :milestone_id,
|
||||
:branch_name, :start_date, :due_date,
|
||||
:subject, :description, :blockchain_token_num,
|
||||
:pm_project_id, :pm_sprint_id,
|
||||
:issue_tag_ids => [],
|
||||
:assigner_ids => [],
|
||||
:attachment_ids => [],
|
||||
:receivers_login => []
|
||||
)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,10 @@
|
|||
class Api::V1::ProjectDatasetsController < Api::V1::BaseController
|
||||
|
||||
def index
|
||||
return render_error("请输入正确的项目id字符串") unless params[:ids].present?
|
||||
ids = params[:ids].split(",")
|
||||
@project_datasets = ProjectDataset.where(project_id: ids).includes(:license, :project)
|
||||
@project_datasets = kaminari_unlimit_paginate(@project_datasets)
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,31 @@
|
|||
class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions::BaseController
|
||||
|
||||
def index
|
||||
begin
|
||||
gitea_result = $gitea_hat_client.get_repos_actions_by_owner_repo(@project&.owner&.login, @project&.identifier)
|
||||
@data = gitea_result[:data]["Workflows"]
|
||||
rescue
|
||||
@data = []
|
||||
end
|
||||
end
|
||||
|
||||
def disable
|
||||
return render_error("请输入正确的流水线文件!") if params[:workflow].blank?
|
||||
gitea_result = $gitea_hat_client.post_repos_actions_disable(@project&.owner&.login, @project&.identifier, {query: {workflow: params[:workflow]}}) rescue nil
|
||||
if gitea_result
|
||||
render_ok
|
||||
else
|
||||
render_error("禁用流水线失败")
|
||||
end
|
||||
end
|
||||
|
||||
def enable
|
||||
return render_error("请输入正确的流水线文件!") if params[:workflow].blank?
|
||||
gitea_result = $gitea_hat_client.post_repos_actions_enable(@project&.owner&.login, @project&.identifier, {query: {workflow: params[:workflow]}}) rescue nil
|
||||
if gitea_result
|
||||
render_ok
|
||||
else
|
||||
render_error("取消禁用流水线失败")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
class Api::V1::Projects::Actions::BaseController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above
|
||||
|
||||
end
|
|
@ -0,0 +1,46 @@
|
|||
class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::BaseController
|
||||
|
||||
def index
|
||||
@result_object = Api::V1::Projects::Actions::Runs::ListService.call(@project, {workflow: params[:workflow], page: page, limit: limit}, current_user&.gitea_token)
|
||||
puts @result_object
|
||||
end
|
||||
|
||||
def rerun
|
||||
return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank?
|
||||
gitea_result = $gitea_hat_client.post_repos_actions_runs_rerun_by_owner_repo_run(@project&.owner&.login, @project&.identifier, params[:run_id]) rescue nil
|
||||
if gitea_result
|
||||
render_ok
|
||||
else
|
||||
render_error("重启所有流水线任务失败")
|
||||
end
|
||||
end
|
||||
|
||||
def job_rerun
|
||||
return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank?
|
||||
return render_error("请输入正确的流水线任务ID") if params[:job].blank?
|
||||
gitea_result = $gitea_hat_client.post_repos_actions_runs_jobs_rerun_by_owner_repo_run_job(@project&.owner&.login, @project&.identifier, params[:run_id], params[:job]) rescue nil
|
||||
if gitea_result
|
||||
render_ok
|
||||
else
|
||||
render_error("重启流水线任务失败")
|
||||
end
|
||||
end
|
||||
|
||||
def job_show
|
||||
@result_object = Api::V1::Projects::Actions::Runs::JobShowService.call(@project, params[:run_id], params[:job], params[:log_cursors], current_user&.gitea_token)
|
||||
end
|
||||
|
||||
def job_logs
|
||||
return render_error("请输入正确的流水线记录ID!") if params[:run_id].blank?
|
||||
return render_error("请输入正确的流水线任务ID") if params[:job].blank?
|
||||
domain = GiteaService.gitea_config[:domain]
|
||||
api_url = GiteaService.gitea_config[:hat_base_url]
|
||||
|
||||
url = "/repos/#{@owner.login}/#{@repository.identifier}/actions/runs/#{CGI.escape(params[:run_id])}/jobs/#{CGI.escape(params[:job])}/logs"
|
||||
file_path = [domain, api_url, url].join
|
||||
file_path = [file_path, "access_token=#{@owner&.gitea_token}"].join("?")
|
||||
|
||||
redirect_to file_path
|
||||
end
|
||||
|
||||
end
|
|
@ -1,15 +1,38 @@
|
|||
class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:index, :all]
|
||||
|
||||
def gitee
|
||||
url = URI("https://gitee.com/api/v5/repos/#{params[:owner]}/#{params[:repo]}/branches?access_token=#{params[:token]}&page=#{page}&per_page=#{limit}")
|
||||
https = Net::HTTP.new(url.host, url.port)
|
||||
https.use_ssl = true
|
||||
request = Net::HTTP::Get.new(url)
|
||||
response = https.request(request)
|
||||
render :json => response.read_body
|
||||
end
|
||||
|
||||
def github
|
||||
url = URI("https://api.github.com/repos/#{params[:owner]}/#{params[:repo]}/branches?page=#{page}&per_page=#{limit}")
|
||||
https = Net::HTTP.new(url.host, url.port)
|
||||
https.use_ssl = true
|
||||
|
||||
request = Net::HTTP::Get.new(url)
|
||||
request["Authorization"] = "Bearer #{params[:token]}"
|
||||
request["Accept"] = "application/vnd.github+json"
|
||||
request["X-GitHub-Api-Version"] = "2022-11-28"
|
||||
|
||||
response = https.request(request)
|
||||
render :json => response.read_body
|
||||
end
|
||||
|
||||
def index
|
||||
@result_object = Api::V1::Projects::Branches::ListService.call(@project, {name: params[:keyword], page: page, limit: limit}, current_user&.gitea_token)
|
||||
@result_object = Api::V1::Projects::Branches::ListService.call(@project, {name: params[:keyword], state: params[:state], page: page, limit: limit}, current_user&.gitea_token)
|
||||
end
|
||||
|
||||
def all
|
||||
@result_object = Api::V1::Projects::Branches::AllListService.call(@project, current_user&.gitea_token)
|
||||
end
|
||||
|
||||
before_action :require_operate_above, only: [:create, :destroy]
|
||||
before_action :require_operate_above, only: [:create, :destroy, :restore]
|
||||
|
||||
def create
|
||||
@result_object = Api::V1::Projects::Branches::CreateService.call(@project, branch_params, current_user&.gitea_token)
|
||||
|
@ -33,6 +56,15 @@ class Api::V1::Projects::BranchesController < Api::V1::BaseController
|
|||
end
|
||||
end
|
||||
|
||||
def restore
|
||||
@result_object = Api::V1::Projects::Branches::RestoreService.call(@project, params[:branch_id], params[:branch_name], current_user&.gitea_token)
|
||||
if @result_object
|
||||
return render_ok
|
||||
else
|
||||
return render_error('恢复分支失败!')
|
||||
end
|
||||
end
|
||||
|
||||
before_action :require_manager_above, only: [:update_default_branch]
|
||||
|
||||
def update_default_branch
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class Api::V1::Projects::CommitsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:index, :diff]
|
||||
before_action :require_public_and_member_above, only: [:index, :diff, :recent]
|
||||
|
||||
def index
|
||||
@result_object = Api::V1::Projects::Commits::ListService.call(@project, {page: page, limit: limit, sha: params[:sha]}, current_user&.gitea_token)
|
||||
|
@ -9,4 +9,11 @@ class Api::V1::Projects::CommitsController < Api::V1::BaseController
|
|||
def diff
|
||||
@result_object = Api::V1::Projects::Commits::DiffService.call(@project, params[:sha], current_user&.gitea_token)
|
||||
end
|
||||
|
||||
def recent
|
||||
hash = Api::V1::Projects::Commits::RecentService.call(@project, {keyword: params[:keyword], page: page, limit: limit}, current_user&.gitea_token)
|
||||
@result_object = hash[:result]
|
||||
@object_detail = hash[:detail]
|
||||
puts @object_detail
|
||||
end
|
||||
end
|
|
@ -0,0 +1,51 @@
|
|||
class Api::V1::Projects::DatasetsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:show]
|
||||
before_action :require_member_above, only: [:create, :update]
|
||||
before_action :find_dataset, only: [:update, :show]
|
||||
before_action :check_menu_authorize
|
||||
|
||||
def create
|
||||
::Projects::Datasets::CreateForm.new(dataset_params).validate!
|
||||
return render_error('该项目下已存在数据集!') if @project.project_dataset.present?
|
||||
@project_dataset = ProjectDataset.new(dataset_params.merge!(project_id: @project.id))
|
||||
if @project_dataset.save!
|
||||
render_ok
|
||||
else
|
||||
render_error('创建数据集失败!')
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def update
|
||||
::Projects::Datasets::CreateForm.new(dataset_params).validate!
|
||||
@project_dataset.attributes = dataset_params
|
||||
if @project_dataset.save!
|
||||
render_ok
|
||||
else
|
||||
render_error("更新数据集失败!")
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def show
|
||||
@attachments = kaminari_paginate(@project_dataset.attachments.includes(:author))
|
||||
end
|
||||
|
||||
private
|
||||
def dataset_params
|
||||
params.permit(:title, :description, :license_id, :paper_content)
|
||||
end
|
||||
|
||||
def find_dataset
|
||||
@project_dataset = @project.project_dataset
|
||||
return render_not_found unless @project_dataset.present?
|
||||
end
|
||||
|
||||
def check_menu_authorize
|
||||
return render_not_found unless @project.has_menu_permission("dataset")
|
||||
end
|
||||
end
|
|
@ -0,0 +1,460 @@
|
|||
class Api::V1::Projects::PipelinesController < Api::V1::BaseController
|
||||
before_action :require_operate_above
|
||||
|
||||
def index
|
||||
@pipelines = Action::Pipeline.where(project_id: @project.id).order(updated_at: :desc)
|
||||
@pipelines = paginate @pipelines
|
||||
end
|
||||
|
||||
def create
|
||||
size = Action::Pipeline.where(pipeline_name: params[:pipeline_name], project_id: @project.id).size
|
||||
tip_exception("已经存在#{params[:pipeline_name]}流水线!") if size > 0
|
||||
@pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id)
|
||||
@pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml"
|
||||
@pipeline.branch = params[:branch] || @project.default_branch
|
||||
@pipeline.json = params[:pipeline_json].to_json
|
||||
pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json])
|
||||
tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank?
|
||||
@pipeline.yaml = pipeline_yaml
|
||||
@pipeline.save!
|
||||
sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch)
|
||||
tip_exception("#{@pipeline.file_name}已存在") if sha
|
||||
interactor = Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create"))
|
||||
tip_exception(interactor.error) unless interactor.success?
|
||||
render_ok({ id: @pipeline.id })
|
||||
end
|
||||
|
||||
def save_yaml
|
||||
@pipeline = Action::Pipeline.new(pipeline_name: params[:pipeline_name], project_id: @project.id)
|
||||
@pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml"
|
||||
@pipeline.branch = params[:branch] || @project.default_branch
|
||||
@pipeline.json = params[:pipeline_json].to_json
|
||||
pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json])
|
||||
tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank?
|
||||
@pipeline.yaml = pipeline_yaml
|
||||
sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch)
|
||||
interactor = sha.present? ? Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update").merge(sha: sha)) : Gitea::CreateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create"))
|
||||
tip_exception(interactor.error) unless interactor.success?
|
||||
file = interactor.result
|
||||
render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: sha.present? ? sha : file['content']['sha'] })
|
||||
end
|
||||
|
||||
def build_yaml
|
||||
if params[:pipeline_json].present?
|
||||
pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json])
|
||||
else
|
||||
pipeline_yaml = build_test_yaml
|
||||
end
|
||||
# render plain: pipeline_yaml
|
||||
render_ok({ pipeline_yaml: pipeline_yaml })
|
||||
end
|
||||
|
||||
def update
|
||||
@pipeline = Action::Pipeline.find(params[:id])
|
||||
@pipeline.pipeline_name = params[:pipeline_name]
|
||||
@pipeline.file_name = ".gitea/workflows/#{@pipeline.pipeline_name}.yml"
|
||||
@pipeline.branch = params[:branch] || @project.default_branch
|
||||
@pipeline.json = params[:pipeline_json].to_json
|
||||
pipeline_yaml = build_pipeline_yaml(params[:pipeline_name], params[:pipeline_json])
|
||||
tip_exception("流水线yaml内空不能为空") if pipeline_yaml.blank?
|
||||
@pipeline.yaml = pipeline_yaml
|
||||
@pipeline.save
|
||||
sha = get_pipeline_file_sha(@pipeline.file_name, @pipeline.branch)
|
||||
interactor = Gitea::UpdateFileInteractor.call(current_user.gitea_token, @owner.login, content_params("create").merge(sha: sha))
|
||||
tip_exception(interactor.error) unless interactor.success?
|
||||
file = interactor.result
|
||||
render_ok({ pipeline_yaml: pipeline_yaml, pipeline_name: params[:pipeline_name], file_name: @pipeline.file_name, sha: file['content']['sha'] })
|
||||
end
|
||||
|
||||
def destroy
|
||||
@pipeline = Action::Pipeline.find(params[:id])
|
||||
if pipeline
|
||||
interactor = Gitea::DeleteFileInteractor.call(current_user.gitea_token, @owner.login, content_params("update"))
|
||||
tip_exception(interactor.error) unless interactor.success?
|
||||
@pipeline.destroy!
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
def show
|
||||
@pipeline = Action::Pipeline.find_by(id: params[:id])
|
||||
@pipeline = Action::Pipeline.new(id: 0, pipeline_name: "test-ss", yaml: build_test_yaml) if @pipeline.blank?
|
||||
end
|
||||
|
||||
def build_pipeline_yaml(pipeline_name, pipeline_json)
|
||||
if pipeline_json.present? && pipeline_json.present?
|
||||
@pipeline_name = pipeline_name
|
||||
params_nodes = pipeline_json["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) }
|
||||
on_nodes = pipeline_json["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) }
|
||||
@on_nodes = build_nodes(on_nodes)
|
||||
@steps_nodes = build_nodes(params_nodes)
|
||||
yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding)
|
||||
# 删除空行内容
|
||||
pipeline_yaml = yaml.gsub(/^\s*\n/, "")
|
||||
else
|
||||
pipeline_yaml = params[:pipeline_yaml]
|
||||
end
|
||||
pipeline_yaml
|
||||
end
|
||||
|
||||
def build_test_yaml
|
||||
@pipeline_name = "I like it"
|
||||
params_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| !["on-push", "on-schedule"].include?(node["name"]) }
|
||||
on_nodes = JSON.parse(demo.to_json)["nodes"].select { |node| ["on-push", "on-schedule"].include?(node["name"]) }
|
||||
@on_nodes = build_nodes(on_nodes)
|
||||
@steps_nodes = []
|
||||
params_nodes.each do |input_node|
|
||||
# Rails.logger.info "input_node=====0===#{input_node["name"]}======#{input_node["inputs"]}"
|
||||
node = Action::Node.find_by(name: input_node["name"])
|
||||
next if node.blank?
|
||||
node.cust_name = input_node["label"] if input_node["label"].present?
|
||||
run_values = {}
|
||||
input_values = {}
|
||||
if input_node["inputs"].present?
|
||||
Rails.logger.info "@inputs=====11===#{input_node["name"]}======#{input_node["inputs"]}"
|
||||
input_node["inputs"].each do |input|
|
||||
# Rails.logger.info "@inputs.input_name===#{input[:name]}"
|
||||
# Rails.logger.info "@inputs.input_value===#{input["value"]}"
|
||||
if input[:name].to_s.gsub("--", "") == "run"
|
||||
run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" })
|
||||
else
|
||||
input_values = input_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" })
|
||||
end
|
||||
end
|
||||
node.run_values = run_values
|
||||
node.input_values = input_values
|
||||
# Rails.logger.info "@input_values run_values===#{node.run_values.to_json}"
|
||||
# Rails.logger.info "@input_values input_values===#{node.input_values.to_json}"
|
||||
end
|
||||
@steps_nodes.push(node)
|
||||
end
|
||||
Rails.logger.info "@@on_nodes===#{@on_nodes.to_json}"
|
||||
Rails.logger.info "@steps_nodes===#{@steps_nodes.to_json}"
|
||||
yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_pipeline.yaml.erb"))).result(binding)
|
||||
pipeline_yaml = yaml.gsub(/^\s*\n/, "")
|
||||
Rails.logger.info "========================="
|
||||
Rails.logger.info pipeline_yaml
|
||||
pipeline_yaml
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def get_pipeline_file_sha(file_name, branch)
|
||||
file_path_uri = URI.parse(URI.encode(file_name))
|
||||
interactor = Repositories::EntriesInteractor.call(@project.owner, @project.identifier, file_path_uri, ref: branch || @project.default_branch)
|
||||
if interactor.success?
|
||||
file = interactor.result
|
||||
file['sha']
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def content_params(opt)
|
||||
{
|
||||
filepath: ".gitea/workflows/#{@pipeline.pipeline_name}.yml",
|
||||
branch: @pipeline.branch,
|
||||
new_branch: @pipeline.branch,
|
||||
content: Base64.encode64(@pipeline.yaml).gsub(/\n/, ''),
|
||||
message: "#{opt} pipeline",
|
||||
committer: {
|
||||
email: current_user.mail,
|
||||
name: current_user.login
|
||||
},
|
||||
identifier: @project.identifier
|
||||
}
|
||||
end
|
||||
|
||||
def build_nodes(params_nodes)
|
||||
steps_nodes = []
|
||||
params_nodes.each do |input_node|
|
||||
node = Action::Node.find_by(name: input_node["name"])
|
||||
next if node.blank?
|
||||
node.cust_name = input_node["labelf"] if input_node["label"].present?
|
||||
run_values = {}
|
||||
input_values = {}
|
||||
if input_node["inputs"].present?
|
||||
Rails.logger.info "@inputs=====11===#{input_node["name"]}======#{input_node["inputs"]}"
|
||||
input_node["inputs"].each do |input|
|
||||
# Rails.logger.info "@inputs.input_name===#{input[:name]}"
|
||||
# Rails.logger.info "@inputs.input_value===#{input["value"]}"
|
||||
if input[:name].to_s.gsub("--", "") == "run"
|
||||
run_values = run_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" })
|
||||
else
|
||||
input_values = input_values.merge({ "#{input[:name].gsub("--", "")}": "#{input["value"]}" })
|
||||
end
|
||||
end
|
||||
node.run_values = run_values
|
||||
node.input_values = input_values
|
||||
end
|
||||
steps_nodes.push(node)
|
||||
end
|
||||
steps_nodes
|
||||
end
|
||||
|
||||
def demo
|
||||
{
|
||||
"nodes": [{
|
||||
"id": "on-schedule-2fcf505",
|
||||
"name": "on-schedule",
|
||||
"full_name": "on-schedule",
|
||||
"description": " 定时器计划器",
|
||||
"icon": "https://testforgeplus.trustie.net/api/attachments/0445403c-5d9e-4495-8414-339f87981ca1",
|
||||
"action_node_types_id": 3,
|
||||
"yaml": "",
|
||||
"sort_no": 0,
|
||||
"use_count": 0,
|
||||
"inputs": [{
|
||||
"id": 8,
|
||||
"name": "cron",
|
||||
"input_type": "input",
|
||||
"description": "示例:\r\n- cron: '20 8 * * *'",
|
||||
"is_required": true,
|
||||
"value": "- corn: '0 10 * * *'"
|
||||
}],
|
||||
"x": 586,
|
||||
"y": 165.328125,
|
||||
"label": "on-schedule",
|
||||
"img": "https://testforgeplus.trustie.net/api/attachments/0445403c-5d9e-4495-8414-339f87981ca1",
|
||||
"isCluster": false,
|
||||
"type": "rect-node",
|
||||
"size": [110, 36],
|
||||
"labelCfg": {
|
||||
"style": {
|
||||
"fill": "transparent",
|
||||
"fontSize": 0,
|
||||
"boxShadow": "0px 0px 12px rgba(75, 84, 137, 0.05)",
|
||||
"overflow": "hidden",
|
||||
"x": -20,
|
||||
"y": 0,
|
||||
"textAlign": "left",
|
||||
"textBaseline": "middle"
|
||||
}
|
||||
},
|
||||
"style": {
|
||||
"active": {
|
||||
"fill": "rgb(247, 250, 255)",
|
||||
"stroke": "rgb(95, 149, 255)",
|
||||
"lineWidth": 2,
|
||||
"shadowColor": "rgb(95, 149, 255)",
|
||||
"shadowBlur": 10
|
||||
},
|
||||
"selected": {
|
||||
"fill": "rgb(255, 255, 255)",
|
||||
"stroke": "rgb(95, 149, 255)",
|
||||
"lineWidth": 4,
|
||||
"shadowColor": "rgb(95, 149, 255)",
|
||||
"shadowBlur": 10,
|
||||
"text-shape": {
|
||||
"fontWeight": 500
|
||||
}
|
||||
},
|
||||
"highlight": {
|
||||
"fill": "rgb(223, 234, 255)",
|
||||
"stroke": "#4572d9",
|
||||
"lineWidth": 2,
|
||||
"text-shape": {
|
||||
"fontWeight": 500
|
||||
}
|
||||
},
|
||||
"inactive": {
|
||||
"fill": "rgb(247, 250, 255)",
|
||||
"stroke": "rgb(191, 213, 255)",
|
||||
"lineWidth": 1
|
||||
},
|
||||
"disable": {
|
||||
"fill": "rgb(250, 250, 250)",
|
||||
"stroke": "rgb(224, 224, 224)",
|
||||
"lineWidth": 1
|
||||
},
|
||||
"nodeSelected": {
|
||||
"fill": "red",
|
||||
"shadowColor": "red",
|
||||
"stroke": "red",
|
||||
"text-shape": {
|
||||
"fill": "red",
|
||||
"stroke": "red"
|
||||
}
|
||||
},
|
||||
"fill": "#fff",
|
||||
"stroke": "transparent",
|
||||
"cursor": "pointer",
|
||||
"radius": 10,
|
||||
"overflow": "hidden",
|
||||
"lineWidth": 0.5,
|
||||
"shadowColor": "rgba(75,84,137,0.05)",
|
||||
"shadowBlur": 12
|
||||
},
|
||||
"cron": "- corn: '0 10 * * *'",
|
||||
"depth": 0
|
||||
}, {
|
||||
"id": "actions/setup-node@v3-257f29d",
|
||||
"name": "node",
|
||||
"full_name": "actions/setup-node@v3",
|
||||
"description": "",
|
||||
"icon": "https://testforgeplus.trustie.net/api/attachments/c4774fc1-ecd9-47fd-9878-1847bdaf98f6",
|
||||
"action_node_types_id": 1,
|
||||
"yaml": "",
|
||||
"sort_no": 0,
|
||||
"use_count": 0,
|
||||
"inputs": [{
|
||||
"id": 2,
|
||||
"name": "node-version",
|
||||
"input_type": "select",
|
||||
"is_required": false,
|
||||
"value": 55
|
||||
}],
|
||||
"x": 608,
|
||||
"y": 357.328125,
|
||||
"label": "node",
|
||||
"img": "https://testforgeplus.trustie.net/api/attachments/c4774fc1-ecd9-47fd-9878-1847bdaf98f6",
|
||||
"isCluster": false,
|
||||
"type": "rect-node",
|
||||
"size": [110, 36],
|
||||
"labelCfg": {
|
||||
"style": {
|
||||
"fill": "transparent",
|
||||
"fontSize": 0,
|
||||
"boxShadow": "0px 0px 12px rgba(75, 84, 137, 0.05)",
|
||||
"overflow": "hidden",
|
||||
"x": -20,
|
||||
"y": 0,
|
||||
"textAlign": "left",
|
||||
"textBaseline": "middle"
|
||||
}
|
||||
},
|
||||
"style": {
|
||||
"active": {
|
||||
"fill": "rgb(247, 250, 255)",
|
||||
"stroke": "rgb(95, 149, 255)",
|
||||
"lineWidth": 2,
|
||||
"shadowColor": "rgb(95, 149, 255)",
|
||||
"shadowBlur": 10
|
||||
},
|
||||
"selected": {
|
||||
"fill": "rgb(255, 255, 255)",
|
||||
"stroke": "rgb(95, 149, 255)",
|
||||
"lineWidth": 4,
|
||||
"shadowColor": "rgb(95, 149, 255)",
|
||||
"shadowBlur": 10,
|
||||
"text-shape": {
|
||||
"fontWeight": 500
|
||||
}
|
||||
},
|
||||
"highlight": {
|
||||
"fill": "rgb(223, 234, 255)",
|
||||
"stroke": "#4572d9",
|
||||
"lineWidth": 2,
|
||||
"text-shape": {
|
||||
"fontWeight": 500
|
||||
}
|
||||
},
|
||||
"inactive": {
|
||||
"fill": "rgb(247, 250, 255)",
|
||||
"stroke": "rgb(191, 213, 255)",
|
||||
"lineWidth": 1
|
||||
},
|
||||
"disable": {
|
||||
"fill": "rgb(250, 250, 250)",
|
||||
"stroke": "rgb(224, 224, 224)",
|
||||
"lineWidth": 1
|
||||
},
|
||||
"nodeSelected": {
|
||||
"fill": "red",
|
||||
"shadowColor": "red",
|
||||
"stroke": "red",
|
||||
"text-shape": {
|
||||
"fill": "red",
|
||||
"stroke": "red"
|
||||
}
|
||||
},
|
||||
"fill": "#fff",
|
||||
"stroke": "transparent",
|
||||
"cursor": "pointer",
|
||||
"radius": 10,
|
||||
"overflow": "hidden",
|
||||
"lineWidth": 0.5,
|
||||
"shadowColor": "rgba(75,84,137,0.05)",
|
||||
"shadowBlur": 12
|
||||
},
|
||||
"depth": 0,
|
||||
"node-version": 55
|
||||
}],
|
||||
"edges": [{
|
||||
"source": "on-schedule-2fcf505",
|
||||
"target": "actions/setup-node@v3-257f29d",
|
||||
"style": {
|
||||
"active": {
|
||||
"stroke": "rgb(95, 149, 255)",
|
||||
"lineWidth": 1
|
||||
},
|
||||
"selected": {
|
||||
"stroke": "rgb(95, 149, 255)",
|
||||
"lineWidth": 2,
|
||||
"shadowColor": "rgb(95, 149, 255)",
|
||||
"shadowBlur": 10,
|
||||
"text-shape": {
|
||||
"fontWeight": 500
|
||||
}
|
||||
},
|
||||
"highlight": {
|
||||
"stroke": "rgb(95, 149, 255)",
|
||||
"lineWidth": 2,
|
||||
"text-shape": {
|
||||
"fontWeight": 500
|
||||
}
|
||||
},
|
||||
"inactive": {
|
||||
"stroke": "rgb(234, 234, 234)",
|
||||
"lineWidth": 1
|
||||
},
|
||||
"disable": {
|
||||
"stroke": "rgb(245, 245, 245)",
|
||||
"lineWidth": 1
|
||||
},
|
||||
"endArrow": {
|
||||
"path": "M 6,0 L 9,-1.5 L 9,1.5 Z",
|
||||
"d": 4.5,
|
||||
"fill": "#CDD0DC"
|
||||
},
|
||||
"cursor": "pointer",
|
||||
"lineWidth": 1,
|
||||
"opacity": 1,
|
||||
"stroke": "#CDD0DC",
|
||||
"radius": 1
|
||||
},
|
||||
"nodeStateStyle": {
|
||||
"hover": {
|
||||
"opacity": 1,
|
||||
"stroke": "#8fe8ff"
|
||||
}
|
||||
},
|
||||
"labelCfg": {
|
||||
"autoRotate": true,
|
||||
"style": {
|
||||
"fontSize": 10,
|
||||
"fill": "#FFF"
|
||||
}
|
||||
},
|
||||
"id": "edge-0.96904321945951241716516719464",
|
||||
"startPoint": {
|
||||
"x": 586,
|
||||
"y": 183.578125,
|
||||
"anchorIndex": 1
|
||||
},
|
||||
"endPoint": {
|
||||
"x": 608,
|
||||
"y": 339.078125,
|
||||
"anchorIndex": 0
|
||||
},
|
||||
"sourceAnchor": 1,
|
||||
"targetAnchor": 0,
|
||||
"type": "cubic-vertical",
|
||||
"curveOffset": [0, 0],
|
||||
"curvePosition": [0.5, 0.5],
|
||||
"minCurveOffset": [0, 0]
|
||||
}],
|
||||
"combos": []
|
||||
}
|
||||
end
|
||||
end
|
|
@ -0,0 +1,148 @@
|
|||
class Api::V1::Projects::SyncRepositoriesController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, except: [:sync]
|
||||
before_action :load_project, only: [:sync]
|
||||
|
||||
def index
|
||||
@sync_repositories = @project.sync_repositories
|
||||
@group_sync_repository = @project.sync_repositories.group(:type, :external_repo_address, :sync_granularity, :external_token).count
|
||||
end
|
||||
|
||||
def create
|
||||
@sync_repository1, @sync_repository2, @sync_repository_branch1, @sync_repository_branch2 = Api::V1::Projects::SyncRepositories::CreateService.call(@project, sync_repository_params)
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def update_info
|
||||
return render_error("请输入正确的同步仓库ID") unless params[:sync_repository_ids].present?
|
||||
Api::V1::Projects::SyncRepositories::UpdateService.call(@project, params[:sync_repository_ids], sync_repository_update_params)
|
||||
render_ok
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def sync
|
||||
return render_error("请输入正确的同步方向!") if params[:sync_direction].blank?
|
||||
if params[:repo_type].present?
|
||||
@sync_repositories = SyncRepository.where(project: @project, type: params[:repo_type], sync_direction: params[:sync_direction])
|
||||
else
|
||||
@sync_repositories = SyncRepository.where(project: @project, sync_direction: params[:sync_direction])
|
||||
end
|
||||
branch = params[:payload].present? ? JSON.parse(params[:payload])["ref"].split("/")[-1] : params[:ref].split("/")[-1] rescue nil
|
||||
if params[:sync_direction].to_i == 1
|
||||
@sync_repository_branches = SyncRepositoryBranch.where(sync_repository_id: @sync_repositories, gitlink_branch_name: branch, enable: true)
|
||||
else
|
||||
@sync_repository_branches = SyncRepositoryBranch.where(sync_repository_id: @sync_repositories, external_branch_name: branch, enable: true)
|
||||
end
|
||||
# 全部分支同步暂时不做
|
||||
# @sync_repositories.each do |item|
|
||||
# TouchSyncJob.perform_later(item)
|
||||
# end
|
||||
@sync_repository_branches.each do |item|
|
||||
TouchSyncJob.set(wait: 5.seconds).perform_later(item)
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def unbind
|
||||
return render_error("请输入正确的同步仓库ID") unless params[:sync_repository_ids].present?
|
||||
@sync_repositories = SyncRepository.where(id: params[:sync_repository_ids].split(","))
|
||||
@sync_repositories.each do |repo|
|
||||
# Reposync::DeleteRepoService.call(repo.repo_name) # 解绑操作放在回调里
|
||||
Api::V1::Projects::Webhooks::DeleteService.call(@project, repo.webhook_gid)
|
||||
repo.destroy
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def change_enable
|
||||
return render_error("请输入正确的仓库类型") if params[:repo_type].blank?
|
||||
return render_error("请输入正确的分支名称") if params[:gitlink_branch_name].blank? || params[:external_branch_name].blank?
|
||||
# return render_error("请输入正确的状态") if params[:enable].blank?
|
||||
@sync_repository_branches = SyncRepositoryBranch.joins(:sync_repository).where(sync_repositories: {project_id: @project.id, type: params[:repo_type]}, gitlink_branch_name: params[:gitlink_branch_name], external_branch_name: params[:external_branch_name])
|
||||
if @sync_repository_branches.update_all({enable: params[:enable]})
|
||||
@sync_repository_branches.each do |branch|
|
||||
branch_sync_direction = branch&.sync_repository&.sync_direction.to_i
|
||||
if branch_sync_direction == 1
|
||||
Reposync::UpdateBranchStatusService.call(branch&.sync_repository&.repo_name, branch.gitlink_branch_name, params[:enable])
|
||||
else
|
||||
Reposync::UpdateBranchStatusService.call(branch&.sync_repository&.repo_name, branch.external_branch_name, params[:enable])
|
||||
end
|
||||
TouchSyncJob.perform_later(branch) if params[:enable] && branch_sync_direction == params[:first_sync_direction].to_i
|
||||
end
|
||||
render_ok
|
||||
else
|
||||
render_error("更新失败!")
|
||||
end
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def create_branch
|
||||
return render_error("请输入正确的同步仓库ID") unless params[:sync_repository_ids].present?
|
||||
return render_error("请输入正确的Gitlink分支名称") unless params[:gitlink_branch_name].present?
|
||||
return render_error("请输入正确的外部仓库分支名称") unless params[:external_branch_name].present?
|
||||
return render_error("请输入正确的首次同步方向") unless params[:first_sync_direction].present?
|
||||
|
||||
params[:sync_repository_ids].split(",").each do |id|
|
||||
repo = SyncRepository.find_by_id id
|
||||
branch = Reposync::CreateSyncBranchService.call(repo.repo_name, params[:gitlink_branch_name], params[:external_branch_name])
|
||||
return render_error(branch[2]) if branch[0].to_i !=0
|
||||
sync_branch = SyncRepositoryBranch.create!(sync_repository_id: id, gitlink_branch_name: params[:gitlink_branch_name], external_branch_name: params[:external_branch_name], reposync_branch_id: branch[1]['id'])
|
||||
TouchSyncJob.perform_later(sync_branch) if params[:first_sync_direction].to_i == repo.sync_direction
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
||||
def branches
|
||||
return render_error("请输入正确的同步仓库ID") unless params[:sync_repository_ids].present?
|
||||
@sync_repository_branches = SyncRepositoryBranch.where(sync_repository_id: params[:sync_repository_ids].split(","))
|
||||
@sync_repository_branches = @sync_repository_branches.ransack(gitlink_branch_name_or_external_branch_name_cont: params[:branch_name]).result if params[:branch_name].present?
|
||||
@group_sync_repository_branch = @sync_repository_branches.joins(:sync_repository).group("sync_repositories.type, sync_repository_branches.gitlink_branch_name, sync_repository_branches.external_branch_name").select("sync_repositories.type as type,max(sync_repository_branches.updated_at) as updated_at, sync_repository_branches.gitlink_branch_name, sync_repository_branches.external_branch_name").sort_by{|i|i.updated_at}
|
||||
@each_json = []
|
||||
@group_sync_repository_branch.each do |item|
|
||||
branches = @sync_repository_branches.joins(:sync_repository).where(sync_repositories: {type: item.type}, gitlink_branch_name: item.gitlink_branch_name, external_branch_name: item.external_branch_name).order(sync_time: :desc)
|
||||
branch = branches.first
|
||||
@each_json << {
|
||||
gitlink_branch_name: item.gitlink_branch_name,
|
||||
external_branch_name: item.external_branch_name,
|
||||
type: branch&.sync_repository&.type,
|
||||
sync_time: branch.sync_time.present? ? branch.sync_time.strftime("%Y-%m-%d %H:%M:%S") : nil,
|
||||
sync_status: branch.sync_status,
|
||||
enable: branch.enable,
|
||||
enable_num: branch.enable ? 1 : 0,
|
||||
created_at: branch.created_at.to_i,
|
||||
reposync_branch_ids: branches.pluck(:reposync_branch_id)
|
||||
}
|
||||
end
|
||||
@each_json = @each_json.sort_by{|h| [-h[:enable_num], h[:created_at]]}
|
||||
render :json => {total_count: @group_sync_repository_branch.count, sync_repository_branches: @each_json}
|
||||
end
|
||||
|
||||
def history
|
||||
return render_error("请输入正确的同步分支ID") unless params[:reposync_branch_ids]
|
||||
@branch = SyncRepositoryBranch.find_by(reposync_branch_id: params[:reposync_branch_ids].split(",")[0])
|
||||
_, @reposync_branch_logs, @total_count, _ = Reposync::GetLogsService.call(nil, params[:reposync_branch_ids], page, limit)
|
||||
end
|
||||
|
||||
private
|
||||
def sync_repository_params
|
||||
params.permit(:type, :external_token, :external_repo_address, :sync_granularity, :external_branch_name, :gitlink_branch_name, :first_sync_direction)
|
||||
end
|
||||
|
||||
def sync_repository_update_params
|
||||
params.permit(:external_token, :external_repo_address)
|
||||
end
|
||||
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
class Api::V1::ProjectsController < Api::V1::BaseController
|
||||
before_action :require_public_and_member_above, only: [:show, :compare, :blame]
|
||||
before_action :require_public_and_member_above, only: [:show, :compare, :blame, :sonar_search]
|
||||
|
||||
def index
|
||||
render_ok
|
||||
|
@ -9,6 +9,7 @@ class Api::V1::ProjectsController < Api::V1::BaseController
|
|||
@result_object = Api::V1::Projects::GetService.call(@project, current_user.gitea_token)
|
||||
end
|
||||
|
||||
|
||||
def compare
|
||||
@result_object = Api::V1::Projects::CompareService.call(@project, params[:from], params[:to], current_user&.gitea_token)
|
||||
end
|
||||
|
|
|
@ -0,0 +1,120 @@
|
|||
class Api::V1::SonarqubesController < Api::V1::BaseController
|
||||
before_action :load_repository
|
||||
def sonar_initialize
|
||||
gitea_params = { has_actions: params[:has_actions] == 'true' ? true :false }
|
||||
gitea_setting = Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params)
|
||||
if gitea_setting['has_actions'] == true
|
||||
Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_HOST_URL', Rails.application.config_for(:configuration)['sonarqube']['url'] ).call
|
||||
Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_TOKEN', Rails.application.config_for(:configuration)['sonarqube']['secret'] ).call
|
||||
else
|
||||
Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_HOST_URL', Rails.application.config_for(:configuration)['sonarqube']['url'] ).destroy
|
||||
Gitea::Repository::ActionSecretsService.new(@owner, @project.identifier, 'SONAR_TOKEN', Rails.application.config_for(:configuration)['sonarqube']['secret'] ).destroy
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
def insert_file
|
||||
sonar_scanner_content = {
|
||||
filepath: '.gitea/workflows/SonarScanner.yaml',
|
||||
branch: params[:branch],
|
||||
new_branch: nil,
|
||||
content: 'b246CiAgIyBUcmlnZ2VyIGFuYWx5c2lzIHdoZW4gcHVzaGluZyB0byB5b3VyIG1haW4gYnJhbmNoZXMsIGFuZCB3aGVuIGNyZWF0aW5nIGEgcHVsbCByZXF1ZXN0LgogIHB1c2g6CiAgICBicmFuY2hlczoKICAgICAgLSBtYWluCiAgICAgIC0gbWFzdGVyCiAgICAgIC0gZGV2ZWxvcAogICAgICAtICdyZWxlYXNlcy8qKicKICBwdWxsX3JlcXVlc3Q6CiAgICAgIHR5cGVzOiBbb3BlbmVkLCBzeW5jaHJvbml6ZSwgcmVvcGVuZWRdCgpuYW1lOiBNYWluIFdvcmtmbG93CmpvYnM6CiAgc29uYXJxdWJlOgogICAgcnVucy1vbjogdWJ1bnR1LWxhdGVzdAogICAgc3RlcHM6CiAgICAtIHVzZXM6IGFjdGlvbnMvY2hlY2tvdXRAdjQKICAgICAgd2l0aDoKICAgICAgICAjIERpc2FibGluZyBzaGFsbG93IGNsb25lcyBpcyByZWNvbW1lbmRlZCBmb3IgaW1wcm92aW5nIHRoZSByZWxldmFuY3kgb2YgcmVwb3J0aW5nCiAgICAgICAgZmV0Y2gtZGVwdGg6IDAKICAgIC0gbmFtZTogU29uYXJRdWJlIFNjYW4KICAgICAgdXNlczogc29uYXJzb3VyY2Uvc29uYXJxdWJlLXNjYW4tYWN0aW9uQG1hc3RlcgogICAgICBlbnY6CiAgICAgICAgU09OQVJfVE9LRU46ICR7eyBzZWNyZXRzLlNPTkFSX1RPS0VOIH19CiAgICAgICAgU09OQVJfSE9TVF9VUkw6ICAke3sgc2VjcmV0cy5TT05BUl9IT1NUX1VSTCB9fQ==',
|
||||
message: 'Add .gitea/workflows/SonarScanner.yaml',
|
||||
committer: {
|
||||
email: @owner.mail,
|
||||
name: @owner.login
|
||||
},
|
||||
identifier: @project.identifier
|
||||
}
|
||||
@path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{params[:branch]}/"
|
||||
sonar_scanner_exit = Repositories::EntriesInteractor.call(@owner, @project.identifier, '.gitea/workflows/SonarScanner.yaml', ref: params[:branch])
|
||||
if sonar_scanner_exit.success?
|
||||
sonar_scanner_content[:content] = Base64.decode64(sonar_scanner_content[:content])
|
||||
Gitea::UpdateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_scanner_content.merge(sha:sonar_scanner_exit.result['sha']))
|
||||
else
|
||||
Gitea::CreateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_scanner_content)
|
||||
end
|
||||
|
||||
sonar_project_content = {
|
||||
filepath: 'sonar-project.properties',
|
||||
branch: params[:branch],
|
||||
new_branch: nil,
|
||||
"content": "sonar.projectKey=#{params[:owner]}-#{params[:repo]}\nsonar.sources=.",
|
||||
"message": 'Add sonar-project.properties',
|
||||
committer: {
|
||||
email: @owner.mail,
|
||||
name: @owner.login
|
||||
},
|
||||
identifier: @project.identifier
|
||||
}
|
||||
sonar_project_exit = Repositories::EntriesInteractor.call(@owner, @project.identifier, 'sonar-project.properties', ref: params[:branch])
|
||||
if sonar_project_exit.success?
|
||||
Gitea::UpdateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_project_content.merge(sha:sonar_project_exit.result['sha']))
|
||||
else
|
||||
sonar_project_content[:content] = Base64.strict_encode64(sonar_project_content[:content])
|
||||
Gitea::CreateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_project_content)
|
||||
end
|
||||
render_ok
|
||||
end
|
||||
|
||||
def issues_search
|
||||
params_data = {
|
||||
components: params[:components],
|
||||
s: params[:s],
|
||||
impactSoftwareQualities: params[:impactSoftwareQualities],
|
||||
issueStatuses: params[:issueStatuses],
|
||||
ps: params[:ps],
|
||||
p: params[:s],
|
||||
facets: params[:facets],
|
||||
additionalFields: params[:additionalFields],
|
||||
timeZone: params[:timeZone]
|
||||
}
|
||||
data = Sonarqube.client.get('/api/issues/search', params_data)
|
||||
render_ok data
|
||||
end
|
||||
|
||||
def ce_component
|
||||
params_data = {
|
||||
components: params[:components]
|
||||
}
|
||||
data = Sonarqube.client.get('/api/ce/component', params_data)
|
||||
render_ok data
|
||||
end
|
||||
|
||||
def sources_issue_snippet
|
||||
params_data = {
|
||||
issueKey: params[:issueKey]
|
||||
}
|
||||
data = Sonarqube.client.get('/api/sources/issue_snippets', params_data)
|
||||
render_ok data
|
||||
end
|
||||
|
||||
def rules_show
|
||||
params_data = {
|
||||
key: params[:key]
|
||||
}
|
||||
data = Sonarqube.client.get('/api/rules/show', params_data)
|
||||
render_ok data
|
||||
end
|
||||
|
||||
def measures_search_history
|
||||
params_data = {
|
||||
from: params[:form],
|
||||
component: params[:component],
|
||||
metrics: params[:metrics],
|
||||
ps: params[:ps]
|
||||
}
|
||||
data = Sonarqube.client.get('/api/measures/search_history', params_data)
|
||||
render_ok data
|
||||
end
|
||||
|
||||
def measures_component
|
||||
params_data = {
|
||||
component: params[:component],
|
||||
additionalFields: params[:additionalFields],
|
||||
metricKeys: params[:metricKeys],
|
||||
}
|
||||
data = Sonarqube.client.get('/api/measures/component', params_data)
|
||||
render_ok data
|
||||
end
|
||||
end
|
|
@ -318,19 +318,19 @@ class ApplicationController < ActionController::Base
|
|||
User.current = find_current_user
|
||||
uid_logger("user_setup: " + (User.current.logged? ? "#{User.current.try(:login)} (id=#{User.current.try(:id)})" : "anonymous"))
|
||||
|
||||
# 开放课程通过链接访问的用户
|
||||
if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank?
|
||||
content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}"
|
||||
|
||||
if Digest::MD5.hexdigest(content) == params[:chinaoocKey]
|
||||
user = open_class_user
|
||||
if user
|
||||
start_user_session(user)
|
||||
set_autologin_cookie(user)
|
||||
end
|
||||
User.current = user
|
||||
end
|
||||
end
|
||||
# # 开放课程通过链接访问的用户
|
||||
# if !User.current.logged? && !params[:chinaoocTimestamp].blank? && !params[:websiteName].blank? && !params[:chinaoocKey].blank?
|
||||
# content = "#{OPENKEY}#{params[:websiteName]}#{params[:chinaoocTimestamp]}"
|
||||
#
|
||||
# if Digest::MD5.hexdigest(content) == params[:chinaoocKey]
|
||||
# user = open_class_user
|
||||
# if user
|
||||
# start_user_session(user)
|
||||
# set_autologin_cookie(user)
|
||||
# end
|
||||
# User.current = user
|
||||
# end
|
||||
# end
|
||||
|
||||
if !User.current.logged? && Rails.env.development?
|
||||
user = User.find 1
|
||||
|
@ -363,15 +363,14 @@ class ApplicationController < ActionController::Base
|
|||
uid_logger("user setup start: session[:user_id] is #{session[:user_id]}")
|
||||
uid_logger("0000000000000user setup start: default_yun_session is #{default_yun_session}, session[:current_user_id] is #{session[:"#{default_yun_session}"]}")
|
||||
current_domain_session = session[:"#{default_yun_session}"]
|
||||
if current_domain_session
|
||||
# existing session
|
||||
User.current = (User.active.find(current_domain_session) rescue nil)
|
||||
elsif autologin_user = try_to_autologin
|
||||
autologin_user
|
||||
elsif params[:format] == 'atom' && params[:key] && request.get? && accept_rss_auth?
|
||||
# RSS key authentication does not start a session
|
||||
User.find_by_rss_key(params[:key])
|
||||
autologin_user = try_to_autologin
|
||||
uid_logger("user setup start: autologin_user is #{autologin_user}")
|
||||
# 多浏览器退出账号时,token不存在处理
|
||||
if current_domain_session && autologin_user.nil?
|
||||
autologin_user = (User.active.find(current_domain_session) rescue nil)
|
||||
set_autologin_cookie(autologin_user)
|
||||
end
|
||||
autologin_user
|
||||
end
|
||||
|
||||
def try_to_autologin
|
||||
|
@ -715,7 +714,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
def find_user_with_id
|
||||
@user = User.find_by_id params[:user_id]
|
||||
@user = User.find_by(type: 'User', id: params[:user_id])
|
||||
# render_not_found("未找到’#{params[:login]}’相关的用户") unless @user
|
||||
render_error("未找到相关的用户") unless @user
|
||||
end
|
||||
|
|
|
@ -95,6 +95,9 @@ class AttachmentsController < ApplicationController
|
|||
@attachment.disk_directory = month_folder
|
||||
@attachment.cloud_url = remote_path
|
||||
@attachment.uuid = SecureRandom.uuid
|
||||
@attachment.description = params[:description]
|
||||
@attachment.container_id = params[:container_id]
|
||||
@attachment.container_type = params[:container_type]
|
||||
@attachment.save!
|
||||
else
|
||||
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
||||
|
@ -124,7 +127,7 @@ class AttachmentsController < ApplicationController
|
|||
|
||||
# 附件为视频时,点击播放
|
||||
def preview_attachment
|
||||
attachment = Attachment.find_by(id: params[:id])
|
||||
attachment = Attachment.where_id_or_uuid(params[:id]).first
|
||||
dir_path = "#{Rails.root}/public/preview"
|
||||
Dir.mkdir(dir_path) unless Dir.exist?(dir_path)
|
||||
if params[:status] == "preview"
|
||||
|
|
|
@ -8,7 +8,7 @@ class BindUsersController < ApplicationController
|
|||
bind_user = User.try_to_login(params[:username], params[:password])
|
||||
tip_exception '用户名或者密码错误' if bind_user.blank?
|
||||
tip_exception '用户名或者密码错误' unless bind_user.check_password?(params[:password].to_s)
|
||||
tip_exception '参数错误' unless ["qq", "wechat", "gitee", "github", "educoder"].include?(params[:type].to_s)
|
||||
tip_exception '参数错误' unless ["qq", "wechat", "gitee", "github", "educoder", "acge"].include?(params[:type].to_s)
|
||||
tip_exception '该账号已被绑定,请更换其他账号进行绑定' if bind_user.bind_open_user?(params[:type].to_s)
|
||||
|
||||
"OpenUsers::#{params[:type].to_s.capitalize}".constantize.create!(user: bind_user, uid: session[:unionid])
|
||||
|
|
|
@ -0,0 +1,67 @@
|
|||
class Oauth::AcgeController < Oauth::BaseController
|
||||
include RegisterHelper
|
||||
|
||||
def create
|
||||
begin
|
||||
uid = params['uid'].to_s.strip
|
||||
tip_exception("uid不能为空") if uid.blank?
|
||||
redirect_uri = params['redirect_uri'].to_s.strip
|
||||
tip_exception("redirect_uri不能为空") if redirect_uri.blank?
|
||||
email = params['email'].to_s.strip
|
||||
tip_exception("email不能为空") if email.blank?
|
||||
phone = params['phone'].to_s.strip
|
||||
tip_exception("phone不能为空") if phone.blank?
|
||||
name = params['name'].to_s.strip
|
||||
tip_exception("name不能为空") if name.blank?
|
||||
|
||||
open_user = OpenUsers::Acge.find_by(uid: uid)
|
||||
if open_user.present? && open_user.user.present?
|
||||
successful_authentication(open_user.user)
|
||||
redirect_to redirect_uri
|
||||
return
|
||||
else
|
||||
if current_user.blank? || !current_user.logged?
|
||||
session[:unionid] = uid
|
||||
user = User.find_by(mail: email) || User.find_by(phone: phone)
|
||||
if user.present?
|
||||
OpenUsers::Acge.create!(user: user, uid: uid)
|
||||
successful_authentication(user)
|
||||
redirect_to redirect_uri
|
||||
|
||||
return
|
||||
else
|
||||
username = uid
|
||||
password = SecureRandom.hex(4)
|
||||
reg_result = autologin_register(username, email, password, 'acge', phone, name)
|
||||
existing_rows = CSV.read("public/操作系统大赛用户信息.csv")
|
||||
new_row = [username, email, password, phone, name]
|
||||
existing_rows << new_row
|
||||
CSV.open("public/操作系统大赛用户信息.csv", 'wb') do |csv|
|
||||
existing_rows.each { |row| csv << row }
|
||||
end
|
||||
if reg_result[:message].blank?
|
||||
open_user = OpenUsers::Acge.create!(user_id: reg_result[:user][:id], uid: uid)
|
||||
successful_authentication(open_user.user)
|
||||
redirect_to redirect_uri
|
||||
|
||||
return
|
||||
else
|
||||
render_error(reg_result[:message])
|
||||
end
|
||||
end
|
||||
else
|
||||
OpenUsers::Acge.create!(user: current_user, uid: uid)
|
||||
successful_authentication(current_user)
|
||||
redirect_to redirect_uri
|
||||
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
Rails.logger.info("[OAuth2] session[:unionid] -> #{session[:unionid]}")
|
||||
# redirect_to "/bindlogin/acge?redirect_uri=#{redirect_uri}"
|
||||
rescue Exception => ex
|
||||
render_error(ex.message)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -4,17 +4,31 @@ class Organizations::OrganizationUsersController < Organizations::BaseController
|
|||
before_action :check_user_can_edit_org, only: [:destroy]
|
||||
|
||||
def index
|
||||
@organization_users = @organization.organization_users.includes(:user)
|
||||
# @organization_users = @organization.organization_users.includes(:user)
|
||||
# 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)
|
||||
|
||||
organization_user_ids = @organization.organization_users.pluck(:user_id).uniq
|
||||
project_member_user_ids = @organization.projects.joins(:members).pluck("members.user_id").uniq
|
||||
ids = organization_user_ids + project_member_user_ids
|
||||
users = User.where(id: ids).reorder(Arel.sql("FIELD(users.id,#{ids.join(',')})"))
|
||||
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")
|
||||
user_ids = User.from("( #{user_condition_users} UNION #{team_condition_teams }) AS users").pluck(:id)
|
||||
|
||||
@organization_users = @organization_users.where(user_id: users).distinct
|
||||
users = users.where(id: user_ids)
|
||||
end
|
||||
|
||||
@organization_users = kaminari_paginate(@organization_users)
|
||||
@users = kaminari_paginate(users)
|
||||
end
|
||||
|
||||
def pm_check_user
|
||||
|
|
|
@ -10,6 +10,8 @@ class Organizations::ProjectsController < Organizations::BaseController
|
|||
@projects = Project.from("( #{ public_projects_sql} UNION #{ private_projects_sql } ) AS projects")
|
||||
# 表情处理
|
||||
keywords = params[:search].to_s.each_char.select { |c| c.bytes.first < 240 }.join('')
|
||||
@projects = @projects.where(id: params[:pm_project_repository_ids].split(',')) if params[:pm_project_repository_ids].present?
|
||||
@projects = @projects.where.not(id: params[:exclude_ids].to_s.split(",")) if params[:exclude_ids].present?
|
||||
@projects = @projects.ransack(name_or_identifier_cont: keywords).result if params[:search].present?
|
||||
@projects = @projects.includes(:owner).order("projects.#{sort} #{sort_direction}")
|
||||
@projects = paginate(@projects)
|
||||
|
|
|
@ -67,7 +67,18 @@ class Organizations::TeamsController < Organizations::BaseController
|
|||
tip_exception("组织团队不允许被删除") if @team.owner?
|
||||
ActiveRecord::Base.transaction do
|
||||
Gitea::Organization::Team::DeleteService.call(@organization.gitea_token, @team.gtid)
|
||||
other_user_ids = @organization.team_users.where.not(team_id: @team.id).pluck(:user_id)
|
||||
team_user_ids = @team.team_users.pluck(:user_id)
|
||||
# 当前删除团队中成员在其他组织其他团队不存在的成员需清除组织
|
||||
remove_user_ids = team_user_ids - other_user_ids
|
||||
Rails.logger.info "remove_user_ids ===========> #{remove_user_ids}"
|
||||
@team.destroy!
|
||||
if remove_user_ids.present?
|
||||
User.where(id: remove_user_ids).each do |user|
|
||||
@organization.organization_users.find_by(user_id: user.id).destroy!
|
||||
Gitea::Organization::OrganizationUser::DeleteService.call(@organization.gitea_token, @organization.login, user.login)
|
||||
end
|
||||
end
|
||||
end
|
||||
render_ok
|
||||
rescue Exception => e
|
||||
|
|
|
@ -21,6 +21,7 @@ class ProjectsController < ApplicationController
|
|||
menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues")
|
||||
menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls") && @project.forge?
|
||||
menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops") && @project.forge?
|
||||
menu.append(menu_hash_by_name("dataset")) if @project.has_menu_permission("dataset") && @project.forge?
|
||||
menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions")
|
||||
menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki") && @project.forge?
|
||||
menu.append(menu_hash_by_name("services")) if @project.has_menu_permission("services") && @project.forge? && (current_user.admin? || @project.member?(current_user.id))
|
||||
|
@ -42,7 +43,8 @@ class ProjectsController < ApplicationController
|
|||
@total_count =
|
||||
if category_id.blank? && params[:search].blank? && params[:topic_id].blank?
|
||||
# 默认查询时count性能问题处理
|
||||
ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count
|
||||
not_category_count = Project.where(project_category_id: nil).count
|
||||
ProjectCategory.sum("projects_count") - Project.visible.joins("left join organization_extensions on organization_extensions.organization_id = projects.user_id").where("organization_extensions.visibility =2").count + not_category_count
|
||||
elsif params[:search].present? || params[:topic_id].present?
|
||||
@projects.total_count
|
||||
else
|
||||
|
@ -58,7 +60,10 @@ class ProjectsController < ApplicationController
|
|||
OpenProjectDevOpsJob.set(wait: 5.seconds).perform_later(@project&.id, current_user.id)
|
||||
UpdateProjectTopicJob.perform_later(@project.id) if @project.id.present?
|
||||
end
|
||||
rescue Exception => e
|
||||
rescue Gitea::Api::ServerError => ex
|
||||
uid_logger_error(ex.message)
|
||||
tip_exception(ex.http_code, ex.message)
|
||||
rescue ApplicationService::Error => e
|
||||
uid_logger_error(e.message)
|
||||
tip_exception(e.message)
|
||||
end
|
||||
|
@ -193,13 +198,19 @@ class ProjectsController < ApplicationController
|
|||
default_branch: @project.default_branch
|
||||
}
|
||||
Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params)
|
||||
elsif project_params.has_key?("has_actions")
|
||||
gitea_params = {
|
||||
has_actions: project_params[:has_actions]
|
||||
}
|
||||
Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params)
|
||||
else
|
||||
validate_params = project_params.slice(:name, :description,
|
||||
:project_category_id, :project_language_id, :private, :identifier)
|
||||
|
||||
Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id, project_identifier: @project.identifier, project_name: @project.name)).validate!
|
||||
|
||||
private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false
|
||||
private = params[:private].nil? ? !@project.is_public : params[:private]
|
||||
private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : private
|
||||
|
||||
new_project_params = project_params.except(:private).merge(is_public: !private)
|
||||
@project.update_attributes!(new_project_params)
|
||||
|
@ -232,15 +243,6 @@ class ProjectsController < ApplicationController
|
|||
def show
|
||||
end
|
||||
|
||||
def mp_show
|
||||
@project = Project.joins(:owner).find params[:project_id]
|
||||
data={
|
||||
owner:@project.owner.try(:login),
|
||||
identifier:@project.identifier
|
||||
}
|
||||
render_ok(data:data)
|
||||
end
|
||||
|
||||
def destroy
|
||||
if current_user.admin? || @project.manager?(current_user)
|
||||
ActiveRecord::Base.transaction do
|
||||
|
@ -347,7 +349,7 @@ class ProjectsController < ApplicationController
|
|||
|
||||
def project_params
|
||||
params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, :identifier,
|
||||
:project_category_id, :project_language_id, :license_id, :ignore_id, :private,
|
||||
:project_category_id, :project_language_id, :license_id, :ignore_id, :private, :has_actions,
|
||||
:blockchain, :blockchain_token_all, :blockchain_init_token, :pr_view_admin)
|
||||
end
|
||||
|
||||
|
|
|
@ -203,6 +203,7 @@ class PullRequestsController < ApplicationController
|
|||
|
||||
def pr_merge
|
||||
return render_forbidden("你没有权限操作.") unless @project.operator?(current_user)
|
||||
return normal_status(-1, "该分支存在冲突,无法自动合并.") unless @pull_request.conflict_files.blank?
|
||||
|
||||
if params[:do].blank?
|
||||
normal_status(-1, "请选择合并方式")
|
||||
|
|
|
@ -64,6 +64,7 @@ class RepositoriesController < ApplicationController
|
|||
@entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder.repo_name)
|
||||
else
|
||||
@entries = Gitea::Repository::Entries::ListService.new(@owner, @project.identifier, ref: @ref).call
|
||||
return render_not_found if @entries.is_a?(Array) && @entries.blank?
|
||||
@entries = @entries.present? ? @entries.sort_by{ |hash| hash['type'] } : []
|
||||
@path = GiteaService.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
||||
end
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class VersionReleasesController < ApplicationController
|
||||
include ApplicationHelper
|
||||
before_action :load_repository
|
||||
before_action :set_user
|
||||
before_action :require_login, except: [:index, :show]
|
||||
|
@ -126,6 +127,16 @@ class VersionReleasesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def download
|
||||
tip_exception(404, '您访问的页面不存在或已被删除') if params["tag_name"].blank? || params["filename"].blank?
|
||||
version = @repository.version_releases.find_by(tag_name: params["tag_name"])
|
||||
attachment = version.attachments.find_by(filename: params["filename"])
|
||||
tip_exception(404, '您访问的页面不存在或已被删除') if attachment.blank?
|
||||
send_file(absolute_path(local_path(attachment)), filename: attachment.title, stream: false, type: attachment.content_type.presence || 'application/octet-stream')
|
||||
update_downloads(attachment)
|
||||
# redirect_to "/api/attachments/#{attachment.uuid}"
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
def set_user
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class Organizations::CreateForm < BaseForm
|
||||
NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||
NAME_REGEX = /^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||
attr_accessor :name, :description, :website, :location, :repo_admin_change_team_access, :visibility, :max_repo_creation, :nickname, :original_name
|
||||
|
||||
validates :name, :nickname, :visibility, presence: true
|
||||
validates :name, :nickname, length: { maximum: 100 }
|
||||
validates :location, length: { maximum: 50 }
|
||||
validates :description, length: { maximum: 200 }
|
||||
validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能以数字或字母开头,仅支持横杠、下划线、点三种符号,不允许符号连续排列,长度4-50个字符" }
|
||||
|
||||
validate do
|
||||
check_name(name) unless name.blank? || name == original_name
|
||||
|
|
|
@ -28,6 +28,10 @@ class Projects::CreateForm < BaseForm
|
|||
raise "ignore_id值无效." if ignore_id && Ignore.find_by(id: ignore_id).blank?
|
||||
end
|
||||
|
||||
def check_auto_init
|
||||
raise "auto_init值无效." if ignore_id && license_id && !auto_init
|
||||
end
|
||||
|
||||
def check_owner
|
||||
@project_owner = Owner.find_by(id: user_id)
|
||||
raise "user_id值无效." if user_id && @project_owner.blank?
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
class Projects::Datasets::CreateForm < BaseForm
|
||||
attr_accessor :title, :description, :license_id, :paper_content
|
||||
|
||||
|
||||
validates :title, presence: true, length: { maximum: 100 }
|
||||
validates :description, presence: true, length: { maximum: 500 }
|
||||
validates :paper_content, length: { maximum: 500 }
|
||||
|
||||
validate :check_license
|
||||
|
||||
def check_license
|
||||
raise "license_id值无效. " if license_id && License.find_by(id: license_id).blank?
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Action::NodeHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Api::Pm::IssueLinksHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Api::Pm::ProjectsHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Api::V1::PmIssuesHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Api::V1::SonarqubesHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module Pm::JournalsHelper
|
||||
end
|
|
@ -67,6 +67,7 @@ module ProjectsHelper
|
|||
jianmu_devops_url: jianmu_devops_url,
|
||||
cloud_ide_saas_url: cloud_ide_saas_url(user),
|
||||
open_blockchain: Site.has_blockchain? && project.use_blockchain,
|
||||
has_dataset: project.project_dataset.present?,
|
||||
ignore_id: project.ignore_id
|
||||
}).compact
|
||||
|
||||
|
|
|
@ -132,6 +132,8 @@ module RepositoriesHelper
|
|||
src_regex_3 = /src= (.*?) /
|
||||
src_regex_4 = /src =(.*?) /
|
||||
src_regex_5 = /src =(.*?) /
|
||||
href_regex = /href=\"(.*?)\"/
|
||||
href_regex_1 = /href=\'(.*?)\'/
|
||||
ss_c = content.to_s.scan(s_regex_c)
|
||||
ss = content.to_s.scan(s_regex)
|
||||
ss_1 = content.to_s.scan(s_regex_1)
|
||||
|
@ -142,7 +144,9 @@ module RepositoriesHelper
|
|||
ss_src_3 = content.to_s.scan(src_regex_3)
|
||||
ss_src_4 = content.to_s.scan(src_regex_4)
|
||||
ss_src_5 = content.to_s.scan(src_regex_5)
|
||||
total_sources = {ss_c: ss_c,ss: ss, ss_1: ss_1, ss_2: ss_2, ss_src: ss_src, ss_src_1: ss_src_1, ss_src_2: ss_src_2, ss_src_3: ss_src_3, ss_src_4: ss_src_4, ss_src_5: ss_src_5}
|
||||
ss_href = content.to_s.scan(href_regex)
|
||||
ss_href_1 = content.to_s.scan(href_regex_1)
|
||||
total_sources = {ss_c: ss_c,ss: ss, ss_1: ss_1, ss_2: ss_2, ss_src: ss_src, ss_src_1: ss_src_1, ss_src_2: ss_src_2, ss_src_3: ss_src_3, ss_src_4: ss_src_4, ss_src_5: ss_src_5, ss_href: ss_href, ss_href_1: ss_href_1}
|
||||
# total_sources.uniq!
|
||||
total_sources.except(:ss, :ss_c).each do |k, sources|
|
||||
sources.each do |s|
|
||||
|
@ -153,6 +157,7 @@ module RepositoriesHelper
|
|||
ext = File.extname(s_content)[1..-1]
|
||||
ext = ext.split("?")[0] if ext.include?("?")
|
||||
if (image_type?(ext) || download_type(ext)) && !ext.blank?
|
||||
s_content = s_content.starts_with?("/") ? s_content[1..-1] : s_content[0..-1]
|
||||
s_content = File.expand_path(s_content, file_path)
|
||||
s_content = s_content.split("#{Rails.root}/")[1]
|
||||
# content = content.gsub(s[0], "/#{s_content}")
|
||||
|
@ -173,13 +178,17 @@ module RepositoriesHelper
|
|||
content = content.gsub("src=#{s[0]}", "src=\'#{s_content}\'")
|
||||
when 'ss_2'
|
||||
content = content.gsub(/]:#{s[0]}/, "]: #{s_content.to_s.gsub(" ","").gsub("\r", "")}")
|
||||
else
|
||||
when 'ss_href'
|
||||
content = content.gsub("href=\"#{s[0]}\"", "href=\"#{s_content}\"")
|
||||
when 'ss_href_1'
|
||||
content = content.gsub("href=\'#{s[0]}\'", "href=\'#{s_content}\'")
|
||||
else
|
||||
content = content.gsub("(#{s[0]})", "(#{s_content})")
|
||||
end
|
||||
else
|
||||
path = [owner&.login, repo&.identifier, 'tree', ref, file_path].join("/")
|
||||
s_content = File.expand_path(s_content, path)
|
||||
s_content = s_content.split("#{Rails.root}/")[1]
|
||||
s_content = s_content.split("#{Rails.root}")[1]
|
||||
case k.to_s
|
||||
when 'ss_src'
|
||||
content = content.gsub("src=\"#{s[0]}\"", "src=\"/#{s_content}\"")
|
||||
|
@ -187,7 +196,11 @@ module RepositoriesHelper
|
|||
content = content.gsub("src=\'#{s[0]}\'", "src=\'/#{s_content}\'")
|
||||
when 'ss_2'
|
||||
content = content.gsub(/]:#{s[0]}/, "]: /#{s_content.to_s.gsub(" ","").gsub("\r", "")}")
|
||||
else
|
||||
when 'ss_href'
|
||||
content = content.gsub("href=\"#{s[0]}\"", "href=\"#{s_content}\"")
|
||||
when 'ss_href_1'
|
||||
content = content.gsub("href=\'#{s[0]}\'", "href=\'#{s_content}\'")
|
||||
else
|
||||
content = content.gsub("(#{s[0]})", "(/#{s_content})")
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,6 +45,7 @@ module Gitea
|
|||
else
|
||||
Rails.logger.error("Gitea::Repository::Entries::DeleteService error[#{response.status}]======#{response.body}")
|
||||
@error = "删除失败,请确认该分支是否是保护分支。"
|
||||
@error = "删除失败,参数sha不匹配。" if response.body.to_s.include?("sha does not match")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,44 @@
|
|||
# 按天获取百度统计数据,pv,访问,ip和来源分类占比
|
||||
# 其他统计:前一周用户留存率
|
||||
class DailyPlatformStatisticsJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(*args)
|
||||
Rails.logger.info("*********开始统计*********")
|
||||
|
||||
tongji_service = Baidu::TongjiService.new
|
||||
access_token = tongji_service.access_token
|
||||
Rails.logger.info "job baidu_tongji_auth access_token ===== #{access_token}"
|
||||
ActiveJob::Base.logger.info "job baidu_tongji_auth access_token ===== #{access_token}"
|
||||
# 从最后一个记录日期开始,如果遗漏日期数据可以补充数据
|
||||
last_date = DailyPlatformStatistic.order(:date).last
|
||||
start_date = last_date.date
|
||||
end_date = Time.now
|
||||
if access_token.present?
|
||||
tongji_service.overview_batch_add(start_date, end_date)
|
||||
|
||||
# 本周访问来源占比,每天记录一次,如果遗漏日期数据可以补充数据
|
||||
tongji_service.source_from_batch_add(start_date, end_date)
|
||||
end
|
||||
# 周用户留存率
|
||||
pre_week_user_ids = User.where(created_on: pre_week).pluck(:id).uniq
|
||||
weekly_keep_user_count = User.where(id: pre_week_user_ids).where(last_login_on: current_week).count
|
||||
weekly_keep_rate = format("%.2f", pre_week_user_ids.size > 0 ? weekly_keep_user_count.to_f / pre_week_user_ids.size : 0)
|
||||
|
||||
job_date = 1.days.ago
|
||||
daily_statistic = DailyPlatformStatistic.find_or_initialize_by(date: job_date)
|
||||
daily_statistic.weekly_keep_rate = weekly_keep_rate
|
||||
daily_statistic.save
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def current_week
|
||||
Time.now.beginning_of_week..Time.now.end_of_day
|
||||
end
|
||||
|
||||
def pre_week
|
||||
# 7.days.ago.beginning_of_week..7.days.ago.beginning_of_week.end_of_week
|
||||
Time.now.prev_week..Time.now.prev_week.end_of_week
|
||||
end
|
||||
end
|
|
@ -13,6 +13,7 @@ class DailyProjectStatisticsJob < ApplicationJob
|
|||
praises = result["praises"].to_i
|
||||
forks = result["forks"].to_i
|
||||
issues = result["issues"].to_i
|
||||
closed_issues = result["closed_issues"].to_i
|
||||
pullrequests = result["pullrequests"].to_i
|
||||
commits = result["commits"].to_i
|
||||
score = visits *1 + watchers *5 + praises * 5 + forks * 10 + issues *5 + pullrequests * 10 + commits * 5
|
||||
|
@ -25,6 +26,7 @@ class DailyProjectStatisticsJob < ApplicationJob
|
|||
praises: praises,
|
||||
forks: forks,
|
||||
issues: issues,
|
||||
closed_issues: closed_issues,
|
||||
pullrequests: pullrequests,
|
||||
commits: commits
|
||||
)
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
class DelayExpiredIssueAndMilestoneJob < ApplicationJob
|
||||
queue_as :message
|
||||
|
||||
def perform
|
||||
Issue.where(due_date: Date.today + 1.days).find_each do |issue|
|
||||
SendTemplateMessageJob.perform_later('IssueExpire', issue.id) if Site.has_notice_menu?
|
||||
end
|
||||
Version.where(effective_date: Date.today + 1.days).find_each do |version|
|
||||
SendTemplateMessageJob.perform_later('ProjectMilestoneEarlyExpired', version.id) if Site.has_notice_menu?
|
||||
end
|
||||
Version.where(effective_date: Date.today - 1.days).find_each do |version|
|
||||
SendTemplateMessageJob.perform_later('ProjectMilestoneExpired', version.id) if Site.has_notice_menu?
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,10 +0,0 @@
|
|||
class DelayExpiredIssueJob < ApplicationJob
|
||||
queue_as :message
|
||||
|
||||
def perform
|
||||
Issue.where(due_date: Date.today + 1.days).find_each do |issue|
|
||||
SendTemplateMessageJob.perform_later('IssueExpire', issue.id) if Site.has_notice_menu?
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -221,6 +221,20 @@ class SendTemplateMessageJob < ApplicationJob
|
|||
receivers_email_string, email_title, email_content = MessageTemplate::ProjectMilestone.get_email_message_content(receiver, operator, milestone)
|
||||
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||
end
|
||||
when 'ProjectMilestoneExpired'
|
||||
milestone_id = args[0]
|
||||
milestone = Version.find_by_id(milestone_id)
|
||||
return unless milestone.present? && milestone&.project.present?
|
||||
receivers = User.where(id: milestone.user_id)
|
||||
receivers_string, content, notification_url = MessageTemplate::ProjectMilestoneExpired.get_message_content(receivers, milestone)
|
||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {milestone_id: milestone_id, operator_id: operator_id})
|
||||
when 'ProjectMilestoneEarlyExpired'
|
||||
milestone_id = args[0]
|
||||
milestone = Version.find_by_id(milestone_id)
|
||||
return unless milestone.present? && milestone&.project.present?
|
||||
receivers = User.where(id: milestone.user_id)
|
||||
receivers_string, content, notification_url = MessageTemplate::ProjectMilestoneEarlyExpired.get_message_content(receivers, milestone)
|
||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {milestone_id: milestone_id, operator_id: operator_id})
|
||||
when 'ProjectPraised'
|
||||
operator_id, project_id = args[0], args[1]
|
||||
operator = User.find_by_id(operator_id)
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
class TouchSyncJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(touchable)
|
||||
puts "aaaa"
|
||||
case touchable.class.to_s
|
||||
when 'SyncRepositories::Github' || 'SyncRepositories::Gitee'
|
||||
Reposync::SyncRepoService.call(touchable.repo_name)
|
||||
when 'SyncRepositoryBranch'
|
||||
sync_repository = touchable.sync_repository
|
||||
result = []
|
||||
if sync_repository.sync_direction == 1
|
||||
result = Reposync::SyncBranchService.call(sync_repository.repo_name, touchable.gitlink_branch_name, sync_repository.sync_direction)
|
||||
else
|
||||
result = Reposync::SyncBranchService.call(sync_repository.repo_name, touchable.external_branch_name, sync_repository.sync_direction)
|
||||
end
|
||||
if result.is_a?(Array) && result[0].to_i == 0
|
||||
touchable.update_attributes!({sync_status: 1, sync_time: Time.now})
|
||||
else
|
||||
touchable.update_attributes!({sync_status: 2, sync_time: Time.now})
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -9,7 +9,7 @@ module CustomRegexp
|
|||
URL = /\Ahttps?:\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|]\z/
|
||||
IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/
|
||||
|
||||
URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i
|
||||
URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i
|
||||
# REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9][a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||
REPOSITORY_NAME_REGEX = /^[a-zA-Z0-9\-\_\.]+[a-zA-Z0-9]$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||
MD_REGEX = /^.+(\.[m|M][d|D])$/
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: action_nodes
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string(255)
|
||||
# full_name :string(255)
|
||||
# description :string(255)
|
||||
# icon :string(255)
|
||||
# action_node_types_id :integer
|
||||
# is_local :boolean default("0")
|
||||
# local_url :string(255)
|
||||
# yaml :text(65535)
|
||||
# sort_no :integer default("0")
|
||||
# use_count :integer default("0")
|
||||
# user_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# by_name (name)
|
||||
# index_action_nodes_on_action_types_id (action_node_types_id)
|
||||
# index_action_nodes_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class Action::Node < ApplicationRecord
|
||||
self.table_name = 'action_nodes'
|
||||
default_scope { order(sort_no: :asc) }
|
||||
|
||||
has_many :action_node_inputs, :class_name => 'Action::NodeInput', foreign_key: "action_nodes_id"
|
||||
has_many :action_node_selects, :class_name => 'Action::NodeSelect', foreign_key: "action_nodes_id"
|
||||
belongs_to :action_node_type, :class_name => 'Action::NodeType', foreign_key: "action_node_types_id"
|
||||
|
||||
belongs_to :user, optional: true
|
||||
|
||||
attr_accessor :cust_name, :run_values, :input_values
|
||||
|
||||
|
||||
def content_yaml
|
||||
"foo".to_yaml
|
||||
<<~YAML
|
||||
- name: Set up JDK ${{ matrix.java }}
|
||||
uses: actions/setup-java@v3
|
||||
with:
|
||||
distribution: 'temurin'
|
||||
java-version: ${{ matrix.java }}
|
||||
YAML
|
||||
end
|
||||
|
||||
def node
|
||||
self
|
||||
end
|
||||
|
||||
def build_yaml
|
||||
yaml = ERB.new(File.read(File.join(Rails.root, "app/views/api/v1/projects/pipelines", "build_node.yaml.erb"))).result(binding)
|
||||
# 删除空行内容
|
||||
yaml = yaml.gsub(/^\s*\n/, "")
|
||||
# Rails.logger.info "========================="
|
||||
# Rails.logger.info yaml
|
||||
yaml
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: action_node_inputs
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# action_nodes_id :integer
|
||||
# name :string(255)
|
||||
# input_type :string(255)
|
||||
# description :string(255)
|
||||
# is_required :boolean default("0")
|
||||
# sort_no :string(255) default("0")
|
||||
# user_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_action_node_inputs_on_action_nodes_id (action_nodes_id)
|
||||
# index_action_node_inputs_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class Action::NodeInput < ApplicationRecord
|
||||
self.table_name = 'action_node_inputs'
|
||||
default_scope { order(sort_no: :asc) }
|
||||
|
||||
belongs_to :action_node, :class_name => 'Action::Node', foreign_key: "action_nodes_id"
|
||||
end
|
|
@ -0,0 +1,39 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: action_node_selects
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# action_nodes_id :integer
|
||||
# name :string(255)
|
||||
# val :string(255)
|
||||
# val_ext :string(255)
|
||||
# description :string(255)
|
||||
# download_url :string(255)
|
||||
# sort_no :integer default("0")
|
||||
# use_count :integer default("0")
|
||||
# user_id :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_action_node_selects_on_action_nodes_id (action_nodes_id)
|
||||
# index_action_node_selects_on_name (name)
|
||||
# index_action_node_selects_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class Action::NodeSelect < ApplicationRecord
|
||||
self.table_name = 'action_node_selects'
|
||||
default_scope { order(sort_no: :asc) }
|
||||
|
||||
belongs_to :action_node, :class_name => 'Action::Node', foreign_key: "action_nodes_id"
|
||||
belongs_to :user, optional: true
|
||||
|
||||
def value
|
||||
if self.val_ext.blank?
|
||||
self.val
|
||||
else
|
||||
"#{self.val}@#{self.val_ext}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,18 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: action_node_types
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string(255)
|
||||
# description :string(255)
|
||||
# sort_no :integer
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class Action::NodeType < ApplicationRecord
|
||||
self.table_name = 'action_node_types'
|
||||
default_scope { order(sort_no: :asc) }
|
||||
|
||||
has_many :action_nodes, :class_name => 'Action::Node', foreign_key: "action_node_types_id"
|
||||
end
|
|
@ -0,0 +1,37 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: action_pipelines
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# project_id :integer
|
||||
# user_id :integer
|
||||
# pipeline_name :string(255)
|
||||
# pipeline_status :string(255)
|
||||
# description :string(255)
|
||||
# file_name :string(255)
|
||||
# is_graphic_design :boolean default("0")
|
||||
# repo_name :string(255)
|
||||
# repo_identifier :string(255)
|
||||
# repo_owner :string(255)
|
||||
# branch :string(255)
|
||||
# event :string(255)
|
||||
# sha :string(255)
|
||||
# json :text(65535)
|
||||
# yaml :text(65535)
|
||||
# disable :boolean default("0")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_action_pipelines_on_project_id (project_id)
|
||||
# index_action_pipelines_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class Action::Pipeline < ApplicationRecord
|
||||
self.table_name = 'action_pipelines'
|
||||
belongs_to :user, optional: true
|
||||
belongs_to :project
|
||||
|
||||
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: action_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# name :string(255)
|
||||
# description :string(255)
|
||||
# img :string(255)
|
||||
# sort_no :string(255) default("0")
|
||||
# json :text(65535)
|
||||
# yaml :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class Action::Template < ApplicationRecord
|
||||
self.table_name = 'action_templates'
|
||||
default_scope { order(sort_no: :asc) }
|
||||
|
||||
end
|
|
@ -1,45 +1,46 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: attachments
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# container_id :integer
|
||||
# container_type :string(30)
|
||||
# filename :string(255) default(""), not null
|
||||
# disk_filename :string(255) default(""), not null
|
||||
# filesize :integer default("0"), not null
|
||||
# content_type :string(255) default("")
|
||||
# digest :string(60) default(""), not null
|
||||
# downloads :integer default("0"), not null
|
||||
# author_id :integer default("0"), not null
|
||||
# created_on :datetime
|
||||
# description :text(65535)
|
||||
# disk_directory :string(255)
|
||||
# attachtype :integer default("1")
|
||||
# is_public :integer default("1")
|
||||
# copy_from :integer
|
||||
# quotes :integer default("0")
|
||||
# is_publish :integer default("1")
|
||||
# publish_time :datetime
|
||||
# resource_bank_id :integer
|
||||
# unified_setting :boolean default("1")
|
||||
# cloud_url :string(255) default("")
|
||||
# course_second_category_id :integer default("0")
|
||||
# delay_publish :boolean default("0")
|
||||
# memo_image :boolean default("0")
|
||||
# extra_type :integer default("0")
|
||||
# uuid :string(255)
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_attachments_on_author_id (author_id)
|
||||
# index_attachments_on_container_id_and_container_type (container_id,container_type)
|
||||
# index_attachments_on_course_second_category_id (course_second_category_id)
|
||||
# index_attachments_on_created_on (created_on)
|
||||
# index_attachments_on_is_public (is_public)
|
||||
# index_attachments_on_quotes (quotes)
|
||||
#
|
||||
|
||||
# == Schema Information
|
||||
#
|
||||
# Table name: attachments
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# container_id :integer
|
||||
# container_type :string(30)
|
||||
# filename :string(255) default(""), not null
|
||||
# disk_filename :string(255) default(""), not null
|
||||
# filesize :integer default("0"), not null
|
||||
# content_type :string(255) default("")
|
||||
# digest :string(60) default(""), not null
|
||||
# downloads :integer default("0"), not null
|
||||
# author_id :integer default("0"), not null
|
||||
# created_on :datetime
|
||||
# description :text(65535)
|
||||
# disk_directory :string(255)
|
||||
# attachtype :integer default("1")
|
||||
# is_public :integer default("1")
|
||||
# copy_from :integer
|
||||
# quotes :integer default("0")
|
||||
# is_publish :integer default("1")
|
||||
# publish_time :datetime
|
||||
# resource_bank_id :integer
|
||||
# unified_setting :boolean default("1")
|
||||
# cloud_url :string(255) default("")
|
||||
# course_second_category_id :integer default("0")
|
||||
# delay_publish :boolean default("0")
|
||||
# memo_image :boolean default("0")
|
||||
# extra_type :integer default("0")
|
||||
# uuid :string(255)
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_attachments_on_author_id (author_id)
|
||||
# index_attachments_on_container_id_and_container_type (container_id,container_type)
|
||||
# index_attachments_on_course_second_category_id (course_second_category_id)
|
||||
# index_attachments_on_created_on (created_on)
|
||||
# index_attachments_on_is_public (is_public)
|
||||
# index_attachments_on_quotes (quotes)
|
||||
# index_attachments_on_uuid (uuid)
|
||||
#
|
||||
|
||||
|
||||
|
||||
|
||||
|
@ -72,7 +73,7 @@ class Attachment < ApplicationRecord
|
|||
scope :unified_setting, -> {where("unified_setting = ? ", 1)}
|
||||
scope :where_id_or_uuid, -> (id) { (Float(id) rescue nil).present? ? where(id: id) : where(uuid: id) }
|
||||
|
||||
validates_length_of :description, maximum: 100, message: "不能超过100个字符"
|
||||
validates_length_of :description, maximum: 255, message: "不能超过255个字符"
|
||||
|
||||
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
|
||||
|
||||
|
|
|
@ -21,68 +21,69 @@ module ProjectOperable
|
|||
end
|
||||
|
||||
def add_member!(user_id, role_name='Developer')
|
||||
if self.owner.is_a?(Organization)
|
||||
case role_name
|
||||
when 'Manager'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.admin.take
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 新增对应的团队成员
|
||||
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
|
||||
# 确保组织成员中有该用户
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
when 'Developer'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.write.take
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 新增对应的团队成员
|
||||
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
|
||||
# 确保组织成员中有该用户
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
when 'Reporter'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.read.take
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 新增对应的团队成员
|
||||
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
|
||||
# 确保组织成员中有该用户
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
end
|
||||
end
|
||||
member = members.create!(user_id: user_id, team_user_id: team_user&.id)
|
||||
# if self.owner.is_a?(Organization)
|
||||
# case role_name
|
||||
# when 'Manager'
|
||||
# # 构建相应的团队
|
||||
# team = self.owner.teams.admin.take
|
||||
# if team.nil?
|
||||
# team = Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false)
|
||||
# gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
# team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
# end
|
||||
#
|
||||
# # 设置项目在团队中的访问权限
|
||||
# team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
# tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
#
|
||||
# # 新增对应的团队成员
|
||||
# team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||
# $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
#
|
||||
# # 确保组织成员中有该用户
|
||||
# OrganizationUser.build(self.user_id, user_id)
|
||||
# when 'Developer'
|
||||
# # 构建相应的团队
|
||||
# team = self.owner.teams.write.take
|
||||
# if team.nil?
|
||||
# team = Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false)
|
||||
# gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
# team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
# end
|
||||
#
|
||||
# # 设置项目在团队中的访问权限
|
||||
# team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
# tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
#
|
||||
# # 新增对应的团队成员
|
||||
# team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||
# $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
#
|
||||
# # 确保组织成员中有该用户
|
||||
# OrganizationUser.build(self.user_id, user_id)
|
||||
# when 'Reporter'
|
||||
# # 构建相应的团队
|
||||
# team = self.owner.teams.read.take
|
||||
# if team.nil?
|
||||
# team = Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false)
|
||||
# gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
# team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
# end
|
||||
#
|
||||
# # 设置项目在团队中的访问权限
|
||||
# team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
# tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
#
|
||||
# # 新增对应的团队成员
|
||||
# team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||
# $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
#
|
||||
# # 确保组织成员中有该用户
|
||||
# OrganizationUser.build(self.user_id, user_id)
|
||||
# end
|
||||
# end
|
||||
# member = members.create!(user_id: user_id, team_user_id: team_user&.id)
|
||||
member = members.create!(user_id: user_id)
|
||||
set_developer_role(member, role_name)
|
||||
end
|
||||
|
||||
|
@ -116,71 +117,71 @@ module ProjectOperable
|
|||
def change_member_role!(user_id, role)
|
||||
member = self.member(user_id)
|
||||
# 所有者为组织,并且该用户属于组织成员
|
||||
if self.owner.is_a?(Organization) && member.team_user.present?
|
||||
case role&.name
|
||||
when 'Manager'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.admin.take
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 更改对应的团队成员
|
||||
team_user = member.team_user
|
||||
$gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
team_user.update_attributes!({team_id: team.id}) unless team.team_users.exists?(user_id: member.user_id)
|
||||
|
||||
# 确保组织成员中有该用户
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
when 'Developer'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.write.take
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
$gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 更改对应的团队成员
|
||||
team_user = member.team_user
|
||||
$gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
team_user.update_attributes!({team_id: team.id}) unless team.team_users.exists?(user_id: member.user_id)
|
||||
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
when 'Reporter'
|
||||
# 构建相应的团队
|
||||
team = self.owner.teams.read.take
|
||||
if team.nil?
|
||||
team = Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false)
|
||||
gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
end
|
||||
|
||||
# 设置项目在团队中的访问权限
|
||||
team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
|
||||
# 更改对应的团队成员
|
||||
team_user = member.team_user
|
||||
$gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||
$gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
team_user.update_attributes!({team_id: team.id}) unless team.team_users.exists?(user_id: member.user_id)
|
||||
|
||||
# 确保组织成员中有该用户
|
||||
OrganizationUser.build(self.user_id, user_id)
|
||||
end
|
||||
end
|
||||
# if self.owner.is_a?(Organization) && member.team_user.present?
|
||||
# case role&.name
|
||||
# when 'Manager'
|
||||
# # 构建相应的团队
|
||||
# team = self.owner.teams.admin.take
|
||||
# if team.nil?
|
||||
# team = Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false)
|
||||
# gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
# team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
# end
|
||||
#
|
||||
# # 设置项目在团队中的访问权限
|
||||
# team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
# tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
#
|
||||
# # 更改对应的团队成员
|
||||
# team_user = member.team_user
|
||||
# $gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||
# $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
# team_user.update_attributes!({team_id: team.id}) unless team.team_users.exists?(user_id: member.user_id)
|
||||
#
|
||||
# # 确保组织成员中有该用户
|
||||
# OrganizationUser.build(self.user_id, user_id)
|
||||
# when 'Developer'
|
||||
# # 构建相应的团队
|
||||
# team = self.owner.teams.write.take
|
||||
# if team.nil?
|
||||
# team = Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false)
|
||||
# gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
# team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
# end
|
||||
# # 设置项目在团队中的访问权限
|
||||
# team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
# $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
#
|
||||
# # 更改对应的团队成员
|
||||
# team_user = member.team_user
|
||||
# $gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||
# $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
# team_user.update_attributes!({team_id: team.id}) unless team.team_users.exists?(user_id: member.user_id)
|
||||
#
|
||||
# OrganizationUser.build(self.user_id, user_id)
|
||||
# when 'Reporter'
|
||||
# # 构建相应的团队
|
||||
# team = self.owner.teams.read.take
|
||||
# if team.nil?
|
||||
# team = Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false)
|
||||
# gteam = $gitea_client.post_orgs_teams_by_org(self.owner.login, {body: team.to_gitea_hash.to_json}) rescue nil
|
||||
# team.update_attributes!({gtid: gteam["id"]}) unless gteam.nil?
|
||||
# end
|
||||
#
|
||||
# # 设置项目在团队中的访问权限
|
||||
# team_project = TeamProject.build(self.user_id, team.id, self.id)
|
||||
# tp_result = $gitea_client.put_teams_repos_by_id_org_repo(team.gtid, self.owner.login, self.identifier) rescue nil
|
||||
#
|
||||
# # 更改对应的团队成员
|
||||
# team_user = member.team_user
|
||||
# $gitea_client.delete_teams_members_by_id_username(team_user.team.gtid, team_user.user&.login) rescue nil # 移除旧的
|
||||
# $gitea_client.put_teams_members_by_id_username(team&.gtid, team_user.user&.login) rescue nil # 新增新的
|
||||
# team_user.update_attributes!({team_id: team.id}) unless team.team_users.exists?(user_id: member.user_id)
|
||||
#
|
||||
# # 确保组织成员中有该用户
|
||||
# OrganizationUser.build(self.user_id, user_id)
|
||||
# end
|
||||
# end
|
||||
member.member_roles.last.update_attributes!(role: role)
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: daily_platform_statistics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# date :date
|
||||
# pv :integer default("0")
|
||||
# visitor :integer default("0")
|
||||
# ip :integer default("0")
|
||||
# weekly_keep_rate :float(24) default("0")
|
||||
# source_through :float(24) default("0")
|
||||
# source_link :float(24) default("0")
|
||||
# source_search :float(24) default("0")
|
||||
# source_custom :float(24) default("0")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_daily_platform_statistics_on_date (date) UNIQUE
|
||||
#
|
||||
|
||||
class DailyPlatformStatistic < ApplicationRecord
|
||||
end
|
|
@ -2,18 +2,20 @@
|
|||
#
|
||||
# Table name: daily_project_statistics
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# project_id :integer
|
||||
# date :string(255)
|
||||
# visits :integer default("0")
|
||||
# watchers :integer default("0")
|
||||
# praises :integer default("0")
|
||||
# forks :integer default("0")
|
||||
# issues :integer default("0")
|
||||
# pullrequests :integer default("0")
|
||||
# commits :integer default("0")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# id :integer not null, primary key
|
||||
# project_id :integer
|
||||
# date :date
|
||||
# score :integer default("0")
|
||||
# visits :integer default("0")
|
||||
# watchers :integer default("0")
|
||||
# praises :integer default("0")
|
||||
# forks :integer default("0")
|
||||
# issues :integer default("0")
|
||||
# pullrequests :integer default("0")
|
||||
# commits :integer default("0")
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# closed_issues :integer default("0")
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
|
|
|
@ -0,0 +1,21 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: gitlink_competition_applies
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# competition_id :integer
|
||||
# competition_identifier :string(255)
|
||||
# team_id :integer
|
||||
# team_name :string(255)
|
||||
# school_name :string(255)
|
||||
# login :string(255)
|
||||
# nickname :string(255)
|
||||
# phone :string(255)
|
||||
# identity :string(255)
|
||||
# role :string(255)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
#
|
||||
|
||||
class GitlinkCompetitionApply < ApplicationRecord
|
||||
end
|
|
@ -63,16 +63,17 @@ class Issue < ApplicationRecord
|
|||
has_many :project_trends, as: :trend, dependent: :destroy
|
||||
has_one :pull_request
|
||||
# belongs_to :issue_tag,optional: true
|
||||
belongs_to :priority, :class_name => 'IssuePriority', foreign_key: :priority_id,optional: true
|
||||
belongs_to :priority, class_name: 'IssuePriority', foreign_key: :priority_id,optional: true
|
||||
belongs_to :version, foreign_key: :fixed_version_id,optional: true, counter_cache: true
|
||||
belongs_to :user,optional: true, foreign_key: :author_id
|
||||
belongs_to :issue_status, foreign_key: :status_id,optional: true
|
||||
belongs_to :parent_issue, class_name: 'Issue', optional: true, foreign_key: :root_id, counter_cache: :child_count
|
||||
has_many :commit_issues
|
||||
has_many :attachments, as: :container, dependent: :destroy
|
||||
# has_many :memos
|
||||
has_many :journals, :as => :journalized, :dependent => :destroy
|
||||
has_many :journals, as: :journalized, dependent: :destroy
|
||||
has_many :journal_details, through: :journals
|
||||
has_many :claims, :dependent => :destroy
|
||||
has_many :claims, dependent: :destroy
|
||||
has_many :claim_users, through: :claims, source: :user
|
||||
has_many :issue_tags_relates, dependent: :destroy
|
||||
has_many :issue_tags, through: :issue_tags_relates
|
||||
|
@ -82,48 +83,98 @@ class Issue < ApplicationRecord
|
|||
has_many :assigners, through: :issue_assigners
|
||||
has_many :issue_participants, dependent: :destroy
|
||||
has_many :participants, through: :issue_participants
|
||||
has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: "atme"}).distinct}, through: :issue_participants, source: :participant
|
||||
has_many :children_issues, class_name: 'Issue', foreign_key: :root_id, dependent: :destroy
|
||||
has_many :show_participants, -> {joins(:issue_participants).where.not(issue_participants: {participant_type: 'atme'}).distinct}, through: :issue_participants, source: :participant
|
||||
has_many :show_assigners, -> {joins(:issue_assigners).distinct}, through: :issue_assigners, source: :assigner
|
||||
has_many :show_issue_tags, -> {joins(:issue_tags_relates).distinct}, through: :issue_tags_relates, source: :issue_tag
|
||||
|
||||
has_many :comment_journals, -> {where.not(notes: nil)}, class_name: "Journal", :as => :journalized
|
||||
has_many :operate_journals, -> {where(notes: nil)}, class_name: "Journal", :as => :journalized
|
||||
has_many :pull_attached_issues, dependent: :destroy
|
||||
has_many :comment_journals, -> {where.not(notes: nil)}, class_name: 'Journal', as: :journalized
|
||||
has_many :operate_journals, -> {where(notes: nil)}, class_name: 'Journal', as: :journalized
|
||||
has_many :pull_attached_issues, dependent: :destroy
|
||||
has_many :attach_pull_requests, through: :pull_attached_issues, source: :pull_request
|
||||
# PM 关联工作项目
|
||||
has_many :pm_links, as: :linkable, dependent: :destroy
|
||||
|
||||
belongs_to :changer, class_name: 'User', foreign_key: :changer_id, optional: true
|
||||
|
||||
scope :issue_includes, ->{includes(:user)}
|
||||
scope :issue_many_includes, ->{includes(journals: :user)}
|
||||
scope :issue_issue, ->{where(issue_classify: [nil,"issue"])}
|
||||
scope :issue_pull_request, ->{where(issue_classify: "pull_request")}
|
||||
scope :issue_issue, ->{where(issue_classify: [nil, 'issue'])}
|
||||
scope :issue_pull_request, ->{where(issue_classify: 'pull_request')}
|
||||
scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)}
|
||||
scope :closed, ->{where(status_id: 5)}
|
||||
scope :opened, ->{where.not(status_id: 5)}
|
||||
after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
|
||||
after_save :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container
|
||||
after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic
|
||||
before_save :check_pm_and_update_due_date
|
||||
after_save :incre_or_decre_closed_issues_count, :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :generate_uuid
|
||||
after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic, :destroy_be_pm_links
|
||||
|
||||
def destroy_be_pm_links
|
||||
PmLink.where(be_linkable_type:"Issue",be_linkable_id:self.id).map(&:destroy)
|
||||
end
|
||||
|
||||
def check_pm_and_update_due_date
|
||||
if pm_project_id.present? && pm_issue_type.present? && status_id_changed?
|
||||
status_ids = case pm_issue_type
|
||||
when 1
|
||||
[3,5]
|
||||
when 2
|
||||
[3,5]
|
||||
when 3
|
||||
[5]
|
||||
else
|
||||
[]
|
||||
end
|
||||
if status_ids.include? self.status_id
|
||||
self.due_date = self.due_date || Time.current
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def is_issuely_issue?
|
||||
self.issue_classify.nil? || self.issue_classify == 'issue'
|
||||
end
|
||||
|
||||
def incre_or_decre_closed_issues_count
|
||||
if previous_changes[:status_id].present? && is_issuely_issue?
|
||||
if previous_changes[:status_id][1] == 5
|
||||
CacheAsyncSetJob.perform_later("project_common_service", {closed_issues: 1}, self.project_id)
|
||||
end
|
||||
if previous_changes[:status_id][0] == 5
|
||||
CacheAsyncSetJob.perform_later("project_common_service", {closed_issues: -1}, self.project_id)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def incre_project_common
|
||||
CacheAsyncSetJob.perform_later("project_common_service", {issues: 1}, self.project_id)
|
||||
CacheAsyncSetJob.perform_later('project_common_service', {issues: 1}, self.project_id) if is_issuely_issue?
|
||||
end
|
||||
|
||||
def decre_project_common
|
||||
CacheAsyncSetJob.perform_later("project_common_service", {issues: -1}, self.project_id)
|
||||
CacheAsyncSetJob.perform_later('project_common_service', {issues: -1}, self.project_id) if is_issuely_issue?
|
||||
end
|
||||
|
||||
def incre_user_statistic
|
||||
CacheAsyncSetJob.perform_later("user_statistic_service", {issue_count: 1}, self.author_id)
|
||||
CacheAsyncSetJob.perform_later('user_statistic_service', {issue_count: 1}, self.author_id) if is_issuely_issue?
|
||||
end
|
||||
|
||||
def decre_user_statistic
|
||||
CacheAsyncSetJob.perform_later("user_statistic_service", {issue_count: -1}, self.author_id)
|
||||
CacheAsyncSetJob.perform_later('user_statistic_service', {issue_count: -1}, self.author_id) if is_issuely_issue?
|
||||
end
|
||||
|
||||
def refresh_root_issue_count
|
||||
return if root_id.nil? || root_id.zero?
|
||||
root_issue = Issue.find_by(id: root_id)
|
||||
root_count = Issue.where(root_id: root_id).count
|
||||
root_issue.update(child_count: root_count)
|
||||
end
|
||||
|
||||
def incre_platform_statistic
|
||||
CacheAsyncSetJob.perform_later("platform_statistic_service", {issue_count: 1})
|
||||
CacheAsyncSetJob.perform_later('platform_statistic_service', {issue_count: 1}) if is_issuely_issue?
|
||||
end
|
||||
|
||||
def decre_platform_statistic
|
||||
CacheAsyncSetJob.perform_later("platform_statistic_service", {issue_count: -1})
|
||||
CacheAsyncSetJob.perform_later('platform_statistic_service', {issue_count: -1}) if is_issuely_issue?
|
||||
end
|
||||
|
||||
def get_assign_user
|
||||
|
@ -132,20 +183,20 @@ class Issue < ApplicationRecord
|
|||
|
||||
def create_journal_detail(change_files, issue_files, issue_file_ids, user_id)
|
||||
journal_params = {
|
||||
journalized_id: self.id, journalized_type: "Issue", user_id: user_id
|
||||
journalized_id: self.id, journalized_type: 'Issue', user_id: user_id
|
||||
}
|
||||
journal = Journal.new journal_params
|
||||
|
||||
if journal.save
|
||||
if change_files
|
||||
old_attachment_names = self.attachments.select(:filename,:id).where(id: issue_file_ids).pluck(:filename).join(",")
|
||||
new_attachment_name = self.attachments.select(:filename,:id).where(id: issue_files).pluck(:filename).join(",")
|
||||
journal.journal_details.create(property: "attachment", prop_key: "#{issue_files.size}", old_value: old_attachment_names, value: new_attachment_name)
|
||||
old_attachment_names = self.attachments.select(:filename,:id).where(id: issue_file_ids).pluck(:filename).join(',')
|
||||
new_attachment_name = self.attachments.select(:filename,:id).where(id: issue_files).pluck(:filename).join(',')
|
||||
journal.journal_details.create(property: 'attachment', prop_key: "#{issue_files.size}", old_value: old_attachment_names, value: new_attachment_name)
|
||||
end
|
||||
change_values = %w(subject description is_private assigned_to_id tracker_id status_id priority_id fixed_version_id start_date due_date estimated_hours done_ratio issue_tags_value issue_type token branch_name)
|
||||
change_values.each do |at|
|
||||
if self.send("saved_change_to_#{at}?")
|
||||
journal.journal_details.create(property: "attr", prop_key: "#{at}", old_value: self.send("#{at}_before_last_save"), value: self.send(at))
|
||||
journal.journal_details.create(property: 'attr', prop_key: "#{at}", old_value: self.send("#{at}_before_last_save"), value: self.send(at))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -153,11 +204,11 @@ class Issue < ApplicationRecord
|
|||
|
||||
def custom_journal_detail(prop_key, old_value, value, user_id)
|
||||
journal_params = {
|
||||
journalized_id: self.id, journalized_type: "Issue", user_id: user_id
|
||||
journalized_id: self.id, journalized_type: 'Issue', user_id: user_id
|
||||
}
|
||||
journal = Journal.new journal_params
|
||||
if journal.save
|
||||
journal.journal_details.create(property: "attr", prop_key: prop_key, old_value: old_value, value: value)
|
||||
journal.journal_details.create(property: 'attr', prop_key: prop_key, old_value: old_value, value: value)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -177,20 +228,29 @@ class Issue < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def generate_uuid
|
||||
# return if pm_project_id.nil?
|
||||
# attachments.map(&:generate_uuid)
|
||||
end
|
||||
|
||||
def is_collaborators?
|
||||
self.assigned_to_id.present? ? self.project.member?(self.assigned_to_id) : false
|
||||
if self.assigned_to_id.present? && self.project.present?
|
||||
self.project.member?(self.assigned_to_id)
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
def get_issue_tags_name
|
||||
if issue_tags.present?
|
||||
issue_tags.select(:name).uniq.pluck(:name).join(",")
|
||||
issue_tags.select(:name).uniq.pluck(:name).join(',')
|
||||
else
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
def only_reply_journals
|
||||
journals.where.not(notes: [nil, ""]).journal_includes.limit(2)
|
||||
journals.where.not(notes: [nil, '']).journal_includes.limit(2)
|
||||
end
|
||||
|
||||
def change_versions_count
|
||||
|
@ -220,7 +280,7 @@ class Issue < ApplicationRecord
|
|||
end
|
||||
|
||||
def update_closed_issues_count_in_project!
|
||||
self.project.decrement!(:closed_issues_count) if self.status_id == 5
|
||||
self.project.decrement!(:closed_issues_count) if self.status_id == 5 && self.project.present?
|
||||
end
|
||||
|
||||
def send_update_message_to_notice_system
|
||||
|
@ -252,8 +312,8 @@ class Issue < ApplicationRecord
|
|||
def to_builder
|
||||
Jbuilder.new do |issue|
|
||||
issue.(self, :id, :project_issues_index, :subject, :description, :branch_name, :start_date, :due_date)
|
||||
issue.created_at self.created_on.strftime("%Y-%m-%d %H:%M")
|
||||
issue.updated_at self.updated_on.strftime("%Y-%m-%d %H:%M")
|
||||
issue.created_at self.created_on.strftime('%Y-%m-%d %H:%M')
|
||||
issue.updated_at self.updated_on.strftime('%Y-%m-%d %H:%M')
|
||||
issue.tags self.show_issue_tags.map{|t| JSON.parse(t.to_builder.target!)}
|
||||
issue.status self.issue_status.to_builder
|
||||
if self.priority.present?
|
||||
|
@ -275,4 +335,12 @@ class Issue < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def self.full_children_issues(issue, issues = [])
|
||||
issue.children_issues.each do |i|
|
||||
issues << i
|
||||
full_children_issues(i, issues)
|
||||
end
|
||||
issues
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -38,4 +38,21 @@ class IssuePriority < ApplicationRecord
|
|||
priority.(self, :id, :name)
|
||||
end
|
||||
end
|
||||
|
||||
def pm_color
|
||||
case name
|
||||
when '低'
|
||||
'#13b33e'
|
||||
when '正常'
|
||||
'#0d5ef8'
|
||||
when '高'
|
||||
'#ff6f00'
|
||||
when '紧急'
|
||||
'#d20f0f'
|
||||
# when '立刻'
|
||||
# '#f5222d'
|
||||
else
|
||||
'#13b33e'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -45,9 +45,28 @@ class IssueStatus < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def to_builder
|
||||
def to_builder
|
||||
Jbuilder.new do |status|
|
||||
status.(self, :id, :name)
|
||||
end
|
||||
end
|
||||
|
||||
def pm_color
|
||||
case name
|
||||
when '新增'
|
||||
'#ff6f00'
|
||||
when '正在解决'
|
||||
'#0d5ef8'
|
||||
when '已解决'
|
||||
'#13b33e'
|
||||
when '关闭'
|
||||
'#b1aaa5'
|
||||
# when '反馈'
|
||||
# '#13c2c2'
|
||||
when '拒绝'
|
||||
'#ff0000'
|
||||
else
|
||||
'#ff6f00'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -15,9 +15,11 @@
|
|||
# gitea_url :string(255)
|
||||
# pull_requests_count :integer default("0")
|
||||
# pm_project_id :integer
|
||||
# organization_id :integer
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_issue_tags_on_organization_id (organization_id)
|
||||
# index_issue_tags_on_user_id_and_name_and_project_id (user_id,name,project_id)
|
||||
#
|
||||
|
||||
|
@ -29,8 +31,15 @@ class IssueTag < ApplicationRecord
|
|||
has_many :pull_request_issues, -> {where(issue_classify: "pull_request")}, source: :issue, through: :issue_tags_relates
|
||||
belongs_to :project, optional: true, counter_cache: true
|
||||
belongs_to :user, optional: true
|
||||
belongs_to :organization, optional: true
|
||||
|
||||
validates :name, uniqueness: {scope: :project_id, message: "已存在" }
|
||||
scope :pm_able, -> {where(project_id: 0)}
|
||||
|
||||
validates :name, uniqueness: {scope: :project_id, message: "已存在" }, if: :pm_project?
|
||||
|
||||
def pm_project?
|
||||
!project_id.zero?
|
||||
end
|
||||
|
||||
def self.init_data(project_id)
|
||||
data = init_issue_tag_data
|
||||
|
@ -41,6 +50,24 @@ class IssueTag < ApplicationRecord
|
|||
$redis_cache.hset("project_init_issue_tags", project_id, 1)
|
||||
end
|
||||
|
||||
def self.pm_init_data(pm_project_id)
|
||||
data = init_issue_tag_data
|
||||
data.each do |item|
|
||||
next if IssueTag.exists?(pm_project_id: pm_project_id, project_id: 0, name: item[0])
|
||||
IssueTag.create!(pm_project_id: pm_project_id, project_id: 0, name: item[0], description: item[1], color: item[2])
|
||||
end
|
||||
$redis_cache.hset("pm_project_init_issue_tags", pm_project_id, 1)
|
||||
end
|
||||
|
||||
def self.pm_org_init_data(organization_id)
|
||||
data = init_issue_tag_data
|
||||
data.each do |item|
|
||||
next if IssueTag.exists?(organization_id: organization_id, project_id: 0, name: item[0])
|
||||
IssueTag.create!(organization_id: organization_id, project_id: 0, name: item[0], description: item[1], color: item[2])
|
||||
end
|
||||
$redis_cache.hset("pm_org_init_issue_tags", organization_id, 1)
|
||||
end
|
||||
|
||||
def reset_counter_field
|
||||
self.update_column(:issues_count, issue_issues.size)
|
||||
self.update_column(:pull_requests_count, pull_request_issues.size)
|
||||
|
|
|
@ -52,6 +52,8 @@ class MessageTemplate < ApplicationRecord
|
|||
self.create(type: 'MessageTemplate::ProjectMilestone', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 创建了一个里程碑:<b>{name}</b>', notification_url: '{baseurl}/{owner}/{identifier}/milestones/{id}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 在 {nickname2}/{repository} 新建了一个里程碑")
|
||||
email_html = File.read("#{email_template_html_dir}/project_milestone_completed.html")
|
||||
self.create(type: 'MessageTemplate::ProjectMilestoneCompleted', sys_notice: '在 <b>{nickname}/{repository}</b> 仓库,里程碑 <b>{name}</b> 的完成度已达到100%', notification_url: '{baseurl}/{owner}/{identifier}/milestones/{id}', email: email_html, email_title: "#{PLATFORM}: 仓库 {nickname}/{repository} 有里程碑已完成")
|
||||
self.create(type: 'MessageTemplate::ProjectMilestoneEarlyExpired', sys_notice: '您创建的里程碑 <b>{name}</b> 已临近截止日期,请尽快处理.', notification_url: '{baseurl}/{owner}/{identifier}/milestones/{id}')
|
||||
self.create(type: 'MessageTemplate::ProjectMilestoneExpired', sys_notice: '您创建的里程碑 <b>{name}</b> 已逾期,请及时更新进度或联系项目团队.', notification_url: '{baseurl}/{owner}/{identifier}/milestones/{id}')
|
||||
self.create(type: 'MessageTemplate::ProjectPraised', sys_notice: '<b>{nickname1}</b> 点赞了你管理的仓库 <b>{nickname2}/{repository}</b>', notification_url: '{baseurl}/{login}')
|
||||
self.create(type: 'MessageTemplate::ProjectOpenDevOps', sys_notice: '您的仓库 <b>{repository}</b> 已成功开通引擎服务,可通过简单的节点编排完成自动化集成与部署。欢迎体验!', notification_url: '{baseurl}/{owner}/{identifier}/devops')
|
||||
email_html = File.read("#{email_template_html_dir}/project_pull_request.html")
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# notification_url :string(255)
|
||||
# email_title :string(255)
|
||||
#
|
||||
|
||||
# 我管理的仓库有里程碑完成
|
||||
class MessageTemplate::ProjectMilestoneEarlyExpired < MessageTemplate
|
||||
|
||||
# MessageTemplate::ProjectMilestoneEarlyExpired.get_message_content(User.where(login: 'yystopf'), Version.find(7))
|
||||
def self.get_message_content(receivers, milestone)
|
||||
receivers.each do |receiver|
|
||||
if receiver.user_template_message_setting.present?
|
||||
send_setting = receiver.user_template_message_setting.notification_body["ManageProject::MilestoneExpired"]
|
||||
send_setting = send_setting.nil? ? UserTemplateMessageSetting.init_notification_body["ManageProject::MilestoneExpired"] : send_setting
|
||||
receivers = receivers.where.not(id: receiver.id) unless send_setting
|
||||
end
|
||||
end
|
||||
return '', '', '' if receivers.blank?
|
||||
project = milestone&.project
|
||||
owner = project&.owner
|
||||
content = sys_notice.gsub('{nickname}', owner&.real_name).gsub('{repository}', project&.name).gsub('{name}', milestone&.name)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', milestone&.id.to_s)
|
||||
|
||||
return receivers_string(receivers), content, url
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::MilestoneEarlyExpired.get_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
def self.get_email_message_content(receiver, milestone)
|
||||
if receiver.user_template_message_setting.present?
|
||||
send_setting = receiver.user_template_message_setting.email_body["ManageProject::MilestoneExpired"]
|
||||
send_setting = send_setting.nil? ? UserTemplateMessageSetting.init_email_body["ManageProject::MilestoneExpired"] : send_setting
|
||||
return '', '', '' unless send_setting
|
||||
project = milestone&.project
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
title.gsub!('{nickname}', owner&.real_name)
|
||||
title.gsub!('{repository}', project&.name)
|
||||
|
||||
content = email
|
||||
content.gsub!('{receiver}', receiver&.real_name)
|
||||
content.gsub!('{baseurl}', base_url)
|
||||
content.gsub!('{nickname}', owner&.real_name)
|
||||
content.gsub!('{repository}', project&.name)
|
||||
content.gsub!('{login}', owner&.login)
|
||||
content.gsub!('{identifier}', project&.identifier)
|
||||
content.gsub!('{id}', milestone&.id.to_s)
|
||||
content.gsub!('{name}', milestone&.name)
|
||||
content.gsub!('{platform}', PLATFORM)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::MilestoneEarlyExpired.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
end
|
||||
end
|
|
@ -0,0 +1,70 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: message_templates
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# type :string(255)
|
||||
# sys_notice :text(65535)
|
||||
# email :text(65535)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# notification_url :string(255)
|
||||
# email_title :string(255)
|
||||
#
|
||||
|
||||
# 我管理的仓库有里程碑完成
|
||||
class MessageTemplate::ProjectMilestoneExpired < MessageTemplate
|
||||
|
||||
# MessageTemplate::ProjectMilestoneExpired.get_message_content(User.where(login: 'yystopf'), Version.find(7))
|
||||
def self.get_message_content(receivers, milestone)
|
||||
receivers.each do |receiver|
|
||||
if receiver.user_template_message_setting.present?
|
||||
send_setting = receiver.user_template_message_setting.notification_body["ManageProject::MilestoneExpired"]
|
||||
send_setting = send_setting.nil? ? UserTemplateMessageSetting.init_notification_body["ManageProject::MilestoneExpired"] : send_setting
|
||||
receivers = receivers.where.not(id: receiver.id) unless send_setting
|
||||
end
|
||||
end
|
||||
return '', '', '' if receivers.blank?
|
||||
project = milestone&.project
|
||||
owner = project&.owner
|
||||
content = sys_notice.gsub('{nickname}', owner&.real_name).gsub('{repository}', project&.name).gsub('{name}', milestone&.name)
|
||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', milestone&.id.to_s)
|
||||
|
||||
return receivers_string(receivers), content, url
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::ProjectMilestoneExpired.get_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
def self.get_email_message_content(receiver, milestone)
|
||||
if receiver.user_template_message_setting.present?
|
||||
send_setting = receiver.user_template_message_setting.email_body["ManageProject::MilestoneExpired"]
|
||||
send_setting = send_setting.nil? ? UserTemplateMessageSetting.init_email_body["ManageProject::MilestoneExpired"] : send_setting
|
||||
return '', '', '' unless send_setting
|
||||
project = milestone&.project
|
||||
owner = project&.owner
|
||||
title = email_title
|
||||
title.gsub!('{nickname}', owner&.real_name)
|
||||
title.gsub!('{repository}', project&.name)
|
||||
|
||||
content = email
|
||||
content.gsub!('{receiver}', receiver&.real_name)
|
||||
content.gsub!('{baseurl}', base_url)
|
||||
content.gsub!('{nickname}', owner&.real_name)
|
||||
content.gsub!('{repository}', project&.name)
|
||||
content.gsub!('{login}', owner&.login)
|
||||
content.gsub!('{identifier}', project&.identifier)
|
||||
content.gsub!('{id}', milestone&.id.to_s)
|
||||
content.gsub!('{name}', milestone&.name)
|
||||
content.gsub!('{platform}', PLATFORM)
|
||||
|
||||
return receiver&.mail, title, content
|
||||
else
|
||||
return '', '', ''
|
||||
end
|
||||
|
||||
rescue => e
|
||||
Rails.logger.info("MessageTemplate::ProjectMilestoneExpired.get_email_message_content [ERROR] #{e}")
|
||||
return '', '', ''
|
||||
end
|
||||
end
|
|
@ -0,0 +1,27 @@
|
|||
# == Schema Information
|
||||
#
|
||||
# Table name: open_users
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# user_id :integer
|
||||
# type :string(255)
|
||||
# uid :string(255)
|
||||
# created_at :datetime not null
|
||||
# updated_at :datetime not null
|
||||
# extra :text(65535)
|
||||
#
|
||||
# Indexes
|
||||
#
|
||||
# index_open_users_on_type_and_uid (type,uid) UNIQUE
|
||||
# index_open_users_on_user_id (user_id)
|
||||
#
|
||||
|
||||
class OpenUsers::Acge < OpenUser
|
||||
def nickname
|
||||
extra&.[]('nickname')
|
||||
end
|
||||
|
||||
def en_type
|
||||
'acge'
|
||||
end
|
||||
end
|
|
@ -64,7 +64,7 @@
|
|||
|
||||
class Organization < Owner
|
||||
alias_attribute :name, :login
|
||||
NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||
NAME_REGEX = /^[a-zA-Z0-9]+([-_.][a-zA-Z0-9]+)*$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||
|
||||
default_scope { where(type: "Organization") }
|
||||
|
||||
|
@ -79,7 +79,7 @@ class Organization < Owner
|
|||
|
||||
validates :login, presence: true
|
||||
validates_uniqueness_of :login, :if => Proc.new { |user| user.login_changed? && user.login.present? }, case_sensitive: false
|
||||
validates :login, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||
validates :login, format: { with: NAME_REGEX, multiline: true, message: "只能以数字或字母开头,仅支持横杠、下划线、点三种符号,不允许符号连续排列,长度4-50个字符" }
|
||||
|
||||
delegate :description, :website, :location, :repo_admin_change_team_access, :recommend,
|
||||
:visibility, :max_repo_creation, :num_projects, :num_users, :num_teams,
|
||||
|
@ -182,14 +182,6 @@ class Organization < Owner
|
|||
organization_users.count
|
||||
end
|
||||
|
||||
def teams_count
|
||||
teams.count
|
||||
end
|
||||
|
||||
def organization_users_count
|
||||
organization_users.count
|
||||
end
|
||||
|
||||
def real_name
|
||||
name = lastname + firstname
|
||||
name = name.blank? ? (nickname.blank? ? login : nickname) : name
|
||||
|
@ -217,4 +209,11 @@ class Organization < Owner
|
|||
enabling_cla == true
|
||||
end
|
||||
|
||||
def num_users
|
||||
organization_user_ids = self.organization_users.pluck(:user_id).uniq
|
||||
project_member_user_ids = self.projects.joins(:members).pluck("members.user_id").uniq
|
||||
ids = organization_user_ids + project_member_user_ids
|
||||
ids.uniq.size
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -28,7 +28,7 @@ class Page < ApplicationRecord
|
|||
belongs_to :project
|
||||
|
||||
# language_frame 前端语言框架
|
||||
enum language_frame: { hugo: 0, jekyll: 1, hexo: 2}
|
||||
enum language_frame: { hugo: 0, jekyll: 1, hexo: 2, files: 3}
|
||||
|
||||
after_create do
|
||||
PageService.genernate_user(user_id)
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
#
|
||||
|
||||
class PageTheme < ApplicationRecord
|
||||
enum language_frame: { hugo: 0, jeklly: 1, hexo: 2}
|
||||
enum language_frame: { hugo: 0, jeklly: 1, hexo: 2, files:3}
|
||||
validates :name, presence: {message: "主题名不能为空"}, uniqueness: {message: "主题名已存在",scope: :language_frame},length: {maximum: 255}
|
||||
|
||||
def image
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue