Compare commits

...

119 Commits

Author SHA1 Message Date
yystopf 2d1d0495c9 fix: default profile completed 2022-04-02 14:22:20 +08:00
yystopf 64dd4dced7 fix: remove tip for profile is not completed 2022-04-02 14:09:26 +08:00
xiaoxiaoqiong 9c723658c4 敏感词同步头歌 2022-04-01 23:01:14 +08:00
xiaoxiaoqiong 1f8f583eb5 邮箱已注册提示 2022-03-23 17:13:55 +08:00
xiaoxiaoqiong 5064e2cc5d 邮箱已注册提示 2022-03-23 17:09:23 +08:00
xiaoxiaoqiong e336adfd0f fixed gitea token and uid 同步 2022-02-21 14:20:13 +08:00
xiaoxiaoqiong 06ff40a26a fixed gitea token and uid 同步 2022-02-21 14:09:55 +08:00
xiaoxiaoqiong fccaa476e4 educoder修改邮箱和密码同步 2021-12-17 10:46:13 +08:00
yystopf 807e91a839 fix 2021-11-05 17:37:55 +08:00
yystopf 13497ae6dc add: setting of engineer_url 2021-11-05 17:05:28 +08:00
jasder 9955619398 Merge pull request 'FIX WIP' (#221) from jasder/forgeplus:dev_educoder into dev_educoder 2021-10-23 16:10:32 +08:00
jasder ae2a2725f7 FIX conflict 2021-10-23 16:09:35 +08:00
jasder 6220d851ae FIX 合并主干分支代码以及解决代码冲突 2021-10-23 16:06:49 +08:00
yystopf d2e18d9c0c fix merge from develop 2021-09-18 10:43:35 +08:00
jasder 039ca21f30 Merge pull request 'FIX merge develop' (#144) from develop into dev_educoder 2021-09-09 09:44:44 +08:00
jasder cbc74e4709 Merge pull request 'Fix 路由规范化' (#141) from jasder/forgeplus:dev_educoder into dev_educoder 2021-09-06 14:18:33 +08:00
jasder fd4806012d FIX 合并develop主干代码(平台路由规范化) 2021-09-06 14:16:38 +08:00
jasder 4825c910f0 FIX merge develop conflict 2021-08-27 16:12:14 +08:00
viletyy ace13abe92 fix: 合并请求对比代码返回合并信息 2021-07-12 18:45:35 +08:00
jasder e8da6364d8 Merge branch 'develop' into dev_educoder 2021-07-12 16:16:59 +08:00
jasder a7e20dcae2 FIX 解决用户同步问题 2021-07-09 17:53:14 +08:00
jasder 06e24a8ea4 Merge branch 'dev_educoder' of https://git.trustie.net/jasder/forgeplus into dev_educoder 2021-07-09 16:58:04 +08:00
jasder 070df3c9dd FIX 解决私有版本库库不能访问、下载图片的问题 2021-07-09 16:57:37 +08:00
viletyy 7c0bc5d444 add: create project owner login 2021-07-07 15:51:05 +08:00
jasder 6ebab1be66 FIX delete gantt、sonar tab 2021-07-07 09:13:40 +08:00
jasder 27f510e6c9 ADD loger info for create gitea user method 2021-07-07 00:07:01 +08:00
jasder d9a27b7728 ADD gantt, sonar menu for menu_list api 2021-07-06 15:49:26 +08:00
jasder 68f1d7f7f6 ADD 项目tab中添加 甘特图和质量分析/检测标识 2021-07-06 15:41:18 +08:00
jasder 7e3517d873 FIX show realname for create project 2021-07-06 11:04:25 +08:00
jasder 877ef54b24 FIX bug 2021-07-06 10:43:55 +08:00
jasder 133eed6afe FIX 合并代码、重构优化gitea 用户注册api 2021-07-05 16:19:23 +08:00
jasder eba2df5a2d Merge branch 'educoder_server' into dev_educoder 2021-07-05 15:21:23 +08:00
jasder 85a37fdbcc Merge branch 'feature/pull_conflict_files' into dev_educoder 2021-06-28 10:05:01 +08:00
jasder 01341d4389 FIX pull、 gitea pull model relation bug 2021-06-28 10:04:48 +08:00
jasder a62b29a263 Merge branch 'feature/pull_conflict_files' into dev_educoder 2021-06-28 10:00:10 +08:00
jasder 3a475a4674 FIX get conflict files bug with create pr api 2021-06-28 09:59:47 +08:00
jasder 0eccafcb69 Merge branch 'feature/pull_conflict_files' into dev_educoder 2021-06-28 09:39:39 +08:00
jasder 0dbed862a7 Merge branch 'develop' into dev_educoder 2021-06-27 21:46:35 +08:00
jasder dfc998a9cc Merge branch 'develop' into dev_educoder 2021-06-18 17:47:59 +08:00
jasder 8be4bc823c Merge branch 'develop' into dev_educoder 2021-06-17 17:31:17 +08:00
jasder 7af6d8d754 FIX merge flick 2021-06-17 17:10:16 +08:00
jasder 5a8dc9d5e7 ADD merge develop branch 2021-06-17 14:09:59 +08:00
jasder ecdb79ee48 fix code bug 2021-06-11 17:40:55 +08:00
jasder 50e0ad9804 Merge branch 'dev_educoder' into educoder_server 2021-06-11 17:36:53 +08:00
jasder 953d6790d0 FIX create gitea user bug 2021-06-11 17:35:27 +08:00
jasder 136d1c1abd Merge branch 'educoder_server' of https://git.trustie.net/jasder/forgeplus into educoder_server 2021-06-11 16:51:30 +08:00
jasder e085ef374b Merge branch 'develop' into dev_educoder 2021-05-24 10:41:05 +08:00
jasder a557139ad0 Merge branch 'develop' into dev_educoder 2021-05-17 17:15:08 +08:00
jasder 6d0ac60d5a ADD phone query params for get list users api 2021-05-17 16:58:42 +08:00
jasder dda1868a72 Merge branch 'develop' into dev_educoder 2021-05-17 16:57:57 +08:00
jasder 93a1a08393 FIX merge develop branch adn fix confict 2021-05-17 16:26:51 +08:00
yystopf 4d4d8d1369 项目模块项目id重定向
项目模块项目id重定向
2021-05-03 19:50:21 +08:00
vilet.yy ab42fb7476 add: projects redirect to 2021-05-03 19:40:30 +08:00
jasder 11ac2f9c9d FIX delete log 2021-04-30 16:16:08 +08:00
jasder 8a9c3df2e5 Merge branch 'educoder_server' into dev_educoder 2021-04-30 16:09:40 +08:00
jasder e90f80255e FIX 完善项目添加成员流程 2021-04-30 16:09:02 +08:00
jasder 1b6c082480 fix merge develop 2021-04-07 11:40:29 +08:00
jasder ce1152cd4f Merge branch 'educoder_server' into dev_educoder 2021-04-02 15:54:07 +08:00
jasder c8a9094ad0 Merge branch 'develop' into dev_educoder 2021-04-02 15:53:48 +08:00
jasder 569088d846 Merge branch 'dev_educoder' into educoder_server 2021-04-01 21:00:41 +08:00
jasder 6159cda155 Merge branch 'develop' into dev_educoder 2021-04-01 21:00:22 +08:00
jasder d738ea432b Merge branch 'dev_educoder' into educoder_server 2021-04-01 15:08:32 +08:00
jasder 4a30e8c83f FIX conflict 2021-04-01 15:08:29 +08:00
jasder b3288937c9 fix merge 2021-04-01 15:07:12 +08:00
jasder 7520fa03c2 Merge branch 'develop' into dev_educoder 2021-03-28 20:05:52 +08:00
jasder f282d971e3 FIX get branches api bug and project menu list bug 2021-03-28 19:56:11 +08:00
jasder 56f01801ae Merge branch 'dev_educoder' into educoder_server 2021-03-28 19:45:24 +08:00
jasder 45e70367d5 Merge branch 'develop' into dev_educoder 2021-03-28 19:45:07 +08:00
jasder a0b376e70a Merge branch 'dev_educoder' into educoder_server 2021-03-27 23:55:11 +08:00
jasder d62d757c42 Merge branch 'develop' into dev_educoder 2021-03-27 23:54:55 +08:00
jasder 033c2607e2 Merge branch 'dev_educoder' into educoder_server 2021-03-25 21:30:46 +08:00
vilet.yy 0d6abdf7d0 fix: setting common arr 2021-03-25 20:59:24 +08:00
jasder 22c68f4c70 FIX bug 2021-03-25 20:29:36 +08:00
jasder fcd86fb01b Merge branch 'dev_educoder' into educoder_server 2021-03-25 19:58:28 +08:00
jasder faecb99136 Merge branch 'develop' into dev_educoder 2021-03-25 19:58:03 +08:00
jasder 15a002f601 Update defalut laboratory setting url 2021-03-23 16:36:35 +08:00
jasder 206d7bc159 Merge branch 'trustie_server' into dev_educoder 2021-03-23 15:58:47 +08:00
jasder 5e0006a830 Merge branch 'trustie_server' into dev_educoder 2021-03-23 15:47:13 +08:00
jasder 3abf993463 Merge branch 'trustie_server' into dev_educoder 2021-03-23 15:43:08 +08:00
jasder efbf6d627d FIX merge 2021-03-23 11:43:24 +08:00
jasder 6836907146 FIX code bug 2021-03-23 10:26:20 +08:00
jasder 6c4058cde5 Merge branch 'educoder_server' into dev_educoder 2021-03-23 10:22:12 +08:00
jasder 5a2e17abe2 FIX project and project_info aasion 2021-03-23 09:34:20 +08:00
jasder 9a8b89bcd8 FIX 解决实训作业关联项目的问题 2021-03-23 09:28:40 +08:00
jasder 4856da1607 Merge branch 'dev_educoder' into educoder_server 2021-03-22 21:02:56 +08:00
jasder 883a5f7e38 Merge branch 'develop' into dev_educoder 2021-03-22 21:02:35 +08:00
jasder 1658c1b923 Merge branch 'dev_educoder' of https://git.trustie.net/jasder/forgeplus into dev_educoder 2021-03-22 17:58:29 +08:00
jasder 74f6a54d29 FIX update setting api for nav bar url 2021-03-22 17:58:15 +08:00
vilet.yy adb315521e fix 2021-03-22 14:20:03 +08:00
vilet.yy 01cad866b8 fix: laboratory 500
fix

fix
2021-03-22 14:17:03 +08:00
jasder 3447b17cdf FIX change password bug 2021-03-22 14:13:25 +08:00
jasder 0079255e98 Merge branch 'develop' into dev_educoder 2021-03-21 11:25:57 +08:00
vilet.yy 490bff5ded fix: form error 2021-03-19 16:18:09 +08:00
vilet.yy 008b8ac709 Merge branch 'develop' into dev_educoder 2021-03-19 15:07:34 +08:00
vilet.yy d0532a8f70 Merge branch 'dev_educoder' of https://git.trustie.net/jasder/forgeplus into dev_educoder 2021-03-19 11:54:10 +08:00
vilet.yy a8c4cde350 add: user info sync_pwd 2021-03-19 11:50:35 +08:00
jasder 5de5974102 FIX remove email for gitea_register api 2021-03-19 10:54:56 +08:00
jasder 3d3e778078 Merge branch 'dev_educoder' of https://git.trustie.net/jasder/forgeplus into dev_educoder 2021-03-19 10:31:12 +08:00
jasder f5ea8dc4a2 FIX change password api 2021-03-19 10:31:06 +08:00
vilet.yy c4b942a5f2 fix 2021-03-18 18:22:07 +08:00
jasder 13391b189a FIX conflict 2021-03-18 18:17:41 +08:00
jasder b116a72ce7 Merge branch 'dev_educoder' of https://git.trustie.net/jasder/forgeplus into dev_educoder 2021-03-18 18:15:22 +08:00
jasder f01aec94d6 FIX 2021-03-18 18:15:08 +08:00
jasder cc97f85a1e ADD has_ansenty 2021-03-18 18:11:06 +08:00
vilet.yy 133995080a add: user info email 2021-03-18 18:11:06 +08:00
vilet.yy 27304c35dc add: user info mark 2021-03-18 18:11:06 +08:00
vilet.yy d6bf85ef73 add: user gitea register 2021-03-18 18:11:06 +08:00
jasder be9c01bf1d ADD educoder api 2021-03-18 18:11:06 +08:00
jasder edeaaa5db7 FIX sync user for educoder 2021-03-18 18:11:06 +08:00
jasder 0e41b6cc9b FIX 整理表结构 2021-03-18 18:11:03 +08:00
jasder 5f3946f187 ADD has_ansenty 2021-03-18 18:07:56 +08:00
jasder b7be00f3ec Merge branch 'dev_educoder' of https://git.trustie.net/jasder/forgeplus into dev_educoder 2021-03-18 17:28:20 +08:00
jasder 9b21e29426 ADD educoder api 2021-03-18 17:27:18 +08:00
vilet.yy f37fccfdb3 add: user info email 2021-03-18 17:22:59 +08:00
vilet.yy 810d2dbac6 add: user info mark 2021-03-18 16:00:05 +08:00
vilet.yy 6af97d865f Merge branch 'dev_educoder' of https://git.trustie.net/jasder/forgeplus into dev_educoder 2021-03-18 15:28:09 +08:00
vilet.yy efba4b2b4f add: user gitea register 2021-03-18 15:28:03 +08:00
jasder aaf1f43cc2 FIX sync user for educoder 2021-03-18 13:46:19 +08:00
jasder 823c99bd71 FIX 整理表结构 2021-03-15 16:02:59 +08:00
60 changed files with 805 additions and 699 deletions

View File

@ -6,6 +6,20 @@ class AccountsController < ApplicationController
render json: session render json: session
end end
# 为了同步平台上未注册gitea的用户
def gitea_register
user = User.find_by(login: sync_gitea_params[:login])
Users::SyncGiteaForm.new(sync_gitea_params.merge(user: user)).validate!
return render_error("该用户已同步协作平台") if user.gitea_token.present? && user.gitea_uid.present?
result = create_gitea_user!(user, sync_gitea_params[:login], sync_gitea_params[:email], sync_gitea_params[:password])
result[:user] ? render_ok : render_error(result[:message])
rescue Exception => e
uid_logger_error(e.message)
tip_exception(-1, e.message)
end
# 其他平台同步注册的用户 # 其他平台同步注册的用户
def remote_register def remote_register
username = params[:username]&.gsub(/\s+/, "") username = params[:username]&.gsub(/\s+/, "")
@ -362,6 +376,10 @@ class AccountsController < ApplicationController
{ login: pre + code, email: email, phone: phone } { login: pre + code, email: email, phone: phone }
end end
def sync_gitea_params
params.permit(:login, :email, :password)
end
def user_params def user_params
params.require(:user).permit(:login, :email, :phone) params.require(:user).permit(:login, :email, :phone)
end end

View File

@ -247,11 +247,11 @@ class ApplicationController < ActionController::Base
end end
def require_profile_completed def require_profile_completed
tip_exception(411, "请完善资料后再操作") unless User.current.profile_is_completed? # tip_exception(411, "请完善资料后再操作") unless User.current.profile_is_completed?
end end
def require_user_profile_completed(user) def require_user_profile_completed(user)
tip_exception(412, "请用户完善资料后再操作") unless user.profile_is_completed? # tip_exception(412, "请用户完善资料后再操作") unless user.profile_is_completed?
end end
# 异常提醒 # 异常提醒

View File

@ -35,15 +35,15 @@ module LaboratoryHelper
# my_projects: "/users/#{current_user.try(:login)}/projects", # my_projects: "/users/#{current_user.try(:login)}/projects",
# my_projects: "https://www.trustie.net/users/#{current_user.try(:login)}/user_projectlist", # my_projects: "https://www.trustie.net/users/#{current_user.try(:login)}/user_projectlist",
{ {
new_syllabuses: "https://www.trustie.net/syllabuses/new", new_syllabuses: "https://forge.educoder.net/syllabuses/new",
new_course: "https://www.trustie.net/courses/new", new_course: "https://forge.educoder.net/courses/new",
edit_account: "https://www.trustie.net/my/account", edit_account: "https://forge.educoder.net/my/account",
my_courses: "https://www.trustie.net/users/#{current_user.try(:login)}/user_courselist", my_courses: "https://forge.educoder.net/users/#{current_user.try(:login)}/user_courselist",
my_projects: "/users/#{current_user.try(:login)}/projects", my_projects: "/users/#{current_user.try(:login)}/projects",
my_organ: "https://www.trustie.net/users/#{current_user.try(:login)}/user_organizations", my_organ: "https://forge.educoder.net/users/#{current_user.try(:login)}/user_organizations",
default_url: Rails.application.config_for(:configuration)['platform_url'], default_url: "https://www.educoder.net/",
tiding_url: "https://www.trustie.net/users/#{current_user.try(:login)}/user_messages", tiding_url: "https://www.educoder.net/users/#{current_user.try(:login)}/user_tidings",
register_url: "https://www.trustie.net/login?login=false" register_url: "https://www.educoder.net/user/register"
} }
end end
end end

View File

@ -2,8 +2,6 @@ module RegisterHelper
extend ActiveSupport::Concern extend ActiveSupport::Concern
def autologin_register(username, email, password, platform= 'forge') def autologin_register(username, email, password, platform= 'forge')
result = {message: nil, user: nil}
user = User.new(admin: false, login: username, mail: email, type: "User") user = User.new(admin: false, login: username, mail: email, type: "User")
user.password = password user.password = password
user.platform = platform user.platform = platform
@ -11,20 +9,36 @@ module RegisterHelper
return unless user.valid? return unless user.valid?
create_gitea_user!(user, username, email, password)
end
def create_gitea_user!(forge_user, username, email, password=random_password)
result = {message: nil, user: nil}
interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password}) interactor = Gitea::RegisterInteractor.call({username: username, email: email, password: password})
if interactor.success? if interactor.success? || interactor.error.to_s.include?("已被注册")
gitea_user = interactor.result gitea_user = interactor.error.to_s.include?("已被注册") ? Gitea::User::GetService.call(username, password) : interactor.result
result = Gitea::User::GenerateTokenService.call(username, password) Rails.logger.info "##### [gitea] create_gitea_user result: #{gitea_user}"
user.gitea_token = result['sha1'] if gitea_user[:body].present?
user.gitea_uid = gitea_user[:body]['id'] result = Gitea::User::GenerateTokenService.call(username, password)
if user.save! forge_user.gitea_token = result['sha1']
UserExtension.create!(user_id: user.id) forge_user.gitea_uid = gitea_user[:body]['id'] if gitea_user[:body].present? && gitea_user[:body]['id'] !=0
result[:user] = {id: user.id, token: user.gitea_token} forge_user.mail = email
if forge_user.save
UserExtension.create!(user_id: forge_user.id) if forge_user.user_extension.blank?
result[:user] = {id: forge_user.id, token: forge_user.gitea_token}
end
else
result[:message] = interactor.error
end end
else else
Rails.logger.info "##### [gitea] create_gitea_user result: #{interactor.error}"
result[:message] = interactor.error result[:message] = interactor.error
end end
result result
end end
def random_password
"#{Random.rand(11111111)}"
end
end end

View File

@ -6,6 +6,14 @@ class ForksController < ApplicationController
def create def create
@new_project = Projects::ForkService.new(current_user, @project, params[:organization]).call @new_project = Projects::ForkService.new(current_user, @project, params[:organization]).call
# TODO: fix Educoder shixun
if @new_project.persisted?
ProjectScore.create(:project_id => @new_project.id, :score => 0) if @new_project.project_score.nil?
project_info = ProjectInfo.new(:user_id => current_user.id, :project_id => @new_project.id)
@project.project_infos << project_info
end
end end
private private

View File

@ -21,6 +21,14 @@ class MainController < ApplicationController
uid_logger("main start is #{cookies[:_educoder_session]}") uid_logger("main start is #{cookies[:_educoder_session]}")
end end
if params[:path] && params[:path].start_with?('projects/')
project_id = params[:path].split("/")[1]
project = Project.find_by_id(project_id)
if project.present?
return redirect_to("/projects/#{project.owner.login}/#{project.identifier}", status: 301)
end
end
# TODO: 这块之后需要整合者架构重新变化统一跳转到index后再路由分发 # TODO: 这块之后需要整合者架构重新变化统一跳转到index后再路由分发
if params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild" if params[:path] && params[:path]&.include?("h5educoderbuild") && params[:path].split("/").first == "h5educoderbuild"
render file: 'public/h5educoderbuild/index.html', :layout => false, :content_type=> 'text/html' render file: 'public/h5educoderbuild/index.html', :layout => false, :content_type=> 'text/html'

View File

@ -8,6 +8,14 @@ class MembersController < ApplicationController
before_action :check_member_not_exists!, only: %i[remove change_role] before_action :check_member_not_exists!, only: %i[remove change_role]
def create def create
if @user.gitea_token.blank?
result = Gitea::User::GetService.call(@user.login)
if result[:status] == :error
# gitea不存在用户@user,直接注册
user_result = create_gitea_user!(@user, @user.login, @user.mail)
return render_error(user_result[:message]) if user_result[:message]
end
end
interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user) interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user)
SendTemplateMessageJob.perform_later('ProjectJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu? SendTemplateMessageJob.perform_later('ProjectJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu?
SendTemplateMessageJob.perform_later('ProjectMemberJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu? SendTemplateMessageJob.perform_later('ProjectMemberJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu?

View File

@ -49,6 +49,13 @@ class ProjectsController < ApplicationController
Projects::CreateForm.new(project_params).validate! Projects::CreateForm.new(project_params).validate!
@project = Projects::CreateService.new(current_user, project_params).call @project = Projects::CreateService.new(current_user, project_params).call
# TODO: fix Educoder shixun
if @project.persisted?
ProjectScore.create(:project_id => @project.id, :score => 0) if @project.project_score.nil?
project_info = ProjectInfo.new(:user_id => current_user.id, :project_id => @project.id)
@project.project_infos << project_info
end
end end
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)

View File

@ -347,7 +347,7 @@ class RepositoriesController < ApplicationController
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id)) local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id))
if local_requests.save if local_requests.save
gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call gitea_request = Gitea::PullRequest::CreateService.new(current_user.try(:gitea_token), @owner.login, @project.try(:identifier), requests_params).call
if gitea_request[:status] == :success && local_requests.update_attributes(gpid: gitea_request["body"]["number"]) if gitea_request[:status] == :success && local_requests.update_attributes(gitea_number: gitea_request["body"]["number"])
local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create") local_requests.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
end end
end end

View File

@ -1,310 +1,347 @@
class UsersController < ApplicationController class UsersController < ApplicationController
include ApplicationHelper include ApplicationHelper
include Ci::DbConnectable include Ci::DbConnectable
before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard] before_action :load_user, only: [:show, :homepage_info, :sync_token, :sync_gitea_pwd, :projects, :watch_users, :fan_users, :hovercard]
before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard] before_action :check_user_exist, only: [:show, :homepage_info,:projects, :watch_users, :fan_users, :hovercard]
before_action :require_login, only: %i[me list sync_user_info] before_action :require_login, only: %i[me list]
before_action :connect_to_ci_db, only: [:get_user_info] before_action :connect_to_ci_db, only: [:get_user_info]
before_action :convert_image!, only: [:update] before_action :convert_image!, only: [:update]
skip_before_action :check_sign, only: [:attachment_show] skip_before_action :check_sign, only: [:attachment_show]
def connect_to_ci_db(options={}) def connect_to_ci_db(options={})
if !(current_user && !current_user.is_a?(AnonymousUser) && current_user.devops_certification?) if !(current_user && !current_user.is_a?(AnonymousUser) && current_user.devops_certification?)
return return
end end
if current_user.ci_cloud_account.server_type == Ci::CloudAccount::SERVER_TYPE_TRUSTIE if current_user.ci_cloud_account.server_type == Ci::CloudAccount::SERVER_TYPE_TRUSTIE
connect_to_trustie_ci_database(options) connect_to_trustie_ci_database(options)
else else
connect_to_ci_database(options) connect_to_ci_database(options)
end end
end end
def list def list
scope = User.active.recent.like(params[:search]).includes(:user_extension) scope = User.active.recent.like(params[:search]).includes(:user_extension)
@total_count = scope.size @total_count = scope.size
@users = paginate(scope) @users = paginate(scope)
end end
def show def show
#待办事项,现在未做 #待办事项,现在未做
if User.current.admin? || User.current.login == @user.login if User.current.admin? || User.current.login == @user.login
@waiting_applied_messages = @user.applied_messages.waiting @waiting_applied_messages = @user.applied_messages.waiting
@common_applied_transfer_projects = AppliedTransferProject.where(owner_id: @user.id).common + AppliedTransferProject.where(owner_id: Organization.joins(team_users: :team).where(team_users: {user_id: @user.id}, teams: {authorize: %w(admin owner)} )).common @common_applied_transfer_projects = AppliedTransferProject.where(owner_id: @user.id).common + AppliedTransferProject.where(owner_id: Organization.joins(team_users: :team).where(team_users: {user_id: @user.id}, teams: {authorize: %w(admin owner)} )).common
@common_applied_projects = AppliedProject.where(project_id: @user.full_admin_projects).common @common_applied_projects = AppliedProject.where(project_id: @user.full_admin_projects).common
@undo_events = @waiting_applied_messages.size + @common_applied_transfer_projects.size + @common_applied_projects.size @undo_events = @waiting_applied_messages.size + @common_applied_transfer_projects.size + @common_applied_projects.size
else else
@waiting_applied_messages = AppliedMessage.none @waiting_applied_messages = AppliedMessage.none
@common_applied_transfer_projects = AppliedTransferProject.none @common_applied_transfer_projects = AppliedTransferProject.none
@common_applied_projects = AppliedProject.none @common_applied_projects = AppliedProject.none
@undo_events = 0 @undo_events = 0
end end
#用户的组织数量 #用户的组织数量
# @user_composes_count = @user.composes.size # @user_composes_count = @user.composes.size
@user_composes_count = 0 @user_composes_count = 0
user_organizations = User.current.logged? ? @user.organizations.with_visibility(%w(common limited)) + @user.organizations.with_visibility("privacy").joins(:team_users).where(team_users: {user_id: current_user.id}) : @user.organizations.with_visibility("common") user_organizations = User.current.logged? ? @user.organizations.with_visibility(%w(common limited)) + @user.organizations.with_visibility("privacy").joins(:team_users).where(team_users: {user_id: current_user.id}) : @user.organizations.with_visibility("common")
@user_org_count = user_organizations.size @user_org_count = user_organizations.size
normal_projects = Project.members_projects(@user.id).to_sql normal_projects = Project.members_projects(@user.id).to_sql
org_projects = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: @user.id}).to_sql org_projects = Project.joins(team_projects: [team: :team_users]).where(team_users: {user_id: @user.id}).to_sql
projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct projects = Project.from("( #{ normal_projects} UNION #{ org_projects } ) AS projects").distinct
user_projects = User.current.logged? && (User.current.admin? || User.current.login == @user.login) ? projects : projects.visible user_projects = User.current.logged? && (User.current.admin? || User.current.login == @user.login) ? projects : projects.visible
@projects_common_count = user_projects.common.size @projects_common_count = user_projects.common.size
@projects_mirrior_count = user_projects.mirror.size @projects_mirrior_count = user_projects.mirror.size
@projects_sync_mirrior_count = user_projects.sync_mirror.size @projects_sync_mirrior_count = user_projects.sync_mirror.size
end end
def watch_users def watch_users
watchers = Watcher.watching_users(@user.id).includes(:user).order("watchers.created_at desc") watchers = Watcher.watching_users(@user.id).includes(:user).order("watchers.created_at desc")
if params[:search].present? if params[:search].present?
search_user_ids = User.where(id: watchers.pluck(:watchable_id)).like(params[:search]).pluck(:id) search_user_ids = User.where(id: watchers.pluck(:watchable_id)).like(params[:search]).pluck(:id)
watchers = watchers.where(watchable_id: search_user_ids) watchers = watchers.where(watchable_id: search_user_ids)
end end
@watchers_count = watchers.size @watchers_count = watchers.size
@watchers = paginate(watchers) @watchers = paginate(watchers)
end end
def fan_users def fan_users
watchers = @user.watchers.includes(:user).order("watchers.created_at desc") watchers = @user.watchers.includes(:user).order("watchers.created_at desc")
watchers = watchers.joins(:user).merge(User.like(params[:search])) watchers = watchers.joins(:user).merge(User.like(params[:search]))
@watchers_count = watchers.size @watchers_count = watchers.size
@watchers = paginate(watchers) @watchers = paginate(watchers)
end end
def hovercard def hovercard
end end
def update def update
return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id]) return render_not_found unless @user = User.find_by(login: params[:id]) || User.find_by_id(params[:id])
return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id) return render_forbidden unless User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
Util.write_file(@image, avatar_path(@user)) if user_params[:image].present? Util.write_file(@image, avatar_path(@user)) if user_params[:image].present?
@user.attributes = user_params.except(:image) @user.attributes = user_params.except(:image)
unless @user.save unless @user.save
render_error(@user.errors.full_messages.join(", ")) render_error(@user.errors.full_messages.join(", "))
end end
end end
def me def me
@user = current_user @user = current_user
end end
# 贴吧获取用户信接口 # 贴吧获取用户信接口
def get_user_info def get_user_info
begin begin
@user = current_user @user = current_user
begin begin
result = Notice::Read::CountService.call(current_user.id) result = Notice::Read::CountService.call(current_user.id)
@message_unread_total = result.nil? ? 0 : result[2]["unread_notification"] @message_unread_total = result.nil? ? 0 : result[2]["unread_notification"]
rescue rescue
@message_unread_total = 0 @message_unread_total = 0
end end
# TODO 等消息上线再打开注释 # TODO 等消息上线再打开注释
#@tidding_count = unviewed_tiddings(current_user) if current_user.present? #@tidding_count = unviewed_tiddings(current_user) if current_user.present?
rescue Exception => e rescue Exception => e
uid_logger_error(e.message) uid_logger_error(e.message)
missing_template missing_template
end end
end end
def attachment_show def attachment_show
file_name = params[:file_name] file_name = params[:file_name]
path = params[:path] || file_storage_directory path = params[:path] || file_storage_directory
send_file "#{path}/#{file_name}", :filename => "#{file_name}", send_file "#{path}/#{file_name}", :filename => "#{file_name}",
:type => 'game', :type => 'game',
:disposition => 'attachment' #inline can open in browser :disposition => 'attachment' #inline can open in browser
end end
def html_show def html_show
@contents = File.read("#{params[:path]}") @contents = File.read("#{params[:path]}")
respond_to do |format| respond_to do |format|
format.html {render :layout => false} format.html {render :layout => false}
end end
end end
# Redo: 消息总数缓存 # Redo: 消息总数缓存
def get_navigation_info def get_navigation_info
# @old_domain = edu_setting('old_edu_host') # @old_domain = edu_setting('old_edu_host')
# @user = current_user # @user = current_user
# # 新消息数 # # 新消息数
# @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0 # @new_message = @user.tidings.where("created_at > '#{@user.click_time}'").count > 0 || @user.private_messages.where("created_at > '#{@user.click_time}'").count > 0
# #
# @user_url = "/users/#{@user.login}" # @user_url = "/users/#{@user.login}"
# @career = Career.where(status: true).order("created_at asc").pluck(:id, :name) # @career = Career.where(status: true).order("created_at asc").pluck(:id, :name)
# @auth = User.current.ec_school.present? ? "#{@old_domain}/ecs/department?school_id=#{User.current.ec_school}" : nil # @auth = User.current.ec_school.present? ? "#{@old_domain}/ecs/department?school_id=#{User.current.ec_school}" : nil
end end
# 用户回复功能 # 用户回复功能
def reply_message def reply_message
message = JournalsForMessage.new(reply_message_params) message = JournalsForMessage.new(reply_message_params)
message.user_id = current_user.id message.user_id = current_user.id
message.save! message.save!
render_ok(id: message.id) render_ok(id: message.id)
end end
# 搜索用户具有管理员角色的项目 # 搜索用户具有管理员角色的项目
def search_user_projects def search_user_projects
projects = Project.where.not(status: 9) projects = Project.where.not(status: 9)
projects = projects.joins(members: :member_roles).where(member_roles: { role_id: 3 }) projects = projects.joins(members: :member_roles).where(member_roles: { role_id: 3 })
projects = projects.where(members: { user_id: current_user.id }) projects = projects.where(members: { user_id: current_user.id })
search = params[:search].to_s.strip search = params[:search].to_s.strip
projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present? projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present?
@projects = projects.select(:id, :name) @projects = projects.select(:id, :name)
end end
#TODO 个人主页信息forge上弃用-hs, 0602 #TODO 个人主页信息forge上弃用-hs, 0602
def homepage_info def homepage_info
#待办事项,现在未做 #待办事项,现在未做
@undo_events = 10 @undo_events = 10
#用户的组织数量 #用户的组织数量
# @user_composes_count = @user.composes.size # @user_composes_count = @user.composes.size
@user_composes_count = 10 @user_composes_count = 10
end end
def brief_introduction def brief_introduction
content = params[:content].to_s.strip content = params[:content].to_s.strip
current_user.user_extension.update!(brief_introduction: content) current_user.user_extension.update!(brief_introduction: content)
render_ok render_ok
end end
def attendance def attendance
attendance = Users::AttendanceService.call(current_user) attendance = Users::AttendanceService.call(current_user)
render_ok(grade: current_user.grade, next_gold: attendance.next_gold) render_ok(grade: current_user.grade, next_gold: attendance.next_gold)
rescue Users::AttendanceService::Error => ex rescue Users::AttendanceService::Error => ex
render_error(ex.message) render_error(ex.message)
end end
# 其他平台登录后必须将token同步到forge平台实现sso登录功能 # 其他平台登录后必须将token同步到forge平台实现sso登录功能
def sync_token def sync_token
return render_error('未找相关用户!') unless @user 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')
token.update_column(:value, params[:token]) token.update_column(:value, params[:token])
render_ok render_ok
end end
def trustie_related_projects def trustie_related_projects
projects = Project.includes(:owner, :members, :project_score).where(id: params[:ids]).order("updated_on desc") projects = Project.includes(:owner, :members, :project_score).where(id: params[:ids]).order("updated_on desc")
projects_json = [] projects_json = []
domain_url = EduSetting.get('host_name') + '/projects' domain_url = EduSetting.get('host_name') + '/projects'
if projects.present? if projects.present?
projects.each do |p| projects.each do |p|
project_url = "/#{p.owner.login}/#{p.identifier}" project_url = "/#{p.owner.login}/#{p.identifier}"
pj = { pj = {
id: p.id, id: p.id,
name: p.name, name: p.name,
is_public: p.is_public, is_public: p.is_public,
updated_on: p.updated_on.strftime("%Y-%m-%d"), updated_on: p.updated_on.strftime("%Y-%m-%d"),
status: p.status, status: p.status,
is_member: p.member?(current_user.try(:id)), is_member: p.member?(current_user.try(:id)),
owner: { owner: {
name: p.owner.try(:show_real_name), name: p.owner.try(:show_real_name),
login: p.owner.login login: p.owner.login
}, },
members_count: p&.members.size, members_count: p&.members.size,
issues_count: p.issues_count - p.pull_requests_count, issues_count: p.issues_count - p.pull_requests_count,
commits_count: p&.project_score&.changeset_num.to_i, commits_count: p&.project_score&.changeset_num.to_i,
http_url: domain_url + project_url, http_url: domain_url + project_url,
http_collaborator_url: domain_url + project_url + "/setting/collaborator", http_collaborator_url: domain_url + project_url + "/setting/collaborator",
http_issues_url: domain_url + project_url + "/issues", http_issues_url: domain_url + project_url + "/issues",
http_commits_url: domain_url + project_url + "/commits", http_commits_url: domain_url + project_url + "/commits",
project_score: p&.project_score.present? ? p&.project_score&.as_json(:except=>[:created_at, :updated_at]).merge!(commit_time: format_time(p&.project_score&.commit_time)) : {} project_score: p&.project_score.present? ? p&.project_score&.as_json(:except=>[:created_at, :updated_at]).merge!(commit_time: format_time(p&.project_score&.commit_time)) : {}
} }
projects_json.push(pj) projects_json.push(pj)
end end
end end
Rails.logger.info("==========projects_json========+########{projects_json}") Rails.logger.info("==========projects_json========+########{projects_json}")
render json: { projects: projects_json.present? ? projects_json : {} } render json: { projects: projects_json.present? ? projects_json : {} }
end end
def trustie_projects def trustie_projects
user_id = User.select(:id, :login).where(login: params[:login])&.first&.id user_id = User.select(:id, :login).where(login: params[:login])&.first&.id
projects = Project.visible projects = Project.visible
projects = projects.joins(:members).where(members: { user_id: user_id }) projects = projects.joins(:members).where(members: { user_id: user_id })
search = params[:search].to_s.strip search = params[:search].to_s.strip
projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present? projects = projects.where('projects.name LIKE ?', "%#{search}%") if search.present?
projects = projects.select(:id, :name).limit(10).as_json projects = projects.select(:id, :name).limit(10).as_json
render json: { projects: projects } render json: { projects: projects }
end end
def projects def projects
is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id) is_current_admin_user = User.current.logged? && (current_user&.admin? || current_user.id == @user.id)
scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user) scope = Projects::ListMyQuery.call(params, @user,is_current_admin_user)
@total_count = scope.size @total_count = scope.size
@projects = paginate(scope) @projects = paginate(scope)
end end
# TODO 其他平台登录时同步修改gitea平台对应用户的密码 # TODO 其他平台登录时同步修改gitea平台对应用户的密码
# 该方法主要用于别的平台初次部署对接forge平台同步用户后gitea平台对应的用户密码与forge平台用户密码不一致是问题 # 该方法主要用于别的平台初次部署对接forge平台同步用户后gitea平台对应的用户密码与forge平台用户密码不一致是问题
def sync_gitea_pwd def sync_gitea_pwd
return render_error("未找到相关的用户") if @user.blank? return render_error("未找到相关的用户") if @user.blank?
flag = sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) flag = sync_pwd_to_gitea!(@user, {password: params[:password].to_s})
flag ? render_ok : render_error('同步失败!') flag ? render_ok : render_error('同步失败!')
end end
# TODO # TODO
# 同步trusite平台用户的salt信息只需同步一次同步完成后该方法可以删除 # 同步trusite平台用户的salt信息只需同步一次同步完成后该方法可以删除
def sync_salt def sync_salt
user = User.find_by_login params[:login] user = User.find_by_login params[:login]
return if user.blank? return if user.blank?
user.update_column(:salt, params[:salt]) user.update_column(:salt, params[:salt])
render_ok render_ok
end end
def sync_user_info # TODO: For Educoder
user = User.find_by_login params[:login] def change_password
return render_forbidden unless user === current_user user = User.find_by_login params[:login]
return render_error("用户 #{params[:login]} 不存在.") if user.nil?
sync_params = {
email: params[:email], form_params= {
password: params[:password] login: params[:login],
} email: user&.mail,
password: params[:password],
Users::UpdateInfoForm.new(sync_params.merge(login: params[:login])).validate! user: user
}
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params) Gitea::User::ChangePasswordForm.new(form_params).validate!
if interactor.success?
user.update!(password: params[:password], mail: params[:email], status: User::STATUS_EDIT_INFO) sync_params = {
render_ok email: user&.mail,
else password: params[:password]
render_error(interactor.error) }
end
end if sync_params.present?
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
private if interactor.success?
def load_user user.update!(password: params[:password], is_sync_pwd: true)
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id]) render_ok
end else
render_error(interactor.error)
def user_params end
params.require(:user).permit(:nickname, :image, end
user_extension_attributes: [ end
:gender, :location, :location_city,
:occupation, :technical_title, # TODO: For Educoder
:school_id, :department_id, :province, :city, def change_email
:custom_department, :identity, :student_id, :description, user = User.find_by_login params[:login]
:show_email, :show_location, :show_department] return render_error("用户 #{rq_params[:login]} 不存在.") if user.nil?
)
end form_params= {
login: params[:login],
def reply_message_params email: user&.mail,
normal_status(-1, "参数不对") if params[:journals_for_message][:jour_type].nil? || params[:journals_for_message][:jour_id].nil? || user: user
params[:journals_for_message][:notes].nil? || params[:journals_for_message][:reply_id].nil? }
params.require(:journals_for_message).permit(:jour_type, :jour_id, :notes, :m_parent_id, :reply_id)
end Gitea::User::ChangeEmailForm.new(form_params).validate!
def check_user_exist sync_params = {
return if @user.present? email: params[:email]
render_not_found }
end
if sync_params.present?
end interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
if interactor.success?
user.update!(mail: params[:email])
render_ok
else
render_error(interactor.error)
end
end
end
private
def load_user
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])
end
def user_params
params.require(:user).permit(:nickname, :image,
user_extension_attributes: [
:gender, :location, :location_city,
:occupation, :technical_title,
:school_id, :department_id, :province, :city,
:custom_department, :identity, :student_id, :description,
:show_email, :show_location, :show_department]
)
end
def reply_message_params
normal_status(-1, "参数不对") if params[:journals_for_message][:jour_type].nil? || params[:journals_for_message][:jour_id].nil? ||
params[:journals_for_message][:notes].nil? || params[:journals_for_message][:reply_id].nil?
params.require(:journals_for_message).permit(:jour_type, :jour_id, :notes, :m_parent_id, :reply_id)
end
def check_user_exist
return if @user.present?
render_not_found
end
end

View File

@ -0,0 +1,9 @@
class Gitea::User::ChangeEmailForm
include ActiveModel::Model
attr_accessor :user
attr_accessor :email, :login
validates :email, presence: true, format: { with: CustomRegexp::EMAIL }
validates :login, presence: true
end

View File

@ -0,0 +1,22 @@
class Gitea::User::ChangePasswordForm
include ActiveModel::Model
attr_accessor :user
attr_accessor :email, :login, :password
validates :email, presence: true, format: { with: CustomRegexp::EMAIL }
validates :login, presence: true
validates :password, presence: true
# validate :check_old_password
def check_old_password
return if user.check_password?(old_password.to_s)
errors.add(:old_password, :password_error)
end
# def check_user!
# user === current_user
# end
end

View File

@ -0,0 +1,18 @@
class Users::SyncGiteaForm
include ActiveModel::Model
attr_accessor :login, :password, :email, :user
validates :login, :password, :email, presence: true
validate :check_user, :check_password
def check_user
user = User.find_by(login: login)
raise '用户不存在.' unless user.present?
end
def check_password
raise '用户密码错误.' unless user.check_password?(password)
end
end

View File

@ -23,13 +23,17 @@ module Gitea
def run def run
Gitea::UserForm.new(params).validate! Gitea::UserForm.new(params).validate!
response = Gitea::User::RegisterService.call(params.merge(token: token)) response = Gitea::User::RegisterService.call(params.merge(token: token))
render_result(response)
if response[:status] == :success
@result = response
else
fail!(response[:message])
end
rescue Exception => exception rescue Exception => exception
Rails.logger.info "Exception ===========> #{exception.message}" Rails.logger.info "Exception ===========> #{exception.message}"
fail!(exception.message) fail!(exception.message)
end end
private private
attr_reader :params attr_reader :params
@ -38,10 +42,6 @@ module Gitea
@error = error @error = error
end end
def render_result(response)
@result = response
end
def token def token
{ {
username: Gitea.gitea_config[:access_key_id], username: Gitea.gitea_config[:access_key_id],

View File

@ -39,6 +39,6 @@ class Gitea::Pull < Gitea::Base
serialize :conflicted_files, Array serialize :conflicted_files, Array
belongs_to :pull_request, class_name: '::PullRequest', foreign_key: :id, primary_key: :gitea_number, optional: true belongs_to :pull_request, class_name: '::PullRequest', foreign_key: :id, primary_key: :gitea_id, optional: true
end end

View File

@ -1,4 +1,3 @@
# == Schema Information # == Schema Information
# #
# Table name: projects # Table name: projects
@ -38,8 +37,6 @@
# rep_identifier :string(255) # rep_identifier :string(255)
# project_category_id :integer # project_category_id :integer
# project_language_id :integer # project_language_id :integer
# license_id :integer
# ignore_id :integer
# praises_count :integer default("0") # praises_count :integer default("0")
# watchers_count :integer default("0") # watchers_count :integer default("0")
# issues_count :integer default("0") # issues_count :integer default("0")
@ -53,9 +50,10 @@
# open_devops_count :integer default("0") # open_devops_count :integer default("0")
# recommend :boolean default("0") # recommend :boolean default("0")
# platform :integer default("0") # platform :integer default("0")
# license_id :integer
# ignore_id :integer
# default_branch :string(255) default("master") # default_branch :string(255) default("master")
# website :string(255) # website :string(255)
# order_index :integer default("0")
# lesson_url :string(255) # lesson_url :string(255)
# #
# Indexes # Indexes
@ -78,7 +76,6 @@
# #
class Project < ApplicationRecord class Project < ApplicationRecord
include Matchable include Matchable
include Publicable include Publicable
@ -110,6 +107,7 @@ class Project < ApplicationRecord
has_one :project_educoder, dependent: :destroy has_one :project_educoder, dependent: :destroy
has_one :project_score, dependent: :destroy has_one :project_score, dependent: :destroy
has_many :project_infos, :dependent => :destroy
has_one :repository, dependent: :destroy has_one :repository, dependent: :destroy
has_many :pull_requests, dependent: :destroy has_many :pull_requests, dependent: :destroy
has_many :issue_tags, -> { order("issue_tags.created_at DESC") }, dependent: :destroy has_many :issue_tags, -> { order("issue_tags.created_at DESC") }, dependent: :destroy

View File

@ -0,0 +1,19 @@
# == Schema Information
#
# Table name: project_infos
#
# id :integer not null, primary key
# project_id :integer
# user_id :integer
# created_at :datetime not null
# updated_at :datetime not null
#
class ProjectInfo < ActiveRecord::Base
belongs_to :project
belongs_to :user
validates_presence_of :project_id, :user_id
validates_uniqueness_of :project_id, :scope => :user_id
end

View File

@ -16,7 +16,7 @@
class ProjectUnit < ApplicationRecord class ProjectUnit < ApplicationRecord
belongs_to :project belongs_to :project
enum unit_type: {code: 1, issues: 2, pulls: 3, wiki:4, devops: 5, versions: 6, resources: 7} enum unit_type: {code: 1, issues: 2, pulls: 3, devops: 4, versions: 5, resources: 6, gantt: 7, sonar: 8}
validates :unit_type, uniqueness: { scope: :project_id} validates :unit_type, uniqueness: { scope: :project_id}

View File

@ -3,8 +3,8 @@
# Table name: pull_requests # Table name: pull_requests
# #
# id :integer not null, primary key # id :integer not null, primary key
# pull_request_id :integer # gitea_id :integer
# gpid :integer # gitea_number :integer
# user_id :integer # user_id :integer
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
@ -37,7 +37,7 @@ class PullRequest < ApplicationRecord
has_many :pull_request_tags, foreign_key: :pull_request_id has_many :pull_request_tags, foreign_key: :pull_request_id
has_many :project_trends, as: :trend, dependent: :destroy has_many :project_trends, as: :trend, dependent: :destroy
has_many :attachments, as: :container, dependent: :destroy has_many :attachments, as: :container, dependent: :destroy
has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_number, class_name: 'Gitea::Pull' has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_id, class_name: 'Gitea::Pull'
scope :merged_and_closed, ->{where.not(status: 0)} scope :merged_and_closed, ->{where.not(status: 0)}
scope :opening, -> {where(status: 0)} scope :opening, -> {where(status: 0)}

View File

@ -631,9 +631,16 @@ class User < Owner
# 工程认证的学校 # 工程认证的学校
def ec_school def ec_school
school_id = self.ec_school_users.pluck(:school_id).first || school_id_hash = ActiveRecord::Base.connection.exec_query("SELECT `ec_school_users`.`school_id` FROM `ec_school_users` WHERE `ec_school_users`.`user_id` = #{self.id}").first ||
self.ec_major_schools.pluck(:school_id).first || ActiveRecord::Base.connection.exec_query("SELECT `ec_major_schools`.`school_id` FROM `ec_major_schools` INNER JOIN `ec_major_school_users` ON `ec_major_schools`.`id` = `ec_major_school_users`.`ec_major_school_id` WHERE`ec_major_school_users`.`user_id` = #{self.id}").first ||
(self.ec_course_users.first && self.ec_course_users.first.try(:ec_course).try(:ec_year).try(:ec_major_school).try(:school_id)) ActiveRecord::Base.connection.exec_query("SELECT `ec_major_schools`.`school_id` FROM `ec_major_schools` INNER JOIN `ec_years` ON `ec_years`.`ec_major_school_id` = `ec_major_schools`.`id` INNER JOIN `ec_courses` ON `ec_courses`.`ec_year_id` = `ec_years`.`id` INNER JOIN `ec_course_users` ON `ec_course_users`.`ec_course_id` = `ec_courses`.`id` WHERE `ec_course_users`.`user_id` = #{self.id}").first
if school_id_hash.nil?
return nil
else
school_id_hash["school_id"]
end
rescue
nil
end end
# 登录,返回用户名与密码匹配的用户 # 登录,返回用户名与密码匹配的用户
@ -760,7 +767,8 @@ class User < Owner
end end
def profile_is_completed? def profile_is_completed?
self.nickname.present? && self.gender.present? && self.mail.present? && self.custom_department.present? # self.nickname.present? && self.gender.present? && self.mail.present? && self.custom_department.present?
true
end end
protected protected

View File

@ -24,7 +24,7 @@
# #
class Version < ApplicationRecord class Version < ApplicationRecord
belongs_to :project, counter_cache: true, touch: true belongs_to :project, counter_cache: true, touch: true, optional: true
has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id" has_many :issues, class_name: "Issue", foreign_key: "fixed_version_id"
belongs_to :user, optional: true belongs_to :user, optional: true

View File

@ -0,0 +1,42 @@
class Gitea::User::GetService < Gitea::ClientService
attr_reader :username, :password
# params:
# username* string # required
def initialize(username, password = "")
@username = username
@password = password
end
def call
params = Hash.new.merge(token: token_params, data: params)
response = get(url, params)
status, message, body = render_response(response)
json_format(status, message, body)
end
private
def url
"/users/#{username}"
end
def token_params
{
username: username,
password: password
}
end
def params
{username: username}
end
def json_format(status, message, body)
case status
when 200 then success(body)
else
error(message, status)
end
end
end

View File

@ -10,8 +10,7 @@ class Gitea::User::RegisterService < Gitea::ClientService
params = Hash.new.merge(data: user_params, token: @token) params = Hash.new.merge(data: user_params, token: @token)
response = post(API_REST, params) response = post(API_REST, params)
status, message, body = render_response(response) response_payload(response)
json_format(status, message, body)
end end
private private
@ -27,11 +26,28 @@ class Gitea::User::RegisterService < Gitea::ClientService
} }
end end
def json_format(status, message, body) def response_payload(response)
status = response.status
body = response&.body
log_error(status, body)
status_payload(status, body)
end
def status_payload(status, body)
case status case status
when 201 then success(body) when 201 then success(json_parse!(body))
else when 403 then error("你没有权限操作!")
error(message, status) when 400 then error("服务器开小差了")
when 422
body = json_parse!(body)
message = body['message']
if message.include?('email')
error("邮箱#{email}已被注册,请在账号管理更换邮箱!")
elsif message.include?('name')
error("用户名#{username}已被注册")
end
else error("系统错误!")
end end
end end

