forked from Gitlink/forgeplus
Compare commits
67 Commits
master
...
dev_hh_ver
Author | SHA1 | Date |
---|---|---|
|
36bae71947 | |
|
c283c7ed58 | |
|
4cf8588343 | |
|
e75fad98f8 | |
|
bc37c59f00 | |
|
a6a745da93 | |
|
5bef80ee58 | |
|
f9bcc7e02b | |
|
d35faf3935 | |
|
8d7dc9cb60 | |
|
248d78d8c1 | |
|
f632424f13 | |
|
95ede63220 | |
|
8fac294d04 | |
|
d67c12beba | |
|
a7e4b85352 | |
![]() |
2ac2920399 | |
![]() |
230b934de4 | |
|
e0bedf175f | |
|
c9a263e03c | |
![]() |
2bd15d9746 | |
|
fc9588fb63 | |
|
e611b519ab | |
|
3dd3944ebd | |
|
f417bf3308 | |
|
9c7c914d12 | |
|
b088befae7 | |
|
d3636e686b | |
|
88d98f0ac4 | |
|
db6aa954b1 | |
|
04a611a4aa | |
|
9ecea83506 | |
|
82a9907fdc | |
|
c56c98fd6e | |
|
2948ad2033 | |
|
fc611140cf | |
|
fcb5f58b69 | |
|
0f38a130f3 | |
|
fc54632a08 | |
|
5963af5c7b | |
|
c1f2f7f6e2 | |
|
271699daf1 | |
|
98da7ea34d | |
|
645e4a3586 | |
|
7beca24a05 | |
|
d1368c7612 | |
|
28e762810e | |
|
0f60d0adc9 | |
|
e634317675 | |
|
6b1a0a96c6 | |
|
298859bd10 | |
|
d4d412ab40 | |
|
57d1a1474e | |
|
055b7dbac5 | |
|
30aad87e5a | |
|
aecd68fe9a | |
|
998a6828d9 | |
|
12c04d02e5 | |
|
d6ef3d8aa3 | |
|
c7a89d1660 | |
|
1939c0d33f | |
![]() |
561b9efd92 | |
![]() |
6c0b87fdd1 | |
![]() |
5d309d1dc4 | |
![]() |
89c230c362 | |
![]() |
d4156a5582 | |
![]() |
ee8cbb8553 |
|
@ -245,7 +245,7 @@ class AccountsController < ApplicationController
|
|||
end
|
||||
|
||||
def set_autologin_cookie(user)
|
||||
token = Token.get_or_create_permanent_login_token(user, "autologin")
|
||||
token = Token.get_or_create_permanent_login_token(user, autologin_cookie_name)
|
||||
cookie_options = {
|
||||
:value => token.value,
|
||||
:expires => 1.month.from_now,
|
||||
|
|
|
@ -373,7 +373,7 @@ class ApplicationController < ActionController::Base
|
|||
# auto-login feature starts a new session
|
||||
user = nil
|
||||
Rails.logger.info("111111111111111111#{default_yun_session}, session is #{session[:"#{default_yun_session}"]} ")
|
||||
user = User.try_to_autologin(cookies[autologin_cookie_name])
|
||||
user = User.try_to_autologin(cookies[autologin_cookie_name], autologin_cookie_name)
|
||||
# start_user_session(user) if user # TODO 解决sso退出不同步的问题
|
||||
user
|
||||
end
|
||||
|
@ -385,7 +385,7 @@ class ApplicationController < ActionController::Base
|
|||
|
||||
def current_user
|
||||
if Rails.env.development?
|
||||
User.current = User.find 36480
|
||||
User.current = User.find 1
|
||||
else
|
||||
User.current
|
||||
end
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
class ApplySignaturesController < ApplicationController
|
||||
def create
|
||||
ActiveRecord::Base.transaction do
|
||||
begin
|
||||
@signature = current_user.apply_signatures.create!(project_id: params[:project_id])
|
||||
@attachment = Attachment.find_by_id(params[:attachment_id])
|
||||
@attachment.container = @signature
|
||||
@attachment.save!
|
||||
rescue Exception => e
|
||||
tip_exception("#{e}")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
render_json
|
||||
end
|
||||
end
|
||||
end
|
|
@ -33,6 +33,7 @@ class AttachmentsController < ApplicationController
|
|||
# 2. 上传到云
|
||||
begin
|
||||
upload_file = params["file"] || params["#{params[:file_param_name]}"]# 这里的file_param_name是为了方便其他插件名称
|
||||
dun_check_file = upload_file.dup
|
||||
uid_logger("#########################file_params####{params["#{params[:file_param_name]}"]}")
|
||||
raise "未上传文件" unless upload_file
|
||||
|
||||
|
@ -70,8 +71,16 @@ class AttachmentsController < ApplicationController
|
|||
@attachment.digest = digest
|
||||
@attachment.author_id = current_user.id
|
||||
@attachment.disk_directory = month_folder
|
||||
@attachment.cloud_url = remote_path
|
||||
@attachment.save!
|
||||
# @attachment.cloud_url = remote_path
|
||||
# @attachment.save!
|
||||
if @attachment.save!
|
||||
check_result = Attachment.check_image_able(dun_check_file)
|
||||
if check_result[:status].to_i == -1
|
||||
@attachment.destroy
|
||||
raise "上传失败,#{check_result[:message]}"
|
||||
# return render json: {status: -1, message: "上传失败,#{check_result[:message]}" }
|
||||
end
|
||||
end
|
||||
else
|
||||
logger.info "文件已存在,id = #{@attachment.id}, filename = #{@attachment.filename}"
|
||||
end
|
||||
|
|
|
@ -8,6 +8,7 @@ module LaboratoryHelper
|
|||
helper_method :default_setting
|
||||
helper_method :default_yun_session
|
||||
helper_method :default_course_links
|
||||
helper_method :manager_main_site_url
|
||||
end
|
||||
|
||||
def current_laboratory
|
||||
|
@ -32,18 +33,21 @@ module LaboratoryHelper
|
|||
end
|
||||
|
||||
def default_course_links
|
||||
# my_projects: "/users/#{current_user.try(:login)}/projects",
|
||||
# my_projects: "https://www.trustie.net/users/#{current_user.try(:login)}/user_projectlist",
|
||||
|
||||
{
|
||||
new_syllabuses: "https://www.trustie.net/syllabuses/new",
|
||||
new_course: "https://www.trustie.net/courses/new",
|
||||
edit_account: "https://www.trustie.net/my/account",
|
||||
my_courses: "https://www.trustie.net/users/#{current_user.try(:login)}/user_courselist",
|
||||
my_projects: "/users/#{current_user.try(:login)}/projects",
|
||||
my_organ: "https://www.trustie.net/users/#{current_user.try(:login)}/user_organizations",
|
||||
default_url: "https://www.trustie.net/",
|
||||
tiding_url: "https://www.trustie.net/users/#{current_user.try(:login)}/user_messages",
|
||||
register_url: "https://www.trustie.net/login?login=false"
|
||||
# new_syllabuses: "https://www.trustie.net/syllabuses/new",
|
||||
# new_course: "https://www.trustie.net/courses/new",
|
||||
# edit_account: "https://www.trustie.net/my/account",
|
||||
# my_courses: "https://www.trustie.net/users/#{current_user.try(:login)}/user_courselist",
|
||||
# my_projects: "/users/#{current_user.try(:login)}/projects",
|
||||
# my_organ: "https://www.trustie.net/users/#{current_user.try(:login)}/user_organizations",
|
||||
# default_url: "https://www.trustie.net/",
|
||||
tiding_url: "http://39.105.176.215/users/#{current_user.try(:login)}/user_tidings",
|
||||
register_url: "http://39.105.176.215/user_join"
|
||||
}
|
||||
end
|
||||
|
||||
def manager_main_site_url
|
||||
{name: '管理', link: "#{EduSetting.get('host_main_site')}/managements"}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,12 +6,12 @@ module LoginHelper
|
|||
end
|
||||
|
||||
def autologin_cookie_name
|
||||
edu_setting('autologin_cookie_name').presence || 'autologin'
|
||||
edu_setting('autologin_cookie_name').presence || 'autologin_forge_military'
|
||||
end
|
||||
|
||||
def set_autologin_cookie(user)
|
||||
token = Token.get_or_create_permanent_login_token(user, "autologin")
|
||||
Rails.logger.info "###### def set_autologin_cookie and get_or_create_permanent_login_token result: #{token&.value}"
|
||||
Rails.logger.info("set_cookie_user_id is=======> #{user.id}")
|
||||
token = Token.get_or_create_permanent_login_token(user, autologin_cookie_name)
|
||||
cookie_options = {
|
||||
:value => token.value,
|
||||
:expires => 1.month.from_now,
|
||||
|
|
|
@ -3,8 +3,11 @@ module RegisterHelper
|
|||
|
||||
def autologin_register(username, email, password, platform= '')
|
||||
result = {message: nil, user: nil}
|
||||
email ||= "#{username@example.org}"
|
||||
|
||||
user = User.new(admin: false, login: username, mail: email, type: "User")
|
||||
user = User.find_by(login: username)
|
||||
user ||= User.new(admin: false, login: username, mail: email, type: "User")
|
||||
|
||||
user.password = password
|
||||
user.platform = platform
|
||||
user.activate
|
||||
|
@ -16,7 +19,7 @@ module RegisterHelper
|
|||
user.gitea_token = result['sha1']
|
||||
user.gitea_uid = gitea_user['id']
|
||||
if user.save!
|
||||
UserExtension.create!(user_id: user.id)
|
||||
UserExtension.create!(user_id: user.id) if user.user_extension.blank?
|
||||
result[:user] = {id: user.id, token: user.gitea_token}
|
||||
end
|
||||
else
|
||||
|
|
|
@ -140,7 +140,7 @@ class IssuesController < ApplicationController
|
|||
# normal_status(0, "创建成功",)
|
||||
render :json => { status: 0, message: "创建成功", id: @issue.id}
|
||||
else
|
||||
normal_status(-1, "创建失败")
|
||||
normal_status(-1, @issue.errors.messages.values[0][0])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -196,13 +196,13 @@ class IssuesController < ApplicationController
|
|||
|
||||
if params[:status_id].to_i == 5
|
||||
@issue.issue_times.update_all(end_time: Time.now)
|
||||
@issue.update_closed_issues_count_in_project!
|
||||
#@issue.update_closed_issues_count_in_project!
|
||||
end
|
||||
|
||||
@issue.create_journal_detail(change_files, issue_files, issue_file_ids, current_user&.id)
|
||||
normal_status(0, "更新成功")
|
||||
else
|
||||
normal_status(-1, "更新失败")
|
||||
normal_status(-1, @issue.errors.messages.values[0][0])
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -46,7 +46,7 @@ class JournalsController < ApplicationController
|
|||
render :json => { status: 0, message: "评论成功", id: journal.id}
|
||||
# normal_status(0, "评论成功")
|
||||
else
|
||||
normal_status(-1, "评论失败")
|
||||
normal_status(-1, journal.errors.messages.values[0][0])
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -70,7 +70,7 @@ class JournalsController < ApplicationController
|
|||
if @journal.update_attribute(:notes, content)
|
||||
normal_status(0, "更新成功")
|
||||
else
|
||||
normal_status(-1, "更新失败")
|
||||
normal_status(-1, @journal.errors.messages.values[0][0])
|
||||
end
|
||||
else
|
||||
normal_status(-1, "评论的内容不能为空")
|
||||
|
|
|
@ -7,7 +7,7 @@ class Oauth::EducoderController < Oauth::BaseController
|
|||
token = params[:token]
|
||||
|
||||
::OauthEducoderForm.new({login: login, token: token, callback_url: callback_url}).validate!
|
||||
|
||||
|
||||
open_user= OpenUsers::Educoder.find_by(uid: login)
|
||||
|
||||
if open_user.present? && open_user.user.present? && open_user.user.email_binded?
|
||||
|
|
|
@ -11,7 +11,11 @@ class ProjectCategoriesController < ApplicationController
|
|||
# else
|
||||
# projects = Project.visible
|
||||
# end
|
||||
projects = Project.no_anomory_projects.visible
|
||||
@category_group_list = projects.joins(:project_category).group("project_categories.id", "project_categories.name").size
|
||||
@project_children_categories = ProjectCategory.descendants
|
||||
projects = Project.no_anomory_projects.secret_and_visible
|
||||
categories = projects.joins(:project_category).where(project_categories: {ancestry: nil}).group("project_categories.name", "project_categories.id").size.keys.to_h
|
||||
extra_category_id = categories.delete("其他")
|
||||
categories = categories.merge({"其他": extra_category_id}) if extra_category_id.present? #其他的放在最后面
|
||||
@category_group_list = categories
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,8 +43,9 @@ class ProjectsController < ApplicationController
|
|||
# else
|
||||
# projects = Project.visible
|
||||
# end
|
||||
projects = Project.no_anomory_projects.visible
|
||||
@project_group_list = projects.group(:project_type).size
|
||||
projects = Project.no_anomory_projects.secret_and_visible
|
||||
language_lists = projects.joins(:project_language).group("project_languages.name", "project_languages.id").size.keys.sort.to_h
|
||||
@project_group_list = language_lists.delete_if { |k, v| k.blank? }
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
@ -96,8 +96,10 @@ class PullRequestsController < ApplicationController
|
|||
normal_status(-1, "PullRequest创建失败")
|
||||
end
|
||||
else
|
||||
normal_status(-1, "PullRequest创建失败")
|
||||
normal_status(-1, local_requests.errors.messages.values[0][0])
|
||||
end
|
||||
else
|
||||
normal_status(-1, pull_issue.errors.messages.values[0][0])
|
||||
end
|
||||
rescue => e
|
||||
normal_status(-1, e.message)
|
||||
|
@ -147,8 +149,10 @@ class PullRequestsController < ApplicationController
|
|||
normal_status(-1, "PullRequest更新失败")
|
||||
end
|
||||
else
|
||||
normal_status(-1, "PullRequest更新失败")
|
||||
normal_status(-1, @pull_request.errors.messages.values[0][0])
|
||||
end
|
||||
else
|
||||
normal_status(-1, @issue.errors.messages.values[0][0])
|
||||
end
|
||||
rescue => e
|
||||
normal_status(-1, e.message)
|
||||
|
|
|
@ -1,6 +1,4 @@
|
|||
class SettingsController < ApplicationController
|
||||
def show
|
||||
@old_projects_url = nil
|
||||
@old_projects_url = "https://www.trustie.net/users/#{current_user.try(:login)}/projects" if User.current.logged?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -12,11 +12,11 @@ class SyncForgeController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
# def create
|
||||
# def create
|
||||
# ActiveRecord::Base.transaction do
|
||||
# params.permit!
|
||||
# sync_params = params[:sync_params]
|
||||
# project_user = User.where(login: sync_params[:owner_login])&.first
|
||||
# project_user = User.where(login: sync_params[:owner_login])&.first
|
||||
# #以前已同步的项目,那么肯定存在仓库
|
||||
# SyncLog.sync_log("=================begin_to_sync_forge: project_identifier: #{sync_params[:identifier]}========")
|
||||
# user_projects = Project.where(user_id: project_user.id)
|
||||
|
@ -38,7 +38,7 @@ class SyncForgeController < ApplicationController
|
|||
# check_sync_project(project, sync_params)
|
||||
# else #新建项目
|
||||
# SyncLog.sync_log("=================begin_to_create_new_project========")
|
||||
|
||||
|
||||
# project_params = {
|
||||
# repository_name: sync_params[:identifier],
|
||||
# user_id: project_user.id,
|
||||
|
@ -53,7 +53,7 @@ class SyncForgeController < ApplicationController
|
|||
# new_project_score = ProjectScore.create(score_params)
|
||||
# SyncLog.sync_log("=================new_project_score:#{new_project_score.try(:id)}========")
|
||||
# end
|
||||
|
||||
|
||||
# SyncRepositoryJob.perform_later(sync_params[:owner_login], sync_params[:identifier], sync_params[:repository], get_sudomain) if sync_params[:repository].present?
|
||||
# check_new_project(project, sync_params)
|
||||
# else
|
||||
|
@ -115,7 +115,7 @@ class SyncForgeController < ApplicationController
|
|||
# SyncLog.sync_log("=================sync_user_failed====#{e}")
|
||||
# end
|
||||
|
||||
# private
|
||||
# private
|
||||
|
||||
# def check_sync_project(project,sync_params)
|
||||
# begin
|
||||
|
@ -125,8 +125,8 @@ class SyncForgeController < ApplicationController
|
|||
# # end
|
||||
|
||||
# SyncLog.sync_log("----begin_to_check_sync_project----project_id:#{project.id}---------------")
|
||||
# change_project_score(project, sync_params[:project_score], sync_params[:repository]) if sync_params[:repository].present? #更新project_score
|
||||
# change_project_issues(project, sync_params[:issues],project.id, gitea_main)
|
||||
# change_project_score(project, sync_params[:project_score], sync_params[:repository]) if sync_params[:repository].present? #更新project_score
|
||||
# change_project_issues(project, sync_params[:issues],project.id, gitea_main)
|
||||
# change_project_members(project, sync_params[:members],gitea_main)
|
||||
# change_project_versions(project, sync_params[:project_versions],gitea_main)
|
||||
# change_project_watchers(project, sync_params[:project_watchers],gitea_main)
|
||||
|
@ -134,7 +134,7 @@ class SyncForgeController < ApplicationController
|
|||
# rescue => e
|
||||
# SyncLog.sync_log("=========check_sync_project_errors:#{e}===================")
|
||||
# end
|
||||
|
||||
|
||||
# end
|
||||
|
||||
# def check_new_project(project,sync_params)
|
||||
|
@ -167,7 +167,7 @@ class SyncForgeController < ApplicationController
|
|||
# parent_id: project.id
|
||||
# }
|
||||
# SyncProjectsJob.perform_later(sync_projects_params,gitea_main)
|
||||
|
||||
|
||||
# SyncLog.sync_log("***6. end_to_sync_parises---------------")
|
||||
# end
|
||||
# end
|
||||
|
@ -189,7 +189,7 @@ class SyncForgeController < ApplicationController
|
|||
# end
|
||||
# end
|
||||
# pre_project_score.save! if change_num > 0 #如果 project_score有变化则更新
|
||||
# else
|
||||
# else
|
||||
# ProjectScore.create!(project_scores.merge(project_id: project.id))
|
||||
# end
|
||||
# SyncLog.sync_log("***1. end_to_sync_project_score---------------")
|
||||
|
@ -206,7 +206,7 @@ class SyncForgeController < ApplicationController
|
|||
# SyncLog.sync_log("***2--01. forge_issue_ids-#{forge_issue_ids.size.to_i}--------------")
|
||||
# if forge_issue_ids.size.to_i <= old_issues_params[:count].to_i
|
||||
# diff_issue_ids = old_issues_params[:ids] - forge_issue_ids
|
||||
|
||||
|
||||
# if diff_issue_ids.size == 0 #issue数量一样,判断评论是否有增减
|
||||
# forge_journal_ids = Journal.select([:id, :journalized_id, :journalized_type]).where(journalized_id: forge_issue_ids).pluck(:id)
|
||||
# diff_journal_ids = old_issues_params[:journals][:ids] - forge_journal_ids
|
||||
|
@ -241,10 +241,10 @@ class SyncForgeController < ApplicationController
|
|||
# # }
|
||||
# # SyncLog.sync_log("***2--03. sync_projects_params_groups-#{sync_projects_params}--------------")
|
||||
# # SyncProjectsJob.perform_later(sync_projects_params, gitea_main)
|
||||
|
||||
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
# # SyncProjectsJob.perform_later(sync_projects_params, gitea_main) if sync_projects_params.present?
|
||||
# SyncLog.sync_log("***2. end_to_syncissues---------------")
|
||||
# rescue Exception => e
|
||||
|
@ -265,7 +265,7 @@ class SyncForgeController < ApplicationController
|
|||
# parent_id: project.id
|
||||
# }
|
||||
# SyncProjectsJob.perform_later(sync_projects_params,gitea_main)
|
||||
|
||||
|
||||
# end
|
||||
# end
|
||||
# SyncLog.sync_log("***5. begin_to_sync_watchers---------------")
|
||||
|
@ -285,7 +285,7 @@ class SyncForgeController < ApplicationController
|
|||
# }
|
||||
# SyncProjectsJob.perform_later(sync_projects_params,gitea_main)
|
||||
# end
|
||||
|
||||
|
||||
# SyncLog.sync_log("***4. end_to_sync_versions---------------")
|
||||
# end
|
||||
# end
|
||||
|
@ -304,17 +304,17 @@ class SyncForgeController < ApplicationController
|
|||
# }
|
||||
# SyncProjectsJob.perform_later(sync_projects_params,gitea_main)
|
||||
# end
|
||||
|
||||
|
||||
# SyncLog.sync_log("***3. end_to_sync_members---------------")
|
||||
# end
|
||||
# end
|
||||
|
||||
# def check_token
|
||||
# sync_params = params[:sync_params]
|
||||
# unless sync_params[:token] && sync_params[:token] == get_token
|
||||
# render json: {message: "token_errors"}
|
||||
# end
|
||||
# end
|
||||
# # def check_token
|
||||
# # sync_params = params[:sync_params]
|
||||
# # unless sync_params[:token] && sync_params[:token] == get_token
|
||||
# # render json: {message: "token_errors"}
|
||||
# # end
|
||||
# # end
|
||||
|
||||
# def get_token
|
||||
# "34c82f51e0b699d9d16d70fd6497c9b1e4821d6ea3e872558a6537a091076b8e"
|
||||
|
@ -331,4 +331,4 @@ class SyncForgeController < ApplicationController
|
|||
# return gitea_main
|
||||
# end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -140,8 +140,7 @@ class UsersController < ApplicationController
|
|||
# 其他平台登录后,必须将token同步到forge平台,实现sso登录功能
|
||||
def sync_token
|
||||
return render_error('未找相关用户!') unless @user
|
||||
|
||||
token = Token.get_or_create_permanent_login_token(@user, 'autologin')
|
||||
token = Token.get_or_create_permanent_login_token(@user, autologin_cookie_name)
|
||||
token.update_column(:value, params[:token])
|
||||
render_ok
|
||||
end
|
||||
|
|
|
@ -83,7 +83,7 @@ class VersionsController < ApplicationController
|
|||
if version.save
|
||||
normal_status(0, "里程碑创建成功")
|
||||
else
|
||||
normal_status(-1, "里程碑创建失败")
|
||||
normal_status(-1, version.errors.messages.values[0][0])
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -121,7 +121,7 @@ class VersionsController < ApplicationController
|
|||
if @version.update_attributes(tag_params)
|
||||
normal_status(0, "里程碑更新成功")
|
||||
else
|
||||
normal_status(-1, "里程碑更新失败")
|
||||
normal_status(-1, version.errors.messages.values[0][0])
|
||||
end
|
||||
end
|
||||
else
|
||||
|
|
|
@ -1,13 +1,24 @@
|
|||
class Contents::CreateForm < BaseForm
|
||||
attr_accessor :filepath, :branch, :new_branch
|
||||
attr_accessor :filepath, :branch, :new_branch, :content
|
||||
|
||||
validates :filepath, presence: true
|
||||
|
||||
validate :check_branch
|
||||
|
||||
validate :dun_content_check
|
||||
|
||||
def check_branch
|
||||
raise "branch和new_branch必须存在一个 " if branch.blank? && new_branch.blank?
|
||||
# raise "branch和new_branch只能存在一个" if !branch.blank? && !new_branch.blank?
|
||||
end
|
||||
|
||||
def dun_content_check
|
||||
if content.present?
|
||||
check_result = DunCheck::TextCheck.new({title: "", content: content}).call
|
||||
if check_result[:status].to_i == -1
|
||||
raise "内容含有:#{check_result[:extra_params][:infos]},请修改"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -149,7 +149,7 @@ module ApplicationHelper
|
|||
File.join("images/avatars", ["#{source.class}", "#{source.id}"]) + "?t=#{ctime}"
|
||||
end
|
||||
elsif source.class.to_s == 'User'
|
||||
str = source.user_extension.try(:gender).to_i == 0 ? "b" : "g"
|
||||
str = source.user_extension.try(:gender).to_i == 0 ? "boy.jpg" : "girl.jpg"
|
||||
File.join(relative_path, "#{source.class}", str)
|
||||
elsif source.class.to_s == 'Subject'
|
||||
File.join("images","educoder", "index", "subject", "subject#{rand(17)}.jpg")
|
||||
|
|
|
@ -47,7 +47,8 @@ module Gitea
|
|||
{
|
||||
filepath: @params[:filepath],
|
||||
branch: @params[:branch],
|
||||
new_branch: @params[:new_branch]
|
||||
new_branch: @params[:new_branch],
|
||||
content: @params[:content]
|
||||
}
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,48 @@
|
|||
class SyncForgeProjectJob < ApplicationJob
|
||||
queue_as :default
|
||||
|
||||
def perform(sync_parmas)
|
||||
# sync_parmas.permit!
|
||||
Rails.logger.info("=======begin to sync forge projects, and sync_parmas: #{sync_parmas}")
|
||||
get_rand_user = rand_user
|
||||
project_params = sync_parmas[:project]
|
||||
repository_params = sync_parmas[:repository]
|
||||
project_socre_params = sync_parmas[:project_socre]
|
||||
begin
|
||||
unless Project.select(:identifier).exists?(identifier: project_params[:identifier])
|
||||
project_params = project_params.merge({user_id: get_rand_user.id })
|
||||
project = Project.new(project_params)
|
||||
if project.save
|
||||
repository_params = {
|
||||
hidden: false,
|
||||
identifier: repository_params[:identifier],
|
||||
mirror_url: repository_params[:url].to_s.gsub("https://gitea.", "https://git."),
|
||||
user_id: get_rand_user.id,
|
||||
login: get_rand_user.login,
|
||||
password: "",
|
||||
is_mirror: false
|
||||
}
|
||||
Repositories::MigrateService.new(get_rand_user, project, repository_params).call
|
||||
project_score = ProjectScore.new(project_socre_params.merge({project_id: project.id}))
|
||||
project_score.save
|
||||
end
|
||||
end
|
||||
Rails.logger.info("=======end to sync forge projects")
|
||||
rescue => e
|
||||
Rails.logger.info("=======sync forge projects has errors: #{e}")
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def rand_user
|
||||
user_ids = User.select(:id, :type, :gitea_token, :gitea_uid).where("gitea_token is not null and gitea_uid is not null and type = ?", "User").pluck(:id)
|
||||
range_user_id = user_ids[rand(user_ids.length-1)]
|
||||
rand_sync_user = User.find_by_id(range_user_id) #生成随机用户
|
||||
unless rand_sync_user.present?
|
||||
rand_user
|
||||
end
|
||||
rand_sync_user
|
||||
end
|
||||
end
|
|
@ -6,6 +6,6 @@ class SyncMirroredRepositoryJob < ApplicationJob
|
|||
current_user = User.find_by(id: user_id)
|
||||
return if repo.blank? || current_user.blank?
|
||||
result = Gitea::Repository::SyncMirroredService.new(repo.user.login, repo.identifier, token: current_user.gitea_token).call
|
||||
repo&.mirror.set_status! if result[:status] === 200
|
||||
repo&.mirror&.set_status! if result[:status] == 200 && repo.mirror.present?
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,167 @@
|
|||
class DunCheck::ImageCheck
|
||||
|
||||
#检测结果,0:通过,1:嫌疑,2:不通过
|
||||
# include ActionView::Helpers::LoopTextsHelper
|
||||
|
||||
require 'uri'
|
||||
require 'net/http'
|
||||
|
||||
def initialize(image_params)
|
||||
@image_params = image_params
|
||||
end
|
||||
|
||||
def call
|
||||
begin
|
||||
Rails.logger.info("==========@image_params===========#{@image_params}")
|
||||
dun_params = check_dun_params(@image_params)
|
||||
|
||||
api_url = EduSetting.get("dun_image_api")
|
||||
|
||||
uri = URI.parse(api_url)
|
||||
|
||||
http = Net::HTTP.new(uri.hostname, uri.port)
|
||||
if api_url.include?("https://")
|
||||
http.use_ssl = true
|
||||
end
|
||||
dun_params_str = URI.encode_www_form(dun_params)
|
||||
|
||||
header = {'content-type':'application/x-www-form-urlencoded'}
|
||||
response = http.post(uri.path, dun_params_str, header)
|
||||
|
||||
response_body = JSON.parse(response.body)
|
||||
if response_body["code"].to_i == 200
|
||||
response_body_result = response_body["antispam"]
|
||||
response_lables = response_body_result[0]["labels"]
|
||||
return_sub_lable = ""
|
||||
if response_lables.present?
|
||||
return_sub_lable = get_sub_labels(response_lables)
|
||||
end
|
||||
render_status = response_body_result[0]["action"].to_i == 0 ? 1 : -1
|
||||
tip_status(render_status, return_sub_lable.present? ? "图片含有: #{return_sub_lable}" : response_body["msg"] )
|
||||
else
|
||||
tip_status(-1, response_body["msg"])
|
||||
end
|
||||
rescue Exception => ex
|
||||
Rails.logger.info "*** transaction abored!"
|
||||
Rails.logger.info "*** errors: #{ex.message}"
|
||||
tip_status(-1, "检测失败")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_dun_params(image_params)
|
||||
|
||||
dun_public_params = DunCheck::PublicParams.new("image")
|
||||
check_params = {
|
||||
version: "v4",
|
||||
images: image_params.to_json
|
||||
}
|
||||
check_params.merge!(dun_public_params.call)
|
||||
dun_params = dun_public_params.generate_sign(check_params)
|
||||
|
||||
return dun_params
|
||||
end
|
||||
|
||||
def tip_status(status, message, msg_params={})
|
||||
return {status: status, message: message, extra_params: msg_params}
|
||||
end
|
||||
|
||||
def get_sub_labels(labels)
|
||||
_sub_labels = []
|
||||
labels.each do |label|
|
||||
error_label = label["subLabels"].present? ? label["subLabels"][0]["subLabel"] : ""
|
||||
if error_label.present?
|
||||
_sub_labels.push(sub_lables[:"#{error_label.to_s}"])
|
||||
end
|
||||
end
|
||||
return _sub_labels.present? ? _sub_labels.join(",") : ""
|
||||
end
|
||||
|
||||
def sub_lables
|
||||
{
|
||||
"10000": "色情",
|
||||
"10001": "女下体",
|
||||
"10002": "女胸",
|
||||
"10003": "男下体",
|
||||
"10004": "性行为",
|
||||
"10005": "臀部",
|
||||
"10006": "口交",
|
||||
"10007": "卡通色情",
|
||||
"10008": "色情人物",
|
||||
"10009": "儿童色情",
|
||||
"11000": "性感低俗",
|
||||
"11001": "亲吻",
|
||||
"11002": "腿部特写",
|
||||
"11003": "非漏点赤膊",
|
||||
"11004": "胸部",
|
||||
"100001": "色情文字-色情其他",
|
||||
"100002": "色情文字-色情传播",
|
||||
"100003": "色情文字-色情性器官",
|
||||
"100004": "色情文字-色情挑逗",
|
||||
"100005": "色情文字-色情低俗段子",
|
||||
"100006": "色情文字-色情性行为",
|
||||
"100007": "色情文字-色情舆情事件",
|
||||
"100008": "色情文字-色情交友类",
|
||||
"20000": "广告",
|
||||
"20001": "广告带文字",
|
||||
"200009": "广告文字-商业推广",
|
||||
"200010": "广告文字-广告法",
|
||||
"200011": "刷量行为",
|
||||
"200012": "广告其他",
|
||||
"260052": "广告文字-广告法-涉医疗用语",
|
||||
"260053": "广告文字-广告法-迷信用语",
|
||||
"260054": "广告文字-广告法-需要凭证",
|
||||
"260055": "广告文字-广告法-限时性用语",
|
||||
"260056": "广告文字-广告法-涉嫌诱导消费者",
|
||||
"260057": "广告文字-广告法-涉嫌欺诈消费者",
|
||||
"260058": "广告文字-广告法-法律风险较高",
|
||||
"260059": "广告文字-广告法-极限词",
|
||||
"21000": "二维码",
|
||||
"30000": "暴恐",
|
||||
"30001": "暴恐图集",
|
||||
"30002": "暴恐旗帜",
|
||||
"30003": "暴恐人物",
|
||||
"30004": "暴恐标识",
|
||||
"30005": "暴恐场景",
|
||||
"300016": "暴恐文字-暴恐其他",
|
||||
"40000": "违禁",
|
||||
"40001": "违禁图集",
|
||||
"40002": "违禁品",
|
||||
"40003": "特殊标识",
|
||||
"40004": "血腥模型",
|
||||
"40005": "公职服饰",
|
||||
"40006": "不文明",
|
||||
"40007": "违禁人物",
|
||||
"40008": "违禁场景",
|
||||
"40009": "火焰",
|
||||
"40010": "骷髅",
|
||||
"40011": "货币",
|
||||
"40012": "毒品",
|
||||
"400017": "违禁文字-违禁其他",
|
||||
"600018": "违禁文字-谩骂其他",
|
||||
"50000": "涉政",
|
||||
"50001": "涉政图集",
|
||||
"50002": "中国地图",
|
||||
"50003": "涉政人物",
|
||||
"50004": "涉政旗帜",
|
||||
"50005": "涉政标识",
|
||||
"50006": "涉政场景",
|
||||
"500013": "涉政文字-涉政其他",
|
||||
"500014": "涉政文字-敏感专项",
|
||||
"500015": "涉政文字-严格涉政",
|
||||
"500039": "涉政文字-时事报道",
|
||||
"500040": "涉政文字-领导人相关",
|
||||
"500041": "涉政文字-英雄烈士相关",
|
||||
"500042": "涉政文字-邪教迷信",
|
||||
"500043": "涉政文字-落马官员相关",
|
||||
"500044": "涉政文字-热点舆情",
|
||||
"500045": "涉政文字-涉政综合",
|
||||
"90000": "其他",
|
||||
"90002": "自定义用户名单",
|
||||
"90003": "自定义IP名单",
|
||||
"900020": "文字违规-其他"
|
||||
}
|
||||
end
|
||||
end
|
|
@ -0,0 +1,31 @@
|
|||
class DunCheck::PublicParams
|
||||
def initialize(type)
|
||||
@type = type
|
||||
end
|
||||
|
||||
def call
|
||||
|
||||
public_params = {
|
||||
secretId: EduSetting.get("dun_secret_id"),
|
||||
businessId: EduSetting.get("dun_#{@type}_businessId"),
|
||||
timestamp: DateTime.current.strftime('%Q').to_i,
|
||||
nonce: rand(10 ** 11).to_i
|
||||
}
|
||||
return public_params
|
||||
end
|
||||
|
||||
def generate_sign(params)
|
||||
secretkey = EduSetting.get("dun_secrect_key")
|
||||
sort_params = params.sort.to_h
|
||||
sign_str = ""
|
||||
sort_params.each do |k,v|
|
||||
sign_str += "#{k.to_s}#{v.to_s}"
|
||||
end
|
||||
sign_str += secretkey
|
||||
md5_sign = Digest::MD5.hexdigest(sign_str.to_s.force_encoding("UTF-8"))
|
||||
return sort_params.merge!(signature: md5_sign)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
@ -0,0 +1,164 @@
|
|||
class DunCheck::TextCheck
|
||||
|
||||
# include DunCheck::PublicParams
|
||||
#text_params = {
|
||||
# content: "ccc", #内容
|
||||
# ip: "xxx", #用户ip
|
||||
# account: "xxx", #登录login
|
||||
# nickname: "xxx", #用户姓名
|
||||
# title: "xxx", #帖子的标题
|
||||
# }
|
||||
|
||||
#检测结果,0:通过,1:嫌疑,2:不通过
|
||||
# include ActionView::Helpers::LoopTextsHelper
|
||||
|
||||
require 'uri'
|
||||
require 'net/http'
|
||||
|
||||
def initialize(text_params)
|
||||
@text_params = text_params
|
||||
end
|
||||
|
||||
def call
|
||||
new_text_params = @text_params
|
||||
text_long_array = []
|
||||
check_content = new_text_params[:content]
|
||||
format_text(check_content,text_long_array)
|
||||
(1..text_long_array.size).each do |i|
|
||||
new_text_params.merge!(content: text_long_array[i-1])
|
||||
check_result = check_text(new_text_params)
|
||||
if check_result[:status].to_i == -1
|
||||
return check_result
|
||||
break
|
||||
else
|
||||
if i == text_long_array.size
|
||||
return check_result
|
||||
else
|
||||
next
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def check_text(text_params)
|
||||
begin
|
||||
dun_params = check_dun_params(text_params)
|
||||
|
||||
# api_url = Redmine::Configuration['dun']['text_api']
|
||||
api_url = EduSetting.get("dun_text_api")
|
||||
uri = URI.parse(api_url)
|
||||
|
||||
http = Net::HTTP.new(uri.hostname, uri.port)
|
||||
if api_url.include?("https://")
|
||||
http.use_ssl = true
|
||||
end
|
||||
dun_params_str = URI.encode_www_form(dun_params)
|
||||
header = {'content-type':'application/x-www-form-urlencoded'}
|
||||
response = http.post(uri.path, dun_params_str, header)
|
||||
response_body = eval(response.body)
|
||||
Rails.logger.info("======response========#{response_body}")
|
||||
|
||||
if response_body[:code].to_i == 200
|
||||
response_body_result = response_body[:result]
|
||||
response_body_labels = response_body_result[:labels].present? ? response_body_result[:labels][0] : []
|
||||
extra_params = {
|
||||
action: response_body_result[:action],
|
||||
taskId: response_body_result[:taskId],
|
||||
infos: response_body_labels.present? ? sub_lables[:"#{response_body_labels[:subLabels][0][:subLabel]}"] : ""
|
||||
}
|
||||
render_status = response_body_result[:action].to_i == 0 ? 1 : -1
|
||||
tip_status(render_status, response_body[:msg], extra_params)
|
||||
else
|
||||
tip_status(-1, response_body[:msg])
|
||||
end
|
||||
rescue Exception => ex
|
||||
Rails.logger.info "*** transaction abored!"
|
||||
Rails.logger.info "*** errors: #{ex.message}"
|
||||
tip_status(-1, "检测失败")
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def check_dun_params(text_params)
|
||||
dun_public_params = DunCheck::PublicParams.new("text")
|
||||
rand_data_id = random_dataId
|
||||
check_params = {
|
||||
dataId: rand_data_id,
|
||||
version: "v3.1",
|
||||
callback: rand_data_id
|
||||
}.merge(text_params)
|
||||
|
||||
check_params.merge!(dun_public_params.call)
|
||||
dun_params = dun_public_params.generate_sign(check_params)
|
||||
return dun_params
|
||||
end
|
||||
|
||||
def format_text(text_long, text_long_array)
|
||||
slice_content = text_long.slice(0..4998)
|
||||
last_slice_content = text_long.slice(4999..-1)
|
||||
text_long_array.push(slice_content)
|
||||
if last_slice_content.present?
|
||||
if last_slice_content.length > 4999
|
||||
format_text(last_slice_content, text_long_array)
|
||||
else
|
||||
text_long_array.push(last_slice_content)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def random_dataId
|
||||
Digest::MD5.hexdigest(rand(100000000).to_s)
|
||||
end
|
||||
|
||||
def check_labels
|
||||
# 100:色情,200:广告,260:广告法,300:暴恐,400:违禁,500:涉政,600:谩骂,700:灌水
|
||||
%w(100 200 260 300 400 500 600 700).join(",")
|
||||
end
|
||||
|
||||
def tip_status(status, message, msg_params={})
|
||||
return {status: status, message: message, extra_params: msg_params}
|
||||
end
|
||||
|
||||
def sub_lables
|
||||
{
|
||||
"100001": "色情其他",
|
||||
"100002": "色情传播",
|
||||
"100003": "色情性器官",
|
||||
"100004": "色情挑逗",
|
||||
"100005": "色情低俗段子",
|
||||
"100006": "色情性行为",
|
||||
"100007": "色情舆情事件",
|
||||
"100008": "色情交友类",
|
||||
"200009": "商业推广",
|
||||
"200010": "广告法",
|
||||
"200011": "刷量行为",
|
||||
"200012": "广告其他",
|
||||
"260052": "广告法-涉医疗用语(非药品禁止宣传药效)",
|
||||
"260053": "广告法-迷信用语",
|
||||
"260054": "广告法-需要凭证(可以写但需要凭证证明)",
|
||||
"260055": "广告法-限时性用语(可以写但必须有具体时间)",
|
||||
"260056": "广告法-涉嫌诱导消费者",
|
||||
"260057": "广告法-涉嫌欺诈消费者",
|
||||
"260058": "广告法-法律风险较高",
|
||||
"260059": "广告法-极限词(用语绝对化)",
|
||||
"300016": "暴恐其他",
|
||||
"400017": "违禁其他",
|
||||
"400021": "违禁网监要求",
|
||||
"500013": "涉政其他",
|
||||
"500014": "敏感专项",
|
||||
"500015": "严格涉政",
|
||||
"500039": "时事报道",
|
||||
"500040": "领导人相关",
|
||||
"500041": "英雄烈士相关",
|
||||
"500042": "邪教迷信",
|
||||
"500043": "落马官员相关",
|
||||
"500044": "热点舆情",
|
||||
"500045": "涉政综合",
|
||||
"600018": "谩骂其他",
|
||||
"700019": "灌水其他",
|
||||
"900020": "其他",
|
||||
}
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class ApplySignature < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :project
|
||||
|
||||
scope :with_user_id, -> (user_id) {where(user_id: user_id)}
|
||||
end
|
|
@ -3,7 +3,7 @@ class Attachment < ApplicationRecord
|
|||
include Publicable
|
||||
include Publishable
|
||||
include Lockable
|
||||
|
||||
include DunCheckImageAble
|
||||
belongs_to :container, polymorphic: true, optional: true
|
||||
belongs_to :author, class_name: "User", foreign_key: :author_id
|
||||
# belongs_to :course, foreign_key: :container_id, optional: true
|
||||
|
|
|
@ -0,0 +1,50 @@
|
|||
module DunCheckAble
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
validate :check_text_able
|
||||
end
|
||||
|
||||
def check_text_able
|
||||
dun_check_params = get_model
|
||||
if dun_check_params[:is_change]
|
||||
dun_check_params.delete(:is_change)
|
||||
check_result = DunCheck::TextCheck.new(dun_check_params).call
|
||||
if check_result[:status].to_i == -1
|
||||
errors.add(:base, "内容含有:#{check_result[:extra_params][:infos]},请修改")
|
||||
# raise ActiveRecord::RecordInvalid.new(self)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_model
|
||||
dun_model = self.class.name
|
||||
case dun_model
|
||||
when "Issue"
|
||||
check_params = {
|
||||
title: self.subject,
|
||||
content: self.description,
|
||||
is_change: (self.subject_changed? || self.description_changed?) && self.subject.present? && self.description.present?
|
||||
}
|
||||
when "PullRequest"
|
||||
check_params = {
|
||||
title: "",
|
||||
content: self.body,
|
||||
is_change: self.body_changed? && self.body.present?
|
||||
}
|
||||
when "Journal"
|
||||
check_params = {
|
||||
title: "",
|
||||
content: self.notes,
|
||||
is_change: self.notes_changed? && self.notes.present?
|
||||
}
|
||||
when "Version"
|
||||
check_params = {
|
||||
title: self.name,
|
||||
content: self.description,
|
||||
is_change: (self.name_changed? || self.description_changed?) && self.name.present? && self.description.present?
|
||||
}
|
||||
end
|
||||
return check_params
|
||||
end
|
||||
end
|
|
@ -0,0 +1,33 @@
|
|||
module DunCheckImageAble
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
def self.check_image_able(file)
|
||||
original_filename = file.original_filename
|
||||
file_extention = original_filename.split(".").last
|
||||
check_include = %w(jpg png bmp gif webp tiff jpeg)
|
||||
|
||||
if file_extention && check_include.include?(file_extention)
|
||||
base64_file = Base64.encode64(file.open.read.force_encoding(Encoding::UTF_8))
|
||||
check_params = [
|
||||
{
|
||||
name: original_filename,
|
||||
type: 2,
|
||||
data: base64_file,
|
||||
}
|
||||
]
|
||||
check_result = DunCheck::ImageCheck.new(check_params).call
|
||||
if check_result[:status].to_i == -1
|
||||
return {status: -1, message: check_result[:message]}
|
||||
else
|
||||
return {status: 1}
|
||||
end
|
||||
else
|
||||
return {status: 1}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
|
@ -1,5 +1,6 @@
|
|||
class Issue < ApplicationRecord
|
||||
#issue_type 1为普通,2为悬赏
|
||||
include DunCheckAble
|
||||
belongs_to :project, :counter_cache => true
|
||||
belongs_to :tracker,optional: true
|
||||
has_many :project_trends, as: :trend, dependent: :destroy
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Journal < ApplicationRecord
|
||||
include DunCheckAble
|
||||
belongs_to :user
|
||||
belongs_to :issue, foreign_key: :journalized_id, :touch => true
|
||||
has_many :journal_details, :dependent => :delete_all
|
||||
|
|
|
@ -22,9 +22,10 @@ class Laboratory < ApplicationRecord
|
|||
|
||||
delegate :name, :navbar, :footer, :login_logo_url, :nav_logo_url, :tab_logo_url, :default_navbar, to: :laboratory_setting
|
||||
|
||||
# TODO 域名申请后更改
|
||||
def site
|
||||
rails_env = EduSetting.get('rails_env')
|
||||
suffix = rails_env && rails_env != 'production' ? ".#{rails_env}.trustie.net" : '.trustie.net'
|
||||
suffix = rails_env && rails_env != 'production' ? "39.105.176.215" : '39.105.176.215'
|
||||
|
||||
identifier ? "#{identifier}#{suffix}" : ''
|
||||
end
|
||||
|
|
|
@ -72,4 +72,4 @@ class LaboratorySetting < ApplicationRecord
|
|||
footer: nil
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
class License < ApplicationRecord
|
||||
include Projectable
|
||||
has_many :attachments, as: :container, dependent: :destroy
|
||||
|
||||
end
|
||||
|
|
|
@ -31,10 +31,14 @@ class Project < ApplicationRecord
|
|||
has_many :versions, -> { order("versions.created_on DESC, versions.name DESC") }, dependent: :destroy
|
||||
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
|
||||
has_and_belongs_to_many :trackers, :order => "#{Tracker.table_name}.position"
|
||||
has_many :apply_signatures, dependent: :destroy
|
||||
|
||||
after_save :check_project_members
|
||||
scope :project_statics_select, -> {select(:id,:name, :is_public, :identifier, :status, :project_type, :user_id, :forked_count, :visits, :project_category_id, :project_language_id, :license_id, :ignore_id, :watchers_count, :created_on)}
|
||||
scope :no_anomory_projects, -> {where("projects.user_id is not null and projects.user_id != ?", 2)}
|
||||
scope :secret_and_visible, -> {joins(:license).where("licenses.is_secret = TRUE OR projects.is_public = TRUE")}
|
||||
|
||||
delegate :is_secret, to: :license
|
||||
|
||||
|
||||
def self.search_project(search)
|
||||
|
|
|
@ -2,4 +2,12 @@ class ProjectCategory < ApplicationRecord
|
|||
include Projectable
|
||||
has_ancestry
|
||||
|
||||
def self.descendants
|
||||
where.not(ancestry: [nil, ""])
|
||||
end
|
||||
|
||||
def self.get_children(target_id)
|
||||
where(ancestry: target_id).pluck(:id,:name)
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
class PullRequest < ApplicationRecord
|
||||
#status 0 默认未合并, 1表示合并, 2表示请求拒绝
|
||||
include DunCheckAble
|
||||
belongs_to :issue
|
||||
belongs_to :user
|
||||
belongs_to :project, :counter_cache => true
|
||||
|
|
|
@ -54,7 +54,7 @@ class Token < ActiveRecord::Base
|
|||
|
||||
# Delete all expired tokens
|
||||
def self.destroy_expired
|
||||
Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api', 'autologin'], Time.now - @@validity_time]
|
||||
Token.delete_all ["action NOT IN (?) AND created_on < ?", ['feeds', 'api', 'autologin', 'autologin_forge_military'], Time.now - @@validity_time]
|
||||
end
|
||||
|
||||
# Returns the active user who owns the key for the given action
|
||||
|
|
|
@ -92,11 +92,12 @@ class User < ApplicationRecord
|
|||
# 教学案例
|
||||
# has_many :libraries, dependent: :destroy
|
||||
has_many :project_trends, dependent: :destroy
|
||||
has_many :apply_signatures, dependent: :destroy
|
||||
|
||||
# Groups and active users
|
||||
scope :active, lambda { where(status: STATUS_ACTIVE) }
|
||||
scope :like, lambda { |keywords|
|
||||
where("LOWER(concat(lastname, firstname, login, mail)) LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
|
||||
where("LOWER(concat(nickname, lastname, firstname, login, mail)) LIKE ?", "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
|
||||
}
|
||||
|
||||
scope :simple_select, -> {select(:id, :login, :lastname,:firstname, :nickname, :gitea_uid)}
|
||||
|
@ -124,7 +125,7 @@ class User < ApplicationRecord
|
|||
|
||||
# 删除自动登录的token,一旦退出下次会提示需要登录
|
||||
def delete_autologin_token(value)
|
||||
Token.where(:user_id => id, :action => 'autologin', :value => value).delete_all
|
||||
Token.where(:user_id => id, :action => autologin_name, :value => value).delete_all
|
||||
end
|
||||
|
||||
def delete_session_token(value)
|
||||
|
@ -510,8 +511,8 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
# Returns the user who matches the given autologin +key+ or nil
|
||||
def self.try_to_autologin(key)
|
||||
user = Token.find_active_user('autologin', key)
|
||||
def self.try_to_autologin(key,type)
|
||||
user = Token.find_active_user(type, key)
|
||||
user.update(last_login_on: Time.now) if user
|
||||
user
|
||||
end
|
||||
|
@ -675,6 +676,10 @@ class User < ApplicationRecord
|
|||
raise("昵称包含敏感词汇,请重新输入") if nickname && !HarmoniousDictionary.clean?(nickname)
|
||||
end
|
||||
|
||||
def autologin_name
|
||||
EduSetting.get('autologin_cookie_name') || "autologin_forge_military"
|
||||
end
|
||||
|
||||
def set_laboratory
|
||||
return unless new_record?
|
||||
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
class Version < ApplicationRecord
|
||||
include DunCheckAble
|
||||
belongs_to :project, counter_cache: true
|
||||
has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id"
|
||||
belongs_to :user, optional: true
|
||||
|
|
|
@ -10,7 +10,7 @@ class Projects::ListQuery < ApplicationQuery
|
|||
end
|
||||
|
||||
def call
|
||||
q = Project.visible.search_project(params[:search])
|
||||
q = Project.secret_and_visible.search_project(params[:search])
|
||||
|
||||
scope = q.result(distinct: true)
|
||||
.includes(:project_category, :project_language, :repository, owner: :user_extension)
|
||||
|
|
|
@ -52,6 +52,11 @@ class Projects::CreateService < ApplicationService
|
|||
# end
|
||||
|
||||
def repo_is_public
|
||||
params[:private].blank? ? true : !params[:private]
|
||||
license = License.find_by_id(params[:license_id])
|
||||
if license.is_secret
|
||||
false
|
||||
else
|
||||
params[:private].blank? ? true : !params[:private]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
require 'uri'
|
||||
require 'net/http'
|
||||
|
||||
class SyncForgeProjectsRake
|
||||
# 运行示例: 检查哪些项目的repo不存在,bundle exec rails runner "SyncForgeProjectsRake.new.call(5)" -e production
|
||||
|
||||
def call(count)
|
||||
|
||||
url = "https://forgeplus.trustie.net/api/sync_forge/sync_range_projects" #trustie上的相关路由
|
||||
count_params = {
|
||||
sync_count: count || 10
|
||||
}
|
||||
Rails.logger.info("============begin to sync project,count: #{count_params} ===========")
|
||||
uri = URI.parse(url)
|
||||
http = Net::HTTP.new(uri.hostname, uri.port)
|
||||
http.use_ssl = true
|
||||
response = http.send_request('POST', uri.path, count_params.to_json, {'Content-Type' => 'application/json'})
|
||||
Rails.logger.info("============end to sync project, status: #{response.code} ===========")
|
||||
end
|
||||
end
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<div class="box search-form-container laboratory-list-form">
|
||||
<%= form_tag(admins_laboratories_path(unsafe_params), method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
|
||||
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-6 col-md-4 ml-3', placeholder: '学校名称/二级域名前缀检索') %>
|
||||
<%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-6 col-md-4 ml-3', placeholder: '二级域名前缀检索') %>
|
||||
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
|
||||
<% end %>
|
||||
|
||||
|
@ -16,4 +16,4 @@
|
|||
</div>
|
||||
|
||||
<%= render 'admins/laboratories/shared/create_laboratory_modal' %>
|
||||
<%= render 'admins/laboratories/shared/add_laboratory_user_modal' %>
|
||||
<%= render 'admins/laboratories/shared/add_laboratory_user_modal' %>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
<% school = laboratory&.school %>
|
||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td class="text-left"><%= school&.name || 'Trustie主站' %></td>
|
||||
<td class="text-left"><%= school&.name || '可控开源社区' %></td>
|
||||
<td class="text-left">
|
||||
<% if laboratory.identifier %>
|
||||
<%= link_to laboratory.site, "https://#{laboratory.site}", target: '_blank' %>
|
||||
<%= link_to laboratory.site, "http://#{laboratory.site}", target: '_blank' %>
|
||||
<% else %>
|
||||
--
|
||||
<% end %>
|
||||
|
@ -51,19 +51,5 @@
|
|||
<% if school.present? && laboratory.id != 1 %>
|
||||
<%= javascript_void_link '添加管理员', class: 'action', data: { laboratory_id: laboratory.id, toggle: 'modal', target: '.admin-add-laboratory-user-modal' } %>
|
||||
<%= link_to '同步用户', synchronize_user_admins_laboratory_path(laboratory), remote: true, data: { confirm: '确认同步该单位下的所有用户到云上实验室吗?' }, class: 'action' %>
|
||||
<% end %>
|
||||
|
||||
<div class="d-inline">
|
||||
<%= javascript_void_link('更多', class: 'action dropdown-toggle', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false) %>
|
||||
<div class="dropdown-menu more-action-dropdown">
|
||||
<%= link_to '轮播图', admins_laboratory_carousels_path(laboratory), class: 'dropdown-item' %>
|
||||
|
||||
<%= link_to '查看实训项目', admins_laboratory_laboratory_shixuns_path(laboratory), class: 'dropdown-item' %>
|
||||
<%= link_to '查看实践课程', admins_laboratory_laboratory_subjects_path(laboratory), class: 'dropdown-item' %>
|
||||
|
||||
<% if school.present? && laboratory.id != 1 %>
|
||||
<%= delete_link '删除', admins_laboratory_path(laboratory, element: ".laboratory-item-#{laboratory.id}"), class: 'dropdown-item delete-laboratory-action' %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</td>
|
||||
|
|
|
@ -19,10 +19,14 @@
|
|||
maxlength: 15, class: 'form-control font-16',
|
||||
'onKeyUp': 'value=value.replace(/[^\w\-\/]/ig,"").toLowerCase()',
|
||||
style: 'text-transform:lowercase'%>
|
||||
<div class="input-group-append">
|
||||
<%
|
||||
=begin%>
|
||||
<div class="input-group-append">
|
||||
<% rails_env = EduSetting.get('rails_env') %>
|
||||
<span class="input-group-text font-14" id="site-prefix"><%= rails_env && rails_env != 'production' ? ".#{rails_env}.educoder.net" : '.educoder.net' %></span>
|
||||
</div>
|
||||
</div>
|
||||
<%
|
||||
=end%>
|
||||
</div>
|
||||
<%# if @laboratory.errors && @laboratory.errors.key?(:identifier) %>
|
||||
<!-- <span id="identifier-error" class="danger text-danger">二级域名已被使用</span>-->
|
||||
|
@ -184,4 +188,4 @@
|
|||
<%= link_to '取消', admins_laboratories_path, class: 'btn btn-secondary px-4' %>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||
<td><%= project.id %></td>
|
||||
<td class="text-left">
|
||||
<%= link_to(project.name, "/projects/#{project.id}", target: '_blank') %>
|
||||
<%= link_to(project.name, "/projects/#{project.owner.login}/#{project.identifier}", target: '_blank') %>
|
||||
</td>
|
||||
<td><%= project.is_public ? '√' : '' %></td>
|
||||
<td><%= project.issues.size %></td>
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
json.id @signature.id
|
||||
json.attachment do
|
||||
json.name @attachment.filename
|
||||
end
|
|
@ -1,2 +1,3 @@
|
|||
json.status 0
|
||||
json.id @attachment.id
|
||||
json.filesize @attachment.filesize
|
||||
|
|
|
@ -1 +1 @@
|
|||
json.licenses @licenses, :id, :name
|
||||
json.licenses @licenses, :id, :name, :is_secret
|
||||
|
|
|
@ -1,5 +1,18 @@
|
|||
json.array! @category_group_list do |category,v|
|
||||
json.id category[0]
|
||||
json.name category[1]
|
||||
json.projects_count v
|
||||
# json.array! @category_group_list do |category,v|
|
||||
# json.id category[0]
|
||||
# json.name category[1]
|
||||
# json.projects_count v
|
||||
# end
|
||||
|
||||
json.array! @category_group_list do |k,v|
|
||||
children_category = @project_children_categories.get_children(v)
|
||||
json.children do
|
||||
json.array! children_category do |cate|
|
||||
json.id cate[0]
|
||||
json.name cate[1]
|
||||
json.parent_id v
|
||||
end
|
||||
end
|
||||
json.id v
|
||||
json.name k.to_s
|
||||
end
|
|
@ -3,38 +3,44 @@ if user.blank?
|
|||
nil
|
||||
else
|
||||
json.id project.id
|
||||
json.repo_id project&.repository&.id
|
||||
json.identifier project.identifier
|
||||
json.name project.name
|
||||
json.description Nokogiri::HTML(project.description).text
|
||||
json.visits project.visits
|
||||
json.praises_count project.praises_count.to_i
|
||||
json.forked_count project.forked_count.to_i
|
||||
json.is_public project.is_public
|
||||
json.mirror_url project.repository&.mirror_url
|
||||
json.type project&.numerical_for_project_type
|
||||
json.last_update_time render_unix_time(project.updated_on)
|
||||
json.time_ago time_from_now(project.updated_on)
|
||||
json.forked_from_project_id project.forked_from_project_id
|
||||
json.author do
|
||||
json.name user.try(:show_real_name)
|
||||
json.login user.login
|
||||
json.image_url url_to_avatar(project.owner)
|
||||
end
|
||||
json.category do
|
||||
if project.project_category.blank?
|
||||
json.nil!
|
||||
else
|
||||
json.id project.project_category.id
|
||||
json.name project.project_category.name
|
||||
json.repo_id project&.repository&.id
|
||||
json.identifier project.identifier
|
||||
json.name project.name
|
||||
json.description Nokogiri::HTML(project.description).text
|
||||
json.visits project.visits
|
||||
json.praises_count project.praises_count.to_i
|
||||
json.forked_count project.forked_count.to_i
|
||||
json.is_public project.is_public
|
||||
json.is_secret project.is_secret
|
||||
json.mirror_url project.repository&.mirror_url
|
||||
json.type project&.numerical_for_project_type
|
||||
json.last_update_time render_unix_time(project.updated_on)
|
||||
json.time_ago time_from_now(project.updated_on)
|
||||
json.forked_from_project_id project.forked_from_project_id
|
||||
json.author do
|
||||
json.name user.try(:show_real_name)
|
||||
json.login user.login
|
||||
json.image_url url_to_avatar(project.owner)
|
||||
end
|
||||
json.category do
|
||||
if project.project_category.blank?
|
||||
json.nil!
|
||||
else
|
||||
json.id project.project_category.id
|
||||
json.name project.project_category.name
|
||||
end
|
||||
end
|
||||
json.language do
|
||||
if project.project_language.blank?
|
||||
json.nil!
|
||||
else
|
||||
json.id project.project_language.id
|
||||
json.name project.project_language.name
|
||||
end
|
||||
end
|
||||
user_apply_signatures = project.apply_signatures.with_user_id(current_user.id)
|
||||
json.user_apply_signatures user_apply_signatures do |signature|
|
||||
json.id signature.id
|
||||
json.status signature.status
|
||||
end
|
||||
end
|
||||
json.language do
|
||||
if project.project_language.blank?
|
||||
json.nil!
|
||||
else
|
||||
json.id project.project_language.id
|
||||
json.name project.project_language.name
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,10 @@
|
|||
json.array! @project_group_list do |type,v|
|
||||
json.project_type type
|
||||
json.name render_zh_project_type(type)
|
||||
json.projects_count v
|
||||
# json.array! @project_group_list do |type,v|
|
||||
# json.project_type type
|
||||
# json.name render_zh_project_type(type)
|
||||
# json.projects_count v
|
||||
# end
|
||||
|
||||
json.array! @project_group_list do |k,v|
|
||||
json.name k
|
||||
json.id v
|
||||
end
|
|
@ -1,6 +1,12 @@
|
|||
json.name @project.name
|
||||
json.identifier @project.identifier
|
||||
json.is_public @project.is_public
|
||||
json.is_secret @project.is_secret
|
||||
json.description @project.description
|
||||
json.repo_id @project.repository.id
|
||||
json.repo_identifier @project.repository.identifier
|
||||
user_apply_signatures = @project.apply_signatures.with_user_id(current_user.id)
|
||||
json.user_apply_signatures user_apply_signatures do |signature|
|
||||
json.id signature.id
|
||||
json.status signature.status
|
||||
end
|
|
@ -21,8 +21,6 @@ json.issues do
|
|||
json.fork_project_id pr&.fork_project_id
|
||||
json.fork_project_identifier pr&.fork_project&.identifier
|
||||
json.fork_project_user pr&.fork_project&.owner.try(:login)
|
||||
|
||||
|
||||
json.id issue.id
|
||||
json.name issue.subject
|
||||
json.pr_time time_from_now(pr.status == 1 ? pr.updated_at : issue.updated_on)
|
||||
|
|
|
@ -5,3 +5,4 @@ json.project_description @project.description
|
|||
json.project_category_id @project.project_category_id
|
||||
json.project_language_id @project.project_language_id
|
||||
json.private !@project.is_public
|
||||
json.is_secret @project.is_secret
|
||||
|
|
|
@ -16,6 +16,12 @@ json.permission User.current&.admin? ? "Manager" : @project.get_premission(@use
|
|||
json.mirror_url @project&.repository.mirror_url
|
||||
json.mirror @project&.repository.mirror_url.present?
|
||||
json.type @project.numerical_for_project_type
|
||||
json.is_secret @project.is_secret
|
||||
user_apply_signatures = @project.apply_signatures.with_user_id(current_user.id)
|
||||
json.user_apply_signatures user_apply_signatures do |signature|
|
||||
json.id signature.id
|
||||
json.status signature.status
|
||||
end
|
||||
|
||||
unless @project.common?
|
||||
json.mirror_status @repo.mirror_status
|
||||
|
|
|
@ -20,14 +20,16 @@ json.setting do
|
|||
# end
|
||||
|
||||
nav_bar = default_setting.navbar
|
||||
if User.current.logged?
|
||||
nav_bar[2]["link"] = "/users/#{current_user.login}/projects"
|
||||
nav_bar[2]["hidden"] = false
|
||||
else
|
||||
nav_bar[2]["link"] = ""
|
||||
nav_bar[2]["hidden"] = true
|
||||
# if User.current.logged?
|
||||
# nav_bar[2]["link"] = "/users/#{current_user.login}/projects"
|
||||
# nav_bar[2]["hidden"] = false
|
||||
# else
|
||||
# nav_bar[2]["link"] = ""
|
||||
# nav_bar[2]["hidden"] = true
|
||||
# end
|
||||
if current_user && current_user.admin?
|
||||
nav_bar << manager_main_site_url
|
||||
end
|
||||
|
||||
json.name default_setting.name
|
||||
json.nav_logo_url default_setting.nav_logo_url&.[](1..-1)
|
||||
json.login_logo_url default_setting.login_logo_url&.[](1..-1)
|
||||
|
@ -42,10 +44,6 @@ json.setting do
|
|||
json.navbar nav_bar
|
||||
|
||||
json.footer default_setting.footer
|
||||
|
||||
json.main_site current_laboratory.main_site?
|
||||
json.new_course default_course_links
|
||||
json.old_projects_url @old_projects_url
|
||||
|
||||
|
||||
end
|
||||
json.main_site current_laboratory.main_site?
|
||||
end
|
||||
|
|
|
@ -17,7 +17,7 @@ Rails.application.routes.draw do
|
|||
get 'oauth/bind', to: 'oauth/educoder#bind'
|
||||
get 'oauth/register', to: 'oauth#register'
|
||||
post 'oauth/auto_register', to: 'oauth#auto_register'
|
||||
|
||||
|
||||
resources :edu_settings
|
||||
|
||||
scope '/api' do
|
||||
|
@ -35,6 +35,7 @@ Rails.application.routes.draw do
|
|||
delete :destroy_files
|
||||
end
|
||||
end
|
||||
resources :apply_signatures, only: [:create]
|
||||
get 'home/index'
|
||||
get 'home/search'
|
||||
get 'main/first_stamp'
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
class CreateProjectCategories < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
# create_table :project_categories do |t|
|
||||
# t.string :name
|
||||
# t.integer :position
|
||||
# t.integer :projects_count, :default => 0
|
||||
#
|
||||
# t.timestamps
|
||||
# end
|
||||
# def change
|
||||
# # create_table :project_categories do |t|
|
||||
# # t.string :name
|
||||
# # t.integer :position
|
||||
# # t.integer :projects_count, :default => 0
|
||||
# #
|
||||
# # t.timestamps
|
||||
# # end
|
||||
|
||||
names = %w(大数据 机器学习 深度学习 人工智能 量子计算 智慧医疗 自动驾驶 其他)
|
||||
names.each do |name|
|
||||
ProjectCategory.find_or_create_by!(name: name)
|
||||
end
|
||||
# names = %w(大数据 机器学习 深度学习 人工智能 量子计算 智慧医疗 自动驾驶 其他)
|
||||
# names.each do |name|
|
||||
# ProjectCategory.find_or_create_by!(name: name)
|
||||
# end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class SortToProjectCategoriesWithPosition < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
ProjectCategory.order(:updated_at).each.with_index(1) do |pc, index|
|
||||
pc.update_column :position, index
|
||||
end
|
||||
end
|
||||
# def change
|
||||
# ProjectCategory.order(:updated_at).each.with_index(1) do |pc, index|
|
||||
# pc.update_column :position, index
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
class CreateProjectLanguages < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :project_languages do |t|
|
||||
t.string :name
|
||||
t.integer :position
|
||||
t.integer :projects_count, :default => 0
|
||||
# create_table :project_languages do |t|
|
||||
# t.string :name
|
||||
# t.integer :position
|
||||
# t.integer :projects_count, :default => 0
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
# t.timestamps
|
||||
# end
|
||||
|
||||
names = %w(Ruby C C# C++ HTML Haml CSS JavaScript Python PHP Java JSON JSX Lex Shell Objective-C Cycript Clojure Go Grace Gradle GraphQL Dart Elixir Erlang Perl R Reason Sass Slice SVG)
|
||||
names.each do |name|
|
||||
ProjectLanguage.find_or_create_by!(name: name)
|
||||
end
|
||||
# names = %w(Ruby C C# C++ HTML Haml CSS JavaScript Python PHP Java JSON JSX Lex Shell Objective-C Cycript Clojure Go Grace Gradle GraphQL Dart Elixir Erlang Perl R Reason Sass Slice SVG)
|
||||
# names.each do |name|
|
||||
# ProjectLanguage.find_or_create_by!(name: name)
|
||||
# end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
class CreateLicenses < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :licenses do |t|
|
||||
t.string :name
|
||||
t.text :content
|
||||
# create_table :licenses do |t|
|
||||
# t.string :name
|
||||
# t.text :content
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
# t.timestamps
|
||||
# end
|
||||
|
||||
dir_url = File.join(Rails.root, "public", "options", "license")
|
||||
GenerateDbService.call(dir_url, 'license')
|
||||
# dir_url = File.join(Rails.root, "public", "options", "license")
|
||||
# GenerateDbService.call(dir_url, 'license')
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,14 +1,14 @@
|
|||
class CreateIgnores < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :ignores do |t|
|
||||
t.string :name
|
||||
t.text :content
|
||||
# create_table :ignores do |t|
|
||||
# t.string :name
|
||||
# t.text :content
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
# t.timestamps
|
||||
# end
|
||||
|
||||
dir_url = File.join(Rails.root, "public", "options", "gitignore")
|
||||
GenerateDbService.call(dir_url, 'ignore')
|
||||
# dir_url = File.join(Rails.root, "public", "options", "gitignore")
|
||||
# GenerateDbService.call(dir_url, 'ignore')
|
||||
|
||||
end
|
||||
end
|
||||
|
|
|
@ -3,8 +3,8 @@ class AddUserRefToRepository < ActiveRecord::Migration[5.2]
|
|||
# add_column :repositories, :user_id, :integer
|
||||
# add_index :repositories, :user_id
|
||||
|
||||
Project.joins(:repository).find_each do |project|
|
||||
project&.repository&.update_column(:user_id, project&.user_id) unless project&.repository.blank?
|
||||
end
|
||||
# Project.joins(:repository).find_each do |project|
|
||||
# project&.repository&.update_column(:user_id, project&.user_id) unless project&.repository.blank?
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class ChangeForkedCountDefaultFromProjects < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column_default :projects, :forked_count, { from: nil, to: 0 }
|
||||
change_column_default :projects, :project_type, { from: nil, to: 0 }
|
||||
# change_column_default :projects, :forked_count, { from: nil, to: 0 }
|
||||
# change_column_default :projects, :project_type, { from: nil, to: 0 }
|
||||
|
||||
Project.find_each do |project|
|
||||
project.update_column('forked_count', 0) if project.forked_count.nil?
|
||||
project.update_column('project_type', 0) if project.project_type.nil?
|
||||
end
|
||||
# Project.find_each do |project|
|
||||
# project.update_column('forked_count', 0) if project.forked_count.nil?
|
||||
# project.update_column('project_type', 0) if project.project_type.nil?
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,18 +1,18 @@
|
|||
class AddIssuePriorityToModel < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
unless ActiveRecord::Base.connection.table_exists? 'IssuePriority'
|
||||
create_table :issue_priorities do |t|
|
||||
t.string :name
|
||||
t.integer :position
|
||||
t.timestamps
|
||||
end
|
||||
# unless ActiveRecord::Base.connection.table_exists? 'IssuePriority'
|
||||
# create_table :issue_priorities do |t|
|
||||
# t.string :name
|
||||
# t.integer :position
|
||||
# t.timestamps
|
||||
# end
|
||||
|
||||
add_index :issue_priorities, [:name]
|
||||
# add_index :issue_priorities, [:name]
|
||||
|
||||
pr_values = %w(低 正常 高 紧急 立刻)
|
||||
pr_values.each_with_index do |v, index|
|
||||
IssuePriority.create!(name: v, position: index+1)
|
||||
end
|
||||
end
|
||||
# pr_values = %w(低 正常 高 紧急 立刻)
|
||||
# pr_values.each_with_index do |v, index|
|
||||
# IssuePriority.create!(name: v, position: index+1)
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class CreateIssueDepends < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :issue_depends do |t|
|
||||
t.integer :user_id
|
||||
t.integer :issue_id
|
||||
t.integer :depend_issue_id
|
||||
t.timestamps
|
||||
end
|
||||
# create_table :issue_depends do |t|
|
||||
# t.integer :user_id
|
||||
# t.integer :issue_id
|
||||
# t.integer :depend_issue_id
|
||||
# t.timestamps
|
||||
# end
|
||||
|
||||
add_index :issue_depends, [:user_id, :issue_id, :depend_issue_id]
|
||||
# add_index :issue_depends, [:user_id, :issue_id, :depend_issue_id]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class CreateProjectTrends < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :project_trends do |t|
|
||||
t.integer :user_id
|
||||
t.integer :project_id
|
||||
t.references :trend, polymorphic: true, index: true
|
||||
t.string :action_type
|
||||
t.timestamps
|
||||
end
|
||||
add_index :project_trends, [:user_id, :project_id]
|
||||
# create_table :project_trends do |t|
|
||||
# t.integer :user_id
|
||||
# t.integer :project_id
|
||||
# t.references :trend, polymorphic: true, index: true
|
||||
# t.string :action_type
|
||||
# t.timestamps
|
||||
# end
|
||||
# add_index :project_trends, [:user_id, :project_id]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
class MigrateDefalutToTiding < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column_default :tidings, :status, from: nil, to: 0
|
||||
# change_column_default :tidings, :status, from: nil, to: 0
|
||||
|
||||
Tiding.where(status: nil).update_all(status: 0)
|
||||
# Tiding.where(status: nil).update_all(status: 0)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
class MigrateTidingStatus < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
Tiding.where(container_type: "JoinCourse", status: 0).each do |tiding|
|
||||
unless CourseMessage.where(course_message_id: tiding.trigger_user_id, course_id: tiding.container_id, course_message_type: "JoinCourseRequest", status: 0).exists?
|
||||
tiding.update!(status: 1)
|
||||
end
|
||||
end
|
||||
# Tiding.where(container_type: "JoinCourse", status: 0).each do |tiding|
|
||||
# unless CourseMessage.where(course_message_id: tiding.trigger_user_id, course_id: tiding.container_id, course_message_type: "JoinCourseRequest", status: 0).exists?
|
||||
# tiding.update!(status: 1)
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
class AddValuesToIssueTagsAndTrackers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
issue_status = %w(新增 正在解决 已解决 反馈 关闭 拒绝)
|
||||
trackers = %w(缺陷 功能 支持 任务 周报)
|
||||
issue_status.each_with_index do |s, index|
|
||||
unless IssueStatus.exists?(name: s)
|
||||
IssueStatus.create!(name: s, is_closed: (index == 4) , is_default: (index == 0), position: index+1)
|
||||
end
|
||||
end
|
||||
# issue_status = %w(新增 正在解决 已解决 反馈 关闭 拒绝)
|
||||
# trackers = %w(缺陷 功能 支持 任务 周报)
|
||||
# issue_status.each_with_index do |s, index|
|
||||
# unless IssueStatus.exists?(name: s)
|
||||
# IssueStatus.create!(name: s, is_closed: (index == 4) , is_default: (index == 0), position: index+1)
|
||||
# end
|
||||
# end
|
||||
|
||||
trackers.each_with_index do |s, index|
|
||||
unless Tracker.exists?(name: s)
|
||||
Tracker.create!(name: s, is_in_chlog: (index == 0 || index == 1) , is_in_roadmap: (index != 0 || index != 2), position: index+1)
|
||||
end
|
||||
end
|
||||
# trackers.each_with_index do |s, index|
|
||||
# unless Tracker.exists?(name: s)
|
||||
# Tracker.create!(name: s, is_in_chlog: (index == 0 || index == 1) , is_in_roadmap: (index != 0 || index != 2), position: index+1)
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class MigrateUserLocation < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
UserExtension.where("location like '%省'").each do |ue|
|
||||
ue.update_column("location", ue.location.chop)
|
||||
end
|
||||
# UserExtension.where("location like '%省'").each do |ue|
|
||||
# ue.update_column("location", ue.location.chop)
|
||||
# end
|
||||
|
||||
UserExtension.where("location_city like '%市'").each do |ue|
|
||||
ue.update_column("location_city", ue.location_city.chop)
|
||||
end
|
||||
# UserExtension.where("location_city like '%市'").each do |ue|
|
||||
# ue.update_column("location_city", ue.location_city.chop)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class ChangeVersionsDescriptions < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column_default :versions, :description, nil
|
||||
change_column :versions, :description, :text
|
||||
# change_column_default :versions, :description, nil
|
||||
# change_column :versions, :description, :text
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class AddLanguageToProjects < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :projects, :language, :string
|
||||
# add_column :projects, :language, :string
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# TODO 该字段用于trusite用户登录时,同步用户密码到gitea平台, 默认为未同步
|
||||
class AddIsSyncPwdToUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :users, :is_sync_pwd, :boolean, :default => true
|
||||
# add_column :users, :is_sync_pwd, :boolean, :default => true
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,69 +1,69 @@
|
|||
class ChangeQuillToMd < ActiveRecord::Migration[5.2]
|
||||
#迁移quill编辑器的内容为md
|
||||
def change
|
||||
migrate_time = Time.current - 20.days
|
||||
# migrate_time = Time.current - 20.days
|
||||
|
||||
all_issues = Issue.where("updated_on > ?", migrate_time)
|
||||
pros = PullRequest.where("updated_at > ?", migrate_time)
|
||||
journals = Journal.where("created_on > ?", migrate_time)
|
||||
# all_issues = Issue.where("updated_on > ?", migrate_time)
|
||||
# pros = PullRequest.where("updated_at > ?", migrate_time)
|
||||
# journals = Journal.where("created_on > ?", migrate_time)
|
||||
|
||||
|
||||
Issue.transaction do
|
||||
if all_issues.size > 0
|
||||
all_issues.each do |i|
|
||||
description = i.description
|
||||
if description.present? && description.include?("insert")
|
||||
new_content = change_content(description)
|
||||
i.update_attribute(:description, new_content)
|
||||
end
|
||||
puts "__update_issue_content_____id:#{i.id}__"
|
||||
end
|
||||
end
|
||||
end
|
||||
# Issue.transaction do
|
||||
# if all_issues.size > 0
|
||||
# all_issues.each do |i|
|
||||
# description = i.description
|
||||
# if description.present? && description.include?("insert")
|
||||
# new_content = change_content(description)
|
||||
# i.update_attribute(:description, new_content)
|
||||
# end
|
||||
# puts "__update_issue_content_____id:#{i.id}__"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
|
||||
Journal.transaction do
|
||||
if journals.size > 0
|
||||
journals.each do |j|
|
||||
description = j.notes
|
||||
if description.present? && description.include?("insert")
|
||||
new_content = change_content(description)
|
||||
j.update_attribute(:notes, new_content)
|
||||
end
|
||||
puts "__update_journal_content_____id:#{j.id}__"
|
||||
end
|
||||
end
|
||||
# Journal.transaction do
|
||||
# if journals.size > 0
|
||||
# journals.each do |j|
|
||||
# description = j.notes
|
||||
# if description.present? && description.include?("insert")
|
||||
# new_content = change_content(description)
|
||||
# j.update_attribute(:notes, new_content)
|
||||
# end
|
||||
# puts "__update_journal_content_____id:#{j.id}__"
|
||||
# end
|
||||
# end
|
||||
|
||||
end
|
||||
# end
|
||||
|
||||
PullRequest.transaction do
|
||||
if pros.size > 0
|
||||
pros.each do |p|
|
||||
description = p.body
|
||||
if description.present? && description.include?("insert")
|
||||
new_content = change_content(description)
|
||||
p.update_attribute(:body, new_content)
|
||||
end
|
||||
puts "__update_pull_request_content_____id:#{p.id}__"
|
||||
end
|
||||
end
|
||||
end
|
||||
# PullRequest.transaction do
|
||||
# if pros.size > 0
|
||||
# pros.each do |p|
|
||||
# description = p.body
|
||||
# if description.present? && description.include?("insert")
|
||||
# new_content = change_content(description)
|
||||
# p.update_attribute(:body, new_content)
|
||||
# end
|
||||
# puts "__update_pull_request_content_____id:#{p.id}__"
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
def change_content(content)
|
||||
puts "####________content_____######{content}"
|
||||
new_content = ""
|
||||
return "" if content.blank?
|
||||
desc = JSON.parse(content)["ops"]
|
||||
if desc.length > 0
|
||||
desc.each do |d|
|
||||
image = d["insert"]["image"]
|
||||
if image.present?
|
||||
new_content += "![#{image['alt']}](#{image['url']})"
|
||||
else
|
||||
new_content += d["insert"].gsub("\n", "")
|
||||
end
|
||||
end
|
||||
end
|
||||
new_content
|
||||
# puts "####________content_____######{content}"
|
||||
# new_content = ""
|
||||
# return "" if content.blank?
|
||||
# desc = JSON.parse(content)["ops"]
|
||||
# if desc.length > 0
|
||||
# desc.each do |d|
|
||||
# image = d["insert"]["image"]
|
||||
# if image.present?
|
||||
# new_content += "![#{image['alt']}](#{image['url']})"
|
||||
# else
|
||||
# new_content += d["insert"].gsub("\n", "")
|
||||
# end
|
||||
# end
|
||||
# end
|
||||
# new_content
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,20 +1,20 @@
|
|||
class AddSomeCountsToProject < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :projects, :versions_count, :integer, default: 0 #里程碑
|
||||
add_column :repositories, :version_releases_count, :integer, default: 0 #版本发布d
|
||||
add_column :projects, :issue_tags_count, :integer, default: 0 #标签的数量
|
||||
# add_column :projects, :versions_count, :integer, default: 0 #里程碑
|
||||
# add_column :repositories, :version_releases_count, :integer, default: 0 #版本发布d
|
||||
# add_column :projects, :issue_tags_count, :integer, default: 0 #标签的数量
|
||||
|
||||
Project.includes(:versions, :issue_tags, repository: :version_releases).find_each do |p|
|
||||
puts "###____change_p.id____######{p.id}"
|
||||
r = p&.repository
|
||||
Project.reset_counters p.id, :versions
|
||||
Project.reset_counters p.id, :issue_tags
|
||||
# Project.includes(:versions, :issue_tags, repository: :version_releases).find_each do |p|
|
||||
# puts "###____change_p.id____######{p.id}"
|
||||
# r = p&.repository
|
||||
# Project.reset_counters p.id, :versions
|
||||
# Project.reset_counters p.id, :issue_tags
|
||||
|
||||
if r.present?
|
||||
puts "###____change_p.id____######{r.id}"
|
||||
Repository.reset_counters r.id, :version_releases
|
||||
end
|
||||
# if r.present?
|
||||
# puts "###____change_p.id____######{r.id}"
|
||||
# Repository.reset_counters r.id, :version_releases
|
||||
# end
|
||||
|
||||
end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class AddForkUrlToRepositories < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :repositories, :fork_url, :string, default: nil
|
||||
# add_column :repositories, :fork_url, :string, default: nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class AddCreatedAtToWatcher < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :watchers, :created_at, :datetime
|
||||
Watcher.update_all(created_at: Time.current)
|
||||
# add_column :watchers, :created_at, :datetime
|
||||
# Watcher.update_all(created_at: Time.current)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
class CreateForkUsers < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :fork_users do |t|
|
||||
t.integer :project_id #原始项目id
|
||||
t.integer :fork_project_id #fork后的项目id
|
||||
t.integer :user_id #fork用户的id
|
||||
t.timestamps
|
||||
end
|
||||
add_index :fork_users, :project_id
|
||||
add_index :fork_users, :user_id
|
||||
# create_table :fork_users do |t|
|
||||
# t.integer :project_id #原始项目id
|
||||
# t.integer :fork_project_id #fork后的项目id
|
||||
# t.integer :user_id #fork用户的id
|
||||
# t.timestamps
|
||||
# end
|
||||
# add_index :fork_users, :project_id
|
||||
# add_index :fork_users, :user_id
|
||||
|
||||
projects = Project.where("forked_from_project_id is not null")
|
||||
projects.each do |p|
|
||||
ForkUser.create(project_id: p.forked_from_project_id, fork_project_id: p.id, user_id: p.user_id)
|
||||
end
|
||||
# projects = Project.where("forked_from_project_id is not null")
|
||||
# projects.each do |p|
|
||||
# ForkUser.create(project_id: p.forked_from_project_id, fork_project_id: p.id, user_id: p.user_id)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class AddWatchersCountToUser < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :users, :watchers_count, :integer, default: 0
|
||||
# add_column :users, :watchers_count, :integer, default: 0
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class CreateMirrors < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :mirrors do |t|
|
||||
t.integer :repo_id, foreign_key: true
|
||||
t.integer :status, default: 0, null: false, comment: "0 - succeeded, 1 - waiting, 2 - failed"
|
||||
t.integer :interval, comment: "mirror interval with unix time"
|
||||
t.datetime :next_update_time, comment: "next update mirror time, for datetime"
|
||||
# create_table :mirrors do |t|
|
||||
# t.integer :repo_id, foreign_key: true
|
||||
# t.integer :status, default: 0, null: false, comment: "0 - succeeded, 1 - waiting, 2 - failed"
|
||||
# t.integer :interval, comment: "mirror interval with unix time"
|
||||
# t.datetime :next_update_time, comment: "next update mirror time, for datetime"
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
# t.timestamps
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class AddIsMirrorToRepositories < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :repositories, :is_mirror, :boolean, default: false
|
||||
# add_column :repositories, :is_mirror, :boolean, default: false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
class ChangeProjectWatchersCount < ActiveRecord::Migration[5.2]
|
||||
#修改project的watchers_count 不正确的问题
|
||||
def change
|
||||
watcher_ids = Watcher.where(watchable_type: "Project").pluck(:watchable_id).uniq
|
||||
watcher_ids.each do |i|
|
||||
puts "#######____update_project_watchers_id____##############{i}"
|
||||
p = Project.includes(:watchers).select(:id, :watchers_count).find_by(id:i)
|
||||
if p.present?
|
||||
Project.reset_counters(i, :watchers)
|
||||
end
|
||||
end
|
||||
# watcher_ids = Watcher.where(watchable_type: "Project").pluck(:watchable_id).uniq
|
||||
# watcher_ids.each do |i|
|
||||
# puts "#######____update_project_watchers_id____##############{i}"
|
||||
# p = Project.includes(:watchers).select(:id, :watchers_count).find_by(id:i)
|
||||
# if p.present?
|
||||
# Project.reset_counters(i, :watchers)
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
class AddClosedIssuesCountToProjects < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :projects, :closed_issues_count, :integer, default: 0
|
||||
# add_column :projects, :closed_issues_count, :integer, default: 0
|
||||
|
||||
projects = Project.joins(:issues).where('status_id = 5').select("projects.id, count('issues.id') as closed_issues_count").group("projects.id")
|
||||
projects.each do |pro|
|
||||
project = Project.find pro.id
|
||||
project.update_column(:closed_issues_count, pro.closed_issues_count) if project.closed_issues_count == 0
|
||||
end
|
||||
# projects = Project.joins(:issues).where('status_id = 5').select("projects.id, count('issues.id') as closed_issues_count").group("projects.id")
|
||||
# projects.each do |pro|
|
||||
# project = Project.find pro.id
|
||||
# project.update_column(:closed_issues_count, pro.closed_issues_count) if project.closed_issues_count == 0
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
class ChangeRepositoryReleasesCount < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
release_ids = VersionRelease.select(:id,:repository_id).pluck(:repository_id).uniq
|
||||
release_ids.each do |i|
|
||||
puts "#######____update_repository_releases_id____##############{i}"
|
||||
p = Repository.includes(:version_releases).select(:id, :version_releases_count).find_by(id:i)
|
||||
if p.present?
|
||||
Repository.reset_counters(i, :version_releases)
|
||||
end
|
||||
end
|
||||
# release_ids = VersionRelease.select(:id,:repository_id).pluck(:repository_id).uniq
|
||||
# release_ids.each do |i|
|
||||
# puts "#######____update_repository_releases_id____##############{i}"
|
||||
# p = Repository.includes(:version_releases).select(:id, :version_releases_count).find_by(id:i)
|
||||
# if p.present?
|
||||
# Repository.reset_counters(i, :version_releases)
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
class AddIndexForProjectLanguageAndCategory < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column :project_categories, :id, :integer, null: false
|
||||
change_column :project_languages, :id, :integer, null: false
|
||||
# change_column :project_categories, :id, :integer, null: false
|
||||
# change_column :project_languages, :id, :integer, null: false
|
||||
|
||||
ProjectCategory.update_all(projects_count:0)
|
||||
ProjectLanguage.update_all(projects_count:0)
|
||||
# ProjectCategory.update_all(projects_count:0)
|
||||
# ProjectLanguage.update_all(projects_count:0)
|
||||
|
||||
project_categories = Project.joins(:project_category).group("project_categories.id").size
|
||||
project_categories.each do |k,v|
|
||||
puts "#######____update_project_category_id____##############{k}"
|
||||
ProjectCategory.update_counters(k, projects_count: v)
|
||||
end
|
||||
# project_categories = Project.joins(:project_category).group("project_categories.id").size
|
||||
# project_categories.each do |k,v|
|
||||
# puts "#######____update_project_category_id____##############{k}"
|
||||
# ProjectCategory.update_counters(k, projects_count: v)
|
||||
# end
|
||||
|
||||
project_languages = Project.joins(:project_language).group("project_languages.id").size
|
||||
project_languages.each do |k,v|
|
||||
puts "#######____update_project_language_id____##############{k}"
|
||||
ProjectLanguage.update_counters(k, projects_count: v)
|
||||
end
|
||||
# project_languages = Project.joins(:project_language).group("project_languages.id").size
|
||||
# project_languages.each do |k,v|
|
||||
# puts "#######____update_project_language_id____##############{k}"
|
||||
# ProjectLanguage.update_counters(k, projects_count: v)
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class ChangeProjectCategoryLanguageIdDefault < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
execute "ALTER TABLE project_languages MODIFY COLUMN id INT AUTO_INCREMENT;"
|
||||
execute "ALTER TABLE project_categories MODIFY COLUMN id INT AUTO_INCREMENT;"
|
||||
# execute "ALTER TABLE project_languages MODIFY COLUMN id INT AUTO_INCREMENT;"
|
||||
# execute "ALTER TABLE project_categories MODIFY COLUMN id INT AUTO_INCREMENT;"
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class RemoveIssuesLockVersionColumn < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
remove_column :issues, :lock_version
|
||||
# remove_column :issues, :lock_version
|
||||
end
|
||||
end
|
|
@ -1,5 +1,5 @@
|
|||
class AddSyncNumToMirrors < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :mirrors, :sync_num, :integer, default: 1
|
||||
# add_column :mirrors, :sync_num, :integer, default: 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
class AddOriginProjectIdToPullRequest < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :pull_requests, :fork_project_id, :integer
|
||||
add_column :pull_requests, :is_original, :boolean, default: false
|
||||
# add_column :pull_requests, :fork_project_id, :integer
|
||||
# add_column :pull_requests, :is_original, :boolean, default: false
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
class ChangeDescriptionLimtFromIssues < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
change_column :issues, :description, :longtext
|
||||
# change_column :issues, :description, :longtext
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
class ChangeProjectsDefaultCount < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
projects = Project.select(:id, :issues_count,:pull_requests_count,:versions_count,:praises_count,:watchers_count).all
|
||||
projects.each do |p|
|
||||
puts p.id
|
||||
# Project.reset_counters( p.id, :issues_count, touch: false )
|
||||
Project.reset_counters( p.id, :pull_requests_count, touch: false )
|
||||
Project.reset_counters( p.id, :versions_count, touch: false )
|
||||
# Project.reset_counters( p.id, :praises_count, touch: false )
|
||||
Project.reset_counters( p.id, :watchers_count, touch: false )
|
||||
end
|
||||
# projects = Project.select(:id, :issues_count,:pull_requests_count,:versions_count,:praises_count,:watchers_count).all
|
||||
# projects.each do |p|
|
||||
# puts p.id
|
||||
# # Project.reset_counters( p.id, :issues_count, touch: false )
|
||||
# Project.reset_counters( p.id, :pull_requests_count, touch: false )
|
||||
# Project.reset_counters( p.id, :versions_count, touch: false )
|
||||
# # Project.reset_counters( p.id, :praises_count, touch: false )
|
||||
# Project.reset_counters( p.id, :watchers_count, touch: false )
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,15 +1,15 @@
|
|||
class ChangeVersionsIssuesCount < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
versions = Version.includes(:issues).select(:id, :closed_issues_count, :percent,:issues_count)
|
||||
versions.each do |v|
|
||||
closed_issues = Issue.select(:id, :fixed_version_id, :status_id).where(fixed_version_id: v.id, status_id: 5).size
|
||||
unless v.closed_issues_count.to_i == closed_issues
|
||||
puts v.id
|
||||
percent = v.issues_count.to_i <=0 ? 0.0 : (closed_issues.to_f / v.issues_count.to_i)
|
||||
v.closed_issues_count = closed_issues
|
||||
v.percent = percent
|
||||
v.save
|
||||
end
|
||||
end
|
||||
# versions = Version.includes(:issues).select(:id, :closed_issues_count, :percent,:issues_count)
|
||||
# versions.each do |v|
|
||||
# closed_issues = Issue.select(:id, :fixed_version_id, :status_id).where(fixed_version_id: v.id, status_id: 5).size
|
||||
# unless v.closed_issues_count.to_i == closed_issues
|
||||
# puts v.id
|
||||
# percent = v.issues_count.to_i <=0 ? 0.0 : (closed_issues.to_f / v.issues_count.to_i)
|
||||
# v.closed_issues_count = closed_issues
|
||||
# v.percent = percent
|
||||
# v.save
|
||||
# end
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class AddIpToUserActions < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :user_actions, :ip, :string
|
||||
end
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
class ResetVersionsCount < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
versions = Version.includes(:issues).select(:id, :closed_issues_count, :percent,:issues_count)
|
||||
versions.each do |v|
|
||||
Version.reset_counters v.id, :issues
|
||||
closed_issues = Issue.select(:id, :fixed_version_id, :status_id).where(fixed_version_id: v.id, status_id: 5).size
|
||||
unless v.closed_issues_count.to_i == closed_issues
|
||||
percent = v.issues_count.to_i <=0 ? 0.0 : (closed_issues.to_f / v.issues_count.to_i)
|
||||
v.closed_issues_count = closed_issues
|
||||
v.percent = percent
|
||||
v.save
|
||||
end
|
||||
puts v.id
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,11 @@
|
|||
class CreateApplySignatures < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
create_table :apply_signatures do |t|
|
||||
t.references :user
|
||||
t.references :project
|
||||
t.integer :status, default: 0
|
||||
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class AddSomeColumnsAboutApplySignatures < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :licenses, :is_secret, :boolean, default: false
|
||||
add_column :members, :is_apply_signature, :boolean, default: false
|
||||
end
|
||||
end
|
|
@ -28,4 +28,11 @@
|
|||
# vod_status: "uploaded",
|
||||
# published_at: nil,
|
||||
# filesize: 14877403
|
||||
# }
|
||||
# }
|
||||
|
||||
|
||||
# lan_ids = ProjectLanguage.select(:name, :id).pluck(:id) * 4
|
||||
# projects = Project.where(project_language_id: [nil, ""])
|
||||
# projects.each_with_index do |p,index|
|
||||
# p.update_attribute(:project_language_id, lan_ids[index])
|
||||
# end
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue