Compare commits

..

No commits in common. "master" and "master" have entirely different histories.

441 changed files with 726 additions and 106877 deletions

1
.gitignore vendored
View File

@ -10,7 +10,6 @@
# Ignore lock config file
*.log
.rubocop.yml
.env
# mac
*.DS_Store

View File

@ -1,6 +1,5 @@
#source 'https://gems.ruby-china.com'
source 'https://mirrors.cloud.tencent.com/rubygems/'
#source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
gem 'rails', '~> 5.2.0'
@ -27,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
@ -71,7 +70,6 @@ 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
@ -116,6 +114,7 @@ gem 'aasm'
gem 'enumerize'
gem 'diffy'
gem 'deep_cloneable', '~> 3.0.0'
# oauth2
@ -142,6 +141,4 @@ gem 'doorkeeper'
gem 'doorkeeper-jwt'
gem 'gitea-client', '~> 1.6.1'
gem 'loofah', '~> 2.20.0'
gem 'gitea-client', '~> 1.4.6'

View File

@ -1,11 +1,3 @@
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:
@ -143,7 +135,7 @@ GEM
fugit (1.4.1)
et-orbi (~> 1.1, >= 1.1.8)
raabro (~> 1.4)
gitea-client (1.4.6)
gitea-client (1.4.2)
rest-client (~> 2.1.0)
globalid (0.4.2)
activesupport (>= 4.2.0)
@ -158,9 +150,6 @@ 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)
@ -198,9 +187,9 @@ GEM
mimemagic (~> 0.3.2)
maruku (0.7.3)
method_source (0.9.2)
mime-types (3.5.2)
mime-types (3.4.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2024.0507)
mime-types-data (3.2023.0218.1)
mimemagic (0.3.10)
nokogiri (~> 1)
rake
@ -448,8 +437,6 @@ 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)
@ -462,7 +449,7 @@ GEM
execjs (>= 0.3.0, < 3)
unf (0.1.4)
unf_ext
unf_ext (0.0.9.1)
unf_ext (0.0.8.2)
unicode-display_width (1.6.1)
web-console (3.7.0)
actionview (>= 5.0)
@ -504,7 +491,7 @@ DEPENDENCIES
enumerize
faraday (~> 0.15.4)
font-awesome-sass (= 4.7.0)
gitea-client (~> 1.4.3)
gitea-client (~> 1.4.2)
grape-entity (~> 0.7.1)
groupdate (~> 4.1.0)
harmonious_dictionary (~> 0.0.1)
@ -552,7 +539,6 @@ DEPENDENCIES
simple_xlsx_reader (~> 1.0.4)
sinatra
solargraph (~> 0.38.0)
sonarqube!
spreadsheet
spring
spring-watcher-listen (~> 2.0.0)

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -1,2 +0,0 @@
// Place all the behaviors and hooks related to the matching controller here.
// All this logic will automatically be available in application.js.

View File