View File

@ -9,10 +9,11 @@
<% end %> <% end %>
</td> </td>
<td> <td>
<% if school && school.identifier.present? %> <%# if school && school.identifier.present? %>
<% else %> <%#= link_to school.identifier.to_s, statistics_college_path(school.identifier), target: '_blank' %>
<%# else %>
-- --
<% end %> <%# end %>
</td> </td>
<td class="member-container"> <td class="member-container">
<div class="laboratory-user"> <div class="laboratory-user">

View File

@ -1,2 +1,2 @@
json.extract! @project, :id, :name,:identifier json.extract! @project, :id, :name,:identifier
json.login @project&.owner.login json.login @project&.owner&.login

View File

@ -64,4 +64,10 @@ json.setting do
else else
json.system_notification nil json.system_notification nil
end end
if current_user.ec_school.blank?
json.engineer_url nil
else
json.engineer_url "#{EduSetting.get('engineer_education')}/ecs/department?school_id=#{current_user.ec_school}"
end
end end

View File

@ -7,11 +7,13 @@ json.user_id @user.id
json.image_url url_to_avatar(@user) json.image_url url_to_avatar(@user)
json.admin @user.admin? json.admin @user.admin?
json.is_teacher @user.user_extension&.teacher? json.is_teacher @user.user_extension&.teacher?
json.has_gitea_user @user.gitea_token.present? && @user.gitea_uid.present?
json.is_sync_pwd @user.is_sync_pwd
json.user_identity @user.identity json.user_identity @user.identity
json.tidding_count 0 json.tidding_count 0
json.user_phone_binded @user.phone.present? json.user_phone_binded @user.phone.present?
# json.phone @user.phone # json.phone @user.phone
# json.email @user.mail json.email @user.mail
json.profile_completed @user.profile_is_completed? json.profile_completed @user.profile_is_completed?
json.professional_certification @user.professional_certification json.professional_certification @user.professional_certification
json.devops_step @user.devops_step json.devops_step @user.devops_step
@ -22,4 +24,4 @@ json.city @user.city
json.custom_department @user.custom_department json.custom_department @user.custom_department
json.description @user.description json.description @user.description
json.(@user, :show_email, :show_department, :show_location) json.(@user, :show_email, :show_department, :show_location)
json.message_unread_total @message_unread_total json.message_unread_total @message_unread_total