@ -40,13 +40,6 @@ body {
}
}
}
.editormd .CodeMirror{
margin-top: 35px!important;
}
.CodeMirror-gutter .CodeMirror-linenumbers {
width: 28px!important;
}
input.form-control {
font-size: 14px;

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// Place all the styles related to the api/v1/sonarqube/issues controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,3 +0,0 @@
// 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/

View File

@ -1,7 +1,6 @@
class AccountsController < ApplicationController
before_action :require_login, only: [:login_check, :simple_update, :change_password]
before_action :require_login, only: [:login_check, :simple_update]
include ApplicationHelper
include AesCryptHelper
#skip_before_action :check_account, :only => [:logout]
@ -144,8 +143,7 @@ class AccountsController < ApplicationController
user = Users::RegisterService.call(register_params)
user.mail = "#{user.login}@example.org" if user.mail.blank?
password = decrypt(register_params[:password]) rescue ""
password = password.strip
password = register_params[:password].strip
# gitea用户注册, email, username, password
interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: password})
@ -195,9 +193,8 @@ class AccountsController < ApplicationController
# 用户登录
def login
password = decrypt(login_params[:password]) rescue ""
Users::LoginForm.new(login_params.merge!({password: password})).validate!
@user = User.try_to_login(params[:login], password)
Users::LoginForm.new(login_params).validate!
@user = User.try_to_login(params[:login], params[:password])
return normal_status(-2, "错误的账号或密码") if @user.blank?
# user is already in local database
@ -206,7 +203,7 @@ class AccountsController < ApplicationController
login_control = LimitForbidControl::UserLogin.new(@user)
return normal_status(-2, "登录密码出错已达上限,账号已被锁定,请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid?
password_ok = @user.check_password?(password.to_s)
password_ok = @user.check_password?(params[:password].to_s)
unless password_ok
if login_control.remain_times-1 == 0
normal_status(-2, "登录密码出错已达上限,账号已被锁定,请#{login_control.forbid_expires/60}分钟后重新登录或找回密码")
@ -219,24 +216,20 @@ class AccountsController < ApplicationController
LimitForbidControl::UserLogin.new(@user).clear
successful_authentication(@user)
sync_pwd_to_gitea!(@user, {password: password.to_s}) # TODO用户密码未同步
sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步
# session[:user_id] = @user.id
end
def change_password
password = decrypt(params[:password]) rescue ""
new_password_repeat = decrypt(params[:new_password_repeat]) rescue ""
old_password = decrypt(params[:old_password]) rescue ""
return render_error("两次输入的密码不一致") if password.to_s != new_password_repeat.to_s
return render_error("两次输入的密码不一致") if params[:password].to_s != params[:new_password_repeat].to_s
@user = User.find_by(login: params[:login])
return render_forbidden unless User.current.login == @user&.login
return render_error("此用户禁止修改密码!") if @user.id.to_i === 104691
return render_error("未找到相关用户!") if @user.blank?
return render_error("旧密码不正确") unless @user.check_password?(old_password)
return render_error("旧密码不正确") unless @user.check_password?(params[:old_password])
sync_params = {
password: password.to_s,
password: params[:password].to_s,
email: @user.mail,
login_name: @user.name,
source_id: 0
@ -244,7 +237,7 @@ class AccountsController < ApplicationController
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
if interactor.success?
@user.update_attribute(:password, password)
@user.update_attribute(:password, params[:password])
render_ok
else
render_error(interactor.error)

View File

@ -1,75 +0,0 @@
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{ render_ok(data: @node_inputs.as_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

View File

@ -1,76 +0,0 @@
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

View File

@ -1,74 +0,0 @@
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
respond_to do |format|
format.html
format.json { render_ok(data: @node_types.as_json) }
end
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
respond_to do |format|
format.html
format.json { render_ok(data: @node_type.as_json) }
end
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
respond_to do |format|
format.html { redirect_to action_node_types_path }
format.json { render_ok }
end
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

View File

@ -1,87 +0,0 @@
class Action::NodesController < ApplicationController
# before_action :require_admin, except: [:index]
before_action :require_login
before_action :find_action_node, except: [:index, :create, :new]
def index
@node_types = Action::NodeType.all
no_node_type = Action::NodeType.find_by(name: "未分类")
@no_type_nodes = Action::Node.where(action_node_types_id: nil)
@no_type_nodes = Action::Node.where(action_node_types_id: nil).or(Action::Node.where(action_node_types_id: no_node_type.id)) if no_node_type.present?
respond_to do |format|
format.html { @nodes = Action::Node.where("name LIKE :search OR full_name LIKE :search", :search => "%#{params[:search]}%") }
format.json
end
end
def create
@node = Action::Node.new(node_params)
if params.require(:node).present? && params.require(:node)[:link_type_array].present?
@node.link_type = (params.require(:node)[:link_type_array] - [""]).join(",")
end
@node.user_id = current_user.id
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
if @node.link_type.present?
@node.link_type_array = @node.link_type.to_s.split(",")
end
end
def update
if params.require(:node).present? && params.require(:node)[:link_type_array].present?
@node.link_type = (params.require(:node)[:link_type_array] - [""]).join(",")
end
@node.user_id = current_user.id if @node.user_id.blank?
@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
respond_to do |format|
format.html { redirect_to action_nodes_path }
format.json { render_ok() }
end
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, :label, :full_name, :description, :icon, :action_node_types_id,
:is_local, :local_url, :yaml, :sort_no, :node_type, :is_mutil_link, :link_type, :link_type_array)
else
params.permit(:name, :label, :full_name, :description, :icon, :action_node_types_id, :is_local, :local_url,
:yaml, :sort_no, :node_type, :is_mutil_link, :link_type, :link_type_array)
end
end
end

View File

@ -1,71 +0,0 @@
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
respond_to do |format|
format.html { redirect_to action_templates_path }
format.json { render_ok }
end
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

View File

@ -23,23 +23,10 @@ class Admins::BaseController < ApplicationController
def require_admin!
return if current_user.blank? || !current_user.logged?
return if current_user.admin_or_business?
return if current_user.admin_or_glcc_admin?
render_forbidden
end
def require_admin
render_forbidden unless User.current.admin?
end
def require_business
render_forbidden unless admin_or_business?
end
def require_glcc_admin
render_forbidden unless admin_or_glcc_admin?
end
# 触发after ajax render partial hooks执行一些因为局部刷新后失效的绑定事件
def rebind_event_if_ajax_render_partial
return if request.format.symbol != :js

View File

@ -1,13 +1,9 @@
class Admins::DashboardsController < Admins::BaseController
def index
# 查询优化
week_greater_id = CommitLog.where(created_at: current_week).limit(1)[0]&.id
#月份统计还需要优化
month_greater_id = CommitLog.where(created_at: current_month).limit(1)[0]&.id
# 用户活跃数
day_user_ids = CommitLog.where(created_at: today).pluck(:user_id).uniq
weekly_user_ids = CommitLog.where(created_at: current_week).where("id>= ?", week_greater_id).distinct.pluck(:user_id)
month_user_ids = CommitLog.where(created_at: current_month).where("id>= ?", month_greater_id).distinct.pluck(:user_id)
weekly_user_ids = CommitLog.where(created_at: current_week).pluck(:user_id).uniq
month_user_ids = CommitLog.where(created_at: current_month).pluck(:user_id).uniq
@active_user_count = User.where(last_login_on: today).or(User.where(id: day_user_ids)).count
@weekly_active_user_count = User.where(last_login_on: current_week).or(User.where(id: weekly_user_ids)).count
@month_active_user_count = User.where(last_login_on: current_month).or(User.where(id: month_user_ids)).count
@ -22,8 +18,8 @@ class Admins::DashboardsController < Admins::BaseController
# 活跃项目数
day_project_ids = (CommitLog.where(created_at: today).pluck(:project_id).uniq + Issue.where(created_on: today).pluck(:project_id).uniq).uniq
weekly_project_ids = (CommitLog.where(created_at: current_week).where("id>= ?", week_greater_id).distinct.pluck(:project_id) + Issue.where(created_on: current_week).pluck(:project_id).uniq).uniq
month_project_ids = (CommitLog.where(created_at: current_month).where("id>= ?", month_greater_id).distinct.pluck(:project_id) + Issue.where(created_on: current_month).pluck(:project_id).uniq).uniq
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 = 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
@ -73,26 +69,26 @@ class Admins::DashboardsController < Admins::BaseController
@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)
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
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

View File

@ -1,5 +1,4 @@
class Admins::EduSettingsController < Admins::BaseController
before_action :require_admin
before_action :find_setting, only: [:edit,:update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::FaqsController < Admins::BaseController
before_action :require_business
before_action :find_faq, only: [:edit,:update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::FeedbacksController < Admins::BaseController
before_action :require_business
before_action :get_feedback, only: [:new_history, :create_history, :destroy]
def index

View File

@ -1,6 +1,4 @@
class Admins::GlccPrCheckController < Admins::BaseController
before_action :require_glcc_admin
def index
params[:sort_by] = params[:sort_by].presence || 'created_on'
params[:sort_direction] = params[:sort_direction].presence || 'desc'

View File

@ -1,5 +1,4 @@
class Admins::IdentityVerificationsController < Admins::BaseController
before_action :require_business
before_action :finder_identity_verification, except: [:index]
def index
params[:sort_by] = params[:sort_by].presence || 'created_at'

View File

@ -1,5 +1,4 @@
class Admins::IssuesRankController < Admins::BaseController
before_action :require_admin
def index
@statistics = DailyProjectStatistic.where('date >= ? AND date <= ?', begin_date, end_date)

View File

@ -1,5 +1,4 @@
class Admins::LaboratoriesController < Admins::BaseController
before_action :require_admin
def index
default_sort('id', 'desc')

View File

@ -1,5 +1,4 @@
class Admins::MessageTemplatesController < Admins::BaseController
before_action :require_admin
before_action :get_template, only: [:edit, :update, :destroy]
def index
@ -8,12 +7,12 @@ class Admins::MessageTemplatesController < Admins::BaseController
end
def new
@message_template = MessageTemplate::CustomTip.new
@message_template = MessageTemplate.new
end
def create
@message_template = MessageTemplate::CustomTip.new
@message_template.attributes = message_template_params
def create
@message_template = MessageTemplate::CustomTip.new(message_template_params)
@message_template.type = "MessageTemplate::CustomTip"
if @message_template.save!
redirect_to admins_message_templates_path
flash[:success] = "创建消息模板成功"
@ -48,7 +47,9 @@ class Admins::MessageTemplatesController < Admins::BaseController
private
def message_template_params
params.require(@message_template.type.split("::").join("_").underscore.to_sym).permit!
# type = @message_template.present? ? @message_template.type : "MessageTemplate::CustomTip"
# params.require(type.split("::").join("_").underscore.to_sym).permit!
params.require(:message_template_custom_tip).permit!
end
def get_template

View File

@ -1,8 +1,7 @@
class Admins::NpsController < Admins::BaseController
before_action :require_business
def index
@on_off_switch = EduSetting.get("nps-on-off-switch").to_s == 'true'
@user_nps = UserNp.order(created_at: :desc)
@user_nps = UserNp.joins(:user).order(created_at: :desc)
keyword = params[:keyword].to_s.strip.presence
if keyword
sql = 'CONCAT(users.lastname, users.firstname) LIKE :keyword OR users.nickname LIKE :keyword OR users.login LIKE :keyword OR users.mail LIKE :keyword OR users.phone LIKE :keyword'

View File

@ -1,6 +1,5 @@
class Admins::OrganizationsController < Admins::BaseController
before_action :require_admin
before_action :finder_org, except: [:index]
before_action :finder_org, except: [:index]
def index
params[:sort_by] = params[:sort_by].presence || 'created_on'

View File

@ -1,5 +1,4 @@
class Admins::PageThemesController < Admins::BaseController
before_action :require_admin
before_action :finder_page_theme, only: [:edit, :update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::ProjectCategoriesController < Admins::BaseController
before_action :require_admin
before_action :get_category, only: [:edit,:update, :destroy]
before_action :validate_names, only: [:create, :update]

View File

@ -1,5 +1,4 @@
class Admins::ProjectIgnoresController < Admins::BaseController
before_action :require_admin
before_action :set_ignore, only: [:edit,:update, :destroy,:show]
# before_action :validate_params, only: [:create, :update]

View File

@ -1,5 +1,4 @@
class Admins::ProjectLanguagesController < Admins::BaseController
before_action :require_admin
before_action :get_language, only: [:edit,:update, :destroy]
before_action :validate_names, only: [:create, :update]

View File

@ -1,5 +1,4 @@
class Admins::ProjectLicensesController < Admins::BaseController
before_action :require_admin
before_action :set_license, only: [:edit,:update, :destroy,:show]
# before_action :validate_params, only: [:create, :update]
@ -7,7 +6,7 @@ class Admins::ProjectLicensesController < Admins::BaseController
sort_by = License.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at'
sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc'
q = License.ransack(name_cont: params[:search])
project_licenses = q.result(distinct: true).reorder("#{sort_by} #{sort_direction}")
project_licenses = q.result(distinct: true).order("#{sort_by} #{sort_direction}")
@project_licenses = paginate(project_licenses)
end
@ -96,7 +95,7 @@ class Admins::ProjectLicensesController < Admins::BaseController
end
def license_params
params.require(:license).permit(:name,:content,:position)
params.require(:license).permit(:name,:content)
end
# def validate_params

View File

@ -1,22 +1,11 @@
class Admins::ProjectsController < Admins::BaseController
before_action :require_admin
before_action :find_project, only: [:edit, :update]
def index
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("id = ? OR name like ? OR identifier LIKE ?", search, "%#{search}%", "%#{search}%").order("#{sort_by} #{sort_direction}")
case params[:category]
when 'public'
projects = projects.where(is_public: true)
when 'private'
projects = projects.where(is_public: false)
when 'fork'
projects = projects.where.not(forked_from_project_id: nil)
when 'original'
projects = projects.where(forked_from_project_id: nil, project_type: 'common')
end
projects = Project.where("name like ?", "%#{search}%").order("#{sort_by} #{sort_direction}")
@projects = paginate projects.includes(:owner, :members, :issues, :versions, :attachments, :project_score)
end
@ -43,12 +32,8 @@ class Admins::ProjectsController < Admins::BaseController
def destroy
project = Project.find_by!(id: params[:id])
ActiveRecord::Base.transaction do
close_fork_pull_requests_by(project)
Gitea::Repository::DeleteService.new(project.owner, project.identifier, current_user.gitea_token).call
Gitea::Repository::DeleteService.new(project.owner, project.identifier).call
project.destroy!
project.forked_projects.update_all(forked_from_project_id: nil)
# 如果该项目有所属的项目分类以及为私有项目,需要更新对应数量
project.project_category.decrement!(:private_projects_count, 1) if project.project_category.present? && !project.is_public
# render_delete_success
UserAction.create(action_id: project.id, action_type: "DestroyProject", user_id: current_user.id, :ip => request.remote_ip, data_bank: project.attributes.to_json)
redirect_to admins_projects_path
@ -67,19 +52,4 @@ class Admins::ProjectsController < Admins::BaseController
def project_update_params
params.require(:project).permit(:is_pinned, :recommend, :recommend_index)
end
def close_fork_pull_requests_by(project)
open_pull_requests = PullRequest.where(fork_project_id: project.id)
if open_pull_requests.present?
open_pull_requests.each do |pull_request|
closed = PullRequests::CloseService.call(pull_request&.project.owner, pull_request&.project.repository, pull_request, current_user)
if closed === true
pull_request.project_trends.create!(user: current_user, project: pull_request&.project,action_type: ProjectTrend::CLOSE)
# 合并请求下issue处理为关闭
pull_request.issue&.update_attributes!({status_id:5})
SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, pull_request.id) if Site.has_notice_menu?
end
end
end
end
end

View File

@ -1,6 +1,4 @@
class Admins::ProjectsRankController < Admins::BaseController
before_action :require_admin
def index
@statistics = DailyProjectStatistic.where("date >= ? AND date <= ?", begin_date, end_date)
@statistics = @statistics.group(:project_id).select("project_id,
@ -12,7 +10,7 @@ class Admins::ProjectsRankController < Admins::BaseController
sum(issues) as issues,
sum(pullrequests) as pullrequests,
sum(commits) as commits").includes(:project)
@statistics = paginate @statistics.order("#{sort_by} #{sort_direction}")
@statistics = @statistics.order("#{sort_by} #{sort_direction}")
export_excel(@statistics.limit(50))
end

View File

@ -1,5 +1,4 @@
class Admins::ReversedKeywordsController < Admins::BaseController
before_action :require_admin
before_action :get_keyword, only: [:edit,:update, :destroy]
# before_action :validate_identifer, only: [:create, :update]

View File

@ -1,5 +1,4 @@
class Admins::SitePagesController < Admins::BaseController
before_action :require_admin
before_action :finder_site_page, except: [:index]
def index

View File

@ -1,5 +1,4 @@
class Admins::SitesController < Admins::BaseController
before_action :require_admin
before_action :find_site, only: [:edit,:update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::SystemNotificationsController < Admins::BaseController
before_action :require_business
before_action :get_notification, only: [:history, :edit,:update, :destroy]
# before_action :validate_identifer, only: [:create, :update]

View File

@ -1,5 +1,4 @@
class Admins::Topic::ActivityForumsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_activity_forum, only: [:edit, :update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::BannersController < Admins::Topic::BaseController
before_action :require_business
before_action :find_banner, only: [:edit, :update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::CardsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_card, only: [:edit, :update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::CooperatorsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_cooperator, only: [:edit, :update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::ExcellentProjectsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_excellent_project, only: [:edit, :update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::ExperienceForumsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_experience_forum, only: [:edit, :update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::GlccNewsController < Admins::Topic::BaseController
before_action :require_glcc_admin
before_action :find_glcc, only: [:edit, :update, :destroy]
def index

View File

@ -1,5 +1,4 @@
class Admins::Topic::PinnedForumsController < Admins::Topic::BaseController
before_action :require_business
before_action :find_pinned_forum, only: [:edit, :update, :destroy]
def index

View File

@ -1,14 +0,0 @@
class Admins::UserActionsController < Admins::BaseController
before_action :require_admin
def index
@user_actions = UserAction.order(created_at: :desc)
@user_actions = @user_actions.where(action_type: params[:action_type]) if params[:action_type].present?
keyword = params[:keyword].to_s.strip.presence
if keyword
sql = 'login LIKE :keyword OR phone LIKE :keyword OR email LIKE :keyword'
@user_actions = @user_actions.where(sql, keyword: "%#{keyword}%")
end
@user_actions = paginate @user_actions
end
end

View File

@ -1,5 +1,4 @@
class Admins::UsersController < Admins::BaseController
before_action :require_admin
before_action :finder_user, except: [:index]
def index
@ -27,30 +26,10 @@ class Admins::UsersController < Admins::BaseController
def destroy
UserAction.create(action_id: @user.id, action_type: "DestroyUser", user_id: current_user.id, :ip => request.remote_ip, data_bank: @user.attributes.to_json)
# org_ids = TeamUser.where(user_id: @user.id).pluck(:organization_id) | OrganizationUser.where(user_id: @user.id).pluck(:organization_id)
# organizations = Organization.where(id: org_ids)
# organizations.each do |org|
# # org.team_users.joins(:team).where(user_id: @user.id, teams: {authorize: %w(owner)})
# owner_count = org.team_users.joins(:team).where(teams: {authorize: %w(owner)}).count
# # 多个owner时,仅将用户从组织移除, 一个时直接删除
# if owner_count > 1
# org.team_users.joins(:team).where(user_id: @user.id, teams: {authorize: %w(owner)}).destroy_all
# org.organization_users.where(user_id: @user.id, organization_id: org.id).destroy_all
# else
# org.destroy
# end
# end
# @user.destroy!
# Gitea::User::DeleteService.call(@user.login, true)
#
# render_delete_success
@result_object = Api::V1::Users::DeleteUserService.call(@user)
if @result_object
render_delete_success
else
render_js_error('删除失败!')
end
@user.destroy!
Gitea::User::DeleteService.call(@user.login)
render_delete_success
end
def lock
@ -94,6 +73,6 @@ class Admins::UsersController < Admins::BaseController
def update_params
params.require(:user).permit(%i[lastname nickname gender technical_title is_shixun_marker
mail phone location location_city school_id department_id admin
password login website_permission business glcc_admin])
password login website_permission])
end
end

View File

@ -1,5 +1,4 @@
class Admins::UsersRankController < Admins::BaseController
before_action :require_admin
def index
@rank_date = rank_date

View File

@ -1,45 +0,0 @@
class Api::Pm::ActionRunsController < Api::Pm::BaseController
before_action :require_login
def index
tip_exception('请输入workflows') if params[:workflows].blank?
@owner = Owner.find_by(login: params[:owner_id].to_s) || Owner.find_by(id: params[:owner_id].to_s)
tip_exception('组织未找到') if @owner.blank?
action_runs = Gitea::ActionRun.where(owner_id: @owner.gitea_uid)
group_data = action_runs.where(workflow_id: params[:workflows].to_s.split(",")).where(status: [1,2]).group(:workflow_id, :status).count
@result = []
params[:workflows].to_s.split(",").each do |file|
last_action_run = action_runs.where(workflow_id: file).order(updated: :desc).first
last_action_run_json = last_action_run.present? ? {
id: last_action_run.id,
schedule: last_action_run.schedule_id > 0,
title: last_action_run.title,
index: last_action_run.index,
status: last_action_run.status,
started: last_action_run.started,
stopped: last_action_run.stopped,
length: last_action_run.stopped - last_action_run.started,
created: last_action_run.created,
updated: last_action_run.updated,
} : {}
total = 0
success = 0
failure = 0
group_data.each do |k,v|
total += v if k[0] == file
success += v if k[0] == file && k[1] == 1
failure += v if k[0] == file && k[1] == 2
end
@result << {
name: file,
total: total,
success: success,
failure: failure
}.merge(last_action_run_json)
end
render :json => {data: @result}
end
end

View File

@ -1,60 +0,0 @@
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

View File

@ -1,137 +0,0 @@
class Api::Pm::DashboardsController < Api::Pm::BaseController
before_action :require_login
def index
end
def todo
return render_error('请输入正确的pm_project_ids.') if params[:pm_project_ids].blank?
pm_project_ids = params[:pm_project_ids].split(",") rescue []
date = params[:date].present? ? params[:date].to_date : Date.today rescue Date.today
@issues = Issue.where("start_date <= ? and due_date >= ?", date, date)
@issues = @issues.where(pm_project_id: pm_project_ids).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'})
@issues = @issues.where.not(status_id: 5)
@issues = kaminari_paginate(@issues.distinct.pm_includes)
end
def my_issues
return render_error('请输入正确的pm_project_ids.') if params[:pm_project_ids].blank?
return render_error('请输入正确的pm_issue_types.') if params[:pm_issue_types].blank?
pm_project_ids = params[:pm_project_ids].split(",") rescue []
pm_issue_types = params[:pm_issue_types].split(",") rescue []
@all_issues = Issue.where(pm_project_id: pm_project_ids, pm_issue_type: pm_issue_types)
@issues = @all_issues.joins(:issue_participants).where(issue_participants: {participant_id: current_user.id})
@issues = kaminari_paginate(@issues.distinct.pm_includes)
@my_assign_requirements_count = @all_issues.where(pm_issue_type: 1).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size
@my_assign_tasks_count = @all_issues.where(pm_issue_type: 2).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size
@my_assign_bugs_count = @all_issues.where(pm_issue_type: 3).joins(:issue_participants).where(issue_participants: {participant_id: current_user.id, participant_type: 'assigned'}).size
end
def my_pm_projects
return render_error('请输入正确的pm_project_id.') if params[:pm_project_id].blank?
@all_issues = Issue.where(pm_project_id: params[:pm_project_id])
time_now = Time.now
@last_week_create_issues_count = @all_issues.where("created_on > ? and created_on < ?", time_now - 7.days, time_now).size
@before_last_week_create_issue_count = @all_issues.where("created_on > ? and created_on < ?", time_now - 14.days, time_now - 7.days).size
@compare_last_week_create_issues = @before_last_week_create_issue_count.zero? ? 0 :(@last_week_create_issues_count - @before_last_week_create_issue_count).to_f / @before_last_week_create_issue_count rescue 0
@last_week_close_issues_count = @all_issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
@before_last_week_close_issue_count = @all_issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 14.days, time_now - 7.days).size
@compare_last_week_close_issues = @before_last_week_close_issue_count.zero? ? 0 :(@last_week_close_issues_count - @before_last_week_close_issue_count).to_f / @before_last_week_close_issue_count rescue 0
@all_requirement_issues_count = @all_issues.where(pm_issue_type: 1).size
@open_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where.not(status_id: 5).size
@last_week_close_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
@last_month_close_requirement_issues_count = @all_issues.where(pm_issue_type: 1).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size
@all_task_issues_count = @all_issues.where(pm_issue_type: 2).size
@open_task_issues_count = @all_issues.where(pm_issue_type: 2).where.not(status_id: 5).size
@last_week_close_tast_issues_count = @all_issues.where(pm_issue_type: 2).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
@last_month_close_task_issues_count = @all_issues.where(pm_issue_type: 2).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size
@all_bug_issues_count = @all_issues.where(pm_issue_type: 3).size
@open_bug_issues_count = @all_issues.where(pm_issue_type: 3).where.not(status_id: 5).size
@last_week_close_bug_issues_count = @all_issues.where(pm_issue_type: 3).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 7.days, time_now).size
@last_month_close_bug_issues_count = @all_issues.where(pm_issue_type: 3).where(status_id: 5).where("updated_on > ? and updated_on < ?", time_now - 30.days, time_now).size
@requirement_close_trend = [[],[]]
@task_close_trend = [[],[]]
@bug_close_trend = [[],[]]
((time_now-29.days).to_date..time_now.to_date).to_a.each do |i|
@requirement_close_trend[0] << i.strftime("%Y.%m.%d")
@task_close_trend[0] << i.strftime("%Y.%m.%d")
@bug_close_trend[0] << i.strftime("%Y.%m.%d")
@requirement_close_trend[1] << @all_issues.where(pm_issue_type: 1, status_id: 5).where("DATE(updated_on) = ?", i).size
@task_close_trend[1] << @all_issues.where(pm_issue_type: 2, status_id: 5).where("DATE(updated_on) = ?", i).size
@bug_close_trend[1] << @all_issues.where(pm_issue_type: 3, status_id: 5).where("DATE(updated_on) = ?", i).size
end
@close_trend = {requirement: @requirement_close_trend, task: @task_close_trend, bug: @bug_close_trend}
render_ok(data: {
last_week_close_issues_count: @last_week_close_issues_count,
before_last_week_close_issue_count: @before_last_week_close_issue_count,
compare_last_week_close_issues: @compare_last_week_close_issues,
last_week_create_issues_count: @last_week_create_issues_count,
before_last_week_create_issue_count: @before_last_week_create_issue_count,
compare_last_week_create_issues: @compare_last_week_create_issues,
all_requirement_issues_count: @all_requirement_issues_count,
open_requirement_issues_count: @open_requirement_issues_count,
last_week_close_requirement_issues_count: @last_week_close_requirement_issues_count,
last_month_close_requirement_issues_count: @last_month_close_requirement_issues_count,
all_task_issues_count: @all_task_issues_count,
open_task_issues_count: @open_task_issues_count,
last_week_close_task_issues_count: @last_week_close_tast_issues_count,
last_month_close_task_issues_count: @last_month_close_task_issues_count,
all_bug_issues_count: @all_bug_issues_count,
open_bug_issues_count: @open_bug_issues_count,
last_week_close_bug_issues_count: @last_week_close_bug_issues_count,
last_month_close_bug_issues_count: @last_month_close_bug_issues_count,
close_trend: @close_trend
})
end
def my_projects
return render_error('请输入正确的project_id.') if params[:project_id].blank?
@project = Project.find_by_id params[:project_id]
return render_error('请输入正确的project_id.') unless @project.present?
time_now = Time.now
branch_tag_result = $gitea_hat_client.get_repos_branch_tag_count_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue {}
languages_result = $gitea_client.get_repos_languages_by_owner_repo(@project&.owner&.login, @project&.identifier) rescue {}
@open_pull_requests_count = @project.pull_requests.opening.size
@last_week_close_pull_requests_count = @project.pull_requests.where(status: 1).where("updated_at > ? and updated_at < ?", time_now - 7.days, time_now).size
@last_month_close_pull_requets_count = @project.pull_requests.where(status: 1).where("updated_at > ? and updated_at < ?", time_now - 30.days, time_now).size
@commits_count = @project.commit_logs.size
@last_week_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 7.days, time_now).size
@last_month_commits_count = @project.commit_logs.where("created_at > ? and created_at < ?", time_now - 30.days, time_now).size
render_ok(data: {
branch_count: branch_tag_result["branch_count"].to_i,
tag_count: branch_tag_result["tag_count"].to_i,
license_name: @project.license&.name,
open_pull_requests_count: @open_pull_requests_count,
last_week_close_pull_requests_count: @last_week_close_pull_requests_count,
last_month_close_pull_requets_count: @last_month_close_pull_requets_count,
commits_count: @commits_count,
last_week_commits_count: @last_week_commits_count,
last_month_commits_count: @last_month_commits_count,
language: hash_transform_precentagable(languages_result),
})
end
def my_operate_journals
return render_error('请输入正确的pm_project_id.') if params[:pm_project_id].blank?
@journals = Journal.operate_journals.joins(:issue).where(issues: {pm_project_id: params[:pm_project_id], pm_issue_type: [1,2,3]})
@journals = kaminari_paginate(@journals.order(updated_on: :desc))
end
private
def hash_transform_precentagable(hash)
total_byte_size = hash.values.sum
hash.transform_values { |v|
ActionController::Base.helpers
.number_to_percentage((v * 100.0 / total_byte_size), precision: 1)
}.select{|k,v| v != "0.0%"}
end
end

View File

@ -1,46 +0,0 @@
class Api::Pm::IssueLinksController < Api::Pm::BaseController
before_action :load_project
before_action :load_issue
def index
@links = PmLink.where(be_linkable_id: @issue.id,be_linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id,linkable_type: 'Issue'))
end
def create
begin
ActiveRecord::Base.transaction do
params[:link_ids].each do |e|
@issue.pm_links.find_or_create_by!(be_linkable_type: 'Issue', be_linkable_id: e)
tag_issue = Issue.find_by_id(e)
next unless tag_issue.present?
journal = tag_issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", value: @issue.id.to_s})
end
journal = @issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: "tag_link_issue", prop_key: "#{params[:link_ids].size}", value: params[:link_ids].join(",")})
end
render_ok
rescue
render_error('创建失败!')
end
end
def destroy
begin
ActiveRecord::Base.transaction do
@links = PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue', linkable_id: params[:id], linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue', be_linkable_id: params[:id], be_linkable_type: 'Issue'))
journal = @issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", old_value: params[:id].to_s})
another_issue = Issue.find_by_id(params[:id])
if another_issue.present?
journal = another_issue.journals.create!({user_id: current_user.id})
journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", old_value: @issue.id.to_s})
end
@link = @links.last
@link.destroy!
end
render_ok
rescue
render_error('删除失败!')
end
end
end

View File

@ -1,71 +0,0 @@
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

View File

@ -1,368 +0,0 @@
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::Pm::Issues::CreateService.call(@project, issue_params, current_user)
render 'api/v1/issues/create'
end
def update
@object_result = Api::Pm::Issues::UpdateService.call(@project, @issue, issue_params, current_user)
render 'api/v1/issues/update'
end
def batch_update
@object_result = Api::Pm::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::Pm::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::Pm::Issues::DeleteService.call(@project, @issue, current_user)
if @object_result
render_ok
else
render_error('删除疑修失败!')
end
end
def export
return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank?
Axlsx::Package.new do |p|
[['requirement', 1], ['task', 2], ['bug', 3]].each do |type|
p.workbook.add_worksheet(:name => type[0]) do |sheet|
@issues = Issue.where(pm_project_id: params[:pm_project_id], pm_issue_type: type[1])
sheet.add_row ["ID", "标题*", "正文", "创建者*", "创建时间", "修改者", "更新时间", "状态", "负责人", "优先级", "标记", "开始时间","结束时间", "预估工时"]
@issues.each do |issue|
sheet.add_row [issue.id, issue.subject, issue.description, issue.user.try(:login), issue.created_on.strftime("%Y-%m-%d %H:%M:%S"), issue.changer.try(:login), issue.updated_on.strftime("%Y-%m-%d %H:%M:%S"), issue.status_id, issue.assigners.pluck(:login).join(","), issue.priority_id, issue.issue_tags.pluck(:name, :color).join(","), issue.start_date.present? ? issue.start_date.strftime("%Y-%m-%d") : "", issue.due_date.present? ? issue.due_date.strftime("%Y-%m-%d") : "", issue.time_scale]
end
end
end
p.workbook.add_worksheet(:name => 'leaf_relations') do |sheet|
leaf_issues = Issue.where(pm_project_id: params[:pm_project_id]).where.not(root_id: nil)
sheet.add_row ["ID", "父工作项ID"]
leaf_issues.each do |issue|
sheet.add_row [issue.id, issue.root_id]
end
end
p.workbook.add_worksheet(:name => 'link_relations') do |sheet|
# links = PmLink.joins(:linkable_issue).where(issues: {pm_project_id: params[:pm_project_id]})
links = PmLink.find_by_sql("SELECT `pm_links`.* FROM `pm_links` INNER JOIN `issues` ON `issues`.`id` = `pm_links`.`linkable_id` AND `pm_links`.`linkable_type` = 'Issue' WHERE `issues`.`pm_project_id` = #{params[:pm_project_id]}")
sheet.add_row ["ID", "被关联工作项ID"]
links.each do |link|
sheet.add_row [link.linkable_id, link.be_linkable_id]
end
end
p.serialize('public/导出工作项.xlsx')
end
send_file('public/导出工作项.xlsx', :type => 'application/octet-stream;charset=utf-8')
end
def import
begin
return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile)
return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank?
return render_error('请输入正确的组织ID.') if params[:organization_id].blank?
ActiveRecord::Base.transaction do
types = {requirement: 1, task: 2, bug: 3}
doc = SimpleXlsxReader.open(params[:file].tempfile)
doc.sheets.each do |sheet|
case sheet.name
when 'requirement', 'task', 'bug'
type = types["#{sheet.name}".to_sym]
sheet.rows.each.with_index do |row, index|
next if index == 0
issue = Issue.new(issue_classify: "issue", project_id: 0, pm_project_id: params[:pm_project_id], pm_issue_type: type, tracker_id: Tracker.first.id)
issue.fake_id = row[0]
issue.subject = row[1]
issue.description = row[2]
author = User.find_by(login: row[3])
issue.user = author
issue.created_on = row[4]
changer = User.find_by(login: row[5])
issue.changer = changer
issue.updated_on = row[6]
issue.status_id = row[7].to_i
if row[8].present?
row[8].split(',').each do |a|
u = User.find_by(login: a)
next unless u.present?
issue.assigners << u
end
end
issue.priority_id = row[9]
if row[10].present?
row[10].split(',').each_slice(2).to_a.each do |t|
tag = IssueTag.find_by(project_id: 0, organization_id: params[:organization_id], name: t[0])
if tag.present?
issue.issue_tags << tag
else
tag = IssueTag.create(project_id: 0,organization_id: params[:organization_id], name: t[0], color: t[1])
issue.issue_tags << tag
end
end
end
issue.start_date = row[11]
issue.due_date = row[12]
issue.time_scale = row[13]
issue.save!
end
when 'leaf_relations'
sheet.rows.each.with_index do |row, index|
next if index == 0
children_issue = Issue.where(fake_id: row[0]).last
parent_issue = Issue.where(fake_id: row[1]).last
next if children_issue.blank? || parent_issue.blank?
children_issue.root_id = parent_issue.id
children_issue.save(touch: false)
end
when 'link_relations'
sheet.rows.each.with_index do |row, index|
next if index == 0
link_issue = Issue.where(fake_id: row[0]).last
be_link_issue = Issue.where(fake_id: row[1]).last
next if link_issue.blank? || be_link_issue.blank?
PmLink.create!(linkable_type: 'Issue', linkable_id: link_issue.id, be_linkable_type: 'Issue', be_linkable_id: be_link_issue.id)
end
else
return render_error('导入失败请上传正确格式的excel文件')
end
end
end
render_ok
rescue
return render_error('导入失败请上传正确格式的excel文件')
end
end
def link_issues
children_issues = @issue.pm_issue_type == 1 ? @issue.child_count > 0 ? Issue.where(id: @issue.id) : Issue.none : Issue.where(root_id: @issue.id)
linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: @issue.id).pluck(:be_linkable_id))
belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: @issue.id).pluck(:linkable_id))
full_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)
compare_link_issues_ids = children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)
i = compare_link_issues_ids.count
while i > 0 do
children_issues = Issue.where(root_id: compare_link_issues_ids)
linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: compare_link_issues_ids).pluck(:be_linkable_id))
belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: compare_link_issues_ids).pluck(:linkable_id))
compare_link_issues_ids = (children_issues.pluck(:id) | linkable_issues.pluck(:id) | belinkable_issues.pluck(:id)) - full_link_issues_ids
full_link_issues_ids = full_link_issues_ids | compare_link_issues_ids
i = compare_link_issues_ids.count
end
exclude_issues_ids = []
exclude_issues = Issue.where(id: full_link_issues_ids).where.not(root_id: nil)
exclude_issues.each do |i|
exclude_issues_ids << i.id if i.pm_issue_type == 1 && full_link_issues_ids.include?(i.root_id)
end
full_link_issues_ids = full_link_issues_ids - exclude_issues_ids
@requirement_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:1, root_id: nil).pm_includes
@task_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:2).pm_includes
@bug_issues = Issue.where(id:full_link_issues_ids, pm_issue_type:3).pm_includes
end
private
def circle_link_issues(issue_ids)
if issue_ids.present?
children_issues = Issue.joins(:parent_issue).where(issues: {id: issue_ids})
linkable_issues = Issue.where(id: PmLink.where(linkable_type: "Issue", linkable_id: issue_ids))
belinkable_issues = Issue.where(id: PmLink.where(be_linkable_type: "Issue", be_linkable_id: issue_ids))
return circle_link_issues(children_issues.pluck(:id))
else
return []
end
end
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

View File

@ -1,61 +0,0 @@
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/pm/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

View File

@ -1,156 +0,0 @@
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], pm_issue_type:[1, 2, 3])
@last_week_close_issues = @issues.where(status_id: 5).where("updated_on > ? and updated_on < ?", Time.now - 7.days, Time.now)
last_week_close_type_count_data = @last_week_close_issues.group(:pm_issue_type).count
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|
# next if e.id == 5
[1,2,3].map{ |type|
next if type == 1 && [1, 6].include?(e.id)
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 + type_status_data[1][3].to_i + type_status_data[1][6].to_i,
"2": type_status_data[2][1].to_i + type_status_data[2][2].to_i + type_status_data[2][3].to_i + type_status_data[2][6].to_i,
"3": type_status_data[3][1].to_i + type_status_data[3][2].to_i + type_status_data[3][3].to_i + type_status_data[3][6].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
if last_week_close_type_count_data.keys.size < 3
nedd_add = [1,2,3] - last_week_close_type_count_data.keys
nedd_add.map{ |e|
last_week_close_type_count_data[e] = 0
}
end
data = {
pie_chart: type_count_data,
bar_chart: type_status_data,
open_data: open_data,
last_week_close_data: last_week_close_type_count_data,
}
render_ok(data: data)
end
def polyline
return tip_exception '参数错误' if params[:pm_project_id].blank?
time_line = (Time.current.beginning_of_day - 29.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: {}
}
30.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

View File

@ -1,109 +0,0 @@
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 = (total_count.zero? || time_count.zero?) ? 0 : total_count.to_f / time_count.to_f
# 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

View File

@ -55,14 +55,9 @@ 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

View File

@ -1,37 +0,0 @@
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

View File

@ -7,4 +7,12 @@ 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

View File

@ -13,7 +13,12 @@ class Api::V1::Issues::IssueTagsController < Api::V1::BaseController
end
end
def create
def pm_index
@issue_tags = IssueTag.init_mp_issues_tags
render_ok(@issue_tags)
end
def create
@issue_tag = @project.issue_tags.new(issue_tag_params)
if @issue_tag.save!
render_ok

View File

@ -46,7 +46,7 @@ class Api::V1::Issues::JournalsController < Api::V1::BaseController
end
def load_issue
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || @project.issues.issue_issue.find_by_id(params[:index])
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index])
if @issue.blank?
render_not_found("疑修不存在!")
end