View File

@ -5,27 +5,13 @@
周永康 周永康
李德生 李德生
王岐山 王岐山
姚依林
回良玉
李源潮
李干成
戴秉国 戴秉国
刘延东 刘延东
刘瑞龙
俞正声 俞正声
薄熙来 薄熙来
薄一波 薄一波
周小川
周建南
温云松
江绵康
李小鹏
李小琳
朱云来
让国人愤怒的第二代身份证 让国人愤怒的第二代身份证
文化大革命 文化大革命
胡海峰
陈良宇
老丁 老丁
莱仕德事件 莱仕德事件
fuck fuck
@ -335,7 +321,6 @@ H漫画
轮盘机 轮盘机
百家乐 百家乐
连线机 连线机
模拟机
彩票机 彩票机
礼品机 礼品机
卢跃刚 卢跃刚
@ -357,7 +342,6 @@ H漫画
学生暴动 学生暴动
镇压学生 镇压学生
广安第二人民医院 广安第二人民医院
胡新宇
趙紫陽 趙紫陽
自由亚州 自由亚州
践踏中国女性 践踏中国女性
@ -440,7 +424,6 @@ H漫画
红海湾 红海湾
升达 升达
沈阳公安 沈阳公安
拦截器
阻无通畅 阻无通畅
民为法执 民为法执
尾行 尾行
@ -486,50 +469,14 @@ H漫画
生成身份证 生成身份证
华国锋 华国锋
叶剑英 叶剑英
李先念
汪东兴
韦国清
乌兰夫
刘伯承
许世友
纪登奎
苏振华
余秋里
张廷发
陈永贵
陈锡联
耿飚 耿飚
聂荣臻 聂荣臻
倪志福 倪志福
徐向前
邓颖超
杨尚昆
杨得志
宋任穷
胡乔木
胡耀邦 胡耀邦
廖承志
秦基伟
陈慕华
田纪云
李铁映
李锡铭
杨汝岱
吴学谦
胡启立 胡启立
芮杏文 芮杏文
杨白冰 杨白冰
邹家华
谭绍文 谭绍文
王汉斌
任建新
于永波
傅全有
王乐泉
王兆国
刘云山
张立昌
张德江
隐形耳机 隐形耳机
隐形摄像头 隐形摄像头
裸聊 裸聊
@ -593,17 +540,6 @@ a级情片
暴政 暴政
北韩 北韩
藏独 藏独
曹长青
曹刚川
陈炳基
陈破空
陈希同
陈小同
陈宣良
陈一谘
陈总统
程铁军
迟浩田
持不同政见 持不同政见
赤匪 赤匪
赤化 赤化
@ -634,11 +570,6 @@ a级情片
发轮 发轮
发正念 发正念
法愣 法愣
法抡
法仑
法伦
法轮
法论
反封锁技术 反封锁技术
反腐败论坛 反腐败论坛
反共 反共
@ -653,7 +584,6 @@ a级情片
台独 台独
轮功 轮功
李红痔 李红痔
李宏志
真善忍 真善忍
炼功 炼功
李总统 李总统
@ -673,7 +603,6 @@ a级情片
强迫 强迫
色情 色情
三級 三級
三级
A片 A片
喷精 喷精
偷窥 偷窥
@ -682,7 +611,6 @@ A片
被迫 被迫
被逼 被逼
强暴 强暴
口技
破处 破处
精液 精液
幼交 幼交
@ -836,7 +764,6 @@ A片
避孕套 避孕套
你妈逼 你妈逼
大鸡巴 大鸡巴
政治
卖春 卖春
买春 买春
朱容基 朱容基
@ -870,11 +797,6 @@ A片
张五常 张五常
张丕林 张丕林
空难 空难
吴邦国
曾庆红
黄菊
吴官正
贾庆林
专制 专制
大紀元 大紀元
江澤民 江澤民
@ -927,7 +849,6 @@ A片
郭岩华 郭岩华
国家安全 国家安全
国家机密 国家机密
国军
国贼 国贼
韩东方 韩东方
韩联潮 韩联潮
@ -989,14 +910,6 @@ A片
劳教 劳教
老江 老江
老毛 老毛
黎安友
李洪宽
李继耐
李兰菊
李少民
李淑娴
李旺阳
李文斌
李月月鸟 李月月鸟
李志绥 李志绥
连胜德 连胜德
@ -1006,28 +919,6 @@ A片
两岸关系 两岸关系
两岸三地论坛 两岸三地论坛
两个中国 两个中国
廖锡龙
林保华
林长盛
林樵清
林慎立
刘宾深
刘宾雁
刘国凯
刘华清
刘俊国
刘凯中
刘千石
刘山青
刘士贤
刘文胜
刘晓波
刘晓竹
刘永川
龙虎豹
陆委会
吕京花
吕秀莲
抡功 抡功
轮大 轮大
罗礼诗 罗礼诗
@ -1087,10 +978,6 @@ A片
双十节 双十节
水扁 水扁
税力 税力
司马晋
司马璐
司徒华
斯诺
四川独立 四川独立
宋书元 宋书元
苏绍智 苏绍智
@ -1112,95 +999,35 @@ A片
统战 统战
屠杀 屠杀
外交与方略 外交与方略
万润南
万晓东
王宝森
王炳章
王超华
王辅臣
王涵万
王沪宁
王军涛
王力雄
王瑞林
王润生
王若望
王希哲
王秀丽
王冶坪
网特
魏新生 魏新生
温元凯 温元凯
文革 文革
无界浏览器 无界浏览器
吴百益
吴方城
吴弘达
吴宏达
吴仁华
吴学灿
吴学璨
吾尔开希 吾尔开希
五不 五不
洗脑 洗脑
项怀诚 项怀诚
项小吉 项小吉
邪恶 邪恶
谢长廷
谢选骏
谢中之
辛灏年
新观察论坛 新观察论坛
新华内情 新华内情
新闻封锁 新闻封锁
新语丝 新语丝
信用危机 信用危机
邢铮
熊炎
熊焱
徐邦秦
徐才厚
徐匡迪
徐水良
许家屯
学潮 学潮
学自联 学自联
雪山狮子 雪山狮子
严家其
严家祺
阎明复
颜射 颜射
央视内部晚会 央视内部晚会
杨怀安
杨建利
杨月清
姚月谦
一中一台 一中一台
异见人士 异见人士
异议人士 异议人士
易丹轩
易志熹
尹庆民
由喜贵
游行 游行
于大海
于浩成
余英时
舆论反制 舆论反制
宇明网 宇明网
远志明 远志明
贼民 贼民
曾培炎 曾培炎
张伯笠
张宏堡
张万年
张伟国
张昭富
张志清
赵海青
赵品潞
赵晓微
赵紫阳
镇压 镇压
争鸣论坛 争鸣论坛
正见网 正见网
@ -1261,8 +1088,6 @@ fa轮
中华民国 中华民国
钟山风雨论坛 钟山风雨论坛
江ze民 江ze民
周锋锁
周天法
陈水扁 陈水扁
朱嘉明 朱嘉明
二逼 二逼
@ -1356,17 +1181,11 @@ B样
成人书库 成人书库
淫图 淫图
交媾 交媾
护士
自拍
大片
夫妻
流血
小穴 小穴
少妇 少妇
北京当局 北京当局
北京之春 北京之春
北美自由论坛 北美自由论坛
博讯
蔡崇国 蔡崇国
大纪元新闻网 大纪元新闻网
大众真人真事 大众真人真事
@ -1375,4 +1194,13 @@ B样
江猪媳 江猪媳
酱猪媳 酱猪媳
枪支 枪支
毒品 毒品
报警
杀人
垃圾
垃 圾
傻 逼
真蠢
蠢猪
徐才厚
才厚