View File

@ -8,4 +8,11 @@ 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

View File

@ -70,7 +70,7 @@ class Api::V1::IssuesController < Api::V1::BaseController
private
def load_issue
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || @project.issues.issue_issue.find_by_id(params[:index])
@issue = @project.issues.issue_issue.where(project_issues_index: params[:index]).where.not(id: params[:index]).take || Issue.find_by_id(params[:index])
if @issue.blank?
render_not_found("疑修不存在!")
end

View File

@ -1,36 +0,0 @@
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

View File

@ -1,10 +0,0 @@
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

View File

@ -1,63 +1,5 @@
class Api::V1::Projects::Actions::ActionsController < Api::V1::Projects::Actions::BaseController
def new_index
@files = $gitea_client.get_repos_contents_by_owner_repo_filepath(@project&.owner&.login, @project&.identifier, ".gitea/workflows") rescue []
@workflows = params[:workflows].split(",") if params[:workflows].present?
@action_runs = Gitea::ActionRun.where(repo_id: @project.gpid)
@action_runs = @action_runs.where(id: params[:ids].split(",")) if params[:ids].present?
@action_runs = @action_runs.where(workflow_id: @workflows) if params[:workflows].present?
group_data = @action_runs.where(status: [1,2]).group(:workflow_id, :status).count
@result = []
@files.map{|i|i['name']}.each do |file|
if @workflows.present?
next if !@workflows.include?(file)
end
last_action_run = @action_runs.where(workflow_id: file).order(updated: :desc).first
last_action_run_json = last_action_run.present? ? {
id: last_action_run.id,
schedule: last_action_run.schedule_id > 0,
title: last_action_run.title,
index: last_action_run.index,
status: last_action_run.status,
started: last_action_run.started,
stopped: last_action_run.stopped,
length: last_action_run.stopped-last_action_run.started,
created: last_action_run.created,
updated: last_action_run.updated,
} : {}
total = 0
success = 0
failure = 0
group_data.each do |k,v|
total += v if k[0] == file
success += v if k[0] == file && k[1] == 1
failure += v if k[0] == file && k[1] == 2
end
pipeline_type = 1
begin
content = Gitea::Repository::Entries::GetService.call(@project&.owner, @project&.identifier, URI.escape(file), ref: last_action_run.present? ? last_action_run.ref.gsub("refs/heads/","") : @project.default_branch)['content']
yaml_string = Base64.decode64(content).force_encoding("GBK").encode("UTF-8") unless Base64.decode64(content).force_encoding('UTF-8').valid_encoding?
yaml_string = Base64.decode64(content).force_encoding('UTF-8')
yml = YAML.safe_load(yaml_string)
pipeline_type = yml.name == file.to_s.gsub(".yml","").gsub(".yaml","") ? 2 : 1
rescue
Rails.logger.info("#{file}不能识别流水线类型")
end
@result << {
filename: file,
name: file.to_s.gsub(".yml","").gsub(".yaml","") ,
branch: last_action_run.present? ? last_action_run.ref.gsub("refs/heads/","") : @project.default_branch,
pipeline_type: pipeline_type,
total: total,
success: success,
failure: failure
}.merge(last_action_run_json)
end
render :json => {data: @result}
end
def index
begin
gitea_result = $gitea_hat_client.get_repos_actions_by_owner_repo(@project&.owner&.login, @project&.identifier)