View File

@ -0,0 +1,17 @@
'zh-CN':
activemodel:
attributes:
gitea/user/change_password_form:
user: ''
email: 邮箱
login: 用户名
old_password: 旧密码
password: 新密码
errors:
models:
gitea/user/change_password_form:
attributes:
old_password:
password_error: 错误
user:
not_exist: 不存在

View File

@ -192,6 +192,7 @@ Rails.application.routes.draw do
get :logout get :logout
get :get_verification_code get :get_verification_code
get :valid_email_and_phone get :valid_email_and_phone
post :gitea_register
post :remote_register post :remote_register
post :remote_update post :remote_update
post :remote_login post :remote_login
@ -227,7 +228,8 @@ Rails.application.routes.draw do
post :sync_salt post :sync_salt
get :trustie_projects get :trustie_projects
get :trustie_related_projects get :trustie_related_projects
post :sync_user_info post :change_password
post :change_email
scope '/ci', module: :ci do scope '/ci', module: :ci do
scope do scope do

View File

@ -1,5 +1,5 @@
class AddPlatformToUsers < ActiveRecord::Migration[5.2] class AddPlatformToUsers < ActiveRecord::Migration[5.2]
def change def change
# add_column :users, :platform, :string, default: 0 add_column :users, :platform, :string, default: 0
end end
end end