View File

@ -1,58 +1,12 @@
class Api::V1::Projects::Actions::RunsController < Api::V1::Projects::Actions::BaseController
def index
def index
@result_object = Api::V1::Projects::Actions::Runs::ListService.call(@project, {workflow: params[:workflow], page: page, limit: limit}, current_user&.gitea_token)
@begin_num = (page.to_i - 1) * limit.to_i
# puts @result_object
end
def create
return render_error("请输入正确的流水线文件!") if params[:workflow].blank?
return render_error("请输入正确的分支!") if params[:ref].blank?
gitea_result = $gitea_hat_client.post_repos_actions_runs_by_owner_repo(@project&.owner&.login, @project&.identifier, {query: {workflow: params[:workflow], ref: params[:ref]}})
if gitea_result
render_ok
else
ender_error("启动流水线任务失败")
end
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
puts @result_object
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

View File

@ -1,29 +1,6 @@
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], state: params[:state], page: page, limit: limit}, current_user&.gitea_token)
end

View File

@ -1,5 +1,5 @@
class Api::V1::Projects::CommitsController < Api::V1::BaseController
before_action :require_public_and_member_above, only: [:index, :diff, :recent, :files]
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)
@ -10,18 +10,7 @@ class Api::V1::Projects::CommitsController < Api::V1::BaseController
@result_object = Api::V1::Projects::Commits::DiffService.call(@project, params[:sha], current_user&.gitea_token)
end
def files
if params[:filepath].present?
@result_object = $gitea_hat_client.get_repos_commits_files_by_owner_repo_sha_filepath(@project&.owner.login, @project&.identifier, params[:sha], CGI.escape(params[:filepath]), {query: {token: current_user&.gitea_token}})
else
@result_object = $gitea_hat_client.get_repos_commits_files_by_owner_repo_sha(@project&.owner.login, @project&.identifier, params[:sha], {query: {token: current_user&.gitea_token, page: page, limit: limit}})
end
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
@result_object = Api::V1::Projects::Commits::RecentService.call(@project, {keyword: params[:keyword], page: page, limit: limit}, current_user&.gitea_token)
end
end

View File

@ -1,58 +0,0 @@
class Api::V1::Projects::CompareController < Api::V1::BaseController
before_action :require_public_and_member_above, only: [:files]
def files
load_compare_params
if params[:type] == "sha"
@compare_result ||= gitea_compare_files(@base, @head)
else
@compare_result ||= @head.include?(":") ? gitea_compare_files(@base, @head) : gitea_compare_files(@head, @base)
@merge_status, @merge_message = get_merge_message
end
end
private
def load_compare_params
@base = params[:base].include?(":") ? Addressable::URI.unescape(params[:base].split(":")[0]) + ':' + Base64.decode64(params[:base].split(":")[1]) : Base64.decode64(params[:base])
@head = params[:head].include?(":") ? Addressable::URI.unescape(params[:head].split(":")[0]) + ':' + Base64.decode64(params[:head].split(":")[1]) : Base64.decode64(params[:head])
end
def gitea_compare_files(base, head)
if params[:filepath].present?
$gitea_hat_client.get_repos_compare_by_owner_repo_baseref_headref(@project&.owner&.login, @project.identifier, Addressable::URI.escape(base), Addressable::URI.escape(head), {query: {token: current_user&.gitea_token, isFiles: true, filepath: params[:filepath]}})
else
$gitea_hat_client.get_repos_compare_by_owner_repo_baseref_headref(@project&.owner&.login, @project.identifier, Addressable::URI.escape(base), Addressable::URI.escape(head), {query: {page:page,limit:limit,token: current_user&.gitea_token, isFiles: true}})
end
end
def get_merge_message
if @base.blank? || @head.blank?
return -2, "请选择分支"
else
return -2, "目标仓库未开启合并请求PR功能" unless @project.has_menu_permission("pulls")
if @head.include?(":")
fork_project = @project.forked_projects.joins(:owner).where(users: {login: @head.to_s.split("/")[0]}).take
return -2, "请选择正确的仓库" unless fork_project.present?
@exist_pullrequest = @project.pull_requests.where(is_original: true, head: @head.to_s.split(":")[1], base: @base, status: 0, fork_project_id: fork_project.id).take
else
@exist_pullrequest = @project.pull_requests.where(is_original: false, head: @base, base: @head, status: 0).take
end
if @exist_pullrequest.present?
return -2, "在这些分支之间的合并请求已存在:<a href='/#{@owner.login}/#{@project.identifier}/pulls/#{@exist_pullrequest.id}'>#{@exist_pullrequest.try(:title)}</a>"
else
Rails.logger.info @compare_result
if params[:filepath].present?
if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
return -2, "分支内容相同,无需创建合并请求"
end
else
if @compare_result[:total_data].to_i < 1
return -2, "分支内容相同,无需创建合并请求"
end
end
end
end
return 0, "可以合并"
end
end

View File

@ -1,51 +0,0 @@
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

View File

@ -1,31 +0,0 @@
class Api::V1::Projects::OssHealthMeasuringController < Api::V1::BaseController
def index
url = URI("#{EduSetting.get("ohm_server_url")}/api/OSS_Health_Measuring/#{params[:owner]}/#{params[:repo]}")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
response = http.request(request)
render :json=> response.read_body
end
def keyid
url = URI("#{EduSetting.get("ohm_server_url")}/api/OSS_Health_Measuring/#{params[:owner]}/#{params[:repo]}/#{params[:key_id]}")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
response = http.request(request)
render :json=> response.read_body
end
def can_get
url = URI("#{EduSetting.get("ohm_server_url")}/api/OHM_can_get/#{params[:owner]}/#{params[:repo]}")
http = Net::HTTP.new(url.host, url.port);
request = Net::HTTP::Get.new(url)
response = http.request(request)
render :json=> response.read_body
end
end

File diff suppressed because it is too large Load Diff

View File

@ -1,52 +0,0 @@
class Api::V1::Projects::PortraitController < Api::V1::BaseController
before_action :require_public_and_member_above
def index
platform_statistic = $redis_cache.hgetall("v2-platform-statistic")
# 社区影响力
praise_count = PraiseTread.where(praise_tread_object_type: "Project", praise_tread_object_id: @project.id).count
watcher_count = Watcher.where(watchable_type:"Project", watchable_id: @project.id).count
fork_count = ForkUser.where(project_id: @project.id).count
community_impact_praise = platform_statistic['max-praise-count'].to_i == 0 ? 0 : 30*(praise_count.to_f/platform_statistic['max-praise-count'].to_i)
community_impact_watcher = platform_statistic['max-watcher-count'].to_i == 0 ? 0 : 30*(watcher_count.to_f/platform_statistic['max-watcher-count'].to_i)
community_impact_fork = platform_statistic['max-fork-count'].to_i == 0 ? 0 : 40*(fork_count.to_f/platform_statistic['max-fork-count'].to_i)
community_impact = format("%.2f", community_impact_praise + community_impact_watcher + community_impact_fork)
# 项目成熟度
pullrequest_count = PullRequest.where(project_id: @project.id).count
issue_count = Issue.issue_issue.where(project_id: @project.id).count
commit_count = CommitLog.joins(:project).merge(Project.common).where(project_id: @project.id).count
project_maturity_pullrequest = platform_statistic['max-pullrequest-count'].to_i == 0 ? 0 : 30*(pullrequest_count.to_f/platform_statistic['max-pullrequest-count'].to_i)
project_maturity_issue = platform_statistic['max-issue-count'].to_i == 0 ? 0 : 30*(issue_count.to_f/platform_statistic['max-issue-count'].to_i)
project_maturity_commit = platform_statistic['max-commit-count'].to_i == 0 ? 0 : 40*(commit_count.to_f/platform_statistic['max-commit-count'].to_i)
project_maturity = format("%.2f", project_maturity_pullrequest + project_maturity_issue + project_maturity_commit)
# 项目健康度
closed_pullrequest_count = PullRequest.where(project_id: @project.id).merged_and_closed.count
closed_issue_count = Issue.issue_issue.where(project_id: @project.id).closed.count
has_license = @project.license.present? ? 1 : 0
project_health_issue = (issue_count < 10 || closed_issue_count < 10) ? 0 : 40*(closed_issue_count-10).to_f/(issue_count-10)
project_health_pullrequest = (pullrequest_count < 5 || closed_pullrequest_count < 5) ? 0 : 30*(closed_pullrequest_count-5).to_f/(pullrequest_count-5)
project_health_license = 20*has_license
project_health = format("%.2f", project_health_issue + project_health_pullrequest + project_health_license)
# 团队影响度
member_count = Member.where(project_id: @project.id).count
recent_one_month_member_count = Member.where(project_id:@project.id).where("created_on > ?", Time.now - 30.days).count
team_impact_member = platform_statistic['max-member-count'].to_i == 0 ? 0 : 40*(member_count.to_f/platform_statistic['max-member-count'].to_i)
team_impact_recent_member = platform_statistic['max-recent-one-month-member-count'].to_i == 0 ? 0 : 60*(recent_one_month_member_count.to_f/platform_statistic['max-recent-one-month-member-count'].to_i)
team_impact = format("%.2f", team_impact_member + team_impact_recent_member)
# 开发活跃度
recent_one_month_pullrequest_count = PullRequest.where(project_id: @project.id).where("created_at > ?", Time.now - 30.days).count
recent_one_month_issue_count = Issue.issue_issue.where(project_id: @project.id).where("created_on > ?", Time.now - 30.days).count
recent_one_month_commit_count = CommitLog.joins(:project).merge(Project.common).where(project_id: @project.id).where("created_at > ?", Time.now - 30.days).count
develop_activity_pullrequest = platform_statistic['max-recent-one-month-pullrequest-count'].to_i == 0 ? 0 : 20*(recent_one_month_pullrequest_count.to_f/platform_statistic['max-recent-one-month-pullrequest-count'].to_i)
develop_activity_issue = platform_statistic['max-recent-one-month-issue-count'].to_i == 0 ? 0 : 20*(recent_one_month_issue_count.to_f/platform_statistic['max-recent-one-month-issue-count'].to_i)
develop_activity_commit = platform_statistic['max-recent-one-month-commit-count'].to_i == 0 ? 0 : 40*(recent_one_month_commit_count.to_f/platform_statistic['max-recent-one-month-commit-count'].to_i)
develop_activity = format("%.2f", 20 + develop_activity_pullrequest + develop_activity_issue + develop_activity_commit)
render :json => {community_impact: community_impact, project_maturity: project_maturity, project_health: project_health, team_impact: team_impact, develop_activity: develop_activity}
end
end