View File

@ -1,5 +1,5 @@
class AddGiteaTokenToUsers < ActiveRecord::Migration[5.2] class AddGiteaTokenToUsers < ActiveRecord::Migration[5.2]
def change def change
# add_column :users, :gitea_token, :string add_column :users, :gitea_token, :string
end end
end end

View File

@ -1,6 +1,6 @@
class AddProjectCategoryIdAndProjectLanguageIdToProjects < ActiveRecord::Migration[5.2] class AddProjectCategoryIdAndProjectLanguageIdToProjects < ActiveRecord::Migration[5.2]
def change def change
# add_column :projects, :project_category_id, :integer add_column :projects, :project_category_id, :integer
# add_column :projects, :project_language_id, :integer add_column :projects, :project_language_id, :integer
end end
end end

View File

@ -1,7 +1,7 @@
class AddUserRefToRepository < ActiveRecord::Migration[5.2] class AddUserRefToRepository < ActiveRecord::Migration[5.2]
def change def change
# add_column :repositories, :user_id, :integer add_column :repositories, :user_id, :integer
# add_index :repositories, :user_id add_index :repositories, :user_id
Project.joins(:repository).find_each do |project| Project.joins(:repository).find_each do |project|
project&.repository&.update_column(:user_id, project&.user_id) unless project&.repository.blank? project&.repository&.update_column(:user_id, project&.user_id) unless project&.repository.blank?

View File

@ -1,5 +1,5 @@
class AddGiteaUidToUsers < ActiveRecord::Migration[5.2] class AddGiteaUidToUsers < ActiveRecord::Migration[5.2]
def change def change
# add_column :users, :gitea_uid, :integer add_column :users, :gitea_uid, :integer
end end
end end

View File

@ -1,5 +1,5 @@
class AddMirrorUrlToRepositories < ActiveRecord::Migration[5.2] class AddMirrorUrlToRepositories < ActiveRecord::Migration[5.2]
def change def change
# add_column :repositories, :mirror_url, :string add_column :repositories, :mirror_url, :string
end end
end end

View File

@ -1,14 +1,14 @@
class CreateIssueTags < ActiveRecord::Migration[5.2] class CreateIssueTags < ActiveRecord::Migration[5.2]
def change def change
# create_table :issue_tags do |t| create_table :issue_tags do |t|
# t.string :title t.string :title
# t.string :description t.string :description
# t.string :color t.string :color
# t.integer :user_id t.integer :user_id
# t.integer :project_id t.integer :project_id
# t.integer :issues_count,default: 0 t.integer :issues_count,default: 0
# t.timestamps t.timestamps
# end end
# add_index :issue_tags, [:user_id, :title,:project_id] add_index :issue_tags, [:user_id, :title,:project_id]
end end
end end

View File

@ -1,5 +1,5 @@
class AddPraisesCountToProjects < ActiveRecord::Migration[5.2] class AddPraisesCountToProjects < ActiveRecord::Migration[5.2]
def change def change
# add_column :projects, :praises_count, :integer, :default => 0 add_column :projects, :praises_count, :integer, :default => 0
end end
end end

View File

@ -1,8 +1,8 @@
class AddIssuesTypeAndToken < ActiveRecord::Migration[5.2] class AddIssuesTypeAndToken < ActiveRecord::Migration[5.2]
def change def change
# add_column :issues, :issue_type, :string add_column :issues, :issue_type, :string
# add_column :issues, :token, :string add_column :issues, :token, :string
# add_column :issues, :issue_tag_ids, :string add_column :issues, :issue_tag_ids, :string
end end
end end

View File

@ -1,5 +1,5 @@
class RenameIssueTagTitle < ActiveRecord::Migration[5.2] class RenameIssueTagTitle < ActiveRecord::Migration[5.2]
def change def change
# rename_column :issue_tags, :title, :name rename_column :issue_tags, :title, :name
end end
end end

View File

@ -1,10 +1,10 @@
class CreateIssueTagsRelates < ActiveRecord::Migration[5.2] class CreateIssueTagsRelates < ActiveRecord::Migration[5.2]
def change def change
# create_table :issue_tags_relates do |t| create_table :issue_tags_relates do |t|
# t.integer :issue_id t.integer :issue_id
# t.integer :issue_tag_id t.integer :issue_tag_id
# t.timestamps t.timestamps
# end end
# add_index :issue_tags_relates, [:issue_id, :issue_tag_id] add_index :issue_tags_relates, [:issue_id, :issue_tag_id]
end end
end end

View File

@ -1,5 +1,5 @@
class RenameIssuesIssueTagIds < ActiveRecord::Migration[5.2] class RenameIssuesIssueTagIds < ActiveRecord::Migration[5.2]
def change def change
# rename_column :issues, :issue_tag_ids, :issue_tags_value rename_column :issues, :issue_tag_ids, :issue_tags_value
end end
end end

View File

@ -1,13 +1,13 @@
class CreateIssueTimes < ActiveRecord::Migration[5.2] class CreateIssueTimes < ActiveRecord::Migration[5.2]
def change def change
# create_table :issue_times do |t| create_table :issue_times do |t|
# t.integer :issue_id t.integer :issue_id
# t.integer :user_id t.integer :user_id
# t.datetime :start_time t.datetime :start_time
# t.datetime :end_time t.datetime :end_time
# t.string :cost_time t.string :cost_time
# t.timestamps t.timestamps
# end end
# add_index :issue_times, [:issue_id, :user_id] add_index :issue_times, [:issue_id, :user_id]
end end
end end

View File

@ -1,5 +1,5 @@
class AddIsLockToIssue < ActiveRecord::Migration[5.2] class AddIsLockToIssue < ActiveRecord::Migration[5.2]
def change def change
# add_column :issues, :is_lock, :boolean, default: false add_column :issues, :is_lock, :boolean, default: false
end end
end end

View File

@ -1,5 +1,5 @@
class AddWatchersCountToProjects < ActiveRecord::Migration[5.2] class AddWatchersCountToProjects < ActiveRecord::Migration[5.2]
def change def change
# add_column :projects, :watchers_count, :integer, :default => 0 add_column :projects, :watchers_count, :integer, :default => 0
end end
end end

View File