View File

@ -6,21 +6,13 @@ class Api::V1::Projects::Pulls::PullsController < Api::V1::BaseController
@pulls = kaminari_paginate(@pulls)
end
before_action :load_pull_request, only: [:show, :files]
before_action :load_pull_request, only: [:show]
def show
@result_object = Api::V1::Projects::Pulls::GetService.call(@project, @pull_request, current_user&.gitea_token)
@last_review = @pull_request.reviews.order(created_at: :desc).take
end
def files
if params[:filepath].present?
@result_object = $gitea_hat_client.get_repos_pulls_files_by_owner_repo_index_filepath(@project&.owner.login, @project&.identifier, @pull_request.gitea_number, CGI.escape(params[:filepath]), {query: {token: current_user&.gitea_token}})
else
@result_object = $gitea_hat_client.get_repos_pulls_files_by_owner_repo_index(@project&.owner.login, @project&.identifier, @pull_request.gitea_number, {query: {isNew: "true",token: current_user&.gitea_token, page: page, limit: limit}})
end
end
private
def query_params
params.permit(:status, :keyword, :priority_id, :issue_tag_id, :version_id, :reviewer_id, :sort_by, :sort_direction)

View File

@ -1,148 +0,0 @@
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

View File

@ -1,5 +1,5 @@
class Api::V1::ProjectsController < Api::V1::BaseController
before_action :require_public_and_member_above, only: [:show, :compare, :blame, :sonar_search]
before_action :require_public_and_member_above, only: [:show, :compare, :blame]
def index
render_ok
@ -9,7 +9,6 @@ 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

View File

@ -1,171 +0,0 @@
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
@project.update(gitea_params)
render_ok
end
def insert_file
checkout_url = 'https://gitlink.org.cn/KingChan/checkout@v4'
scanner_url = 'https://gitlink.org.cn/KingChan/sonarqube-scan-action@master'
begin
config = Rails.application.config_for(:configuration)
sonarqube_config = config.dig('sonarqube')
if sonarqube_config.present? && sonarqube_config['checkout'].present?
checkout_url = sonarqube_config['checkout']
end
if sonarqube_config.present? && sonarqube_config['scanner'].present?
scanner_url = sonarqube_config['scanner']
end
raise 'sonar config missing' if sonarqube_config.blank?
rescue => ex
raise ex if Rails.env.production?
puts %Q{\033[33m [warning] soanrqube config or configuration.yml missing,
please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m}
end
sonar_scanner_content = {
filepath: '.gitea/workflows/SonarScanner.yaml',
branch: params[:branch],
new_branch: nil,
content: "
on:
# Trigger analysis when pushing to your main branches, and when creating a pull request.
push:
branches:
- main
- master
- develop
- 'releases/**'
pull_request:
types: [opened, synchronize, reopened]
name: Main Workflow
jobs:
sonarqube:
runs-on: ubuntu-latest
steps:
- uses: #{checkout_url}
with:
# Disabling shallow clones is recommended for improving the relevancy of reporting
fetch-depth: 0
- name: SonarQube Scan
uses: #{scanner_url}
env:
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
SONAR_HOST_URL: ${{ secrets.SONAR_HOST_URL }}
",
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?
Gitea::UpdateFileInteractor.call(@owner.gitea_token, @owner.login, sonar_scanner_content.merge(sha:sonar_scanner_exit.result['sha']))
else
sonar_scanner_content[:content] = Base64.strict_encode64(sonar_scanner_content[:content])
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]}-#{@project.id}\nsonar.sources=.\nsonar.java.binaries=.",
"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[:owner]}-#{@project.id}",
s: params[:s],
impactSoftwareQualities: params[:impactSoftwareQualities],
issueStatuses: params[:issueStatuses],
ps: params[:ps],
p: params[:p],
facets: params[:facets],
additionalFields: params[:additionalFields],
timeZone: params[:timeZone],
types: params[:types],
impactSeverities: params[:impactSeverities],
tags: params[:tags]
}
data = Sonarqube.client.get('/api/issues/search', query: params_data)
render_ok data
end
def ce_component
params_data = {
components: "#{params[:owner]}-#{@project.id}",
}
data = Sonarqube.client.get('/api/ce/component', query: params_data)
render_ok data
end
def sources_issue_snippet
params_data = {
issueKey: params[:issueKey]
}
data = Sonarqube.client.get('/api/sources/issue_snippets', query: params_data)
render_ok data
end
def rules_show
params_data = {
key: params[:key]
}
data = Sonarqube.client.get('/api/rules/show', query: params_data)
render_ok data
end
def measures_search_history
params_data = {
from: params[:form],
component: "#{params[:owner]}-#{@project.id}",
metrics: params[:metrics],
ps: params[:ps]
}
data = Sonarqube.client.get('/api/measures/search_history', query: params_data)
render_ok data
end
def measures_component
params_data = {
component: "#{params[:owner]}-#{@project.id}",
additionalFields: params[:additionalFields],
metricKeys: params[:metricKeys]
}
data = Sonarqube.client.get('/api/measures/component', query: params_data)
render_ok data
end
end

View File

@ -1,23 +0,0 @@
class Api::V1::Users::HomeTopSettingsController < Api::V1::BaseController
before_action :load_observe_user
before_action :check_auth_for_observe_user
def create
@result = Api::V1::Users::HomeTopSettings::CreateService.call(@observe_user, home_top_setting_params)
return render_error("置顶失败.") if @result.nil?
return render_ok
end
def cancel
@result = Api::V1::Users::HomeTopSettings::DeleteService.call(@observe_user, home_top_setting_params)
return render_error("取消置顶失败.") if @result.nil?
return render_ok
end
private
def home_top_setting_params
params.permit(:top_type, :top_id)
end
end

View File

@ -8,6 +8,6 @@ class Api::V1::Users::ProjectsController < Api::V1::BaseController
private
def query_params
params.permit(:category, :is_public, :project_type, :sort_by, :sort_direction, :search, :start_at, :end_at)
params.permit(:category, :is_public, :project_type, :sort_by, :sort_direction, :search)
end
end

View File

@ -1,5 +1,4 @@
class Api::V1::UsersController < Api::V1::BaseController
include AesCryptHelper
before_action :load_observe_user, except: [:check_user_id, :check_user_login]
before_action :check_auth_for_observe_user, except: [:check_user_id, :check_user_login]
@ -54,7 +53,7 @@ class Api::V1::UsersController < Api::V1::BaseController
end
def check_password
password = decrypt(params[:password]) rescue ""
password = params[:password]
return tip_exception(-5, "8~16位密码支持字母数字和符号") unless password =~ CustomRegexp::PASSWORD
return tip_exception(-5, "密码错误") unless @observe_user.check_password?(password)
render_ok
@ -116,29 +115,4 @@ class Api::V1::UsersController < Api::V1::BaseController
return render_error('更改手机号失败!')
end
end
def check_user_can_delete
org_ids = TeamUser.where(user_id: @observe_user.id).pluck(:organization_id) | OrganizationUser.where(user_id: @observe_user.id).pluck(:organization_id)
org_count = TeamUser.where(organization_id: org_ids).where(user_id: @observe_user.id).joins(:team).where(teams: {authorize: %w(owner)}).count
project_count = Project.where(user_id: @observe_user.id).count
render_ok({ can_delete: org_count == 0 && project_count == 0, org_count: org_count, project_count: project_count })
end
def destroy
password = decrypt(params[:password]) rescue ""
return tip_exception(-1, "密码不正确.") unless @observe_user.check_password?(password)
org_ids = TeamUser.where(user_id: @observe_user.id).pluck(:organization_id) | OrganizationUser.where(user_id: @observe_user.id).pluck(:organization_id)
org_count = TeamUser.where(organization_id: org_ids).where(user_id: @observe_user.id).joins(:team).where(teams: {authorize: %w(owner)}).count
project_count = Project.where(user_id: @observe_user.id).count
return tip_exception(-1, "当前账号名下存在拥有的组织/代码库,请先删除或转让后再尝试注销操作.") if org_count > 0 || project_count > 0
UserAction.create(action_id: @observe_user.id, action_type: "DestroyUser", user_id: @observe_user.id, :ip => request.remote_ip, data_bank: @observe_user.attributes.to_json, memo: params[:memo])
@result_object = Api::V1::Users::DeleteUserService.call(@observe_user)
if @result_object
return render_ok
else
return render_error('删除失败!')
end
end
end

View File

@ -75,11 +75,7 @@ class ApplicationController < ActionController::Base
def admin_or_business?
User.current.admin? || User.current.business?
end
def admin_or_glcc_admin?
User.current.admin? || User.current.glcc_admin?
User.current.admin? || User.current.business?
end
# 判断用户的邮箱或者手机是否可用
@ -199,10 +195,6 @@ class ApplicationController < ActionController::Base
normal_status(403, "") unless admin_or_business?
end
def require_glcc_admin
normal_status(403, "") unless admin_or_glcc_admin?
end
# 前端会捕捉401,弹登录弹框
# 未授权的捕捉407弹试用申请弹框
def require_login
@ -210,10 +202,6 @@ class ApplicationController < ActionController::Base
tip_exception(401, "请登录后再操作") unless User.current.logged?
end
def require_referer
tip_exception(403, "你没有权限访问") if request.host.present? && !request.referer.to_s.include?(request.host.to_s.gsub("www.",""))
end
def require_login_or_token
if params[:token].present?
user = User.try_to_autologin(params[:token])
@ -330,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
@ -375,14 +363,15 @@ 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}"]
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) if autologin_user.present?
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])
end
autologin_user
end
def try_to_autologin

View File

@ -30,33 +30,25 @@ class AttachmentsController < ApplicationController
def get_file
Rails.logger.info("request.host===#{request.host},request.referer===#{request.referer}")
tip_exception(403, "你没有权限访问") if request.host.present? && !request.referer.to_s.include?(request.host.to_s.gsub("www.",""))
normal_status(-1, "参数缺失") if params[:download_url].blank?
url = base_url.starts_with?("https:") ? params[:download_url].to_s.gsub("http:", "https:") : params[:download_url].to_s
md5_file = Digest::MD5.hexdigest(params[:download_url])
FileUtils.mkdir_p("#{Rails.root}#{EduSetting.get("attachment_folder")}gitea/") unless Dir.exists?("#{Rails.root}#{EduSetting.get("attachment_folder")}gitea/")
tmp_path = "#{Rails.root}#{EduSetting.get("attachment_folder")}gitea/#{Time.now.strftime('%Y%m%d')}-#{md5_file}"
if url.starts_with?(base_url) && !url.starts_with?("#{base_url}/repo")
domain = GiteaService.gitea_config[:domain]
api_url = GiteaService.gitea_config[:base_url]
url = ("/repos"+url.split(base_url + "/api")[1])
filepath, ref = url.split("/")[-1].split("?")
url.gsub!(url.split("/")[-1], '')
# Rails.logger.info("url===#{url}")
Rails.logger.info("url===#{url}")
Rails.logger.info(filepath)
ref = ref.blank? ? "" : URI.escape(ref.split('ref=')[1])
request_url = [domain, api_url, URI.encode(url), URI.escape(filepath), "?ref=#{ref}&access_token=#{User.where(admin: true).take&.gitea_token}"].join
request_url = [domain, api_url, URI.encode(url), URI.escape(filepath), "?ref=#{URI.escape(ref.split('ref=')[1])}&access_token=#{User.where(admin: true).take&.gitea_token}"].join
Rails.logger.info("request_url===#{request_url}")
File.delete(tmp_path) if File.exist?(tmp_path) # 删除之前的文件
Util.download_file(request_url, tmp_path)
response = Faraday.get(request_url)
filename = filepath
else
File.delete(tmp_path) if File.exist?(tmp_path) # 删除之前的文件
Util.download_file(URI.encode(url), tmp_path)
response = Faraday.get(URI.encode(url))
filename = params[:download_url].to_s.split("/").pop()
end
send_file(tmp_path, filename: filename, type: "application/octet-stream", disposition: 'attachment')
send_data(response.body.force_encoding("UTF-8"), filename: filename, type: "application/octet-stream", disposition: 'attachment')
end
def create
@ -103,9 +95,6 @@ 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}"
@ -135,7 +124,7 @@ class AttachmentsController < ApplicationController
# 附件为视频时,点击播放
def preview_attachment
attachment = Attachment.where_id_or_uuid(params[:id]).first
attachment = Attachment.find_by(id: params[:id])
dir_path = "#{Rails.root}/public/preview"
Dir.mkdir(dir_path) unless Dir.exist?(dir_path)
if params[:status] == "preview"

View File

@ -19,23 +19,12 @@ class CommitLogsController < ApplicationController
params[:commits].each do |commit|
commit_id = commit[:id]
message = commit[:message]
commit_date = Time.parse(commit[:timestamp]) || Time.now
commit_log = CommitLog.create(user: user, project: project, repository_id: repository_id,
name: repository_name, full_name: repository_full_name,
ref: ref, commit_id: commit_id, message: message, created_at: commit_date, updated_at: commit_date)
ref: ref, commit_id: commit_id, message: message)
commit_log.project_trends.create(user_id: user.id, project_id: project&.id, action_type: "create") if user.id !=2
# 统计数据新增
CacheAsyncSetJob.perform_later("project_common_service", {commits: 1}, project.id)
commit_user = User.find_by(mail: commit[:committer][:email]) rescue nil
commit_user = User.find_by(login: commit[:committer][:name]) if commit_user.blank? rescue nil
next if commit_user.blank?
# 触发变更issue状态的job
close_issue_content = message.to_s.scan(/\b(Close|Closes|Closed|Closing|close|closes|closed|closing)\s*(#\d+(,\s*#\d+)*)?\b/)
ChangeIssueStatusByMessageJob.perform_later(commit_id, project, commit_user, close_issue_content[0][1], 5) if close_issue_content[0].present? && close_issue_content[0][1].present?
solve_issue_content = message.to_s.scan(/\b(Fix|Fixes|Fixed|Fixing|fix|fixes|fixed|fixing|Resolve|Resolves|Resolved|Resolving|resolve|resolves|resolved|resolving|Implement|Implements|Implemented|Implementing|implement|implements|implemented|implementing)\s*(#\d+(,\s*#\d+)*)?\b/)
ChangeIssueStatusByMessageJob.perform_later(commit_id, project, commit_user, solve_issue_content[0][1], 3) if solve_issue_content[0].present? && solve_issue_content[0][1].present?
end
end

View File

@ -18,7 +18,6 @@ class CompareController < ApplicationController
@page_limit = page_limit <=0 ? 15 : page_limit
@page_offset = (@page_size -1) * @page_limit
Rails.logger.info("+========#{@page_size}-#{@page_limit}-#{@page_offset}")
Rails.logger.info @compare_result
end
private
@ -37,7 +36,7 @@ class CompareController < ApplicationController
if @exist_pullrequest.present?
return -2, "在这些分支之间的合并请求已存在:<a href='/#{@owner.login}/#{@project.identifier}/pulls/#{@exist_pullrequest.id}'>#{@exist_pullrequest.try(:title)}</a>"
else
if @compare_result["FilesCount"].to_i == 0 && @compare_result["CommitsCount"].to_i == 0
if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
return -2, "分支内容相同,无需创建合并请求"
end
end

View File

@ -3,7 +3,7 @@ module Api::PullHelper
def load_pull_request
pull_request_id = params[:pull_id] || params[:id]
@pull_request = @project.pull_requests.where(gitea_number: pull_request_id).where.not(id: pull_request_id).take || @project.pull_requests.find_by_id(pull_request_id)
@pull_request = @project.pull_requests.where(gitea_number: pull_request_id).where.not(id: pull_request_id).take || PullRequest.find_by_id(pull_request_id)
@issue = @pull_request&.issue
if @pull_request
logger.info "###########pull_request founded"

View File

@ -77,12 +77,4 @@ module GitHelper
cha_path = path.present? ? path.split("") : []
cha_path.reject(&:blank?)[0].try(:strip)
end
def expain_issue_commit(commit_message)
respace_arr= commit_message.to_s.scan(/#(\d+)/).map{|s|[s[0], "##{s[0]}"]}.uniq.sort_by{|s|-s[0].to_i}
respace_arr.each do |item|
issue = Issue.find_by_id(item[0].to_i)
end
end
end

View File

@ -73,17 +73,6 @@ module LoginHelper
session[:"#{default_yun_session}"] = nil
end
def clear_user_cookie
if edu_setting('cookie_domain').present?
cookies.delete(autologin_cookie_name, domain: edu_setting('cookie_domain'))
else
cookies.delete(autologin_cookie_name)
end
# 清除前端写入的用户名
Rails.logger.info("########________cookies['login']___________###########{cookies['login']}")
cookies.delete("login")
end
# Sets the logged in user
def logged_user=(user)
reset_session

View File

@ -21,7 +21,6 @@ class MainController < ApplicationController
end
def index
Rails.logger.info("request.referer============#{request.referer},#{params[:path]}") if request.referer.to_s.include?("educoder.net")
domain_session = params[:_educoder_session]
if domain_session
uid_logger("main start domain_session is #{domain_session}")

View File

@ -50,7 +50,7 @@ class MarkFilesController < ApplicationController
end
def load_pull_request
@pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || @project.pull_requests.find_by_id(params[:id])
@pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || PullRequest.find_by_id(params[:id])
end
end

View File

@ -1,18 +1,6 @@
class Oauth::AcgeController < Oauth::BaseController
include RegisterHelper
def refer
uid = params['uid'].to_s.strip
tip_exception("uid不能为空") if uid.blank?
open_user = OpenUsers::Acge.find_by(uid: uid)
if open_user.present? && open_user.user.present?
render :json => {login: open_user.user.login}
else
render_not_found
end
end
def create
begin
uid = params['uid'].to_s.strip
@ -42,7 +30,7 @@ class Oauth::AcgeController < Oauth::BaseController
return
else
username = uid
username = uid[0..7]
password = SecureRandom.hex(4)
reg_result = autologin_register(username, email, password, 'acge', phone, name)
existing_rows = CSV.read("public/操作系统大赛用户信息.csv")

Some files were not shown because too many files have changed in this diff Show More