@ -1,18 +1,18 @@
class CreateVersionReleases < ActiveRecord::Migration[5.2] class CreateVersionReleases < ActiveRecord::Migration[5.2]
def change def change
# create_table :version_releases do |t| create_table :version_releases do |t|
# t.integer :user_id t.integer :user_id
# t.string :name t.string :name
# t.text :body t.text :body
# t.string :tag_name t.string :tag_name
# t.string :target_commitish t.string :target_commitish
# t.boolean :draft, default: false t.boolean :draft, default: false
# t.boolean :prerelease, default: false t.boolean :prerelease, default: false
# t.string :tarball_url t.string :tarball_url
# t.string :zipball_url t.string :zipball_url
# t.string :url t.string :url
# t.string :version_gid t.string :version_gid
# t.timestamps t.timestamps
# end end
end end
end end

View File

@ -1,6 +1,6 @@
class AddProjectIdToVersionRelease < ActiveRecord::Migration[5.2] class AddProjectIdToVersionRelease < ActiveRecord::Migration[5.2]
def change def change
# add_column :version_releases, :repository_id, :integer add_column :version_releases, :repository_id, :integer
# add_index :version_releases, [:repository_id] add_index :version_releases, [:repository_id]
end end
end end

View File

@ -1,6 +1,6 @@
class AddColumnToIssueTags < ActiveRecord::Migration[5.2] class AddColumnToIssueTags < ActiveRecord::Migration[5.2]
def change def change
# add_column :issue_tags, :gid, :integer add_column :issue_tags, :gid, :integer
# add_column :issue_tags, :gitea_url, :string add_column :issue_tags, :gitea_url, :string
end end
end end

View File

@ -1,8 +1,8 @@
class AddColumnToPullRequests < ActiveRecord::Migration[5.2] class AddColumnToPullRequests < ActiveRecord::Migration[5.2]
def change def change
# add_column :pull_requests, :version_id, :integer add_column :pull_requests, :version_id, :integer
# add_column :pull_requests, :body, :text add_column :pull_requests, :body, :text
# add_column :pull_requests, :from_ref, :string add_column :pull_requests, :from_ref, :string
# add_column :pull_requests, :to_ref, :string add_column :pull_requests, :to_ref, :string
end end
end end

View File

@ -4,10 +4,10 @@ class ChangePullRequestsColumns < ActiveRecord::Migration[5.2]
# add_column :pull_request_assigns, :user_login, :string # add_column :pull_request_assigns, :user_login, :string
# #
# add_index :pull_request_assigns, [:user_login] # add_index :pull_request_assigns, [:user_login]
#
# rename_column :pull_requests, :version_id, :milestone rename_column :pull_requests, :version_id, :milestone
# rename_column :pull_requests, :from_ref, :head rename_column :pull_requests, :from_ref, :head
# rename_column :pull_requests, :to_ref, :base rename_column :pull_requests, :to_ref, :base
end end

View File

@ -1,6 +1,6 @@
class AddColumnsToPullRequests < ActiveRecord::Migration[5.2] class AddColumnsToPullRequests < ActiveRecord::Migration[5.2]
def change def change
# add_column :pull_requests, :issue_id, :integer add_column :pull_requests, :issue_id, :integer
# add_column :issues, :issue_classify, :string add_column :issues, :issue_classify, :string
end end
end end

View File

@ -1,6 +1,6 @@
class AddIssuesRefNameAndBranchName < ActiveRecord::Migration[5.2] class AddIssuesRefNameAndBranchName < ActiveRecord::Migration[5.2]
def change def change
# add_column :issues, :ref_name, :string add_column :issues, :ref_name, :string
# add_column :issues, :branch_name, :string add_column :issues, :branch_name, :string
end end
end end

View File

@ -1,9 +1,9 @@
class MigrateTidingStatus < ActiveRecord::Migration[5.2] class MigrateTidingStatus < ActiveRecord::Migration[5.2]
def change def change
Tiding.where(container_type: "JoinCourse", status: 0).each do |tiding| # 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? # 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) # tiding.update!(status: 1)
end # end
end # end
end end
end end

View File

@ -1,6 +1,6 @@
class AddIssuesCountAndPullRequestsCountToProjects < ActiveRecord::Migration[5.2] class AddIssuesCountAndPullRequestsCountToProjects < ActiveRecord::Migration[5.2]
def change def change
# add_column :projects, :issues_count, :integer, :default => 0 add_column :projects, :issues_count, :integer, :default => 0
# add_column :projects, :pull_requests_count, :integer, :default => 0 add_column :projects, :pull_requests_count, :integer, :default => 0
end end
end end

View File

@ -1,11 +1,11 @@
class MigrateUserLocation < ActiveRecord::Migration[5.2] class MigrateUserLocation < ActiveRecord::Migration[5.2]
def change def change
UserExtension.where("location like '%省'").each do |ue| # UserExtension.where("location like '%省'").each do |ue|
ue.update_column("location", ue.location.chop) # ue.update_column("location", ue.location.chop)
end # end
#
UserExtension.where("location_city like '%市'").each do |ue| # UserExtension.where("location_city like '%市'").each do |ue|
ue.update_column("location_city", ue.location_city.chop) # ue.update_column("location_city", ue.location_city.chop)
end # end
end end
end end

View File

@ -1,7 +1,7 @@
class AddIssuesCountToVersions < ActiveRecord::Migration[5.2] class AddIssuesCountToVersions < ActiveRecord::Migration[5.2]
def change def change
# add_column :versions, :issues_count, :integer, :default => 0 add_column :versions, :issues_count, :integer, :default => 0
# add_column :versions, :closed_issues_count, :integer, :default => 0 add_column :versions, :closed_issues_count, :integer, :default => 0
# add_column :versions, :percent, :float, default: 0.0 add_column :versions, :percent, :float, default: 0.0
end end
end end

View File

@ -1,69 +1,69 @@
class ChangeQuillToMd < ActiveRecord::Migration[5.2] class ChangeQuillToMd < ActiveRecord::Migration[5.2]
#迁移quill编辑器的内容为md #迁移quill编辑器的内容为md
def change def change
migrate_time = Time.current - 20.days migrate_time = Time.current - 20.days
all_issues = Issue.where("updated_on > ?", migrate_time) all_issues = Issue.where("updated_on > ?", migrate_time)
pros = PullRequest.where("updated_at > ?", migrate_time) pros = PullRequest.where("updated_at > ?", migrate_time)
journals = Journal.where("created_on > ?", migrate_time) journals = Journal.where("created_on > ?", migrate_time)
Issue.transaction do # Issue.transaction do
if all_issues.size > 0 # if all_issues.size > 0
all_issues.each do |i| # all_issues.each do |i|
description = i.description # description = i.description
if description.present? && description.include?("insert") # if description.present? && description.include?("insert")
new_content = change_content(description) # new_content = change_content(description)
i.update_attribute(:description, new_content) # i.update_attribute(:description, new_content)
end # end
puts "__update_issue_content_____id:#{i.id}__" # puts "__update_issue_content_____id:#{i.id}__"
end # end
end # end
end # end
Journal.transaction do # Journal.transaction do
if journals.size > 0 # if journals.size > 0
journals.each do |j| # journals.each do |j|
description = j.notes # description = j.notes
if description.present? && description.include?("insert") # if description.present? && description.include?("insert")
new_content = change_content(description) # new_content = change_content(description)
j.update_attribute(:notes, new_content) # j.update_attribute(:notes, new_content)
end # end
puts "__update_journal_content_____id:#{j.id}__" # puts "__update_journal_content_____id:#{j.id}__"
end # end
end # end
#
end # end
PullRequest.transaction do # PullRequest.transaction do
if pros.size > 0 # if pros.size > 0
pros.each do |p| # pros.each do |p|
description = p.body # description = p.body
if description.present? && description.include?("insert") # if description.present? && description.include?("insert")
new_content = change_content(description) # new_content = change_content(description)
p.update_attribute(:body, new_content) # p.update_attribute(:body, new_content)
end # end
puts "__update_pull_request_content_____id:#{p.id}__" # puts "__update_pull_request_content_____id:#{p.id}__"
end # end
end # end
end # end
end end
def change_content(content) # def change_content(content)
puts "####________content_____######{content}" # puts "####________content_____######{content}"
new_content = "" # new_content = ""
return "" if content.blank? # return "" if content.blank?
desc = JSON.parse(content)["ops"] # desc = JSON.parse(content)["ops"]
if desc.length > 0 # if desc.length > 0
desc.each do |d| # desc.each do |d|
image = d["insert"]["image"] # image = d["insert"]["image"]
if image.present? # if image.present?
new_content += "![#{image['alt']}](#{image['url']})" # new_content += "![#{image['alt']}](#{image['url']})"
else # else
new_content += d["insert"].gsub("\n", "") # new_content += d["insert"].gsub("\n", "")
end # end
end # end
end # end
new_content # new_content
end # end
end end

View File

@ -0,0 +1,6 @@
class AddColumnsToProjects < ActiveRecord::Migration[5.2]
def change
add_column :projects, :license_id, :integer
add_column :projects, :ignore_id, :integer
end
end

View File

@ -15,15 +15,27 @@ namespace :sync_data_to_gitea do
next unless regx.match user.mail next unless regx.match user.mail
tmp_password = set_password tmp_password = set_password
user_params = {
username: user.login,
email: user.mail,
password: tmp_password
}
gitea_user = Gitea::User::RegisterService.new(user_params).call # TODO: Educoder sync
result = Gitea::User::GenerateTokenService.new(user.login, tmp_password).call interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: tmp_password})
user.update_columns(gitea_token: result['sha1'], gitea_uid: gitea_user['id']) if interactor.success?
gitea_user = interactor.result
result = Gitea::User::GenerateTokenService.call(user.login, tmp_password)
user.update_columns(gitea_token: result['sha1'], gitea_uid: gitea_user[:body]['id'])
else
puts "#################【Gitea: 用户同步失败: #{interactor.error} #################"
end
# TODO: Trustie sync
# user_params = {
# username: user.login,
# email: user.mail,
# password: tmp_password
# }
#
# gitea_user = Gitea::User::RegisterService.new(user_params).call
# result = Gitea::User::GenerateTokenService.new(user.login, tmp_password).call
# user.update_columns(gitea_token: result['sha1'], gitea_uid: gitea_user['id'])
rescue Exception => e rescue Exception => e
Rails.logger.error e Rails.logger.error e
next next