forked from Gitlink/forgeplus
Compare commits
230 Commits
master
...
dev_educod
| Author | SHA1 | Date |
|---|---|---|
|
|
eadc517a25 | |
|
|
1652e615be | |
|
|
2ea78b4f20 | |
|
|
e36c7a4b6a | |
|
|
8e8ec821f2 | |
|
|
5cf257c3cc | |
|
|
aa18fe0ad4 | |
|
|
1358c23ca6 | |
|
|
c27cc063e6 | |
|
|
b0092487e6 | |
|
|
fbebd0a623 | |
|
|
fe23c2afbf | |
|
|
779c86108a | |
|
|
83e43f0c97 | |
|
|
e545424b7d | |
|
|
e237fd46f7 | |
|
|
ca3c564529 | |
|
|
9cd18397f7 | |
|
|
7574071445 | |
|
|
77620f7735 | |
|
|
50dc5cce5d | |
|
|
a6cee63d17 | |
|
|
000197b0d1 | |
|
|
6aa3321d17 | |
|
|
d44308fc82 | |
|
|
ae7d0d1329 | |
|
|
55c74de8e4 | |
|
|
7c88ea3d67 | |
|
|
f15cd44dff | |
|
|
3abd6037d9 | |
|
|
ec3a556a6f | |
|
|
793cbb372a | |
|
|
396ac55429 | |
|
|
088c617cc1 | |
|
|
17314b9164 | |
|
|
e6521ffdd2 | |
|
|
fc3cf01d3f | |
|
|
8f5bb0e2d9 | |
|
|
ef559b11a0 | |
|
|
7f59f6739f | |
|
|
d6937f195c | |
|
|
2dfd69ae21 | |
|
|
720c073f32 | |
|
|
0076468a15 | |
|
|
910ae48556 | |
|
|
eac7331070 | |
|
|
551f333261 | |
|
|
dec264d169 | |
|
|
7055974443 | |
|
|
3536918938 | |
|
|
56278b84f2 | |
|
|
882a50cf56 | |
|
|
db4031b8bf | |
|
|
ecfc39565c | |
|
|
9ced678f91 | |
|
|
7951ca28d5 | |
|
|
4bbb843edf | |
|
|
747646cd9d | |
|
|
d0d906d04c | |
|
|
bc639488aa | |
|
|
99fbecc834 | |
|
|
8d0a6d267a | |
|
|
b1c03ed5e8 | |
|
|
ef12f85687 | |
|
|
e120c4dac2 | |
|
|
e1cf2fcdeb | |
|
|
c4f380873e | |
|
|
5cb2e55f74 | |
|
|
1dd3fbc69a | |
|
|
b97c42d0ae | |
|
|
a2612d8009 | |
|
|
2f2655525f | |
|
|
1a93477635 | |
|
|
7c664addbd | |
|
|
c6b79f82bc | |
|
|
4e3f9cc019 | |
|
|
5ed7b3e4ad | |
|
|
4e2c46260c | |
|
|
9ba00b21c9 | |
|
|
b11f5fd228 | |
|
|
90dbe0730a | |
|
|
d6633cb73a | |
|
|
a7a6abd22a | |
|
|
c956667ce0 | |
|
|
5701c818ed | |
|
|
1ac2ddfaa5 | |
|
|
4aac05d4e1 | |
|
|
84b56bfcb8 | |
|
|
7485564bb9 | |
|
|
b5acf2308a | |
|
|
e3f4313c80 | |
|
|
b223abe229 | |
|
|
b3bede308c | |
|
|
2f170a54c6 | |
|
|
22293572ac | |
|
|
8720cab1e9 | |
|
|
959c1e8d95 | |
|
|
29dc3fff39 | |
|
|
298abdd1b1 | |
|
|
26f87fba16 | |
|
|
1e9a32a93e | |
|
|
2dc79052c2 | |
|
|
380ca3a066 | |
|
|
237b0afb08 | |
|
|
e14936e820 | |
|
|
655c85851f | |
|
|
1c7e414aa4 | |
|
|
099fc52e00 | |
|
|
490957ec3b | |
|
|
b1884d30d5 | |
|
|
98d8ee1fb6 | |
|
|
2ca77732c8 | |
|
|
70d22f7c4f | |
|
|
25d0e784bb | |
|
|
5d45b24299 | |
|
|
b6b8befde7 | |
|
|
f33b9559cd | |
|
|
f9bc2258ec | |
|
|
2a09ced1ce | |
|
|
7a1e6cfbad | |
|
|
47d1f727ce | |
|
|
a7665df0ea | |
|
|
84f12adce8 | |
|
|
7fde1e0e12 | |
|
|
499734ebf9 | |
|
|
f339df699e | |
|
|
cfd94cb3b7 | |
|
|
43e0617429 | |
|
|
d6b66d5324 | |
|
|
0c1df3b2cb | |
|
|
fa86d3ea10 | |
|
|
8c99b754fb | |
|
|
f3cf2c87c9 | |
|
|
8e4e6fc0ac | |
|
|
75f3166ffa | |
|
|
04bf423fcb | |
|
|
51e8c9d908 | |
|
|
4304a35b80 | |
|
|
076375633a | |
|
|
dbf5e711a5 | |
|
|
4432e65683 | |
|
|
dcf44a78f0 | |
|
|
12edc620df | |
|
|
4ce03145df | |
|
|
3e04a37ece | |
|
|
78f464ccba | |
|
|
64423f1999 | |
|
|
05c3f60dab | |
|
|
0083ef33cb | |
|
|
36b68df273 | |
|
|
e1a5918c22 | |
|
|
26ae9b35df | |
|
|
8e79b43aaf | |
|
|
d28eba6423 | |
|
|
688be1bb7d | |
|
|
df69dee282 | |
|
|
45a77e5c07 | |
|
|
7849bd0ebf | |
|
|
3649bf1fd0 | |
|
|
6ffc2938a1 | |
|
|
aa60de1dac | |
|
|
29f98513e2 | |
|
|
e35cdf39fb | |
|
|
e51b86538b | |
|
|
da4fd3a762 | |
|
|
efc82b9841 | |
|
|
e3df503dd2 | |
|
|
6a2ad67386 | |
|
|
3d12db3a07 | |
|
|
1faaf1d7d1 | |
|
|
f8a6f62342 | |
|
|
66d1246a6c | |
|
|
f79beef3f9 | |
|
|
81e6691632 | |
|
|
38d6519381 | |
|
|
16418675ac | |
|
|
102858bc8c | |
|
|
0d64768e4b | |
|
|
beccac652f | |
|
|
30eb1958c1 | |
|
|
33e17e8439 | |
|
|
e0c47c2abd | |
|
|
422549f9e7 | |
|
|
0358229b95 | |
|
|
c4586fbb36 | |
|
|
f94006abfd | |
|
|
4d61e7618a | |
|
|
36286d9003 | |
|
|
51356da7f3 | |
|
|
ebe893022f | |
|
|
c5f22e6c70 | |
|
|
922561afb1 | |
|
|
6f7899d16f | |
|
|
4e3c8e414c | |
|
|
d588a78f62 | |
|
|
a7d681c4dd | |
|
|
7a93db9ed2 | |
|
|
74e5fa0e31 | |
|
|
de995c8714 | |
|
|
ea156cec7e | |
|
|
7499d8af89 | |
|
|
f8654edc3b | |
|
|
d16f290aa6 | |
|
|
9385d346f1 | |
|
|
22f3371090 | |
|
|
c0a4f8f4ec | |
|
|
7586a0fb21 | |
|
|
c0e3a91a46 | |
|
|
7ebd8681fa | |
|
|
72553dec57 | |
|
|
dee68808b1 | |
|
|
96d7917bbf | |
|
|
abca0fe432 | |
|
|
d7612a0921 | |
|
|
c54950a95f | |
|
|
be0f68cede | |
|
|
1b92b53099 | |
|
|
5634413cac | |
|
|
1a9ed1425e | |
|
|
f9d4316a8e | |
|
|
6f7f815fd4 | |
|
|
ddb826733b | |
|
|
1f989d0a37 | |
|
|
d63626424e | |
|
|
55ab694505 | |
|
|
0885575cc4 | |
|
|
a188648287 | |
|
|
8011dabaac | |
|
|
88a08e73c0 | |
|
|
6713f9b280 |
|
|
@ -23,7 +23,7 @@
|
||||||
* Fix 版本库中附件下载400(#51625)
|
* Fix 版本库中附件下载400(#51625)
|
||||||
* Fix loading页面优化(#51588)
|
* Fix loading页面优化(#51588)
|
||||||
* Fix 提交详情页面优化(#51577)
|
* Fix 提交详情页面优化(#51577)
|
||||||
* Fix 修复易修复制功能(#51569)
|
* Fix 修复疑修复制功能(#51569)
|
||||||
* Fix 修复新建发行版用户信息显示错误的问题(#51665)
|
* Fix 修复新建发行版用户信息显示错误的问题(#51665)
|
||||||
* Fix 修复查看文件详细信息报错的问题(#51561)
|
* Fix 修复查看文件详细信息报错的问题(#51561)
|
||||||
* Fix 修复提交记录中时间显示格式问题(#51526)
|
* Fix 修复提交记录中时间显示格式问题(#51526)
|
||||||
|
|
@ -62,7 +62,7 @@
|
||||||
## [v3.0.3](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2021-05-08
|
## [v3.0.3](https://forgeplus.trustie.net/projects/jasder/forgeplus/releases) - 2021-05-08
|
||||||
|
|
||||||
* BUGFIXES
|
* BUGFIXES
|
||||||
* Fix 解决易修标题过长导致的排版问题(45469)
|
* Fix 解决疑修标题过长导致的排版问题(45469)
|
||||||
* Fix 解决合并请求详情页面排版错误的问题(45457)
|
* Fix 解决合并请求详情页面排版错误的问题(45457)
|
||||||
* FIX 解决转移仓库界面专有名词描述错误的问题(45455)
|
* FIX 解决转移仓库界面专有名词描述错误的问题(45455)
|
||||||
* Fix 解决markdown格式文件自动生成数字排序的问题(45454)
|
* Fix 解决markdown格式文件自动生成数字排序的问题(45454)
|
||||||
|
|
|
||||||
|
|
@ -1,371 +1,416 @@
|
||||||
class AccountsController < ApplicationController
|
class AccountsController < ApplicationController
|
||||||
include ApplicationHelper
|
before_action :require_login, only: [:login_check, :simple_update]
|
||||||
|
include ApplicationHelper
|
||||||
#skip_before_action :check_account, :only => [:logout]
|
|
||||||
|
#skip_before_action :check_account, :only => [:logout]
|
||||||
def index
|
|
||||||
render json: session
|
def simple_update
|
||||||
end
|
simple_update_params.merge!(username: params[:username]&.gsub(/\s+/, ""))
|
||||||
|
simple_update_params.merge!(email: params[:email]&.gsub(/\s+/, ""))
|
||||||
# 其他平台同步注册的用户
|
simple_update_params.merge!(platform: (params[:platform] || 'forge')&.gsub(/\s+/, ""))
|
||||||
def remote_register
|
Register::RemoteForm.new(simple_update_params).validate!
|
||||||
username = params[:username]&.gsub(/\s+/, "")
|
|
||||||
tip_exception("无法使用以下关键词:#{username},请重新命名") if ReversedKeyword.check_exists?(username)
|
ActiveRecord::Base.transaction do
|
||||||
email = params[:email]&.gsub(/\s+/, "")
|
result = auto_update(current_user, simple_update_params)
|
||||||
password = params[:password]
|
if result[:message].blank?
|
||||||
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")
|
render_ok
|
||||||
|
else
|
||||||
ActiveRecord::Base.transaction do
|
render_error(result[:message])
|
||||||
result = autologin_register(username, email, password, platform)
|
end
|
||||||
if result[:message].blank?
|
end
|
||||||
render_ok({user: result[:user]})
|
end
|
||||||
else
|
|
||||||
render_error(result[:message])
|
def index
|
||||||
end
|
render json: session
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
|
||||||
uid_logger_error(e.message)
|
# 为了同步平台上未注册gitea的用户
|
||||||
tip_exception(-1, e.message)
|
def gitea_register
|
||||||
end
|
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?
|
||||||
def remote_update
|
|
||||||
ActiveRecord::Base.transaction do
|
result = create_gitea_user!(user, sync_gitea_params[:login], sync_gitea_params[:email], sync_gitea_params[:password])
|
||||||
user_params = params[:user_params]
|
result[:user] ? render_ok : render_error(result[:message])
|
||||||
user_extension_params = params[:user_extension_params]
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
u = User.find_by(login: params[:old_user_login])
|
tip_exception(-1, e.message)
|
||||||
user_mail = u.try(:mail)
|
end
|
||||||
|
|
||||||
if u.present?
|
# 其他平台同步注册的用户
|
||||||
ue = u.user_extension
|
def remote_register
|
||||||
u.login = user_params["login"] if user_params["login"]
|
Register::RemoteForm.new(remote_register_params).validate!
|
||||||
u.mail = user_params["mail"] if user_params["mail"]
|
username = params[:username]&.gsub(/\s+/, "")
|
||||||
u.lastname = user_params["lastname"] if user_params["lastname"]
|
tip_exception("无法使用以下关键词:#{username},请重新命名") if ReversedKeyword.check_exists?(username)
|
||||||
|
email = params[:email]&.gsub(/\s+/, "")
|
||||||
ue.gender = user_extension_params["gender"]
|
password = params[:password]
|
||||||
ue.school_id = user_extension_params["school_id"]
|
platform = (params[:platform] || 'forge')&.gsub(/\s+/, "")
|
||||||
ue.location = user_extension_params["location"]
|
|
||||||
ue.location_city = user_extension_params["location_city"]
|
ActiveRecord::Base.transaction do
|
||||||
ue.identity = user_extension_params["identity"]
|
result = autologin_register(username, email, password, platform)
|
||||||
ue.technical_title = user_extension_params["technical_title"]
|
if result[:message].blank?
|
||||||
ue.student_id = user_extension_params["student_id"]
|
render_ok({user: result[:user]})
|
||||||
ue.description = user_extension_params["description"]
|
else
|
||||||
ue.save!
|
render_error(result[:message])
|
||||||
u.save!
|
end
|
||||||
|
end
|
||||||
sync_params = {}
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
if (user_params["mail"] && user_params["mail"] != user_mail)
|
tip_exception(-1, e.message)
|
||||||
sync_params = sync_params.merge(email: user_params["mail"])
|
end
|
||||||
end
|
|
||||||
|
# 其他平台修改用户的信息,这边同步修改
|
||||||
if sync_params.present?
|
def remote_update
|
||||||
interactor = Gitea::User::UpdateInteractor.call(u.login, sync_params)
|
ActiveRecord::Base.transaction do
|
||||||
if interactor.success?
|
user_params = params[:user_params]
|
||||||
render_ok
|
user_extension_params = params[:user_extension_params]
|
||||||
else
|
|
||||||
render_error(interactor.error)
|
u = User.find_by(login: params[:old_user_login])
|
||||||
end
|
user_mail = u.try(:mail)
|
||||||
end
|
|
||||||
end
|
if u.present?
|
||||||
end
|
ue = u.user_extension
|
||||||
rescue Exception => e
|
u.login = user_params["login"] if user_params["login"]
|
||||||
uid_logger_error(e.message)
|
u.mail = user_params["mail"] if user_params["mail"]
|
||||||
tip_exception(-1, e.message)
|
u.lastname = user_params["lastname"] if user_params["lastname"]
|
||||||
end
|
|
||||||
|
ue.gender = user_extension_params["gender"]
|
||||||
# 其他平台同步登录
|
ue.school_id = user_extension_params["school_id"]
|
||||||
def remote_login
|
ue.location = user_extension_params["location"]
|
||||||
@user = User.try_to_login(params[:login], params[:password])
|
ue.location_city = user_extension_params["location_city"]
|
||||||
if @user
|
ue.identity = user_extension_params["identity"]
|
||||||
successful_authentication(@user)
|
ue.technical_title = user_extension_params["technical_title"]
|
||||||
render_ok({user: {id: @user.id, token: @user.gitea_token}})
|
ue.student_id = user_extension_params["student_id"]
|
||||||
else
|
ue.description = user_extension_params["description"]
|
||||||
render_error("用户不存在")
|
ue.save!
|
||||||
end
|
u.save!
|
||||||
end
|
|
||||||
|
sync_params = {}
|
||||||
#修改密码
|
|
||||||
def remote_password
|
if (user_params["mail"] && user_params["mail"] != user_mail)
|
||||||
@user = User.find_by(login: params[:login])
|
sync_params = sync_params.merge(email: user_params["mail"])
|
||||||
return render_error("未找到相关用户!") if @user.blank?
|
end
|
||||||
|
|
||||||
sync_params = {
|
if sync_params.present?
|
||||||
password: params[:password].to_s,
|
interactor = Gitea::User::UpdateInteractor.call(u.login, sync_params)
|
||||||
email: @user.mail
|
if interactor.success?
|
||||||
}
|
render_ok
|
||||||
|
else
|
||||||
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
render_error(interactor.error)
|
||||||
if interactor.success?
|
end
|
||||||
@user.update_attribute(:password, params[:password])
|
end
|
||||||
render_ok
|
end
|
||||||
else
|
end
|
||||||
render_error(interactor.error)
|
rescue Exception => e
|
||||||
end
|
uid_logger_error(e.message)
|
||||||
end
|
tip_exception(-1, e.message)
|
||||||
|
end
|
||||||
|
|
||||||
|
# 其他平台同步登录
|
||||||
# 用户注册
|
def remote_login
|
||||||
# 注意:用户注册需要兼顾本地版,本地版是不需要验证码及激活码以及使用授权的,注册完成即可使用
|
@user = User.try_to_login(params[:login], params[:password])
|
||||||
# params[:login] 邮箱或者手机号
|
if @user
|
||||||
# params[:namespace] 登录名
|
successful_authentication(@user)
|
||||||
# params[:code] 验证码
|
render_ok({user: {id: @user.id, token: @user.gitea_token}})
|
||||||
# code_type 1:注册手机验证码 8:邮箱注册验证码
|
else
|
||||||
# 本地forge注册入口需要重新更改逻辑
|
render_error("用户不存在")
|
||||||
def register
|
end
|
||||||
# type只可能是1或者8
|
end
|
||||||
user = nil
|
|
||||||
begin
|
#修改密码
|
||||||
Register::Form.new(register_params).validate!
|
def remote_password
|
||||||
|
@user = User.find_by(login: params[:login])
|
||||||
user = Users::RegisterService.call(register_params)
|
return render_error("未找到相关用户!") if @user.blank?
|
||||||
password = register_params[:password].strip
|
|
||||||
|
sync_params = {
|
||||||
# gitea用户注册, email, username, password
|
password: params[:password].to_s,
|
||||||
interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: password})
|
email: @user.mail
|
||||||
if interactor.success?
|
}
|
||||||
gitea_user = interactor.result
|
|
||||||
result = Gitea::User::GenerateTokenService.call(user.login, password)
|
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
||||||
user.gitea_token = result['sha1']
|
if interactor.success?
|
||||||
user.gitea_uid = gitea_user[:body]['id']
|
@user.update_attribute(:password, params[:password])
|
||||||
if user.save!
|
render_ok
|
||||||
UserExtension.create!(user_id: user.id)
|
else
|
||||||
successful_authentication(user)
|
render_error(interactor.error)
|
||||||
render_ok
|
end
|
||||||
end
|
end
|
||||||
else
|
|
||||||
tip_exception(-1, interactor.error)
|
|
||||||
end
|
|
||||||
rescue Register::BaseForm::EmailError => e
|
# 用户注册
|
||||||
render_error(-2, e.message)
|
# 注意:用户注册需要兼顾本地版,本地版是不需要验证码及激活码以及使用授权的,注册完成即可使用
|
||||||
rescue Register::BaseForm::LoginError => e
|
# params[:login] 邮箱或者手机号
|
||||||
render_error(-3, e.message)
|
# params[:namespace] 登录名
|
||||||
rescue Register::BaseForm::PhoneError => e
|
# params[:code] 验证码
|
||||||
render_error(-4, e.message)
|
# code_type 1:注册手机验证码 8:邮箱注册验证码
|
||||||
rescue Register::BaseForm::PasswordFormatError => e
|
# 本地forge注册入口需要重新更改逻辑
|
||||||
render_error(-5, e.message)
|
def register
|
||||||
rescue Register::BaseForm::VerifiCodeError => e
|
# type只可能是1或者8
|
||||||
render_error(-6, e.message)
|
user = nil
|
||||||
rescue Exception => e
|
begin
|
||||||
Gitea::User::DeleteService.call(user.login) unless user.nil?
|
Register::Form.new(register_params).validate!
|
||||||
uid_logger_error(e.message)
|
|
||||||
tip_exception(-1, e.message)
|
user = Users::RegisterService.call(register_params)
|
||||||
end
|
password = register_params[:password].strip
|
||||||
end
|
|
||||||
|
# gitea用户注册, email, username, password
|
||||||
# 用户登录
|
interactor = Gitea::RegisterInteractor.call({username: user.login, email: user.mail, password: password})
|
||||||
def login
|
if interactor.success?
|
||||||
Users::LoginForm.new(account_params).validate!
|
gitea_user = interactor.result
|
||||||
@user = User.try_to_login(params[:login], params[:password])
|
result = Gitea::User::GenerateTokenService.call(user.login, password)
|
||||||
|
user.gitea_token = result['sha1']
|
||||||
return normal_status(-2, "错误的账号或密码") if @user.blank?
|
user.gitea_uid = gitea_user[:body]['id']
|
||||||
# user is already in local database
|
if user.save!
|
||||||
return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked?
|
UserExtension.create!(user_id: user.id)
|
||||||
|
successful_authentication(user)
|
||||||
login_control = LimitForbidControl::UserLogin.new(@user)
|
render_ok
|
||||||
return normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid?
|
end
|
||||||
|
else
|
||||||
password_ok = @user.check_password?(params[:password].to_s)
|
tip_exception(-1, interactor.error)
|
||||||
unless password_ok
|
end
|
||||||
if login_control.remain_times-1 == 0
|
rescue Register::BaseForm::EmailError => e
|
||||||
normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码")
|
render_error(-2, e.message)
|
||||||
else
|
rescue Register::BaseForm::LoginError => e
|
||||||
normal_status(-2, "你已经输错密码#{login_control.error_times+1}次,还剩余#{login_control.remain_times-1}次机会")
|
render_error(-3, e.message)
|
||||||
end
|
rescue Register::BaseForm::PhoneError => e
|
||||||
login_control.increment!
|
render_error(-4, e.message)
|
||||||
return
|
rescue Register::BaseForm::PasswordFormatError => e
|
||||||
end
|
render_error(-5, e.message)
|
||||||
|
rescue Register::BaseForm::VerifiCodeError => e
|
||||||
successful_authentication(@user)
|
render_error(-6, e.message)
|
||||||
sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步
|
rescue Exception => e
|
||||||
|
Gitea::User::DeleteService.call(user.login) unless user.nil?
|
||||||
# session[:user_id] = @user.id
|
uid_logger_error(e.message)
|
||||||
end
|
tip_exception(-1, e.message)
|
||||||
|
end
|
||||||
def change_password
|
end
|
||||||
@user = User.find_by(login: params[:login])
|
|
||||||
return render_error("未找到相关用户!") if @user.blank?
|
# 用户登录
|
||||||
return render_error("旧密码不正确") unless @user.check_password?(params[:old_password])
|
def login
|
||||||
|
Users::LoginForm.new(account_params).validate!
|
||||||
sync_params = {
|
@user = User.try_to_login(params[:login], params[:password])
|
||||||
password: params[:password].to_s,
|
|
||||||
email: @user.mail
|
return normal_status(-2, "错误的账号或密码") if @user.blank?
|
||||||
}
|
# user is already in local database
|
||||||
|
return normal_status(-2, "违反平台使用规范,账号已被锁定") if @user.locked?
|
||||||
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
|
||||||
if interactor.success?
|
login_control = LimitForbidControl::UserLogin.new(@user)
|
||||||
@user.update_attribute(:password, params[:password])
|
return normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码") if login_control.forbid?
|
||||||
render_ok
|
|
||||||
else
|
password_ok = @user.check_password?(params[:password].to_s)
|
||||||
render_error(interactor.error)
|
unless password_ok
|
||||||
end
|
if login_control.remain_times-1 == 0
|
||||||
end
|
normal_status(-2, "登录密码出错已达上限,账号已被锁定, 请#{login_control.forbid_expires/60}分钟后重新登录或找回密码")
|
||||||
|
else
|
||||||
# 忘记密码
|
normal_status(-2, "你已经输错密码#{login_control.error_times+1}次,还剩余#{login_control.remain_times-1}次机会")
|
||||||
def reset_password
|
end
|
||||||
begin
|
login_control.increment!
|
||||||
code = params[:code]
|
return
|
||||||
login_type = phone_mail_type(params[:login].strip)
|
end
|
||||||
# 获取验证码
|
|
||||||
if login_type == 1
|
successful_authentication(@user)
|
||||||
phone = params[:login]
|
sync_pwd_to_gitea!(@user, {password: params[:password].to_s}) # TODO用户密码未同步
|
||||||
verifi_code = VerificationCode.where(phone: phone, code: code, code_type: 2).last
|
|
||||||
user = User.find_by_phone(phone)
|
# session[:user_id] = @user.id
|
||||||
else
|
end
|
||||||
email = params[:login]
|
|
||||||
verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last
|
def change_password
|
||||||
user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs
|
@user = User.find_by(login: params[:login])
|
||||||
end
|
return render_error("未找到相关用户!") if @user.blank?
|
||||||
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
|
return render_error("旧密码不正确") unless @user.check_password?(params[:old_password])
|
||||||
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
|
|
||||||
return normal_status(-1, "8~16位密码,支持字母数字和符号") unless params[:new_password] =~ CustomRegexp::PASSWORD
|
sync_params = {
|
||||||
|
password: params[:password].to_s,
|
||||||
user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
email: @user.mail,
|
||||||
ActiveRecord::Base.transaction do
|
login_name: @user.login,
|
||||||
user.save!
|
source_id: 0
|
||||||
LimitForbidControl::UserLogin.new(user).clear
|
}
|
||||||
end
|
|
||||||
sucess_status
|
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
|
||||||
rescue Exception => e
|
if interactor.success?
|
||||||
uid_logger_error(e.message)
|
@user.update_attribute(:password, params[:password])
|
||||||
tip_exception(e.message)
|
render_ok
|
||||||
end
|
else
|
||||||
end
|
render_error(interactor.error)
|
||||||
|
end
|
||||||
def successful_authentication(user)
|
end
|
||||||
uid_logger("Successful authentication start: '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}")
|
|
||||||
# Valid user
|
# 忘记密码
|
||||||
self.logged_user = user
|
def reset_password
|
||||||
# generate a key and set cookie if autologin
|
begin
|
||||||
|
code = params[:code]
|
||||||
set_autologin_cookie(user)
|
login_type = phone_mail_type(params[:login].strip)
|
||||||
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip)
|
# 获取验证码
|
||||||
user.update_column(:last_login_on, Time.now)
|
if login_type == 1
|
||||||
session[:"#{default_yun_session}"] = user.id
|
phone = params[:login]
|
||||||
Rails.logger.info("#########_____session_default_yun_session__________###############{default_yun_session}")
|
verifi_code = VerificationCode.where(phone: phone, code: code, code_type: 2).last
|
||||||
# 注册完成后有一天的试用申请(先去掉)
|
user = User.find_by_phone(phone)
|
||||||
# UserDayCertification.create(user_id: user.id, status: 1)
|
else
|
||||||
end
|
email = params[:login]
|
||||||
|
verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last
|
||||||
def set_autologin_cookie(user)
|
user = User.find_by_mail(email) #这里有问题,应该是为email,而不是mail 6.13-hs
|
||||||
token = Token.get_or_create_permanent_login_token(user, "autologin")
|
end
|
||||||
sync_user_token_to_trustie(user.login, token.value)
|
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
|
||||||
|
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
|
||||||
cookie_options = {
|
return normal_status(-1, "8~16位密码,支持字母数字和符号") unless params[:new_password] =~ CustomRegexp::PASSWORD
|
||||||
:value => token.value,
|
|
||||||
:expires => 1.month.from_now,
|
user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation]
|
||||||
:path => '/',
|
ActiveRecord::Base.transaction do
|
||||||
:secure => false,
|
user.save!
|
||||||
:httponly => true
|
LimitForbidControl::UserLogin.new(user).clear
|
||||||
}
|
end
|
||||||
if edu_setting('cookie_domain').present?
|
sucess_status
|
||||||
cookie_options = cookie_options.merge(domain: edu_setting('cookie_domain'))
|
rescue Exception => e
|
||||||
end
|
uid_logger_error(e.message)
|
||||||
cookies[autologin_cookie_name] = cookie_options
|
tip_exception(e.message)
|
||||||
cookies.signed[:user_id] ||= user.id
|
end
|
||||||
|
end
|
||||||
logger.info("cookies is #{cookies} ======> #{cookies.signed[:user_id]} =====> #{cookies[autologin_cookie_name]}")
|
|
||||||
end
|
def successful_authentication(user)
|
||||||
|
uid_logger("Successful authentication start: '#{user.login}' from #{request.remote_ip} at #{Time.now.utc}")
|
||||||
def logout
|
# Valid user
|
||||||
Rails.logger.info("########___logout_current_user____________########{current_user.try(:id)}")
|
self.logged_user = user
|
||||||
UserAction.create(action_id: User.current.id, action_type: "Logout", user_id: User.current.id, :ip => request.remote_ip)
|
# generate a key and set cookie if autologin
|
||||||
logout_user
|
|
||||||
render :json => {status: 1, message: "退出成功!"}
|
set_autologin_cookie(user)
|
||||||
end
|
UserAction.create(:action_id => user.try(:id), :action_type => "Login", :user_id => user.try(:id), :ip => request.remote_ip)
|
||||||
|
user.update_column(:last_login_on, Time.now)
|
||||||
# 检验邮箱是否已被注册及邮箱或者手机号是否合法
|
session[:"#{default_yun_session}"] = user.id
|
||||||
# 参数type为事件类型 1:注册;2:忘记密码;3:绑定
|
Rails.logger.info("#########_____session_default_yun_session__________###############{default_yun_session}")
|
||||||
def valid_email_and_phone
|
# 注册完成后有一天的试用申请(先去掉)
|
||||||
check_mail_and_phone_valid(params[:login], params[:type])
|
# UserDayCertification.create(user_id: user.id, status: 1)
|
||||||
end
|
end
|
||||||
|
|
||||||
# 发送验证码
|
def set_autologin_cookie(user)
|
||||||
# params[:login] 手机号或者邮箱号
|
token = Token.get_or_create_permanent_login_token(user, "autologin")
|
||||||
# params[:type]为事件通知类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验收手机号有效 # 如果有新的继续后面加
|
sync_user_token_to_trustie(user.login, token.value)
|
||||||
# 发送验证码:send_type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 4:绑定手机 5:绑定邮箱
|
|
||||||
# 6:手机验证码登录 7:邮箱验证码登录 8:邮箱注册验证码 9: 验收手机号有效
|
cookie_options = {
|
||||||
def get_verification_code
|
:value => token.value,
|
||||||
code = %W(0 1 2 3 4 5 6 7 8 9)
|
:expires => 1.month.from_now,
|
||||||
value = params[:login]
|
:path => '/',
|
||||||
type = params[:type].strip.to_i
|
:secure => false,
|
||||||
login_type = phone_mail_type(value)
|
:httponly => true
|
||||||
send_type = verify_type(login_type, type)
|
}
|
||||||
verification_code = code.sample(6).join
|
if edu_setting('cookie_domain').present?
|
||||||
|
cookie_options = cookie_options.merge(domain: edu_setting('cookie_domain'))
|
||||||
sign = Digest::MD5.hexdigest("#{OPENKEY}#{value}")
|
end
|
||||||
tip_exception(501, "请求不合理") if sign != params[:smscode]
|
cookies[autologin_cookie_name] = cookie_options
|
||||||
|
cookies.signed[:user_id] ||= user.id
|
||||||
logger.info "########### 验证码:#{verification_code}"
|
|
||||||
logger.info("########get_verification_code: login_type: #{login_type}, send_type:#{send_type}, ")
|
logger.info("cookies is #{cookies} ======> #{cookies.signed[:user_id]} =====> #{cookies[autologin_cookie_name]}")
|
||||||
|
end
|
||||||
# 记录验证码
|
|
||||||
check_verification_code(verification_code, send_type, value)
|
def logout
|
||||||
render_ok
|
Rails.logger.info("########___logout_current_user____________########{current_user.try(:id)}")
|
||||||
end
|
UserAction.create(action_id: User.current.id, action_type: "Logout", user_id: User.current.id, :ip => request.remote_ip)
|
||||||
|
logout_user
|
||||||
# check user's login or email or phone is used
|
render :json => {status: 1, message: "退出成功!"}
|
||||||
# params[:value] 手机号或者邮箱号或者登录名
|
end
|
||||||
# params[:type] 为事件类型 1:登录名(login) 2:email(邮箱) 3:phone(手机号)
|
|
||||||
def check
|
# 检验邮箱是否已被注册及邮箱或者手机号是否合法
|
||||||
Register::CheckColumnsForm.new(check_params).validate!
|
# 参数type为事件类型 1:注册;2:忘记密码;3:绑定
|
||||||
render_ok
|
def valid_email_and_phone
|
||||||
end
|
check_mail_and_phone_valid(params[:login], params[:type])
|
||||||
|
end
|
||||||
private
|
|
||||||
|
# 发送验证码
|
||||||
# type 事件类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验证手机号是否有效 # 如果有新的继续后面加
|
# params[:login] 手机号或者邮箱号
|
||||||
# login_type 1:手机类型 2:邮箱类型
|
# params[:type]为事件通知类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验收手机号有效 # 如果有新的继续后面加
|
||||||
def verify_type login_type, type
|
# 发送验证码:send_type 1:注册手机验证码 2:找回密码手机验证码 3:找回密码邮箱验证码 4:绑定手机 5:绑定邮箱
|
||||||
case type
|
# 6:手机验证码登录 7:邮箱验证码登录 8:邮箱注册验证码 9: 验收手机号有效
|
||||||
when 1
|
def get_verification_code
|
||||||
login_type == 1 ? 1 : 8
|
code = %W(0 1 2 3 4 5 6 7 8 9)
|
||||||
when 2
|
value = params[:login]
|
||||||
login_type == 1 ? 2 : 3
|
type = params[:type].strip.to_i
|
||||||
when 3
|
login_type = phone_mail_type(value)
|
||||||
login_type == 1 ? 4 : tip_exception('请填写正确的手机号')
|
send_type = verify_type(login_type, type)
|
||||||
when 4
|
verification_code = code.sample(6).join
|
||||||
login_type == 1 ? tip_exception('请填写正确的邮箱') : 5
|
|
||||||
when 5
|
sign = Digest::MD5.hexdigest("#{OPENKEY}#{value}")
|
||||||
login_type == 1 ? 9 : tip_exception('请填写正确的手机号')
|
tip_exception(501, "请求不合理") if sign != params[:smscode]
|
||||||
end
|
|
||||||
end
|
logger.info "########### 验证码:#{verification_code}"
|
||||||
|
logger.info("########get_verification_code: login_type: #{login_type}, send_type:#{send_type}, ")
|
||||||
def generate_login(login)
|
|
||||||
type = phone_mail_type(login.strip)
|
# 记录验证码
|
||||||
|
check_verification_code(verification_code, send_type, value)
|
||||||
if type == 1
|
render_ok
|
||||||
uid_logger("start register by phone: type is #{type}")
|
end
|
||||||
pre = 'p'
|
|
||||||
email = nil
|
# check user's login or email or phone is used
|
||||||
phone = login
|
# params[:value] 手机号或者邮箱号或者登录名
|
||||||
else
|
# params[:type] 为事件类型 1:登录名(login) 2:email(邮箱) 3:phone(手机号)
|
||||||
uid_logger("start register by email: type is #{type}")
|
def check
|
||||||
pre = 'm'
|
Register::CheckColumnsForm.new(check_params).validate!
|
||||||
email = login
|
render_ok
|
||||||
phone = nil
|
end
|
||||||
end
|
|
||||||
code = generate_identifier User, 8, pre
|
def login_check
|
||||||
|
Register::LoginCheckColumnsForm.new(check_params.merge(user: current_user)).validate!
|
||||||
{ login: pre + code, email: email, phone: phone }
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def user_params
|
private
|
||||||
params.require(:user).permit(:login, :email, :phone)
|
|
||||||
end
|
# type 事件类型 1:用户注册 2:忘记密码 3: 绑定手机 4: 绑定邮箱, 5: 验证手机号是否有效 # 如果有新的继续后面加
|
||||||
|
# login_type 1:手机类型 2:邮箱类型
|
||||||
def account_params
|
def verify_type login_type, type
|
||||||
params.require(:account).permit(:login, :password)
|
case type
|
||||||
end
|
when 1
|
||||||
|
login_type == 1 ? 1 : 8
|
||||||
def check_params
|
when 2
|
||||||
params.permit(:type, :value)
|
login_type == 1 ? 2 : 3
|
||||||
end
|
when 3
|
||||||
|
login_type == 1 ? 4 : tip_exception('请填写正确的手机号')
|
||||||
def register_params
|
when 4
|
||||||
params.permit(:login, :namespace, :password, :code)
|
login_type == 1 ? tip_exception('请填写正确的邮箱') : 5
|
||||||
end
|
when 5
|
||||||
|
login_type == 1 ? 9 : tip_exception('请填写正确的手机号')
|
||||||
end
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def generate_login(login)
|
||||||
|
type = phone_mail_type(login.strip)
|
||||||
|
|
||||||
|
if type == 1
|
||||||
|
uid_logger("start register by phone: type is #{type}")
|
||||||
|
pre = 'p'
|
||||||
|
email = nil
|
||||||
|
phone = login
|
||||||
|
else
|
||||||
|
uid_logger("start register by email: type is #{type}")
|
||||||
|
pre = 'm'
|
||||||
|
email = login
|
||||||
|
phone = nil
|
||||||
|
end
|
||||||
|
code = generate_identifier User, 8, pre
|
||||||
|
|
||||||
|
{ login: pre + code, email: email, phone: phone }
|
||||||
|
end
|
||||||
|
|
||||||
|
def user_params
|
||||||
|
params.require(:user).permit(:login, :email, :phone)
|
||||||
|
end
|
||||||
|
|
||||||
|
def account_params
|
||||||
|
params.require(:account).permit(:login, :password)
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_params
|
||||||
|
params.permit(:type, :value)
|
||||||
|
end
|
||||||
|
|
||||||
|
def register_params
|
||||||
|
params.permit(:login, :namespace, :password, :code)
|
||||||
|
end
|
||||||
|
|
||||||
|
def remote_register_params
|
||||||
|
params.permit(:username, :email, :password, :platform)
|
||||||
|
end
|
||||||
|
|
||||||
|
def simple_update_params
|
||||||
|
params.permit(:username, :email, :password, :platform)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ class Admins::ImportUsersController < Admins::BaseController
|
||||||
def create
|
def create
|
||||||
return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile)
|
return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile)
|
||||||
|
|
||||||
result = Admins::ImportUserService.call(params[:file].to_io)
|
result = Admins::ImportUserFromExcelService.call(params[:file].to_io)
|
||||||
render_ok(result)
|
render_ok(result)
|
||||||
rescue Admins::ImportUserService::Error => ex
|
rescue Admins::ImportUserService::Error => ex
|
||||||
render_error(ex)
|
render_error(ex)
|
||||||
|
|
|
||||||
|
|
@ -174,11 +174,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
|
||||||
|
|
||||||
# 异常提醒
|
# 异常提醒
|
||||||
|
|
@ -709,14 +709,20 @@ class ApplicationController < ActionController::Base
|
||||||
Rails.application.config_for(:configuration)['platform_url'] || request.base_url
|
Rails.application.config_for(:configuration)['platform_url'] || request.base_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def image_type?(str)
|
||||||
|
default_type = %w(png jpg gif tif psd svg bmp webp jpeg ico psd)
|
||||||
|
default_type.include?(str&.downcase)
|
||||||
|
end
|
||||||
|
|
||||||
def convert_image!
|
def convert_image!
|
||||||
@image = params[:image]
|
@image = params[:image]
|
||||||
@image = @image.nil? && params[:user].present? ? params[:user][:image] : @image
|
@image = @image.nil? && params[:user].present? ? params[:user][:image] : @image
|
||||||
return unless @image.present?
|
return unless @image.present?
|
||||||
max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M
|
max_size = EduSetting.get('upload_avatar_max_size') || 2 * 1024 * 1024 # 2M
|
||||||
if @image.class == ActionDispatch::Http::UploadedFile
|
if @image.class == ActionDispatch::Http::UploadedFile
|
||||||
render_error('请上传文件') if @image.size.zero?
|
return render_error('请上传文件') if @image.size.zero?
|
||||||
render_error('文件大小超过限制') if @image.size > max_size.to_i
|
return render_error('文件大小超过限制') if @image.size > max_size.to_i
|
||||||
|
return render_error('头像格式不正确!') unless image_type?(File.extname(@image.original_filename.to_s)[1..-1])
|
||||||
else
|
else
|
||||||
image = @image.to_s.strip
|
image = @image.to_s.strip
|
||||||
return render_error('请上传正确的图片') if image.blank?
|
return render_error('请上传正确的图片') if image.blank?
|
||||||
|
|
|
||||||
|
|
@ -217,7 +217,7 @@ class AttachmentsController < ApplicationController
|
||||||
if @file.container && current_user.logged?
|
if @file.container && current_user.logged?
|
||||||
if @file.container.is_a?(Issue)
|
if @file.container.is_a?(Issue)
|
||||||
course = @file.container.project
|
course = @file.container.project
|
||||||
candown = course.member?(current_user)
|
candown = course.member?(current_user) || course.is_public
|
||||||
elsif @file.container.is_a?(Journal)
|
elsif @file.container.is_a?(Journal)
|
||||||
course = @file.container.issue.project
|
course = @file.container.issue.project
|
||||||
candown = course.member?(current_user)
|
candown = course.member?(current_user)
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,7 @@ class Ci::BaseController < ApplicationController
|
||||||
namespace = params[:owner]
|
namespace = params[:owner]
|
||||||
id = params[:repo] || params[:id]
|
id = params[:repo] || params[:id]
|
||||||
|
|
||||||
@ci_user, @repo = Ci::Repo.find_with_namespace(namespace, id)
|
@ci_user, @repo = Ci::Repo.find_with_namespace(namespace, id, current_user.login)
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_all_repo
|
def load_all_repo
|
||||||
|
|
|
||||||
|
|
@ -46,7 +46,7 @@ class Ci::SecretsController < Ci::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def ci_drone_url
|
def ci_drone_url
|
||||||
user = User.find_by(login: params[:owner])
|
user = User.find_by(login: params[:owner]) || User.find_by(login: current_user.login)
|
||||||
user&.ci_cloud_account.drone_url
|
user&.ci_cloud_account.drone_url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,23 +9,29 @@ class CompareController < ApplicationController
|
||||||
load_compare_params
|
load_compare_params
|
||||||
compare
|
compare
|
||||||
@merge_status, @merge_message = get_merge_message
|
@merge_status, @merge_message = get_merge_message
|
||||||
|
@page_size = page_size <= 0 ? 1 : page_size
|
||||||
|
@page_limit = page_limit <=0 ? 15 : page_limit
|
||||||
|
@page_offset = (@page_size -1) * @page_limit
|
||||||
|
Rails.logger.info("+========#{@page_size}-#{@page_limit}-#{@page_offset}")
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def get_merge_message
|
|
||||||
|
def get_merge_message
|
||||||
if @base.blank? || @head.blank?
|
if @base.blank? || @head.blank?
|
||||||
return -2, "请选择分支"
|
return -2, "请选择分支"
|
||||||
else
|
else
|
||||||
|
return -2, "目标仓库未开启合并请求(PR)功能" unless @project.has_menu_permission("pulls")
|
||||||
if @head.include?(":")
|
if @head.include?(":")
|
||||||
fork_project = @project.forked_projects.joins(:owner).where(users: {login: @head.to_s.split("/")[0]}).take
|
fork_project = @project.forked_projects.joins(:owner).where(users: { login: @head.to_s.split("/")[0] }).take
|
||||||
return -2, "请选择正确的仓库" unless fork_project.present?
|
return -2, "请选择正确的仓库" unless fork_project.present?
|
||||||
@exist_pullrequest = @project.pull_requests.where(is_original: true, head: @head.to_s.split(":")[1], base: @base, status: 0, fork_project_id: fork_project.id).take
|
@exist_pullrequest = @project.pull_requests.where(is_original: true, head: @head.to_s.split(":")[1], base: @base, status: 0, fork_project_id: fork_project.id).take
|
||||||
else
|
else
|
||||||
@exist_pullrequest = @project.pull_requests.where(is_original: false, head: @base, base: @head, status: 0).take
|
@exist_pullrequest = @project.pull_requests.where(is_original: false, head: @base, base: @head, status: 0).last
|
||||||
end
|
end
|
||||||
if @exist_pullrequest.present?
|
if @exist_pullrequest.present?
|
||||||
return -2, "在这些分支之间的合并请求已存在:<a href='/#{@owner.login}/#{@project.identifier}/pulls/#{@exist_pullrequest.id}'>#{@exist_pullrequest.try(:title)}</a>"
|
return -2, "在这些分支之间的合并请求已存在:<a href='/#{@owner.login}/#{@project.identifier}/pulls/#{@exist_pullrequest.id}'>#{@exist_pullrequest.try(:title)}</a>"
|
||||||
else
|
else
|
||||||
if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
|
if @compare_result["Commits"].blank? && @compare_result["Diff"].blank?
|
||||||
return -2, "分支内容相同,无需创建合并请求"
|
return -2, "分支内容相同,无需创建合并请求"
|
||||||
end
|
end
|
||||||
|
|
@ -42,12 +48,22 @@ class CompareController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def load_compare_params
|
def load_compare_params
|
||||||
@base = Addressable::URI.unescape(params[:base])
|
# @base = Addressable::URI.unescape(params[:base])
|
||||||
@head = params[:head].include?('json') ? params[:head]&.split('.json')[0] : params[:head]
|
@base = params[:base].include?(":") ? Addressable::URI.unescape(params[:base].split(":")[0]) + ':' + Base64.decode64(params[:base].split(":")[1]) : Base64.decode64(params[:base])
|
||||||
|
@head = params[:head].include?('.json') ? params[:head][0..-6] : params[:head]
|
||||||
|
# @head = Addressable::URI.unescape(@head)
|
||||||
|
@head = @head.include?(":") ? Addressable::URI.unescape(@head.split(":")[0]) + ':' + Base64.decode64(@head.split(":")[1]) : Base64.decode64(@head)
|
||||||
end
|
end
|
||||||
|
|
||||||
def gitea_compare(base, head)
|
def gitea_compare(base, head)
|
||||||
Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, base, head, current_user.gitea_token)
|
Gitea::Repository::Commits::CompareService.call(@owner.login, @project.identifier, Addressable::URI.escape(base), Addressable::URI.escape(head), current_user.gitea_token)
|
||||||
|
end
|
||||||
|
|
||||||
|
def page_size
|
||||||
|
params.fetch(:page, 1).to_i
|
||||||
|
end
|
||||||
|
|
||||||
|
def page_limit
|
||||||
|
params.fetch(:limit, 15).to_i
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -179,7 +179,7 @@ module Ci::CloudAccountManageable
|
||||||
|
|
||||||
def drone_oauth_user!(url, state)
|
def drone_oauth_user!(url, state)
|
||||||
logger.info "[drone] drone_oauth_user url: #{url}"
|
logger.info "[drone] drone_oauth_user url: #{url}"
|
||||||
conn = Faraday.new(url: url) do |req|
|
conn = Faraday.new(url: "#{Gitea.gitea_config[:domain]}#{url}") do |req|
|
||||||
req.request :url_encoded
|
req.request :url_encoded
|
||||||
req.adapter Faraday.default_adapter
|
req.adapter Faraday.default_adapter
|
||||||
req.headers["cookie"] = "_session_=#{SecureRandom.hex(28)}; _oauth_state_=#{state}"
|
req.headers["cookie"] = "_session_=#{SecureRandom.hex(28)}; _oauth_state_=#{state}"
|
||||||
|
|
@ -188,7 +188,8 @@ module Ci::CloudAccountManageable
|
||||||
response = conn.get
|
response = conn.get
|
||||||
logger.info "[drone] response headers: #{response.headers}"
|
logger.info "[drone] response headers: #{response.headers}"
|
||||||
|
|
||||||
response.headers['location'].include?('error') ? false : true
|
true
|
||||||
|
# response.headers['location'].include?('error') ? false : true
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,11 @@ module LoginHelper
|
||||||
def sync_pwd_to_gitea!(user, hash={})
|
def sync_pwd_to_gitea!(user, hash={})
|
||||||
return true if user.is_sync_pwd?
|
return true if user.is_sync_pwd?
|
||||||
|
|
||||||
sync_params = { email: user.mail }
|
sync_params = {
|
||||||
|
login_name: user.name,
|
||||||
|
source_id: 0,
|
||||||
|
email: user.mail
|
||||||
|
}
|
||||||
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params.merge(hash))
|
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params.merge(hash))
|
||||||
if interactor.success?
|
if interactor.success?
|
||||||
Rails.logger.info "########_ login is #{user.login} sync_pwd_to_gitea success _########"
|
Rails.logger.info "########_ login is #{user.login} sync_pwd_to_gitea success _########"
|
||||||
|
|
|
||||||
|
|
@ -2,7 +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
|
||||||
|
|
@ -11,20 +10,64 @@ 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)
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|
def auto_update(user, params={})
|
||||||
|
return if params.blank?
|
||||||
|
result = {message: nil, user: nil}
|
||||||
|
before_login = user.login
|
||||||
|
user.login = params[:username]
|
||||||
|
user.password = params[:password]
|
||||||
|
user.mail = params[:email]
|
||||||
|
|
||||||
|
if user.save!
|
||||||
|
sync_params = {
|
||||||
|
password: params[:password].to_s,
|
||||||
|
email: params[:email],
|
||||||
|
login_name: params[:username],
|
||||||
|
new_name: params[:username],
|
||||||
|
source_id: 0
|
||||||
|
}
|
||||||
|
|
||||||
|
interactor = Gitea::User::UpdateInteractor.call(before_login, sync_params)
|
||||||
|
if interactor.success?
|
||||||
|
result[:user] = user
|
||||||
|
else
|
||||||
|
result[:message] = '用户同步Gitea失败!'
|
||||||
|
end
|
||||||
|
else
|
||||||
|
result[:message] = user.errors.full_messages.join(",")
|
||||||
|
return
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ module RenderHelper
|
||||||
render json: { status: 0, message: 'success' }.merge(data)
|
render json: { status: 0, message: 'success' }.merge(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_error(status = -1, message = '')
|
def render_error(message = '', status=-1)
|
||||||
render json: { status: status, message: message }
|
render json: { status: status, message: message }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,13 @@ 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
|
||||||
|
|
@ -13,7 +20,7 @@ class ForksController < ApplicationController
|
||||||
if current_user&.id == @project.user_id
|
if current_user&.id == @project.user_id
|
||||||
render_result(-1, "自己不能fork自己的项目")
|
render_result(-1, "自己不能fork自己的项目")
|
||||||
elsif Project.exists?(user_id: current_user.id, identifier: @project.identifier)
|
elsif Project.exists?(user_id: current_user.id, identifier: @project.identifier)
|
||||||
render_result(-1, "fork失败,你已拥有了这个项目")
|
render_result(0, "fork失败,你已拥有了这个项目")
|
||||||
end
|
end
|
||||||
# return if current_user != @project.owner
|
# return if current_user != @project.owner
|
||||||
# render_result(-1, "自己不能fork自己的项目")
|
# render_result(-1, "自己不能fork自己的项目")
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ class IssueTagsController < ApplicationController
|
||||||
before_action :require_login, except: [:index]
|
before_action :require_login, except: [:index]
|
||||||
before_action :load_repository
|
before_action :load_repository
|
||||||
before_action :set_user
|
before_action :set_user
|
||||||
before_action :check_issue_permission, except: :index
|
before_action :check_issue_tags_permission
|
||||||
before_action :set_issue_tag, only: [:edit, :update, :destroy]
|
before_action :set_issue_tag, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ class IssueTagsController < ApplicationController
|
||||||
|
|
||||||
|
|
||||||
def create
|
def create
|
||||||
title = params[:name].to_s.strip.first(10)
|
title = params[:name].to_s.strip.first(15)
|
||||||
desc = params[:description].to_s.first(30)
|
desc = params[:description].to_s.first(30)
|
||||||
color = params[:color] || "#ccc"
|
color = params[:color] || "#ccc"
|
||||||
|
|
||||||
|
|
@ -29,7 +29,7 @@ class IssueTagsController < ApplicationController
|
||||||
|
|
||||||
if title.present?
|
if title.present?
|
||||||
if IssueTag.exists?(name: title, project_id: @project.id)
|
if IssueTag.exists?(name: title, project_id: @project.id)
|
||||||
normal_status(-1, "标签已存在")
|
normal_status(-1, "项目标记已存在")
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
|
|
@ -37,12 +37,12 @@ class IssueTagsController < ApplicationController
|
||||||
if issue_tag.save
|
if issue_tag.save
|
||||||
# gitea_tag = Gitea::Labels::CreateService.new(current_user, @repository.try(:identifier), tag_params).call
|
# gitea_tag = Gitea::Labels::CreateService.new(current_user, @repository.try(:identifier), tag_params).call
|
||||||
# if gitea_tag && issue_tag.update_attributes(gid: gitea_tag["id"], gitea_url: gitea_tag["url"])
|
# if gitea_tag && issue_tag.update_attributes(gid: gitea_tag["id"], gitea_url: gitea_tag["url"])
|
||||||
# normal_status(0, "标签创建成功")
|
normal_status(0, "项目标记创建成功!")
|
||||||
# else
|
# else
|
||||||
# normal_status(-1, "标签创建失败")
|
# normal_status(-1, "项目标记创建失败")
|
||||||
# end
|
# end
|
||||||
else
|
else
|
||||||
normal_status(-1, "标签创建失败")
|
normal_status(-1, "项目标记创建失败")
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
puts "create version release error: #{e.message}"
|
puts "create version release error: #{e.message}"
|
||||||
|
|
@ -51,7 +51,7 @@ class IssueTagsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
normal_status(-1, "标签名称不能为空")
|
normal_status(-1, "项目标记名称不能为空")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -60,8 +60,8 @@ class IssueTagsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
title = params[:name]
|
title = params[:name].to_s.strip.first(15)
|
||||||
desc = params[:description]
|
desc = params[:description].to_s.first(30)
|
||||||
color = params[:color] || "#ccc"
|
color = params[:color] || "#ccc"
|
||||||
|
|
||||||
tag_params = {
|
tag_params = {
|
||||||
|
|
@ -71,19 +71,19 @@ class IssueTagsController < ApplicationController
|
||||||
}
|
}
|
||||||
if title.present?
|
if title.present?
|
||||||
if IssueTag.exists?(name: title, project_id: @project.id) && (@issue_tag.name != title)
|
if IssueTag.exists?(name: title, project_id: @project.id) && (@issue_tag.name != title)
|
||||||
normal_status(-1, "标签已存在")
|
normal_status(-1, "项目标记已存在")
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
if @issue_tag.update_attributes(tag_params)
|
if @issue_tag.update_attributes(tag_params)
|
||||||
# gitea_tag = Gitea::Labels::UpdateService.new(current_user, @repository.try(:identifier),@issue_tag.try(:gid), tag_params).call
|
# gitea_tag = Gitea::Labels::UpdateService.new(current_user, @repository.try(:identifier),@issue_tag.try(:gid), tag_params).call
|
||||||
# if gitea_tag
|
# if gitea_tag
|
||||||
# normal_status(0, "标签更新成功")
|
# normal_status(0, "项目标记更新成功")
|
||||||
# else
|
# else
|
||||||
# normal_status(-1, "标签更新失败")
|
# normal_status(-1, "项目标记更新失败")
|
||||||
# end
|
# end
|
||||||
else
|
else
|
||||||
normal_status(-1, "标签更新失败")
|
normal_status(-1, "项目标记更新失败")
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
puts "create version release error: #{e.message}"
|
puts "create version release error: #{e.message}"
|
||||||
|
|
@ -92,7 +92,7 @@ class IssueTagsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
normal_status(-1, "标签名称不能为空")
|
normal_status(-1, "项目标记名称不能为空")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -102,12 +102,12 @@ class IssueTagsController < ApplicationController
|
||||||
if @issue_tag.destroy
|
if @issue_tag.destroy
|
||||||
# issue_tag = Gitea::Labels::DeleteService.new(@user, @repository.try(:identifier), @issue_tag.try(:gid)).call
|
# issue_tag = Gitea::Labels::DeleteService.new(@user, @repository.try(:identifier), @issue_tag.try(:gid)).call
|
||||||
# if issue_tag
|
# if issue_tag
|
||||||
# normal_status(0, "标签删除成功")
|
# normal_status(0, "项目标记删除成功")
|
||||||
# else
|
# else
|
||||||
# normal_status(-1, "标签删除失败")
|
# normal_status(-1, "项目标记删除失败")
|
||||||
# end
|
# end
|
||||||
else
|
else
|
||||||
normal_status(-1, "标签删除失败")
|
normal_status(-1, "项目标记删除失败")
|
||||||
end
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
puts "create version release error: #{e.message}"
|
puts "create version release error: #{e.message}"
|
||||||
|
|
@ -122,16 +122,16 @@ class IssueTagsController < ApplicationController
|
||||||
@user = @project.owner
|
@user = @project.owner
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_issue_permission
|
def check_issue_tags_permission
|
||||||
unless @project.member?(current_user) || current_user.admin?
|
unless @project.manager?(current_user) || current_user.admin?
|
||||||
normal_status(-1, "您没有权限")
|
return render_forbidden('你不是管理员,没有权限操作')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def set_issue_tag
|
def set_issue_tag
|
||||||
@issue_tag = IssueTag.find_by_id(params[:id])
|
@issue_tag = IssueTag.find_by_id(params[:id])
|
||||||
unless @issue_tag.present?
|
unless @issue_tag.present?
|
||||||
normal_status(-1, "标签不存在")
|
normal_status(-1, "项目标记不存在")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ class IssuesController < ApplicationController
|
||||||
include TagChosenHelper
|
include TagChosenHelper
|
||||||
|
|
||||||
def index
|
def index
|
||||||
|
@user_operate_issue = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user))
|
||||||
@user_admin_or_member = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user) || @project.is_public?)
|
@user_admin_or_member = current_user.present? && current_user.logged? && (current_user.admin || @project.member?(current_user) || @project.is_public?)
|
||||||
issues = @project.issues.issue_issue.issue_index_includes
|
issues = @project.issues.issue_issue.issue_index_includes
|
||||||
issues = issues.where(is_private: false) unless @user_admin_or_member
|
issues = issues.where(is_private: false) unless @user_admin_or_member
|
||||||
|
|
@ -23,13 +24,13 @@ class IssuesController < ApplicationController
|
||||||
@filter_issues = @all_issues
|
@filter_issues = @all_issues
|
||||||
@filter_issues = @filter_issues.where.not(status_id: IssueStatus::CLOSED) if params[:status_type].to_i == IssueStatus::ADD
|
@filter_issues = @filter_issues.where.not(status_id: IssueStatus::CLOSED) if params[:status_type].to_i == IssueStatus::ADD
|
||||||
@filter_issues = @filter_issues.where(status_id: IssueStatus::CLOSED) if params[:status_type].to_i == IssueStatus::SOLVING
|
@filter_issues = @filter_issues.where(status_id: IssueStatus::CLOSED) if params[:status_type].to_i == IssueStatus::SOLVING
|
||||||
@filter_issues = @filter_issues.where("subject LIKE ? OR description LIKE ? ", "%#{params[:search]}%", "%#{params[:search]}%") if params[:search].present?
|
@filter_issues = @filter_issues.where("issues.subject LIKE ? OR issues.description LIKE ? ", "%#{params[:search]}%", "%#{params[:search]}%") if params[:search].present?
|
||||||
@open_issues = @all_issues.where.not(status_id: IssueStatus::CLOSED)
|
@open_issues = @all_issues.where.not(status_id: IssueStatus::CLOSED)
|
||||||
@close_issues = @all_issues.where(status_id: IssueStatus::CLOSED)
|
@close_issues = @all_issues.where(status_id: IssueStatus::CLOSED)
|
||||||
@assign_to_me = @filter_issues.where(assigned_to_id: current_user&.id)
|
|
||||||
@my_published = @filter_issues.where(author_id: current_user&.id)
|
|
||||||
scopes = Issues::ListQueryService.call(issues,params.delete_if{|k,v| v.blank?}, "Issue")
|
scopes = Issues::ListQueryService.call(issues,params.delete_if{|k,v| v.blank?}, "Issue")
|
||||||
@issues_size = scopes.size
|
@issues_size = scopes.size
|
||||||
|
@assign_to_me = scopes.where(assigned_to_id: current_user&.id)
|
||||||
|
@my_published = scopes.where(author_id: current_user&.id)
|
||||||
@issues = paginate(scopes)
|
@issues = paginate(scopes)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
|
|
@ -108,7 +109,7 @@ class IssuesController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
issue_params = issue_send_params(params)
|
issue_params = issue_send_params(params)
|
||||||
Issues::CreateForm.new({subject:issue_params[:subject]}).validate!
|
Issues::CreateForm.new({subject: issue_params[:subject], description: issue_params[:description].blank? ? issue_params[:description] : issue_params[:description].b}).validate!
|
||||||
@issue = Issue.new(issue_params)
|
@issue = Issue.new(issue_params)
|
||||||
if @issue.save!
|
if @issue.save!
|
||||||
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if Site.has_notice_menu?
|
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if Site.has_notice_menu?
|
||||||
|
|
@ -125,9 +126,15 @@ class IssuesController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if params[:issue_tag_ids].present?
|
if params[:issue_tag_ids].present?
|
||||||
params[:issue_tag_ids].each do |tag|
|
if params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size > 1
|
||||||
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
return normal_status(-1, "最多只能创建一个标记。")
|
||||||
end
|
elsif params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size == 1
|
||||||
|
params[:issue_tag_ids].each do |tag|
|
||||||
|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return normal_status(-1, "请输入正确的标记。")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if params[:assigned_to_id].present?
|
if params[:assigned_to_id].present?
|
||||||
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
|
Tiding.create!(user_id: params[:assigned_to_id], trigger_user_id: current_user.id,
|
||||||
|
|
@ -142,11 +149,13 @@ class IssuesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: "create")
|
||||||
|
@issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) if params[:status_id].to_i == 5
|
||||||
|
|
||||||
|
|
||||||
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
Rails.logger.info "[ATME] maybe to at such users: #{@atme_receivers.pluck(:login)}"
|
||||||
AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0
|
AtmeService.call(current_user, @atme_receivers, @issue) if @atme_receivers.size > 0
|
||||||
|
|
||||||
render json: {status: 0, message: "创建成", id: @issue.id}
|
render json: {status: 0, message: "创建成功", id: @issue.id}
|
||||||
else
|
else
|
||||||
normal_status(-1, "创建失败")
|
normal_status(-1, "创建失败")
|
||||||
end
|
end
|
||||||
|
|
@ -165,11 +174,18 @@ class IssuesController < ApplicationController
|
||||||
last_token = @issue.token
|
last_token = @issue.token
|
||||||
last_status_id = @issue.status_id
|
last_status_id = @issue.status_id
|
||||||
@issue&.issue_tags_relates&.destroy_all if params[:issue_tag_ids].blank?
|
@issue&.issue_tags_relates&.destroy_all if params[:issue_tag_ids].blank?
|
||||||
if params[:issue_tag_ids].present? && !@issue&.issue_tags_relates.where(issue_tag_id: params[:issue_tag_ids]).exists?
|
if params[:issue_tag_ids].present?
|
||||||
@issue&.issue_tags_relates&.destroy_all
|
if params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size > 1
|
||||||
params[:issue_tag_ids].each do |tag|
|
return normal_status(-1, "最多只能创建一个标记。")
|
||||||
IssueTagsRelate.create(issue_id: @issue.id, issue_tag_id: tag)
|
elsif params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size == 1
|
||||||
end
|
@issue&.issue_tags_relates&.destroy_all
|
||||||
|
params[:issue_tag_ids].each do |tag|
|
||||||
|
next if tag == [""]
|
||||||
|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return normal_status(-1, "请输入正确的标记。")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
issue_files = params[:attachment_ids]
|
issue_files = params[:attachment_ids]
|
||||||
|
|
@ -207,7 +223,7 @@ class IssuesController < ApplicationController
|
||||||
normal_status(-1, "不允许修改为关闭状态")
|
normal_status(-1, "不允许修改为关闭状态")
|
||||||
else
|
else
|
||||||
issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id)
|
issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id)
|
||||||
Issues::UpdateForm.new({subject:issue_params[:subject]}).validate!
|
Issues::UpdateForm.new({subject: issue_params[:subject], description: issue_params[:description].blank? ? issue_params[:description] : issue_params[:description].b}).validate!
|
||||||
if @issue.update_attributes(issue_params)
|
if @issue.update_attributes(issue_params)
|
||||||
if @issue&.pull_request.present?
|
if @issue&.pull_request.present?
|
||||||
SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @issue&.pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) if Site.has_notice_menu?
|
SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @issue&.pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) if Site.has_notice_menu?
|
||||||
|
|
@ -231,7 +247,7 @@ class IssuesController < ApplicationController
|
||||||
end
|
end
|
||||||
if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时
|
if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时
|
||||||
@issue.issue_times.update_all(end_time: Time.now)
|
@issue.issue_times.update_all(end_time: Time.now)
|
||||||
@issue.update_closed_issues_count_in_project!
|
# @issue.update_closed_issues_count_in_project!
|
||||||
if @issue.issue_type.to_s == "2" && last_status_id != 5
|
if @issue.issue_type.to_s == "2" && last_status_id != 5
|
||||||
if @issue.assigned_to_id.present? && last_status_id == 3 #只有当用户完成100%时,才给token
|
if @issue.assigned_to_id.present? && last_status_id == 3 #只有当用户完成100%时,才给token
|
||||||
post_to_chain("add", @issue.token, @issue.get_assign_user.try(:login))
|
post_to_chain("add", @issue.token, @issue.get_assign_user.try(:login))
|
||||||
|
|
@ -473,7 +489,8 @@ class IssuesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def operate_issue_permission
|
def operate_issue_permission
|
||||||
return render_forbidden("您没有权限进行此操作.") unless current_user.present? && current_user.logged? && (current_user.admin? || @project.member?(current_user) || @project.is_public?)
|
@issue = Issue.find_by_id(params[:id]) unless @issue.present?
|
||||||
|
return render_forbidden("您没有权限进行此操作.") unless current_user.present? && current_user.logged? && (current_user.admin? || @project.member?(current_user) || (@project.is_public && @issue.nil?) || (@project.is_public && @issue.present? && @issue.author_id == current_user.id))
|
||||||
end
|
end
|
||||||
|
|
||||||
def export_issues(issues)
|
def export_issues(issues)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ class JournalsController < ApplicationController
|
||||||
normal_status(-1, "评论内容不能为空")
|
normal_status(-1, "评论内容不能为空")
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
|
Journals::CreateForm.new({notes: notes.to_s.strip.blank? ? notes.to_s.strip : notes.to_s.strip.b}).validate!
|
||||||
journal_params = {
|
journal_params = {
|
||||||
journalized_id: @issue.id ,
|
journalized_id: @issue.id ,
|
||||||
journalized_type: "Issue",
|
journalized_type: "Issue",
|
||||||
|
|
@ -53,6 +54,9 @@ class JournalsController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue Exception => exception
|
||||||
|
puts exception.message
|
||||||
|
normal_status(-1, exception.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy
|
def destroy
|
||||||
|
|
@ -70,7 +74,8 @@ class JournalsController < ApplicationController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
content = params[:content]
|
content = params[:content]
|
||||||
if content.present?
|
if content.present?
|
||||||
|
Journals::UpdateForm.new({notes: notes.to_s.strip.blank? ? notes.to_s.strip : notes.to_s.strip.b}).validate!
|
||||||
if @journal.update_attribute(:notes, content)
|
if @journal.update_attribute(:notes, content)
|
||||||
normal_status(0, "更新成功")
|
normal_status(0, "更新成功")
|
||||||
else
|
else
|
||||||
|
|
@ -79,7 +84,9 @@ class JournalsController < ApplicationController
|
||||||
else
|
else
|
||||||
normal_status(-1, "评论的内容不能为空")
|
normal_status(-1, "评论的内容不能为空")
|
||||||
end
|
end
|
||||||
|
rescue Exception => exception
|
||||||
|
puts exception.message
|
||||||
|
normal_status(-1, exception.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_children_journals
|
def get_children_journals
|
||||||
|
|
|
||||||
|
|
@ -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'
|
||||||
|
|
|
||||||
|
|
@ -3,11 +3,19 @@ class MembersController < ApplicationController
|
||||||
before_action :load_project
|
before_action :load_project
|
||||||
before_action :find_user_with_id, only: %i[create remove change_role]
|
before_action :find_user_with_id, only: %i[create remove change_role]
|
||||||
before_action :check_user_profile_completed, only: [:create]
|
before_action :check_user_profile_completed, only: [:create]
|
||||||
before_action :operate!, except: %i[index]
|
before_action :operate!
|
||||||
before_action :check_member_exists!, only: %i[create]
|
before_action :check_member_exists!, only: %i[create]
|
||||||
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?
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
class NoticesController < ApplicationController
|
||||||
|
|
||||||
|
def create
|
||||||
|
tip_exception("参数有误") if params["source"].blank?
|
||||||
|
user_id = params[:user_id]
|
||||||
|
|
||||||
|
if params["source"] == "CompetitionBegin"
|
||||||
|
competition_id = params[:competition_id]
|
||||||
|
SendTemplateMessageJob.perform_later('CompetitionBegin', user_id, competition_id)
|
||||||
|
elsif params["source"] == "CompetitionResult"
|
||||||
|
competition_id = params[:competition_id]
|
||||||
|
SendTemplateMessageJob.perform_later('CompetitionResult', user_id, competition_id)
|
||||||
|
elsif params["source"] == "CompetitionReview"
|
||||||
|
competition_id = params[:competition_id]
|
||||||
|
SendTemplateMessageJob.perform_later('CompetitionReview', user_id, competition_id)
|
||||||
|
else
|
||||||
|
tip_exception("#{params["source"]}未配置")
|
||||||
|
end
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -5,7 +5,11 @@ class Organizations::OrganizationUsersController < Organizations::BaseController
|
||||||
def index
|
def index
|
||||||
@organization_users = @organization.organization_users.includes(:user)
|
@organization_users = @organization.organization_users.includes(:user)
|
||||||
search = params[:search].to_s.downcase
|
search = params[:search].to_s.downcase
|
||||||
@organization_users = @organization_users.joins(:user).merge(User.like(search))
|
user_condition_users = User.like(search).to_sql
|
||||||
|
team_condition_teams = User.joins(:teams).merge(@organization.teams.like(search)).to_sql
|
||||||
|
users = User.from("( #{user_condition_users} UNION #{team_condition_teams }) AS users")
|
||||||
|
|
||||||
|
@organization_users = @organization_users.where(user_id: users).distinct
|
||||||
|
|
||||||
@organization_users = kaminari_paginate(@organization_users)
|
@organization_users = kaminari_paginate(@organization_users)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
def create
|
def create
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
tip_exception("无法使用以下关键词:#{organization_params[:name]},请重新命名") if ReversedKeyword.check_exists?(organization_params[:name])
|
tip_exception("无法使用以下关键词:#{organization_params[:name]},请重新命名") if ReversedKeyword.check_exists?(organization_params[:name])
|
||||||
Organizations::CreateForm.new(organization_params).validate!
|
Organizations::CreateForm.new(organization_params.merge(original_name: "")).validate!
|
||||||
@organization = Organizations::CreateService.call(current_user, organization_params)
|
@organization = Organizations::CreateService.call(current_user, organization_params)
|
||||||
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
|
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
|
||||||
end
|
end
|
||||||
|
|
@ -39,14 +39,14 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
|
|
||||||
def update
|
def update
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Organizations::CreateForm.new(organization_params).validate!
|
Organizations::CreateForm.new(organization_params.merge(original_name: @organization.login)).validate!
|
||||||
login = @organization.login
|
login = @organization.login
|
||||||
@organization.login = organization_params[:name] if organization_params[:name].present?
|
@organization.login = organization_params[:name] if organization_params[:name].present?
|
||||||
@organization.nickname = organization_params[:nickname] if organization_params[:nickname].present?
|
@organization.nickname = organization_params[:nickname] if organization_params[:nickname].present?
|
||||||
@organization.save!
|
@organization.save!
|
||||||
sync_organization_extension!
|
sync_organization_extension!
|
||||||
|
|
||||||
Gitea::Organization::UpdateService.call(@organization.gitea_token, login, @organization.reload)
|
Gitea::Organization::UpdateService.call(current_user.gitea_token, login, @organization.reload)
|
||||||
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
|
Util.write_file(@image, avatar_path(@organization)) if params[:image].present?
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
@ -57,10 +57,16 @@ class Organizations::OrganizationsController < Organizations::BaseController
|
||||||
def destroy
|
def destroy
|
||||||
tip_exception("密码不正确") unless current_user.check_password?(password)
|
tip_exception("密码不正确") unless current_user.check_password?(password)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Gitea::Organization::DeleteService.call(@organization.gitea_token, @organization.login)
|
gitea_destroy = Gitea::Organization::DeleteService.call(current_user.gitea_token, @organization.login)
|
||||||
@organization.destroy!
|
if gitea_destroy[:status] == 204
|
||||||
|
@organization.destroy!
|
||||||
|
render_ok
|
||||||
|
elsif gitea_destroy[:status] == 500
|
||||||
|
tip_exception("当组织内含有仓库时,无法删除此组织")
|
||||||
|
else
|
||||||
|
tip_exception("")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
render_ok
|
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ class Organizations::TeamUsersController < Organizations::BaseController
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@team_user = TeamUser.build(@organization.id, @operate_user.id, @team.id)
|
@team_user = TeamUser.build(@organization.id, @operate_user.id, @team.id)
|
||||||
@organization_user = OrganizationUser.build(@organization.id, @operate_user.id)
|
@organization_user = OrganizationUser.build(@organization.id, @operate_user.id)
|
||||||
SendTemplateMessageJob.perform_later('OrganizationRole', @operate_user.id, @organization.id, @team.authorize_name) if Site.has_notice_menu?
|
SendTemplateMessageJob.perform_later('TeamJoined', @operate_user.id, @organization.id, @team.id) if Site.has_notice_menu?
|
||||||
Gitea::Organization::TeamUser::CreateService.call(@organization.gitea_token, @team.gtid, @operate_user.login)
|
Gitea::Organization::TeamUser::CreateService.call(@organization.gitea_token, @team.gtid, @operate_user.login)
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
@ -31,6 +31,7 @@ class Organizations::TeamUsersController < Organizations::BaseController
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@team_user.destroy!
|
@team_user.destroy!
|
||||||
Gitea::Organization::TeamUser::DeleteService.call(@organization.gitea_token, @team.gtid, @operate_user.login)
|
Gitea::Organization::TeamUser::DeleteService.call(@organization.gitea_token, @team.gtid, @operate_user.login)
|
||||||
|
SendTemplateMessageJob.perform_later('TeamLeft', @operate_user.id, @organization.id, @team.id) if Site.has_notice_menu?
|
||||||
org_team_users = @organization.team_users.where(user_id: @operate_user.id)
|
org_team_users = @organization.team_users.where(user_id: @operate_user.id)
|
||||||
unless org_team_users.present?
|
unless org_team_users.present?
|
||||||
@organization.organization_users.find_by(user_id: @operate_user.id).destroy!
|
@organization.organization_users.find_by(user_id: @operate_user.id).destroy!
|
||||||
|
|
|
||||||
|
|
@ -4,15 +4,24 @@ class Organizations::TeamsController < Organizations::BaseController
|
||||||
before_action :check_user_can_edit_org, only: [:create, :update, :destroy]
|
before_action :check_user_can_edit_org, only: [:create, :update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
#if @organization.is_owner?(current_user) || current_user.admin?
|
|
||||||
@teams = @organization.teams
|
|
||||||
#else
|
|
||||||
# @teams = @organization.teams.joins(:team_users).where(team_users: {user_id: current_user.id})
|
|
||||||
#end
|
|
||||||
@is_admin = can_edit_org?
|
|
||||||
@teams = @teams.includes(:team_units, :team_users)
|
|
||||||
|
|
||||||
@teams = kaminari_paginate(@teams)
|
if params[:is_full].present?
|
||||||
|
if can_edit_org?
|
||||||
|
@teams = @organization.teams
|
||||||
|
else
|
||||||
|
@teams = []
|
||||||
|
end
|
||||||
|
else
|
||||||
|
#if @organization.is_owner?(current_user) || current_user.admin?
|
||||||
|
@teams = @organization.teams
|
||||||
|
#else
|
||||||
|
# @teams = @organization.teams.joins(:team_users).where(team_users: {user_id: current_user.id})
|
||||||
|
#end
|
||||||
|
@is_admin = can_edit_org?
|
||||||
|
@teams = @teams.includes(:team_units, :team_users)
|
||||||
|
|
||||||
|
@teams = kaminari_paginate(@teams)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def search
|
def search
|
||||||
|
|
@ -34,8 +43,12 @@ class Organizations::TeamsController < Organizations::BaseController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
Organizations::CreateTeamForm.new(team_params).validate!
|
if @organization.teams.count >= 50
|
||||||
@team = Organizations::Teams::CreateService.call(current_user, @organization, team_params)
|
return tip_exception("组织的团队数量已超过限制!")
|
||||||
|
else
|
||||||
|
Organizations::CreateTeamForm.new(team_params).validate!
|
||||||
|
@team = Organizations::Teams::CreateService.call(current_user, @organization, team_params)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
|
|
||||||
|
|
@ -20,7 +20,7 @@ class OwnersController < ApplicationController
|
||||||
@is_admin = current_user.admin? || @owner.is_owner?(current_user.id)
|
@is_admin = current_user.admin? || @owner.is_owner?(current_user.id)
|
||||||
@is_member = @owner.is_member?(current_user.id)
|
@is_member = @owner.is_member?(current_user.id)
|
||||||
# 用户
|
# 用户
|
||||||
else
|
elsif @owner.is_a?(User)
|
||||||
#待办事项,现在未做
|
#待办事项,现在未做
|
||||||
if User.current.admin? || User.current.login == @owner.login
|
if User.current.admin? || User.current.login == @owner.login
|
||||||
@waiting_applied_messages = @owner.applied_messages.waiting
|
@waiting_applied_messages = @owner.applied_messages.waiting
|
||||||
|
|
@ -45,7 +45,6 @@ class OwnersController < ApplicationController
|
||||||
@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
|
||||||
puts @owner.as_json
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ class PraiseTreadController < ApplicationController
|
||||||
begin
|
begin
|
||||||
return normal_status(2, "你已点过赞了") if current_user.liked?(@project)
|
return normal_status(2, "你已点过赞了") if current_user.liked?(@project)
|
||||||
current_user.like!(@project)
|
current_user.like!(@project)
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectPraised', current_user.id, @project.id) if Site.has_notice_menu?
|
||||||
render_ok({praises_count: @project.praises_count, praised: current_user.liked?(@project)})
|
render_ok({praises_count: @project.praises_count, praised: current_user.liked?(@project)})
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ class ProjectTrendsController < ApplicationController
|
||||||
before_action :check_project_public
|
before_action :check_project_public
|
||||||
|
|
||||||
def index
|
def index
|
||||||
project_trends = @project.project_trends.preload(:user, trend: :user)
|
project_trends = @project.project_trends.preload(:user, trend: :user, project: :owner)
|
||||||
|
|
||||||
check_time = params[:time] #时间的筛选
|
check_time = params[:time] #时间的筛选
|
||||||
check_type = params[:type] #动态类型的筛选,目前已知的有 Issue, PullRequest, Version
|
check_type = params[:type] #动态类型的筛选,目前已知的有 Issue, PullRequest, Version
|
||||||
|
|
|
||||||
|
|
@ -13,16 +13,19 @@ class ProjectsController < ApplicationController
|
||||||
def menu_list
|
def menu_list
|
||||||
menu = []
|
menu = []
|
||||||
|
|
||||||
|
user_is_admin = current_user.admin? || @project.manager?(current_user)
|
||||||
|
|
||||||
menu.append(menu_hash_by_name("home"))
|
menu.append(menu_hash_by_name("home"))
|
||||||
menu.append(menu_hash_by_name("code")) if @project.has_menu_permission("code")
|
menu.append(menu_hash_by_name("code")) if @project.has_menu_permission("code")
|
||||||
menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues")
|
menu.append(menu_hash_by_name("issues")) if @project.has_menu_permission("issues")
|
||||||
menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls")
|
menu.append(menu_hash_by_name("pulls")) if @project.has_menu_permission("pulls") && @project.forge?
|
||||||
menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki")
|
menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops") && @project.forge?
|
||||||
menu.append(menu_hash_by_name("devops")) if @project.has_menu_permission("devops")
|
|
||||||
menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions")
|
menu.append(menu_hash_by_name("versions")) if @project.has_menu_permission("versions")
|
||||||
menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources")
|
menu.append(menu_hash_by_name("wiki")) if @project.has_menu_permission("wiki") && @project.forge?
|
||||||
|
menu.append(menu_hash_by_name("resources")) if @project.has_menu_permission("resources") && @project.forge?
|
||||||
menu.append(menu_hash_by_name("activity"))
|
menu.append(menu_hash_by_name("activity"))
|
||||||
menu.append(menu_hash_by_name("settings")) if current_user.admin? || @project.manager?(current_user)
|
menu.append(menu_hash_by_name("settings")) if user_is_admin && @project.forge?
|
||||||
|
menu.append(menu_hash_by_name("quit")) if !user_is_admin && @project.member(current_user.id) && @project.forge?
|
||||||
|
|
||||||
render json: menu
|
render json: menu
|
||||||
end
|
end
|
||||||
|
|
@ -49,6 +52,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)
|
||||||
|
|
@ -59,7 +69,7 @@ class ProjectsController < ApplicationController
|
||||||
Projects::MigrateForm.new(mirror_params).validate!
|
Projects::MigrateForm.new(mirror_params).validate!
|
||||||
|
|
||||||
@project =
|
@project =
|
||||||
if enable_accelerator?(mirror_params[:clone_addr])
|
if EduSetting.get("mirror_address").to_s.include?("github") && enable_accelerator?(mirror_params[:clone_addr])
|
||||||
source_clone_url = mirror_params[:clone_addr]
|
source_clone_url = mirror_params[:clone_addr]
|
||||||
uid_logger("########## 已动加速器 ##########")
|
uid_logger("########## 已动加速器 ##########")
|
||||||
result = Gitea::Accelerator::MigrateService.call(mirror_params)
|
result = Gitea::Accelerator::MigrateService.call(mirror_params)
|
||||||
|
|
@ -71,6 +81,11 @@ class ProjectsController < ApplicationController
|
||||||
else
|
else
|
||||||
Projects::MigrateService.call(current_user, mirror_params)
|
Projects::MigrateService.call(current_user, mirror_params)
|
||||||
end
|
end
|
||||||
|
elsif EduSetting.get("mirror_address").to_s.include?("cnpmjs") && mirror_params[:clone_addr].include?("github.com")
|
||||||
|
source_clone_url = mirror_params[:clone_addr]
|
||||||
|
clone_url = source_clone_url.gsub('github.com', 'github.com.cnpmjs.org')
|
||||||
|
uid_logger("########## 更改clone_addr ##########")
|
||||||
|
Projects::MigrateService.call(current_user, mirror_params.merge(source_clone_url: source_clone_url, clone_addr: clone_url))
|
||||||
else
|
else
|
||||||
Projects::MigrateService.call(current_user, mirror_params)
|
Projects::MigrateService.call(current_user, mirror_params)
|
||||||
end
|
end
|
||||||
|
|
@ -82,8 +97,9 @@ class ProjectsController < ApplicationController
|
||||||
def branches
|
def branches
|
||||||
return @branches = [] unless @project.forge?
|
return @branches = [] unless @project.forge?
|
||||||
|
|
||||||
result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier)
|
# result = Gitea::Repository::Branches::ListService.call(@owner, @project.identifier)
|
||||||
@branches = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
result = Gitea::Repository::Branches::ListNameService.call(@owner, @project.identifier, params[:name])
|
||||||
|
@branches = result.is_a?(Hash) ? (result.key?(:status) ? [] : result["branch_name"]) : result
|
||||||
end
|
end
|
||||||
|
|
||||||
def branches_slice
|
def branches_slice
|
||||||
|
|
@ -94,18 +110,18 @@ class ProjectsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def group_type_list
|
def group_type_list
|
||||||
project_statics = ProjectStatistic.first
|
# project_statics = ProjectStatistic.first
|
||||||
|
|
||||||
@project_statics_list = [
|
@project_statics_list = [
|
||||||
{
|
{
|
||||||
project_type: 'common',
|
project_type: 'common',
|
||||||
name: '开源托管项目',
|
name: '开源托管项目',
|
||||||
projects_count: project_statics&.common_projects_count || 0
|
projects_count: Project.common.size || 0
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
project_type: 'mirror',
|
project_type: 'mirror',
|
||||||
name: '开源镜像项目',
|
name: '开源镜像项目',
|
||||||
projects_count: project_statics&.mirror_projects_count || 0
|
projects_count: Project.sync_mirror.size + Project.mirror.size || 0
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
@ -129,7 +145,7 @@ class ProjectsController < ApplicationController
|
||||||
validate_params = project_params.slice(:name, :description,
|
validate_params = project_params.slice(:name, :description,
|
||||||
:project_category_id, :project_language_id, :private, :identifier)
|
:project_category_id, :project_language_id, :private, :identifier)
|
||||||
|
|
||||||
Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id, project_identifier: @project.identifier)).validate!
|
Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id, project_identifier: @project.identifier, project_name: @project.name)).validate!
|
||||||
|
|
||||||
private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false
|
private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false
|
||||||
|
|
||||||
|
|
@ -171,6 +187,22 @@ class ProjectsController < ApplicationController
|
||||||
tip_exception(e.message)
|
tip_exception(e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def quit
|
||||||
|
user_is_admin = current_user.admin? || @project.manager?(current_user)
|
||||||
|
if !user_is_admin && @project.member(current_user.id) && @project.forge?
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
Projects::DeleteMemberInteractor.call(@project.owner, @project, current_user)
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectMemberLeft', current_user.id, current_user.id, @project.id) if Site.has_notice_menu?
|
||||||
|
render_ok
|
||||||
|
end
|
||||||
|
else
|
||||||
|
render_forbidden('你不能退出该仓库')
|
||||||
|
end
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
tip_exception(e.message)
|
||||||
|
end
|
||||||
|
|
||||||
def watch_users
|
def watch_users
|
||||||
watchers = @project.watchers.includes(:user).order("watchers.created_at desc").distinct
|
watchers = @project.watchers.includes(:user).order("watchers.created_at desc").distinct
|
||||||
@watchers_count = watchers.size
|
@watchers_count = watchers.size
|
||||||
|
|
@ -184,7 +216,7 @@ class ProjectsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def fork_users
|
def fork_users
|
||||||
fork_users = @project.fork_users.includes(:user, :project, :fork_project).order("fork_users.created_at desc").distinct
|
fork_users = @project.fork_users.includes(:owner, :project, :fork_project).order("fork_users.created_at desc").distinct
|
||||||
@forks_count = fork_users.size
|
@forks_count = fork_users.size
|
||||||
@fork_users = paginate(fork_users)
|
@fork_users = paginate(fork_users)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ class PullRequestsController < ApplicationController
|
||||||
before_action :require_login, except: [:index, :show, :files, :commits]
|
before_action :require_login, except: [:index, :show, :files, :commits]
|
||||||
before_action :require_profile_completed, only: [:create]
|
before_action :require_profile_completed, only: [:create]
|
||||||
before_action :load_repository
|
before_action :load_repository
|
||||||
before_action :check_menu_authorize
|
before_action :check_menu_authorize, only: [:index, :show, :create, :update, :refuse_merge, :pr_merge]
|
||||||
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos, :files, :commits]
|
before_action :find_pull_request, except: [:index, :new, :create, :check_can_merge,:get_branches,:create_merge_infos, :files, :commits]
|
||||||
before_action :load_pull_request, only: [:files, :commits]
|
before_action :load_pull_request, only: [:files, :commits]
|
||||||
before_action :find_atme_receivers, only: [:create, :update]
|
before_action :find_atme_receivers, only: [:create, :update]
|
||||||
|
|
@ -16,7 +16,7 @@ class PullRequestsController < ApplicationController
|
||||||
issues = issues.where(is_private: false) unless current_user.present? && (current_user.admin? || @project.member?(current_user))
|
issues = issues.where(is_private: false) unless current_user.present? && (current_user.admin? || @project.member?(current_user))
|
||||||
@all_issues = issues.distinct
|
@all_issues = issues.distinct
|
||||||
@filter_issues = @all_issues
|
@filter_issues = @all_issues
|
||||||
@filter_issues = @filter_issues.where("subject LIKE ? OR description LIKE ? ", "%#{params[:search]}%", "%#{params[:search]}%") if params[:search].present?
|
@filter_issues = @filter_issues.where("issues.subject LIKE ? OR issues.description LIKE ? ", "%#{params[:search]}%", "%#{params[:search]}%") if params[:search].present?
|
||||||
@open_issues = @filter_issues.joins(:pull_request).where(pull_requests: {status: PullRequest::OPEN})
|
@open_issues = @filter_issues.joins(:pull_request).where(pull_requests: {status: PullRequest::OPEN})
|
||||||
@close_issues = @filter_issues.joins(:pull_request).where(pull_requests: {status: PullRequest::CLOSED})
|
@close_issues = @filter_issues.joins(:pull_request).where(pull_requests: {status: PullRequest::CLOSED})
|
||||||
@merged_issues = @filter_issues.joins(:pull_request).where(pull_requests: {status: PullRequest::MERGED})
|
@merged_issues = @filter_issues.joins(:pull_request).where(pull_requests: {status: PullRequest::MERGED})
|
||||||
|
|
@ -29,7 +29,7 @@ class PullRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@all_branches = Branches::ListService.call(@owner, @project)
|
@all_branches = Branches::ListService.call(@owner, @project, params[:branch_name])
|
||||||
@is_fork = @project.forked_from_project_id.present?
|
@is_fork = @project.forked_from_project_id.present?
|
||||||
@projects_names = [{
|
@projects_names = [{
|
||||||
project_user_login: @owner.try(:login),
|
project_user_login: @owner.try(:login),
|
||||||
|
|
@ -50,13 +50,15 @@ class PullRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_branches
|
def get_branches
|
||||||
branch_result = Branches::ListService.call(@owner, @project)
|
branch_result = Branches::ListService.call(@owner, @project, params[:name])
|
||||||
render json: branch_result
|
render json: branch_result
|
||||||
# return json: branch_result
|
# return json: branch_result
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
|
# return normal_status(-1, "您不是目标分支开发者,没有权限,请联系目标分支作者.") unless @project.operator?(current_user)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
|
Issues::CreateForm.new({subject: params[:title], description: params[:body].blank? ? params[:body] : params[:body].b}).validate!
|
||||||
@pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params)
|
@pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params)
|
||||||
if @gitea_pull_request[:status] == :success
|
if @gitea_pull_request[:status] == :success
|
||||||
@pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"])
|
@pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"])
|
||||||
|
|
@ -69,6 +71,8 @@ class PullRequestsController < ApplicationController
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
rescue => e
|
||||||
|
normal_status(-1, e.message)
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
|
@ -78,6 +82,7 @@ class PullRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def update
|
def update
|
||||||
|
return render_forbidden("你没有权限操作.") unless @project.operator?(current_user)
|
||||||
if params[:title].nil?
|
if params[:title].nil?
|
||||||
normal_status(-1, "名称不能为空")
|
normal_status(-1, "名称不能为空")
|
||||||
elsif params[:issue_tag_ids].nil?
|
elsif params[:issue_tag_ids].nil?
|
||||||
|
|
@ -85,14 +90,21 @@ class PullRequestsController < ApplicationController
|
||||||
else
|
else
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
|
Issues::UpdateForm.new({subject: params[:title], description: params[:body].blank? ? params[:body] : params[:body].b}).validate!
|
||||||
merge_params
|
merge_params
|
||||||
|
|
||||||
@issue&.issue_tags_relates&.destroy_all if params[:issue_tag_ids].blank?
|
@issue&.issue_tags_relates&.destroy_all if params[:issue_tag_ids].blank?
|
||||||
if params[:issue_tag_ids].present? && !@issue&.issue_tags_relates.where(issue_tag_id: params[:issue_tag_ids]).exists?
|
if params[:issue_tag_ids].present? && !@issue&.issue_tags_relates.where(issue_tag_id: params[:issue_tag_ids]).exists?
|
||||||
@issue&.issue_tags_relates&.destroy_all
|
if params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size > 1
|
||||||
params[:issue_tag_ids].each do |tag|
|
return normal_status(-1, "最多只能创建一个标记。")
|
||||||
IssueTagsRelate.create(issue_id: @issue.id, issue_tag_id: tag)
|
elsif params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size == 1
|
||||||
end
|
@issue&.issue_tags_relates&.destroy_all
|
||||||
|
params[:issue_tag_ids].each do |tag|
|
||||||
|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return normal_status(-1, "请输入正确的标记。")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if @issue.update_attributes(@issue_params)
|
if @issue.update_attributes(@issue_params)
|
||||||
|
|
@ -102,9 +114,16 @@ class PullRequestsController < ApplicationController
|
||||||
|
|
||||||
if gitea_pull[:status] === :success
|
if gitea_pull[:status] === :success
|
||||||
if params[:issue_tag_ids].present?
|
if params[:issue_tag_ids].present?
|
||||||
params[:issue_tag_ids].each do |tag|
|
if params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size > 1
|
||||||
IssueTagsRelate.create(issue_id: @issue.id, issue_tag_id: tag)
|
return normal_status(-1, "最多只能创建一个标记。")
|
||||||
end
|
elsif params[:issue_tag_ids].is_a?(Array) && params[:issue_tag_ids].size == 1
|
||||||
|
@issue&.issue_tags_relates&.destroy_all
|
||||||
|
params[:issue_tag_ids].each do |tag|
|
||||||
|
IssueTagsRelate.create!(issue_id: @issue.id, issue_tag_id: tag)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
return normal_status(-1, "请输入正确的标记。")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
if params[:status_id].to_i == 5
|
if params[:status_id].to_i == 5
|
||||||
@issue.issue_times.update_all(end_time: Time.now)
|
@issue.issue_times.update_all(end_time: Time.now)
|
||||||
|
|
@ -197,7 +216,7 @@ class PullRequestsController < ApplicationController
|
||||||
def check_can_merge
|
def check_can_merge
|
||||||
target_head = params[:head] #源分支
|
target_head = params[:head] #源分支
|
||||||
target_base = params[:base] #目标分支
|
target_base = params[:base] #目标分支
|
||||||
is_original = params[:is_original]
|
is_original = params[:is_original] || false
|
||||||
if target_head.blank? || target_base.blank?
|
if target_head.blank? || target_base.blank?
|
||||||
normal_status(-2, "请选择分支")
|
normal_status(-2, "请选择分支")
|
||||||
elsif target_head === target_base && !is_original
|
elsif target_head === target_base && !is_original
|
||||||
|
|
@ -228,11 +247,11 @@ class PullRequestsController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
def load_pull_request
|
def load_pull_request
|
||||||
@pull_request = PullRequest.find params[:id]
|
@pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || PullRequest.find_by_id(params[:id])
|
||||||
end
|
end
|
||||||
|
|
||||||
def find_pull_request
|
def find_pull_request
|
||||||
@pull_request = PullRequest.find_by_id(params[:id])
|
@pull_request = @project.pull_requests.where(gitea_number: params[:id]).where.not(id: params[:id]).take || PullRequest.find_by_id(params[:id])
|
||||||
@issue = @pull_request&.issue
|
@issue = @pull_request&.issue
|
||||||
if @pull_request.blank?
|
if @pull_request.blank?
|
||||||
normal_status(-1, "合并请求不存在")
|
normal_status(-1, "合并请求不存在")
|
||||||
|
|
@ -256,12 +275,12 @@ class PullRequestsController < ApplicationController
|
||||||
base: params[:base], #目标分支
|
base: params[:base], #目标分支
|
||||||
milestone: 0, #里程碑,未与本地的里程碑关联
|
milestone: 0, #里程碑,未与本地的里程碑关联
|
||||||
}
|
}
|
||||||
|
assignee_login = User.find_by_id(params[:assigned_to_id])&.login
|
||||||
@requests_params = @local_params.merge({
|
@requests_params = @local_params.merge({
|
||||||
assignee: current_user.try(:login),
|
|
||||||
# assignees: ["#{params[:assigned_login].to_s}"],
|
# assignees: ["#{params[:assigned_login].to_s}"],
|
||||||
assignees: ["#{current_user.try(:login).to_s}"],
|
assignees: ["#{assignee_login.to_s}"],
|
||||||
labels: params[:issue_tag_ids],
|
labels: params[:issue_tag_ids]
|
||||||
due_date: Time.now
|
# due_date: Time.now
|
||||||
})
|
})
|
||||||
@issue_params = {
|
@issue_params = {
|
||||||
author_id: current_user.id,
|
author_id: current_user.id,
|
||||||
|
|
@ -271,7 +290,7 @@ class PullRequestsController < ApplicationController
|
||||||
assigned_to_id: params[:assigned_to_id],
|
assigned_to_id: params[:assigned_to_id],
|
||||||
fixed_version_id: params[:fixed_version_id],
|
fixed_version_id: params[:fixed_version_id],
|
||||||
issue_tags_value: params[:issue_tag_ids].present? ? params[:issue_tag_ids].join(",") : "",
|
issue_tags_value: params[:issue_tag_ids].present? ? params[:issue_tag_ids].join(",") : "",
|
||||||
priority_id: params[:priority_id] || "2",
|
priority_id: params[:priority_id],
|
||||||
issue_classify: "pull_request",
|
issue_classify: "pull_request",
|
||||||
issue_type: params[:issue_type] || "1",
|
issue_type: params[:issue_type] || "1",
|
||||||
tracker_id: 2,
|
tracker_id: 2,
|
||||||
|
|
|
||||||
|
|
@ -64,7 +64,6 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
def sub_entries
|
def sub_entries
|
||||||
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||||
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
|
||||||
|
|
||||||
if @project.educoder?
|
if @project.educoder?
|
||||||
if params[:type] === 'file'
|
if params[:type] === 'file'
|
||||||
|
|
@ -72,18 +71,35 @@ class RepositoriesController < ApplicationController
|
||||||
logger.info "######### sub_entries: #{@sub_entries}"
|
logger.info "######### sub_entries: #{@sub_entries}"
|
||||||
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
|
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
|
||||||
|
|
||||||
tmp_entries = [{
|
tmp_entries = {
|
||||||
"content" => @sub_entries['data']['content'],
|
"content" => @sub_entries['data']['content'],
|
||||||
"type" => "blob"
|
"type" => "blob"
|
||||||
}]
|
}
|
||||||
@sub_entries = {
|
@sub_entries = {
|
||||||
"trees"=>tmp_entries,
|
"trees"=>tmp_entries,
|
||||||
"commits" => [{}]
|
"commits" => [{}]
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri})
|
begin
|
||||||
|
@sub_entries = Educoder::Repository::Entries::ListService.call(@project&.project_educoder&.repo_name, {path: file_path_uri})
|
||||||
|
if @sub_entries.blank? || @sub_entries['status'].to_i === -1
|
||||||
|
@sub_entries = Educoder::Repository::Entries::GetService.call(@project&.project_educoder&.repo_name, file_path_uri)
|
||||||
|
return render_error('该文件暂未开放,敬请期待.') if @sub_entries['status'].to_i === -1
|
||||||
|
tmp_entries = {
|
||||||
|
"content" => @sub_entries['data']['content'],
|
||||||
|
"type" => "blob"
|
||||||
|
}
|
||||||
|
@sub_entries = {
|
||||||
|
"trees"=>tmp_entries,
|
||||||
|
"commits" => [{}]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
return render_error('该文件暂未开放,敬请期待.')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
@path = Gitea.gitea_config[:domain]+"/#{@project.owner.login}/#{@project.identifier}/raw/branch/#{@ref}/"
|
||||||
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: @ref)
|
interactor = Repositories::EntriesInteractor.call(@owner, @project.identifier, file_path_uri, ref: @ref)
|
||||||
if interactor.success?
|
if interactor.success?
|
||||||
result = interactor.result
|
result = interactor.result
|
||||||
|
|
@ -95,13 +111,17 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def commits
|
def commits
|
||||||
if params[:filepath].present?
|
if @project.educoder?
|
||||||
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
@commits = Educoder::Repository::Commits::ListService.call(@project&.project_educoder&.repo_name)
|
||||||
@hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri,
|
|
||||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
|
||||||
else
|
else
|
||||||
@hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier,
|
if params[:filepath].present?
|
||||||
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
file_path_uri = URI.parse(URI.encode(params[:filepath].to_s.strip))
|
||||||
|
@hash_commit = Gitea::Repository::Commits::FileListService.new(@owner.login, @project.identifier, file_path_uri,
|
||||||
|
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
||||||
|
else
|
||||||
|
@hash_commit = Gitea::Repository::Commits::ListService.new(@owner.login, @project.identifier,
|
||||||
|
sha: params[:sha], page: params[:page], limit: params[:limit], token: current_user&.gitea_token).call
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -112,8 +132,12 @@ class RepositoriesController < ApplicationController
|
||||||
|
|
||||||
def commit
|
def commit
|
||||||
@sha = params[:sha]
|
@sha = params[:sha]
|
||||||
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
|
if @project.educoder?
|
||||||
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true})
|
return render_error('暂未开放,敬请期待.')
|
||||||
|
else
|
||||||
|
@commit = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token)
|
||||||
|
@commit_diff = Gitea::Repository::Commits::GetService.call(@owner.login, @repository.identifier, @sha, current_user&.gitea_token, {diff: true})
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def tags
|
def tags
|
||||||
|
|
@ -123,11 +147,14 @@ class RepositoriesController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
def contributors
|
def contributors
|
||||||
if params[:filepath].present?
|
if params[:filepath].present? || @project.educoder?
|
||||||
@contributors = []
|
@contributors = []
|
||||||
else
|
else
|
||||||
@contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier)
|
result = Gitea::Repository::Contributors::GetService.call(@owner, @repository.identifier)
|
||||||
|
@contributors = result.is_a?(Hash) && result.key?(:status) ? [] : result
|
||||||
end
|
end
|
||||||
|
rescue
|
||||||
|
@contributors = []
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
|
@ -195,21 +222,27 @@ class RepositoriesController < ApplicationController
|
||||||
else
|
else
|
||||||
result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token)
|
result = Gitea::Repository::Readme::GetService.call(@owner.login, @repository.identifier, params[:ref], current_user&.gitea_token)
|
||||||
end
|
end
|
||||||
|
@path = Gitea.gitea_config[:domain]+"/#{@owner.login}/#{@repository.identifier}/raw/branch/#{params[:ref]}/"
|
||||||
@readme = result[:status] === :success ? result[:body] : nil
|
@readme = result[:status] === :success ? result[:body] : nil
|
||||||
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref])
|
@readme['content'] = decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
||||||
render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha")
|
@readme['replace_content'] = readme_decode64_content(@readme, @owner, @repository, params[:ref], @path)
|
||||||
|
render json: @readme.slice("type", "encoding", "size", "name", "path", "content", "sha", "replace_content")
|
||||||
rescue
|
rescue
|
||||||
render json: nil
|
render json: nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def languages
|
def languages
|
||||||
render json: languages_precentagable
|
if @project.educoder?
|
||||||
|
render json: {}
|
||||||
|
else
|
||||||
|
render json: languages_precentagable
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def archive
|
def archive
|
||||||
domain = Gitea.gitea_config[:domain]
|
domain = Gitea.gitea_config[:domain]
|
||||||
api_url = Gitea.gitea_config[:base_url]
|
api_url = Gitea.gitea_config[:base_url]
|
||||||
archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{params[:archive]}"
|
archive_url = "/repos/#{@owner.login}/#{@repository.identifier}/archive/#{Addressable::URI.escape(params[:archive])}"
|
||||||
|
|
||||||
file_path = [domain, api_url, archive_url].join
|
file_path = [domain, api_url, archive_url].join
|
||||||
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden?
|
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("?") if @repository.hidden?
|
||||||
|
|
@ -223,11 +256,11 @@ class RepositoriesController < ApplicationController
|
||||||
domain = Gitea.gitea_config[:domain]
|
domain = Gitea.gitea_config[:domain]
|
||||||
api_url = Gitea.gitea_config[:base_url]
|
api_url = Gitea.gitea_config[:base_url]
|
||||||
|
|
||||||
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{params[:filepath]}?ref=#{params[:ref]}"
|
url = "/repos/#{@owner.login}/#{@repository.identifier}/raw/#{Addressable::URI.escape(params[:filepath])}?ref=#{Addressable::URI.escape(params[:ref])}"
|
||||||
file_path = [domain, api_url, url].join
|
file_path = [domain, api_url, url].join
|
||||||
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&") if @repository.hidden?
|
file_path = [file_path, "access_token=#{current_user&.gitea_token}"].join("&")
|
||||||
|
|
||||||
redirect_to URI.escape(file_path)
|
redirect_to file_path
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
@ -347,7 +380,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
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,23 @@
|
||||||
class SettingsController < ApplicationController
|
class SettingsController < ApplicationController
|
||||||
def show
|
def show
|
||||||
@old_projects_url = nil
|
@old_projects_url = nil
|
||||||
|
get_navbar
|
||||||
get_add_menu
|
get_add_menu
|
||||||
get_common_menu
|
get_common_menu
|
||||||
get_personal_menu
|
get_personal_menu
|
||||||
get_top_system_notification
|
get_top_system_notification
|
||||||
|
get_banner
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def get_navbar
|
||||||
|
@navbar = default_laboratory.navbar
|
||||||
|
if User.current.logged?
|
||||||
|
pernal_index = {"name"=>"个人主页", "link"=>get_site_url("url", "#{Rails.application.config_for(:configuration)['platform_url']}/current_user"), "hidden"=>false}
|
||||||
|
@navbar << pernal_index
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def get_add_menu
|
def get_add_menu
|
||||||
@add = []
|
@add = []
|
||||||
Site.add.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site|
|
Site.add.select(:id, :name, :url, :key).to_a.map(&:serializable_hash).each do |site|
|
||||||
|
|
@ -58,4 +68,14 @@ class SettingsController < ApplicationController
|
||||||
def append_http(url)
|
def append_http(url)
|
||||||
url.to_s.start_with?("http") ? url : [request.protocol, request.host_with_port, url].join('')
|
url.to_s.start_with?("http") ? url : [request.protocol, request.host_with_port, url].join('')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def get_banner
|
||||||
|
@banner = {
|
||||||
|
title: EduSetting.get("banner_title") || '大学开源',
|
||||||
|
sub_title: EduSetting.get("banner_sub_title") || '让大学绽放开源之花',
|
||||||
|
content: EduSetting.get("banner_content") || "Powered by Trustie and GitLink"
|
||||||
|
}
|
||||||
|
|
||||||
|
@banner
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ class Users::StatisticsController < Users::BaseController
|
||||||
@commit_data = []
|
@commit_data = []
|
||||||
date_range.each do |date|
|
date_range.each do |date|
|
||||||
@date_data << date.strftime("%Y.%m.%d")
|
@date_data << date.strftime("%Y.%m.%d")
|
||||||
@issue_data << observed_user.issues.where("DATE(created_on) = ?", date).size
|
@issue_data << observed_user.issues.issue_issue.where("DATE(created_on) = ?", date).size
|
||||||
@pull_request_data << observed_user.pull_requests.where("DATE(created_at) = ?", date).size
|
@pull_request_data << observed_user.pull_requests.where("DATE(created_at) = ?", date).size
|
||||||
date_commit_data = commit_data.blank? ? nil : commit_data.select{|item| item["timestamp"] == date.to_time.to_i}
|
date_commit_data = commit_data.blank? ? nil : commit_data.select{|item| item["timestamp"] == date.to_time.to_i}
|
||||||
@commit_data << (date_commit_data.blank? ? 0 : date_commit_data[0]["contributions"].to_i)
|
@commit_data << (date_commit_data.blank? ? 0 : date_commit_data[0]["contributions"].to_i)
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,8 @@ class Users::TemplateMessageSettingsController < Users::BaseController
|
||||||
def get_current_setting
|
def get_current_setting
|
||||||
@current_setting = @_observed_user.user_template_message_setting
|
@current_setting = @_observed_user.user_template_message_setting
|
||||||
@current_setting = UserTemplateMessageSetting.build(@_observed_user.id) if @current_setting.nil?
|
@current_setting = UserTemplateMessageSetting.build(@_observed_user.id) if @current_setting.nil?
|
||||||
|
@current_setting.notification_body.merge!(UserTemplateMessageSetting.init_notification_body.except(*@current_setting.notification_body.keys))
|
||||||
|
@current_setting.email_body.merge!(UserTemplateMessageSetting.init_email_body.except(*@current_setting.email_body.keys))
|
||||||
end
|
end
|
||||||
|
|
||||||
def setting_params
|
def setting_params
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@ class UsersController < ApplicationController
|
||||||
|
|
||||||
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]
|
||||||
|
|
@ -51,8 +51,6 @@ class UsersController < ApplicationController
|
||||||
@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
|
||||||
# 为了缓存活跃用户的基本信息,后续删除
|
|
||||||
Cache::V2::OwnerCommonService.new(@user.id).read
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def watch_users
|
def watch_users
|
||||||
|
|
@ -85,6 +83,24 @@ class UsersController < ApplicationController
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def update_image
|
||||||
|
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)
|
||||||
|
|
||||||
|
Util.write_file(@image, avatar_path(@user))
|
||||||
|
return render_ok({message: '头像修改成功'})
|
||||||
|
rescue Exception => e
|
||||||
|
uid_logger_error(e.message)
|
||||||
|
render_error(-1, '头像修改失败!')
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_image
|
||||||
|
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)
|
||||||
|
|
||||||
|
redirect_to Rails.application.config_for(:configuration)['platform_url'] + "/" + url_to_avatar(@user).to_s
|
||||||
|
end
|
||||||
|
|
||||||
def me
|
def me
|
||||||
@user = current_user
|
@user = current_user
|
||||||
end
|
end
|
||||||
|
|
@ -193,7 +209,7 @@ class UsersController < ApplicationController
|
||||||
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')
|
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}"
|
||||||
|
|
@ -262,26 +278,68 @@ class UsersController < ApplicationController
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
def sync_user_info
|
# TODO: For Educoder
|
||||||
|
def change_password
|
||||||
user = User.find_by_login params[:login]
|
user = User.find_by_login params[:login]
|
||||||
return render_forbidden unless user === current_user
|
return render_error("用户 #{params[:login]} 不存在.") if user.nil?
|
||||||
|
|
||||||
|
form_params= {
|
||||||
|
login: params[:login],
|
||||||
|
email: user&.mail,
|
||||||
|
password: params[:password],
|
||||||
|
user: user
|
||||||
|
}
|
||||||
|
Gitea::User::ChangePasswordForm.new(form_params).validate!
|
||||||
|
|
||||||
sync_params = {
|
sync_params = {
|
||||||
email: params[:email],
|
email: user&.mail,
|
||||||
password: params[:password]
|
password: params[:password]
|
||||||
}
|
}
|
||||||
|
|
||||||
Users::UpdateInfoForm.new(sync_params.merge(login: params[:login])).validate!
|
if sync_params.present?
|
||||||
|
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
|
||||||
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
|
if interactor.success?
|
||||||
if interactor.success?
|
user.update!(password: params[:password], is_sync_pwd: true)
|
||||||
user.update!(password: params[:password], mail: params[:email], status: User::STATUS_EDIT_INFO)
|
render_ok
|
||||||
render_ok
|
else
|
||||||
else
|
render_error(interactor.error)
|
||||||
render_error(interactor.error)
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# TODO: For Educoder
|
||||||
|
def change_email
|
||||||
|
user = User.find_by_login params[:login]
|
||||||
|
return render_error("用户 #{rq_params[:login]} 不存在.") if user.nil?
|
||||||
|
|
||||||
|
form_params= {
|
||||||
|
login: params[:login],
|
||||||
|
email: user&.mail,
|
||||||
|
user: user
|
||||||
|
}
|
||||||
|
|
||||||
|
Gitea::User::ChangeEmailForm.new(form_params).validate!
|
||||||
|
|
||||||
|
sync_params = {
|
||||||
|
email: params[:email]
|
||||||
|
}
|
||||||
|
|
||||||
|
if sync_params.present?
|
||||||
|
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
|
||||||
|
|
||||||
|
def email_search
|
||||||
|
return render_error('请输入email') if params[:email].blank?
|
||||||
|
@user = User.find_by(mail: params[:email])
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def load_user
|
def load_user
|
||||||
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])
|
@user = User.find_by_login(params[:id]) || User.find_by(id: params[:id])
|
||||||
|
|
@ -294,6 +352,7 @@ class UsersController < ApplicationController
|
||||||
:occupation, :technical_title,
|
:occupation, :technical_title,
|
||||||
:school_id, :department_id, :province, :city,
|
:school_id, :department_id, :province, :city,
|
||||||
:custom_department, :identity, :student_id, :description,
|
:custom_department, :identity, :student_id, :description,
|
||||||
|
:show_super_description, :super_description,
|
||||||
:show_email, :show_location, :show_department]
|
:show_email, :show_location, :show_department]
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,7 @@ class VersionReleasesController < ApplicationController
|
||||||
def new
|
def new
|
||||||
#获取所有的分支
|
#获取所有的分支
|
||||||
@all_branches = []
|
@all_branches = []
|
||||||
get_all_branches = Gitea::Repository::Branches::ListService.new(@user, @repository.try(:identifier)).call
|
get_all_branches = Gitea::Repository::Branches::ListService.new(@user, @repository.try(:identifier), params[:branch_name]).call
|
||||||
if get_all_branches && get_all_branches.size > 0
|
if get_all_branches && get_all_branches.size > 0
|
||||||
get_all_branches.each do |b|
|
get_all_branches.each do |b|
|
||||||
@all_branches.push(b["name"])
|
@all_branches.push(b["name"])
|
||||||
|
|
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 9.4 KiB After Width: | Height: | Size: 13 KiB |
|
|
@ -280,7 +280,7 @@ repo |是| |string |项目标识identifier
|
||||||
### 返回字段说明
|
### 返回字段说明
|
||||||
参数 | 类型 | 字段说明
|
参数 | 类型 | 字段说明
|
||||||
--------- | ----------- | -----------
|
--------- | ----------- | -----------
|
||||||
menu_name |string|导航名称, home:主页,code:代码库,issues:易修,pulls:合并请求,devops:工作流,versions:里程碑,activity:动态,setting:仓库设置
|
menu_name |string|导航名称, home:主页,code:代码库,issues:疑修,pulls:合并请求,devops:工作流,versions:里程碑,activity:动态,setting:仓库设置
|
||||||
|
|
||||||
|
|
||||||
> 返回的JSON示例:
|
> 返回的JSON示例:
|
||||||
|
|
@ -408,7 +408,7 @@ await octokit.request('POST /api/yystopf/ceshi/project_units')
|
||||||
### 请求参数
|
### 请求参数
|
||||||
参数 | 必选 | 默认 | 类型 | 字段说明
|
参数 | 必选 | 默认 | 类型 | 字段说明
|
||||||
--------- | ------- | ------- | -------- | ----------
|
--------- | ------- | ------- | -------- | ----------
|
||||||
|unit_types |是| |array | 项目模块内容, 支持以下参数:code:代码库,issues:易修,pulls:合并请求,devops:工作流,versions:里程碑 |
|
|unit_types |是| |array | 项目模块内容, 支持以下参数:code:代码库,issues:疑修,pulls:合并请求,devops:工作流,versions:里程碑 |
|
||||||
|
|
||||||
|
|
||||||
### 返回字段说明:
|
### 返回字段说明:
|
||||||
|
|
|
||||||
|
|
@ -1240,11 +1240,11 @@ await octokit.request('GET /api/yystopf/ceshi/webhooks/3/edit.json')
|
||||||
|delete|分支或标签删除|
|
|delete|分支或标签删除|
|
||||||
|fork|仓库被fork|
|
|fork|仓库被fork|
|
||||||
|push|git仓库推送|
|
|push|git仓库推送|
|
||||||
|issue|易修已打开、已关闭、已重新打开或编辑|
|
|issue|疑修已打开、已关闭、已重新打开或编辑|
|
||||||
|issue_assign|易修被指派|
|
|issue_assign|疑修被指派|
|
||||||
|issue_label|易修标签被更新或删除|
|
|issue_label|疑修标签被更新或删除|
|
||||||
|issue_milestone|易修被收入里程碑|
|
|issue_milestone|疑修被收入里程碑|
|
||||||
|issue_comment|易修评论|
|
|issue_comment|疑修评论|
|
||||||
|pull_request|合并请求|
|
|pull_request|合并请求|
|
||||||
|pull_request_assign|合并请求被指派|
|
|pull_request_assign|合并请求被指派|
|
||||||
|pull_request_label|合并请求被贴上标签|
|
|pull_request_label|合并请求被贴上标签|
|
||||||
|
|
@ -1337,11 +1337,11 @@ await octokit.request('POST /api/yystopf/ceshi/webhooks.json')
|
||||||
|delete|分支或标签删除|
|
|delete|分支或标签删除|
|
||||||
|fork|仓库被fork|
|
|fork|仓库被fork|
|
||||||
|push|git仓库推送|
|
|push|git仓库推送|
|
||||||
|issue|易修已打开、已关闭、已重新打开或编辑|
|
|issue|疑修已打开、已关闭、已重新打开或编辑|
|
||||||
|issue_assign|易修被指派|
|
|issue_assign|疑修被指派|
|
||||||
|issue_label|易修标签被更新或删除|
|
|issue_label|疑修标签被更新或删除|
|
||||||
|issue_milestone|易修被收入里程碑|
|
|issue_milestone|疑修被收入里程碑|
|
||||||
|issue_comment|易修评论|
|
|issue_comment|疑修评论|
|
||||||
|pull_request|合并请求|
|
|pull_request|合并请求|
|
||||||
|pull_request_assign|合并请求被指派|
|
|pull_request_assign|合并请求被指派|
|
||||||
|pull_request_label|合并请求被贴上标签|
|
|pull_request_label|合并请求被贴上标签|
|
||||||
|
|
@ -1440,11 +1440,11 @@ await octokit.request('PATCH /api/yystopf/ceshi/webhooks/7.json')
|
||||||
|delete|分支或标签删除|
|
|delete|分支或标签删除|
|
||||||
|fork|仓库被fork|
|
|fork|仓库被fork|
|
||||||
|push|git仓库推送|
|
|push|git仓库推送|
|
||||||
|issue|易修已打开、已关闭、已重新打开或编辑|
|
|issue|疑修已打开、已关闭、已重新打开或编辑|
|
||||||
|issue_assign|易修被指派|
|
|issue_assign|疑修被指派|
|
||||||
|issue_label|易修标签被更新或删除|
|
|issue_label|疑修标签被更新或删除|
|
||||||
|issue_milestone|易修被收入里程碑|
|
|issue_milestone|疑修被收入里程碑|
|
||||||
|issue_comment|易修评论|
|
|issue_comment|疑修评论|
|
||||||
|pull_request|合并请求|
|
|pull_request|合并请求|
|
||||||
|pull_request_assign|合并请求被指派|
|
|pull_request_assign|合并请求被指派|
|
||||||
|pull_request_label|合并请求被贴上标签|
|
|pull_request_label|合并请求被贴上标签|
|
||||||
|
|
|
||||||
|
|
@ -90,13 +90,12 @@ await octokit.request('GET /api/users/:login/messages.json')
|
||||||
#### 消息来源source字段说明
|
#### 消息来源source字段说明
|
||||||
类型|说明
|
类型|说明
|
||||||
--------- | -----------
|
--------- | -----------
|
||||||
|IssueAssigned | 有新指派给我的易修 |
|
|IssueAssigned | 有新指派给我的疑修 |
|
||||||
|IssueAssignerExpire | 我负责的易修截止日期到达最后一天 |
|
|IssueExpire | 我创建或负责的疑修截止日期到达最后一天 |
|
||||||
|IssueAtme | 在易修中@我 |
|
|IssueAtme | 在疑修中@我 |
|
||||||
|IssueChanged | 我创建或负责的易修状态变更 |
|
|IssueChanged | 我创建或负责的疑修状态变更 |
|
||||||
|IssueCreatorExpire | 我创建的易修截止日期到达最后一天 |
|
|IssueDeleted | 我创建或负责的疑修删除 |
|
||||||
|IssueDeleted | 我创建或负责的易修删除 |
|
|IssueJournal | 我创建或负责的疑修有新的评论 |
|
||||||
|IssueJournal | 我创建或负责的易修有新的评论 |
|
|
||||||
|LoginIpTip | 登录异常提示 |
|
|LoginIpTip | 登录异常提示 |
|
||||||
|OrganizationJoined | 账号被拉入组织 |
|
|OrganizationJoined | 账号被拉入组织 |
|
||||||
|OrganizationLeft | 账号被移出组织 |
|
|OrganizationLeft | 账号被移出组织 |
|
||||||
|
|
@ -104,11 +103,12 @@ await octokit.request('GET /api/users/:login/messages.json')
|
||||||
|ProjectDeleted | 我关注的仓库被删除 |
|
|ProjectDeleted | 我关注的仓库被删除 |
|
||||||
|ProjectFollowed | 我管理的仓库被关注 |
|
|ProjectFollowed | 我管理的仓库被关注 |
|
||||||
|ProjectForked | 我管理的仓库被复刻 |
|
|ProjectForked | 我管理的仓库被复刻 |
|
||||||
|ProjectIssue | 我管理/关注的仓库有新的易修 |
|
|ProjectIssue | 我管理/关注的仓库有新的疑修 |
|
||||||
|ProjectJoined | 账号被拉入项目 |
|
|ProjectJoined | 账号被拉入项目 |
|
||||||
|ProjectLeft | 账号被移出项目 |
|
|ProjectLeft | 账号被移出项目 |
|
||||||
|ProjectMemberJoined | 我管理的仓库有成员加入 |
|
|ProjectMemberJoined | 我管理的仓库有成员加入 |
|
||||||
|ProjectMemberLeft | 我管理的仓库有成员移出 |
|
|ProjectMemberLeft | 我管理的仓库有成员移出 |
|
||||||
|
|ProjectMilestoneCompleted | 我管理的仓库有里程碑完成度100% |
|
||||||
|ProjectMilestone | 我管理的仓库有新的里程碑 |
|
|ProjectMilestone | 我管理的仓库有新的里程碑 |
|
||||||
|ProjectPraised | 我管理的仓库被点赞 |
|
|ProjectPraised | 我管理的仓库被点赞 |
|
||||||
|ProjectPullRequest | 我管理/关注的仓库有新的合并请求 |
|
|ProjectPullRequest | 我管理/关注的仓库有新的合并请求 |
|
||||||
|
|
@ -250,7 +250,7 @@ await octokit.request('POST /api/users/:login/messages.json')
|
||||||
--------- | ----------- | -----------
|
--------- | ----------- | -----------
|
||||||
|type | string | 消息类型 |
|
|type | string | 消息类型 |
|
||||||
|receivers_login | array | 需要发送消息的用户名数组|
|
|receivers_login | array | 需要发送消息的用户名数组|
|
||||||
|atmeable_type | string | atme消息对象,是从哪里@我的,比如评论:Journal、易修:Issue、合并请求:PullRequest |
|
|atmeable_type | string | atme消息对象,是从哪里@我的,比如评论:Journal、疑修:Issue、合并请求:PullRequest |
|
||||||
|atmeable_id | integer | atme消息对象id |
|
|atmeable_id | integer | atme消息对象id |
|
||||||
|
|
||||||
> 请求的JSON示例:
|
> 请求的JSON示例:
|
||||||
|
|
@ -469,7 +469,7 @@ await octokit.request('GET /api/template_message_settings.json')
|
||||||
"total_settings_count": 4,
|
"total_settings_count": 4,
|
||||||
"settings": [
|
"settings": [
|
||||||
{
|
{
|
||||||
"name": "易修被指派",
|
"name": "疑修被指派",
|
||||||
"key": "IssueAssigned",
|
"key": "IssueAssigned",
|
||||||
"notification_disabled": true,
|
"notification_disabled": true,
|
||||||
"email_disabled": false
|
"email_disabled": false
|
||||||
|
|
@ -488,7 +488,7 @@ await octokit.request('GET /api/template_message_settings.json')
|
||||||
"total_settings_count": 4,
|
"total_settings_count": 4,
|
||||||
"settings": [
|
"settings": [
|
||||||
{
|
{
|
||||||
"name": "有新的易修",
|
"name": "有新的疑修",
|
||||||
"key": "Issue",
|
"key": "Issue",
|
||||||
"notification_disabled": true,
|
"notification_disabled": true,
|
||||||
"email_disabled": false
|
"email_disabled": false
|
||||||
|
|
@ -875,7 +875,7 @@ await octokit.request('GET /api/users/:login/statistics/activity.json')
|
||||||
参数 | 类型 | 字段说明
|
参数 | 类型 | 字段说明
|
||||||
--------- | ----------- | -----------
|
--------- | ----------- | -----------
|
||||||
|dates |array |时间 |
|
|dates |array |时间 |
|
||||||
|issues_count |array |易修数量|
|
|issues_count |array |疑修数量|
|
||||||
|pull_requests_count |array |合并请求数量|
|
|pull_requests_count |array |合并请求数量|
|
||||||
|commtis_count |array |贡献数量|
|
|commtis_count |array |贡献数量|
|
||||||
|
|
||||||
|
|
@ -1084,7 +1084,7 @@ await octokit.request('GET /api/users/:login/project_trends.json')
|
||||||
参数 | 类型 | 字段说明
|
参数 | 类型 | 字段说明
|
||||||
--------- | ----------- | -----------
|
--------- | ----------- | -----------
|
||||||
|total_count |int |所选时间内的总动态数 |
|
|total_count |int |所选时间内的总动态数 |
|
||||||
|project_trends.trend_type |string|动态类型,Issue:易修,VersionRelease:版本发布,PullRequest:合并请求|
|
|project_trends.trend_type |string|动态类型,Issue:疑修,VersionRelease:版本发布,PullRequest:合并请求|
|
||||||
|project_trends.action_type |string|操作类型|
|
|project_trends.action_type |string|操作类型|
|
||||||
|project_trends.trend_id |integer|动态id|
|
|project_trends.trend_id |integer|动态id|
|
||||||
|project_trends.user_name |string|用户名称|
|
|project_trends.user_name |string|用户名称|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ under the License.
|
||||||
</span>
|
</span>
|
||||||
</a>
|
</a>
|
||||||
<div class="toc-wrapper">
|
<div class="toc-wrapper">
|
||||||
<%= image_tag "logo.png", class: 'logo' %>
|
<%= image_tag "logo.png", class: 'logo ' %>
|
||||||
<% if language_tabs.any? %>
|
<% if language_tabs.any? %>
|
||||||
<div class="lang-selector">
|
<div class="lang-selector">
|
||||||
<% language_tabs.each do |lang| %>
|
<% language_tabs.each do |lang| %>
|
||||||
|
|
|
||||||
|
|
@ -77,6 +77,7 @@ html, body {
|
||||||
margin: 15px auto;
|
margin: 15px auto;
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
margin-bottom: $logo-margin;
|
margin-bottom: $logo-margin;
|
||||||
|
max-width: 80%;
|
||||||
}
|
}
|
||||||
|
|
||||||
&>.search {
|
&>.search {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,34 @@ class BaseForm
|
||||||
raise "项目标识已被占用." if ReversedKeyword.check_exists?(repository_name)
|
raise "项目标识已被占用." if ReversedKeyword.check_exists?(repository_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def check_password(password)
|
||||||
|
password = strip(password)
|
||||||
|
raise PasswordFormatError, "密码8~16位密码,支持字母数字和符号" unless password =~ CustomRegexp::PASSWORD
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_password_confirmation(password, password_confirmation)
|
||||||
|
password = strip(password)
|
||||||
|
password_confirmation = strip(password_confirmation)
|
||||||
|
|
||||||
|
raise PasswordFormatError, "确认密码为8~16位密码,支持字母数字和符号" unless password_confirmation =~ CustomRegexp::PASSWORD
|
||||||
|
raise PasswordConfirmationError, "两次输入的密码不一致" unless password == password_confirmation
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_verifi_code(verifi_code, code)
|
||||||
|
code = strip(code)
|
||||||
|
# return if code == "123123" # TODO 万能验证码,用于测试
|
||||||
|
raise VerifiCodeError, "验证码已失效" if !verifi_code&.effective?
|
||||||
|
raise VerifiCodeError, "验证码不正确" if verifi_code&.code != code
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
def strip(str)
|
def strip(str)
|
||||||
str.to_s.strip.presence
|
str.to_s.strip.presence
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# 1 手机类型;0 邮箱类型
|
||||||
|
# 注意新版的login是自动名生成的
|
||||||
|
def phone_mail_type value
|
||||||
|
value =~ /^1\d{10}$/ ? 1 : 0
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -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
|
||||||
|
|
@ -4,7 +4,7 @@ class Gitea::User::UpdateForm
|
||||||
|
|
||||||
attr_accessor :username, :email, :admin, :allow_create_organization, :allow_git_hook, :allow_import_local,
|
attr_accessor :username, :email, :admin, :allow_create_organization, :allow_git_hook, :allow_import_local,
|
||||||
:full_name, :location, :login_name, :max_repo_creation, :must_change_password, :password, :prohibit_login,
|
:full_name, :location, :login_name, :max_repo_creation, :must_change_password, :password, :prohibit_login,
|
||||||
:source_id, :website
|
:source_id, :website, :new_name
|
||||||
|
|
||||||
validates :username, presence: true
|
validates :username, presence: true
|
||||||
validates :email, presence: true, format: { with: EMAIL_REGEX, multiline: true }
|
validates :email, presence: true, format: { with: EMAIL_REGEX, multiline: true }
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
class Issues::CreateForm
|
class Issues::CreateForm
|
||||||
include ActiveModel::Model
|
include ActiveModel::Model
|
||||||
|
|
||||||
attr_accessor :subject
|
attr_accessor :subject, :description
|
||||||
|
|
||||||
validates :subject, presence: { message: "不能为空" }
|
validates :subject, presence: { message: "不能为空" }
|
||||||
|
|
||||||
validates :subject, length: { maximum: 200, too_long: "不能超过200个字符" }
|
validates :subject, length: { maximum: 200, too_long: "不能超过200个字符" }
|
||||||
|
|
||||||
|
validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"}
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
class Issues::UpdateForm
|
class Issues::UpdateForm
|
||||||
include ActiveModel::Model
|
include ActiveModel::Model
|
||||||
|
|
||||||
attr_accessor :subject
|
attr_accessor :subject, :description
|
||||||
|
|
||||||
validates :subject, presence: { message: "不能为空" }
|
validates :subject, presence: { message: "不能为空" }
|
||||||
|
|
||||||
validates :subject, length: { maximum: 200, too_long: "不能超过200个字符" }
|
validates :subject, length: { maximum: 200, too_long: "不能超过200个字符" }
|
||||||
|
|
||||||
|
validates :description, length: { maximum: 65535, too_long: "不能超过65535个字符"}
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
@ -0,0 +1,7 @@
|
||||||
|
class Journals::CreateForm
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_accessor :notes
|
||||||
|
|
||||||
|
validates :notes, length: { maximum: 65535, too_long: "不能超过65535个字符"}
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
class Journals::UpdateForm
|
||||||
|
include ActiveModel::Model
|
||||||
|
|
||||||
|
attr_accessor :notes
|
||||||
|
|
||||||
|
validates :notes, length: { maximum: 65535, too_long: "不能超过65535个字符"}
|
||||||
|
|
||||||
|
end
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
class Organizations::CreateForm < BaseForm
|
class Organizations::CreateForm < BaseForm
|
||||||
NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||||
attr_accessor :name, :description, :website, :location, :repo_admin_change_team_access, :visibility, :max_repo_creation, :nickname
|
attr_accessor :name, :description, :website, :location, :repo_admin_change_team_access, :visibility, :max_repo_creation, :nickname, :original_name
|
||||||
|
|
||||||
validates :name, :nickname, :visibility, presence: true
|
validates :name, :nickname, :visibility, presence: true
|
||||||
validates :name, :nickname, length: { maximum: 100 }
|
validates :name, :nickname, length: { maximum: 100 }
|
||||||
|
|
@ -8,4 +8,11 @@ class Organizations::CreateForm < BaseForm
|
||||||
validates :description, length: { maximum: 200 }
|
validates :description, length: { maximum: 200 }
|
||||||
validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
validates :name, format: { with: NAME_REGEX, multiline: true, message: "只能含有数字、字母、下划线且不能以下划线开头和结尾" }
|
||||||
|
|
||||||
|
validate do
|
||||||
|
check_name(name) unless name.blank? || name == original_name
|
||||||
|
end
|
||||||
|
|
||||||
|
def check_name(name)
|
||||||
|
raise "组织账号已被使用." if Owner.where(login: name.strip).exists?
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
class Projects::UpdateForm < BaseForm
|
class Projects::UpdateForm < BaseForm
|
||||||
attr_accessor :name, :description, :project_category_id, :project_language_id, :private, :identifier, :user_id, :project_identifier
|
attr_accessor :name, :description, :project_category_id, :project_language_id, :private, :identifier, :user_id, :project_identifier, :project_name
|
||||||
validates :name, presence: true
|
validates :name, presence: true
|
||||||
validates :name, length: { maximum: 50 }
|
validates :name, length: { maximum: 50 }
|
||||||
validates :description, length: { maximum: 200 }
|
validates :description, length: { maximum: 200 }
|
||||||
|
|
@ -10,6 +10,7 @@ class Projects::UpdateForm < BaseForm
|
||||||
check_project_language(project_language_id)
|
check_project_language(project_language_id)
|
||||||
|
|
||||||
check_repository_name(user_id, identifier) unless identifier.blank? || identifier == project_identifier
|
check_repository_name(user_id, identifier) unless identifier.blank? || identifier == project_identifier
|
||||||
|
check_project_name(user_id, name) unless name.blank? || name == project_name
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -10,28 +10,40 @@ module Register
|
||||||
VerifiCodeError = Class.new(Error)
|
VerifiCodeError = Class.new(Error)
|
||||||
|
|
||||||
private
|
private
|
||||||
def check_login(login)
|
def check_login(login, user=nil)
|
||||||
login = strip(login)
|
login = strip(login)
|
||||||
raise LoginError, "登录名格式有误" unless login =~ CustomRegexp::LOGIN
|
raise LoginError, "登录名格式有误" unless login =~ CustomRegexp::LOGIN
|
||||||
|
|
||||||
login_exist = Owner.exists?(login: login) || ReversedKeyword.check_exists?(login)
|
login_exist = Owner.exists?(login: login) || ReversedKeyword.check_exists?(login)
|
||||||
raise LoginError, '登录名已被使用' if login_exist
|
if user.present?
|
||||||
|
raise LoginError, '登录名已被使用' if login_exist && login != user&.login
|
||||||
|
else
|
||||||
|
raise LoginError, '登录名已被使用' if login_exist
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_mail(mail)
|
def check_mail(mail, user=nil)
|
||||||
mail = strip(mail)
|
mail = strip(mail)
|
||||||
raise EmailError, "邮件格式有误" unless mail =~ CustomRegexp::EMAIL
|
raise EmailError, "邮件格式有误" unless mail =~ CustomRegexp::EMAIL
|
||||||
|
|
||||||
mail_exist = Owner.exists?(mail: mail)
|
mail_exist = Owner.exists?(mail: mail)
|
||||||
raise EmailError, '邮箱已被使用' if mail_exist
|
if user.present?
|
||||||
|
raise EmailError, '邮箱已被使用' if mail_exist && mail != user&.mail
|
||||||
|
else
|
||||||
|
raise EmailError, '邮箱已被使用' if mail_exist
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_phone(phone)
|
def check_phone(phone, user=nil)
|
||||||
phone = strip(phone)
|
phone = strip(phone)
|
||||||
raise PhoneError, "手机号格式有误" unless phone =~ CustomRegexp::PHONE
|
raise PhoneError, "手机号格式有误" unless phone =~ CustomRegexp::PHONE
|
||||||
|
|
||||||
phone_exist = Owner.exists?(phone: phone)
|
phone_exist = Owner.exists?(phone: phone)
|
||||||
raise PhoneError, '手机号已被使用' if phone_exist
|
if user.present?
|
||||||
|
raise PhoneError, '手机号已被使用' if phone_exist && phone != user&.phone
|
||||||
|
else
|
||||||
|
raise PhoneError, '手机号已被使用' if phone_exist
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_password(password)
|
def check_password(password)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,8 @@ module Register
|
||||||
|
|
||||||
def check!
|
def check!
|
||||||
Rails.logger.info "Register::Form params: code: #{code}; login: #{login}; namespace: #{namespace}; password: #{password}; type: #{type}"
|
Rails.logger.info "Register::Form params: code: #{code}; login: #{login}; namespace: #{namespace}; password: #{password}; type: #{type}"
|
||||||
db_verifi_code =
|
type = phone_mail_type(strip(login))
|
||||||
|
db_verifi_code =
|
||||||
if type == 1
|
if type == 1
|
||||||
check_phone(login)
|
check_phone(login)
|
||||||
VerificationCode.where(phone: login, code: code, code_type: 1).last
|
VerificationCode.where(phone: login, code: code, code_type: 1).last
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,19 @@
|
||||||
|
module Register
|
||||||
|
class LoginCheckColumnsForm < Register::BaseForm
|
||||||
|
attr_accessor :type, :value, :user
|
||||||
|
|
||||||
|
validates :type, presence: true, numericality: true
|
||||||
|
validates :value, presence: true
|
||||||
|
validate :check!
|
||||||
|
|
||||||
|
def check!
|
||||||
|
# params[:type] 为事件类型 1:登录名(login) 2:email(邮箱) 3:phone(手机号)
|
||||||
|
case strip(type).to_i
|
||||||
|
when 1 then check_login(strip(value), user)
|
||||||
|
when 2 then check_mail(strip(value), user)
|
||||||
|
when 3 then check_phone(strip(value), user)
|
||||||
|
else raise("type值无效")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,16 @@
|
||||||
|
module Register
|
||||||
|
class RemoteForm < Register::BaseForm
|
||||||
|
# login 登陆方式,支持邮箱、登陆、手机号等
|
||||||
|
attr_accessor :username, :email, :password, :platform
|
||||||
|
|
||||||
|
validates :username, :email, :password, presence: true
|
||||||
|
validate :check!
|
||||||
|
|
||||||
|
def check!
|
||||||
|
Rails.logger.info "Register::RemoteForm params: username: #{username}; email: #{email}; password: #{password}; platform: #{platform}"
|
||||||
|
check_login(username)
|
||||||
|
check_mail(email)
|
||||||
|
check_password(password)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -4,5 +4,5 @@ class Users::LoginForm
|
||||||
attr_accessor :password, :login
|
attr_accessor :password, :login
|
||||||
|
|
||||||
validates :login, presence: true
|
validates :login, presence: true
|
||||||
validates :password, presence: true, length: { minimum: 8, maximum: 16 }, format: { with: CustomRegexp::PASSWORD, message: "8~16位,支持字母数字和符号" }
|
validates :password, presence: true, length: { minimum: 6, maximum: 16 }, format: { with: CustomRegexp::LOGIN_PASSWORD, message: "6~16位,支持字母数字和符号" }
|
||||||
end
|
end
|
||||||
|
|
@ -147,6 +147,15 @@ module ApplicationHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url_to_avatar_with_platform_url(source)
|
||||||
|
platform_url = Rails.application.config_for(:configuration)['platform_url']
|
||||||
|
if platform_url
|
||||||
|
return Rails.application.config_for(:configuration)['platform_url'] + "/" + url_to_avatar(source).to_s
|
||||||
|
else
|
||||||
|
return url_to_avatar(source).to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
# 主页banner图
|
# 主页banner图
|
||||||
def banner_img(source_type)
|
def banner_img(source_type)
|
||||||
if File.exist?(disk_filename(source_type, "banner"))
|
if File.exist?(disk_filename(source_type, "banner"))
|
||||||
|
|
|
||||||
|
|
@ -10,19 +10,19 @@ module RepositoriesHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_type(str)
|
def download_type(str)
|
||||||
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb RData rdata doc docx mpp vsdx dot otf eot ttf woff woff2)
|
default_type = %w(xlsx xls ppt pptx pdf zip 7z rar exe pdb obj idb RData rdata doc docx mpp vsdx dot otf eot ttf woff woff2 mp4 mov wmv flv mpeg avi avchd webm mkv)
|
||||||
default_type.include?(str&.downcase)
|
default_type.include?(str&.downcase) || str.blank?
|
||||||
end
|
end
|
||||||
|
|
||||||
def image_type?(str)
|
def image_type?(str)
|
||||||
default_type = %w(png jpg gif tif psd svg bmp webp jpeg)
|
default_type = %w(png jpg gif tif psd svg bmp webp jpeg ico psd)
|
||||||
default_type.include?(str&.downcase)
|
default_type.include?(str&.downcase)
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_readme?(type, str)
|
def is_readme?(type, str)
|
||||||
return false if type != 'file' || str.blank?
|
return false if type != 'file' || str.blank?
|
||||||
readme_types = ["readme.md", "readme", "readme_en.md", "readme_zh.md", "readme_en", "readme_zh"]
|
readme_types = ["readme.md", "readme", "readme_en.md", "readme_zh.md", "readme_en", "readme_zh"]
|
||||||
readme_types.include?(str.to_s.downcase)
|
readme_types.include?(str.to_s.downcase) || str =~ CustomRegexp::MD_REGEX
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_commit_author(author_json)
|
def render_commit_author(author_json)
|
||||||
|
|
@ -36,7 +36,6 @@ module RepositoriesHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_cache_commit_author(author_json)
|
def render_cache_commit_author(author_json)
|
||||||
Rails.logger.info author_json['Email']
|
|
||||||
if author_json["name"].present? && author_json["email"].present?
|
if author_json["name"].present? && author_json["email"].present?
|
||||||
return find_user_in_redis_cache(author_json['name'], author_json['email'])
|
return find_user_in_redis_cache(author_json['name'], author_json['email'])
|
||||||
end
|
end
|
||||||
|
|
@ -45,7 +44,7 @@ module RepositoriesHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def readme_render_decode64_content(str, path)
|
def readme_render_decode64_content(str, owner, repo, ref)
|
||||||
return nil if str.blank?
|
return nil if str.blank?
|
||||||
begin
|
begin
|
||||||
content = Base64.decode64(str).force_encoding('UTF-8')
|
content = Base64.decode64(str).force_encoding('UTF-8')
|
||||||
|
|
@ -57,21 +56,28 @@ module RepositoriesHelper
|
||||||
total_images = ss + ss_src
|
total_images = ss + ss_src
|
||||||
if total_images.length > 0
|
if total_images.length > 0
|
||||||
total_images.each do |s|
|
total_images.each do |s|
|
||||||
|
begin
|
||||||
image_title = /\"(.*?)\"/
|
image_title = /\"(.*?)\"/
|
||||||
r_content = s[0]
|
r_content = s[0]
|
||||||
remove_title = r_content.to_s.scan(image_title)
|
remove_title = r_content.to_s.scan(image_title)
|
||||||
if remove_title.length > 0
|
if remove_title.length > 0
|
||||||
r_content = r_content.gsub(/#{remove_title[0]}/, "").strip
|
r_content = r_content.gsub(/#{remove_title[0]}/, "").strip
|
||||||
end
|
end
|
||||||
if r_content.include?("?")
|
# if r_content.include?("?")
|
||||||
new_r_content = r_content + "&raw=true"
|
# new_r_content = r_content + "&raw=true"
|
||||||
else
|
# else
|
||||||
new_r_content = r_content + "?raw=true"
|
# new_r_content = r_content + "?raw=true"
|
||||||
end
|
# end
|
||||||
|
new_r_content = r_content
|
||||||
|
|
||||||
unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:")
|
unless r_content.include?("http://") || r_content.include?("https://") || r_content.include?("mailto:")
|
||||||
new_r_content = "#{path}" + new_r_content
|
# new_r_content = "#{path}" + new_r_content
|
||||||
|
new_r_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{r_content}&ref=#{ref}"].join
|
||||||
end
|
end
|
||||||
content = content.gsub(/#{r_content}/, new_r_content)
|
content = content.gsub(/#{r_content}/, new_r_content)
|
||||||
|
rescue
|
||||||
|
next
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -81,6 +87,46 @@ module RepositoriesHelper
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# author hui.he
|
||||||
|
def new_readme_render_decode64_content(str, owner, repo, ref, readme_path, readme_name)
|
||||||
|
file_path = readme_path.include?('/') ? readme_path.gsub("/#{readme_name}", '') : readme_path.gsub("#{readme_name}", '')
|
||||||
|
return nil if str.blank?
|
||||||
|
content = Base64.decode64(str).force_encoding('UTF-8')
|
||||||
|
s_regex = /\[.*?\]\((.*?)\)/
|
||||||
|
src_regex = /src=\"(.*?)\"/
|
||||||
|
ss = content.to_s.scan(s_regex)
|
||||||
|
ss_src = content.to_s.scan(src_regex)
|
||||||
|
total_sources = ss + ss_src
|
||||||
|
total_sources.uniq!
|
||||||
|
total_sources.each do |s|
|
||||||
|
begin
|
||||||
|
s_content = s[0]
|
||||||
|
# 链接直接跳过不做替换
|
||||||
|
next if s_content.starts_with?('http://') || s_content.starts_with?('https://') || s_content.starts_with?('mailto:') || s_content.blank?
|
||||||
|
ext = File.extname(s_content)[1..-1]
|
||||||
|
|
||||||
|
if image_type?(ext) || download_type(ext)
|
||||||
|
s_content = File.expand_path(s_content, file_path)
|
||||||
|
s_content = s_content.split("#{Rails.root}/")[1]
|
||||||
|
# content = content.gsub(s[0], "/#{s_content}")
|
||||||
|
s_content = [base_url, "/api/#{owner&.login}/#{repo.identifier}/raw?filepath=#{s_content}&ref=#{ref}"].join
|
||||||
|
content = content.gsub(s[0], s_content)
|
||||||
|
else
|
||||||
|
path = [owner&.login, repo&.identifier, 'tree', ref, file_path].join("/")
|
||||||
|
s_content = File.expand_path(s_content, path)
|
||||||
|
s_content = s_content.split("#{Rails.root}/")[1]
|
||||||
|
content = content.gsub(s[0], "/#{s_content}")
|
||||||
|
end
|
||||||
|
rescue
|
||||||
|
next
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return content
|
||||||
|
rescue
|
||||||
|
return str
|
||||||
|
end
|
||||||
|
|
||||||
# unix_time values for example: 1604382982
|
# unix_time values for example: 1604382982
|
||||||
def render_format_time_with_unix(unix_time)
|
def render_format_time_with_unix(unix_time)
|
||||||
Time.at(unix_time).strftime("%Y-%m-%d %H:%M")
|
Time.at(unix_time).strftime("%Y-%m-%d %H:%M")
|
||||||
|
|
@ -91,10 +137,21 @@ module RepositoriesHelper
|
||||||
date.to_time.strftime("%Y-%m-%d %H:%M")
|
date.to_time.strftime("%Y-%m-%d %H:%M")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def readme_decode64_content(entry, owner, repo, ref, path=nil)
|
||||||
|
Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}")
|
||||||
|
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
|
||||||
|
Rails.logger.info("content===#{content}")
|
||||||
|
# readme_render_decode64_content(content, owner, repo, ref)
|
||||||
|
new_readme_render_decode64_content(content, owner, repo, ref, entry['path'], entry['name'])
|
||||||
|
end
|
||||||
|
|
||||||
def decode64_content(entry, owner, repo, ref, path=nil)
|
def decode64_content(entry, owner, repo, ref, path=nil)
|
||||||
if is_readme?(entry['type'], entry['name'])
|
if is_readme?(entry['type'], entry['name'])
|
||||||
|
Rails.logger.info("entry===#{entry["type"]} #{entry["name"]}")
|
||||||
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
|
content = Gitea::Repository::Entries::GetService.call(owner, repo.identifier, URI.escape(entry['path']), ref: ref)['content']
|
||||||
readme_render_decode64_content(content, path)
|
Rails.logger.info("content===#{content}")
|
||||||
|
# readme_render_decode64_content(content, owner, repo, ref)
|
||||||
|
return Base64.decode64(content).force_encoding('UTF-8')
|
||||||
else
|
else
|
||||||
file_type = File.extname(entry['name'].to_s)[1..-1]
|
file_type = File.extname(entry['name'].to_s)[1..-1]
|
||||||
if image_type?(file_type)
|
if image_type?(file_type)
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,13 @@ module TagChosenHelper
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_branches(project)
|
def render_branches(project)
|
||||||
branches = Gitea::Repository::Branches::ListService.call(project&.owner, project.identifier)
|
if project.educoder?
|
||||||
branches.collect{|i| i["name"] if i.is_a?(Hash)}
|
return ['master']
|
||||||
|
else
|
||||||
|
branches = Gitea::Repository::Branches::ListNameService.call(project&.owner, project.identifier)
|
||||||
|
return branches.collect{|i| i["name"] if i.is_a?(Hash)} if branches.is_a?(Array)
|
||||||
|
return branches["branch_name"] if branches.is_a?(Hash)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def render_cache_trackers
|
def render_cache_trackers
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
class Admins::NewImportUserFromExcel < BaseImportXlsx
|
||||||
|
UserData = Struct.new(:login, :email, :password, :nickname)
|
||||||
|
|
||||||
|
def read_each(&block)
|
||||||
|
sheet.each_row_streaming(pad_cells: true, offset: 1) do |row|
|
||||||
|
data = row.map(&method(:cell_value))[0..3]
|
||||||
|
block.call UserData.new(*data)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
def cell_value(obj)
|
||||||
|
obj&.cell_value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -23,7 +23,11 @@ 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)
|
||||||
|
|
@ -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],
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ class CacheAsyncClearJob < ApplicationJob
|
||||||
Cache::V2::ProjectCommonService.new(id).clear
|
Cache::V2::ProjectCommonService.new(id).clear
|
||||||
when "owner_common_service"
|
when "owner_common_service"
|
||||||
Cache::V2::OwnnerCommonService.new(id).clear
|
Cache::V2::OwnnerCommonService.new(id).clear
|
||||||
|
when "project_rank_service"
|
||||||
|
Cache::V2::ProjectRankService.new(id).clear
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -3,8 +3,7 @@ class DelayExpiredIssueJob < ApplicationJob
|
||||||
|
|
||||||
def perform
|
def perform
|
||||||
Issue.where(due_date: Date.today + 1.days).find_each do |issue|
|
Issue.where(due_date: Date.today + 1.days).find_each do |issue|
|
||||||
SendTemplateMessageJob.perform_later('IssueAssignerExpire', issue.id) if Site.has_notice_menu?
|
SendTemplateMessageJob.perform_later('IssueExpire', issue.id) if Site.has_notice_menu?
|
||||||
SendTemplateMessageJob.perform_later('IssueCreatorExpire', issue.id) if Site.has_notice_menu?
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ class MigrateRemoteRepositoryJob < ApplicationJob
|
||||||
return if repo.blank?
|
return if repo.blank?
|
||||||
|
|
||||||
puts "############ MigrateRemoteRepositoryJob starting ... ############"
|
puts "############ MigrateRemoteRepositoryJob starting ... ############"
|
||||||
|
params.except!(:auth_password, :auth_username) if params[:auth_username].nil?
|
||||||
gitea_repository = Gitea::Repository::MigrateService.new(token, params).call
|
gitea_repository = Gitea::Repository::MigrateService.new(token, params).call
|
||||||
puts "#gitea_repository#{gitea_repository}"
|
puts "#gitea_repository#{gitea_repository}"
|
||||||
if gitea_repository[0]==201
|
if gitea_repository[0]==201
|
||||||
|
|
|
||||||
|
|
@ -24,19 +24,13 @@ class SendTemplateMessageJob < ApplicationJob
|
||||||
receivers_email_string, email_title, email_content = MessageTemplate::IssueAssigned.get_email_message_content(receiver, operator, issue)
|
receivers_email_string, email_title, email_content = MessageTemplate::IssueAssigned.get_email_message_content(receiver, operator, issue)
|
||||||
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
end
|
end
|
||||||
when 'IssueAssignerExpire'
|
|
||||||
issue_id = args[0]
|
|
||||||
issue = Issue.find_by_id(issue_id)
|
|
||||||
return unless issue.present?
|
|
||||||
receivers = User.where(id: issue&.assigned_to_id)
|
|
||||||
receivers_string, content, notification_url = MessageTemplate::IssueAssignerExpire.get_message_content(receivers, issue)
|
|
||||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {issue_id: issue.id})
|
|
||||||
when 'IssueAtme'
|
when 'IssueAtme'
|
||||||
receivers, operator_id, issue_id = args[0], args[1], args[2]
|
receivers, operator_id, issue_id = args[0], args[1], args[2]
|
||||||
operator = User.find_by_id(operator_id)
|
operator = User.find_by_id(operator_id)
|
||||||
issue = Issue.find_by_id(issue_id)
|
issue = Issue.find_by_id(issue_id)
|
||||||
return unless operator.present? && issue.present?
|
return unless operator.present? && issue.present?
|
||||||
# receivers = receivers.where.not(id: operator&.id)
|
# receivers = receivers.where.not(id: operator&.id)
|
||||||
|
receivers = User.where(id: receivers)
|
||||||
receivers_string, content, notification_url = MessageTemplate::IssueAtme.get_message_content(receivers, operator, issue)
|
receivers_string, content, notification_url = MessageTemplate::IssueAtme.get_message_content(receivers, operator, issue)
|
||||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id}, 2, operator_id)
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id}, 2, operator_id)
|
||||||
when 'IssueChanged'
|
when 'IssueChanged'
|
||||||
|
|
@ -51,13 +45,17 @@ class SendTemplateMessageJob < ApplicationJob
|
||||||
receivers_email_string, email_title, email_content = MessageTemplate::IssueChanged.get_email_message_content(receiver, operator, issue, change_params)
|
receivers_email_string, email_title, email_content = MessageTemplate::IssueChanged.get_email_message_content(receiver, operator, issue, change_params)
|
||||||
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
end
|
end
|
||||||
when 'IssueCreatorExpire'
|
when 'IssueExpire'
|
||||||
issue_id = args[0]
|
issue_id = args[0]
|
||||||
issue = Issue.find_by_id(issue_id)
|
issue = Issue.find_by_id(issue_id)
|
||||||
return unless issue.present?
|
return unless issue.present?
|
||||||
receivers = User.where(id: issue&.author_id)
|
receivers = User.where(id: [issue&.assigned_to_id, issue&.author_id])
|
||||||
receivers_string, content, notification_url = MessageTemplate::IssueCreatorExpire.get_message_content(receivers, issue)
|
receivers_string, content, notification_url = MessageTemplate::IssueExpire.get_message_content(receivers, issue)
|
||||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {issue_id: issue.id})
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {issue_id: issue.id})
|
||||||
|
receivers.find_each do |receiver|
|
||||||
|
receivers_email_string, email_title, email_content = MessageTemplate::IssueExpire.get_email_message_content(receiver, issue)
|
||||||
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
|
end
|
||||||
when 'IssueDeleted'
|
when 'IssueDeleted'
|
||||||
operator_id, issue_title, issue_assigned_to_id, issue_author_id = args[0], args[1], args[2], args[3]
|
operator_id, issue_title, issue_assigned_to_id, issue_author_id = args[0], args[1], args[2], args[3]
|
||||||
operator = User.find_by_id(operator_id)
|
operator = User.find_by_id(operator_id)
|
||||||
|
|
@ -93,18 +91,14 @@ class SendTemplateMessageJob < ApplicationJob
|
||||||
receivers_email_string, email_title, email_content = MessageTemplate::OrganizationLeft.get_email_message_content(receiver, organization)
|
receivers_email_string, email_title, email_content = MessageTemplate::OrganizationLeft.get_email_message_content(receiver, organization)
|
||||||
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
end
|
end
|
||||||
when 'OrganizationRole'
|
when 'ProjectForked'
|
||||||
user_id, organization_id, role = args[0], args[1], args[2]
|
operator_id, project_id = args[0], args[1]
|
||||||
user = User.find_by_id(user_id)
|
operator = User.find_by_id(operator_id)
|
||||||
organization = Organization.find_by_id(organization_id)
|
project = Project.find_by_id(project_id)
|
||||||
return unless user.present? && organization.present?
|
return unless operator.present? && project.present?
|
||||||
receivers = User.where(id: user.id)
|
receivers = project&.all_managers.where.not(id: operator&.id)
|
||||||
receivers_string, content, notification_url = MessageTemplate::OrganizationRole.get_message_content(receivers, organization, role)
|
receivers_string, content, notification_url = MessageTemplate::ProjectForked.get_message_content(receivers, operator, project)
|
||||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id, role: role})
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, project_id: project.id})
|
||||||
receivers.find_each do |receiver|
|
|
||||||
receivers_email_string, email_title, email_content = MessageTemplate::OrganizationRole.get_email_message_content(receiver, organization, role)
|
|
||||||
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
|
||||||
end
|
|
||||||
when 'ProjectIssue'
|
when 'ProjectIssue'
|
||||||
operator_id, issue_id = args[0], args[1]
|
operator_id, issue_id = args[0], args[1]
|
||||||
operator = User.find_by_id(operator_id)
|
operator = User.find_by_id(operator_id)
|
||||||
|
|
@ -174,6 +168,37 @@ class SendTemplateMessageJob < ApplicationJob
|
||||||
receivers_email_string, email_title, email_content = MessageTemplate::ProjectMemberLeft.get_email_message_content(receiver, user, project)
|
receivers_email_string, email_title, email_content = MessageTemplate::ProjectMemberLeft.get_email_message_content(receiver, user, project)
|
||||||
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
end
|
end
|
||||||
|
when 'ProjectMilestoneCompleted'
|
||||||
|
milestone_id = args[0]
|
||||||
|
milestone = Version.find_by_id(milestone_id)
|
||||||
|
return unless milestone.present? && milestone&.project.present?
|
||||||
|
receivers = milestone&.project&.all_managers
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::ProjectMilestoneCompleted.get_message_content(receivers, milestone)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {milestone_id: milestone_id})
|
||||||
|
receivers.find_each do |receiver|
|
||||||
|
receivers_email_string, email_title, email_content = MessageTemplate::ProjectMilestoneCompleted.get_email_message_content(receiver, milestone)
|
||||||
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
|
end
|
||||||
|
when 'ProjectMilestone'
|
||||||
|
milestone_id, operator_id = args[0], args[1]
|
||||||
|
milestone = Version.find_by_id(milestone_id)
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
return unless milestone.present? && milestone&.project.present? && operator.present?
|
||||||
|
receivers = milestone&.project&.all_managers.where.not(id: operator_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::ProjectMilestone.get_message_content(receivers, operator, milestone)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {milestone_id: milestone_id, operator_id: operator_id})
|
||||||
|
receivers.find_each do |receiver|
|
||||||
|
receivers_email_string, email_title, email_content = MessageTemplate::ProjectMilestone.get_email_message_content(receiver, operator, milestone)
|
||||||
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
|
end
|
||||||
|
when 'ProjectPraised'
|
||||||
|
operator_id, project_id = args[0], args[1]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
project = Project.find_by_id(project_id)
|
||||||
|
return unless operator.present? && project.present?
|
||||||
|
receivers = project&.all_managers.where.not(id: operator&.id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::ProjectPraised.get_message_content(receivers, operator, project)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, project_id: project.id})
|
||||||
when 'ProjectPullRequest'
|
when 'ProjectPullRequest'
|
||||||
operator_id, pull_request_id = args[0], args[1]
|
operator_id, pull_request_id = args[0], args[1]
|
||||||
operator = User.find_by_id(operator_id)
|
operator = User.find_by_id(operator_id)
|
||||||
|
|
@ -235,6 +260,7 @@ class SendTemplateMessageJob < ApplicationJob
|
||||||
pull_request = PullRequest.find_by_id(pull_request_id)
|
pull_request = PullRequest.find_by_id(pull_request_id)
|
||||||
return unless operator.present? && pull_request.present?
|
return unless operator.present? && pull_request.present?
|
||||||
# receivers = receivers.where.not(id: operator&.id)
|
# receivers = receivers.where.not(id: operator&.id)
|
||||||
|
receivers = User.where(id: receivers)
|
||||||
receivers_string, content, notification_url = MessageTemplate::PullRequestAtme.get_message_content(receivers, operator, pull_request)
|
receivers_string, content, notification_url = MessageTemplate::PullRequestAtme.get_message_content(receivers, operator, pull_request)
|
||||||
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id}, 2, operator_id)
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id}, 2, operator_id)
|
||||||
when 'PullRequestChanged'
|
when 'PullRequestChanged'
|
||||||
|
|
@ -274,6 +300,56 @@ class SendTemplateMessageJob < ApplicationJob
|
||||||
receivers_email_string, email_title, email_content = MessageTemplate::PullRequestMerged.get_email_message_content(receiver, operator, pull_request)
|
receivers_email_string, email_title, email_content = MessageTemplate::PullRequestMerged.get_email_message_content(receiver, operator, pull_request)
|
||||||
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
end
|
end
|
||||||
|
when 'TeamJoined'
|
||||||
|
user_id, organization_id, team_id = args[0], args[1], args[2]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
organization = Organization.find_by_id(organization_id)
|
||||||
|
team = Team.find_by_id(team_id)
|
||||||
|
return unless user.present? && organization.present? && team.present?
|
||||||
|
receivers = User.where(id: user.id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::TeamJoined.get_message_content(receivers, organization, team)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id, team_id: team.id})
|
||||||
|
receivers.find_each do |receiver|
|
||||||
|
receivers_email_string, email_title, email_content = MessageTemplate::TeamJoined.get_email_message_content(receiver, organization, team)
|
||||||
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
|
end
|
||||||
|
when 'TeamLeft'
|
||||||
|
user_id, organization_id, team_id = args[0], args[1], args[2]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
organization = Organization.find_by_id(organization_id)
|
||||||
|
team = Team.find_by_id(team_id)
|
||||||
|
return unless user.present? && organization.present? && team.present?
|
||||||
|
receivers = User.where(id: user.id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::TeamLeft.get_message_content(receivers, organization, team)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id, team_id: team.id})
|
||||||
|
receivers.find_each do |receiver|
|
||||||
|
receivers_email_string, email_title, email_content = MessageTemplate::TeamLeft.get_email_message_content(receiver, organization, team)
|
||||||
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
|
end
|
||||||
|
when 'CompetitionBegin'
|
||||||
|
user_id, competition_id = args[0], args[1]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
project = Project.find_by_sql("select *,title as name from competitions where id=#{competition_id}")
|
||||||
|
return unless user.present? && project.present?
|
||||||
|
receivers = User.where(id: user_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::CompetitionBegin.get_message_content(receivers, project.first)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user_id, competition_name: project.first&.name, identifier: project.first&.identifier})
|
||||||
|
when 'CompetitionReview'
|
||||||
|
user_id, competition_id = args[0], args[1]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
project = Project.find_by_sql("select *,title as name from competitions where id=#{competition_id}")
|
||||||
|
return unless user.present? && project.present?
|
||||||
|
receivers = User.where(id: user_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::CompetitionReview.get_message_content(receivers, project.first)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user_id, competition_name: project.first&.name, identifier: project.first&.identifier})
|
||||||
|
when 'CompetitionResult'
|
||||||
|
user_id, competition_id = args[0], args[1]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
project = Project.find_by_sql("select *,title as name from competitions where id=#{competition_id}")
|
||||||
|
return unless user.present? && project.present?
|
||||||
|
receivers = User.where(id: user_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::CompetitionResult.get_message_content(receivers, project.first)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user_id, competition_name: project.first&.name, identifier: project.first&.identifier})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
module CustomRegexp
|
module CustomRegexp
|
||||||
PHONE = /1\d{10}/
|
PHONE = /1\d{10}/
|
||||||
EMAIL = /\A[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+\z/
|
EMAIL = /\A[a-zA-Z0-9]+([._\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+\z/
|
||||||
LOGIN = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
LOGIN = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]{4,15}\z/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||||
LASTNAME = /\A[a-zA-Z0-9\u4e00-\u9fa5]+\z/
|
LASTNAME = /\A[a-zA-Z0-9\u4e00-\u9fa5]+\z/
|
||||||
NICKNAME = /\A[\u4e00-\u9fa5_a-zA-Z0-9]+\z/
|
NICKNAME = /\A[\u4e00-\u9fa5_a-zA-Z0-9]+\z/
|
||||||
PASSWORD = /\A[a-z_A-Z0-9\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'_<>~\·`\?:;|]{8,16}\z/
|
PASSWORD = /\A[a-z_A-Z0-9\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'_<>~\·`\?:;|]{8,16}\z/
|
||||||
|
LOGIN_PASSWORD = /\A[a-z_A-Z0-9\-\.!@#\$%\\\^&\*\)\(\+=\{\}\[\]\/",'_<>~\·`\?:;|]{6,16}\z/
|
||||||
URL = /\Ahttps?:\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|]\z/
|
URL = /\Ahttps?:\/\/[-A-Za-z0-9+&@#\/%?=~_|!:,.;]+[-A-Za-z0-9+&@#\/%=~_|]\z/
|
||||||
IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/
|
IP = /^((\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$/
|
||||||
|
|
||||||
URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i
|
URL_REGEX = /\A(?:(?:https?|ftp):\/\/)(?:\S+(?::\S*)?@)?(?:(?!10(?:\.\d{1,3}){3})(?!127(?:\.\d{1,3}){3})(?!169\.254(?:\.\d{1,3}){2})(?!192\.168(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]+-?)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})))(?::\d{2,5})?(?:\/[^\s]*)?\z/i
|
||||||
REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
REPOSITORY_NAME_REGEX = /^(?!_)(?!.*?_$)[a-zA-Z0-9_-]+$/ #只含有数字、字母、下划线不能以下划线开头和结尾
|
||||||
|
MD_REGEX = /^.+(\.[m|M][d|D])$/
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -7,7 +7,7 @@ module Notice
|
||||||
config = Rails.application.config_for(:configuration).symbolize_keys!
|
config = Rails.application.config_for(:configuration).symbolize_keys!
|
||||||
notice_config = config[:notice].symbolize_keys!
|
notice_config = config[:notice].symbolize_keys!
|
||||||
raise 'notice config missing' if notice_config.blank?
|
raise 'notice config missing' if notice_config.blank?
|
||||||
rescue => exception
|
rescue => ex
|
||||||
raise ex if Rails.env.production?
|
raise ex if Rails.env.production?
|
||||||
|
|
||||||
puts %Q{\033[33m [warning] gitea config or configuration.yml missing,
|
puts %Q{\033[33m [warning] gitea config or configuration.yml missing,
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,21 @@
|
||||||
|
module Trace
|
||||||
|
class << self
|
||||||
|
def trace_config
|
||||||
|
trace_config = {}
|
||||||
|
|
||||||
|
begin
|
||||||
|
config = Rails.application.config_for(:configuration).symbolize_keys!
|
||||||
|
trace_config = config[:trace].symbolize_keys!
|
||||||
|
raise 'trace config missing' if trace_config.blank?
|
||||||
|
rescue => ex
|
||||||
|
raise ex if Rails.env.production?
|
||||||
|
|
||||||
|
puts %Q{\033[33m [warning] gitea config or configuration.yml missing,
|
||||||
|
please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m}
|
||||||
|
trace_config = {}
|
||||||
|
end
|
||||||
|
|
||||||
|
trace_config
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -29,6 +29,7 @@ module Util
|
||||||
file.write(io)
|
file.write(io)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
true
|
||||||
end
|
end
|
||||||
|
|
||||||
def download_file(url, save_path)
|
def download_file(url, save_path)
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,10 @@ class Ci::Repo < Ci::RemoteBase
|
||||||
has_one :perm, foreign_key: :perm_repo_uid
|
has_one :perm, foreign_key: :perm_repo_uid
|
||||||
has_many :builds, foreign_key: :build_repo_id, dependent: :destroy
|
has_many :builds, foreign_key: :build_repo_id, dependent: :destroy
|
||||||
|
|
||||||
def self.find_with_namespace(namespace_path, identifier)
|
def self.find_with_namespace(namespace_path, identifier, user_login)
|
||||||
logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} "
|
logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} "
|
||||||
|
user_login = user_login || namespace_path
|
||||||
user = Ci::User.find_by_user_login namespace_path
|
user = Ci::User.find_by(user_login: user_login)
|
||||||
repo = Ci::Repo.where(repo_namespace: namespace_path, repo_name: identifier).first
|
repo = Ci::Repo.where(repo_namespace: namespace_path, repo_name: identifier).first
|
||||||
|
|
||||||
[user, repo]
|
[user, repo]
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@ module Matchable
|
||||||
scope :with_project_category, ->(category_id) { where(project_category_id: category_id) unless category_id.blank? }
|
scope :with_project_category, ->(category_id) { where(project_category_id: category_id) unless category_id.blank? }
|
||||||
scope :with_project_language, ->(language_id) { where(project_language_id: language_id) unless language_id.blank? }
|
scope :with_project_language, ->(language_id) { where(project_language_id: language_id) unless language_id.blank? }
|
||||||
scope :with_project_type, ->(project_type) { where(project_type: project_type) if Project.project_types.include?(project_type) }
|
scope :with_project_type, ->(project_type) { where(project_type: project_type) if Project.project_types.include?(project_type) }
|
||||||
scope :by_name_or_identifier, ->(search) { where("name like :search or identifier LIKE :search", :search => "#{search.split(" ").join('|')}%") unless search.blank? }
|
scope :by_name_or_identifier, ->(search) { where("name like :search or identifier LIKE :search", :search => "%#{search.split(" ").join('|')}%") unless search.blank? }
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -21,13 +21,37 @@ module ProjectOperable
|
||||||
end
|
end
|
||||||
|
|
||||||
def add_member!(user_id, role_name='Developer')
|
def add_member!(user_id, role_name='Developer')
|
||||||
member = members.create!(user_id: user_id)
|
if self.owner.is_a?(Organization)
|
||||||
|
case role_name
|
||||||
|
when 'Manager'
|
||||||
|
team = self.owner.teams.admin.take
|
||||||
|
team = team.nil? ? Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false) : team
|
||||||
|
TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
|
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||||
|
when 'Developer'
|
||||||
|
team = self.owner.teams.write.take
|
||||||
|
team = team.nil? ? Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false) : team
|
||||||
|
TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
|
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||||
|
when 'Reporter'
|
||||||
|
team = self.owner.teams.read.take
|
||||||
|
team = team.nil? ? Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false) : team
|
||||||
|
TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
|
team_user = TeamUser.build(self.user_id, user_id, team.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
member = members.create!(user_id: user_id, team_user_id: team_user&.id)
|
||||||
set_developer_role(member, role_name)
|
set_developer_role(member, role_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def remove_member!(user_id)
|
def remove_member!(user_id)
|
||||||
member = members.find_by(user_id: user_id)
|
member = members.find_by(user_id: user_id)
|
||||||
member.destroy! if member && self.user_id != user_id
|
member.destroy! if member && self.user_id != user_id
|
||||||
|
team_user = TeamUser.find_by_id(member&.team_user_id)
|
||||||
|
team_user.destroy! if team_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def member?(user_id)
|
def member?(user_id)
|
||||||
|
|
@ -47,6 +71,28 @@ module ProjectOperable
|
||||||
|
|
||||||
def change_member_role!(user_id, role)
|
def change_member_role!(user_id, role)
|
||||||
member = self.member(user_id)
|
member = self.member(user_id)
|
||||||
|
if self.owner.is_a?(Organization) && member.team_user.present?
|
||||||
|
case role&.name
|
||||||
|
when 'Manager'
|
||||||
|
team = self.owner.teams.admin.take
|
||||||
|
team = team.nil? ? Team.build(self.user_id, 'admin', '管理员', '', 'admin', false, false) : team
|
||||||
|
TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
|
team_user = member.team_user.update(team_id: team&.id)
|
||||||
|
when 'Developer'
|
||||||
|
team = self.owner.teams.write.take
|
||||||
|
team = team.nil? ? Team.build(self.user_id, 'developer', '开发者', '', 'write', false, false) : team
|
||||||
|
TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
|
team_user = member.team_user.update(team_id: team&.id)
|
||||||
|
when 'Reporter'
|
||||||
|
team = self.owner.teams.read.take
|
||||||
|
team = team.nil? ? Team.build(self.user_id, 'reporter', '报告者', '', 'read', false, false) : team
|
||||||
|
TeamProject.build(self.user_id, team.id, self.id)
|
||||||
|
OrganizationUser.build(self.user_id, user_id)
|
||||||
|
team_user = member.team_user.update(team_id: team&.id)
|
||||||
|
end
|
||||||
|
end
|
||||||
member.member_roles.last.update_attributes!(role: role)
|
member.member_roles.last.update_attributes!(role: role)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@
|
||||||
|
|
||||||
class ForkUser < ApplicationRecord
|
class ForkUser < ApplicationRecord
|
||||||
belongs_to :project
|
belongs_to :project
|
||||||
belongs_to :user
|
belongs_to :owner, class_name: 'Owner', foreign_key: :user_id
|
||||||
belongs_to :fork_project, class_name: 'Project', foreign_key: :fork_project_id
|
belongs_to :fork_project, class_name: 'Project', foreign_key: :fork_project_id
|
||||||
|
|
||||||
after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
|
after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
|
||||||
|
|
|
||||||
|
|
@ -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
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
class Gitea::WebhookTask < Gitea::Base
|
class Gitea::WebhookTask < Gitea::Base
|
||||||
serialize :payload_content, JSON
|
serialize :payload_content, JSON
|
||||||
serialize :request_content, JSON
|
serialize :request_content, JSON
|
||||||
serialize :response_content, JSON
|
|
||||||
|
|
||||||
self.inheritance_column = nil
|
self.inheritance_column = nil
|
||||||
|
|
||||||
|
|
@ -10,4 +9,10 @@ class Gitea::WebhookTask < Gitea::Base
|
||||||
belongs_to :webhook, class_name: "Gitea::Webhook", foreign_key: :hook_id
|
belongs_to :webhook, class_name: "Gitea::Webhook", foreign_key: :hook_id
|
||||||
|
|
||||||
enum type: {gogs: 1, slack: 2, gitea: 3, discord: 4, dingtalk: 5, telegram: 6, msteams: 7, feishu: 8, matrix: 9}
|
enum type: {gogs: 1, slack: 2, gitea: 3, discord: 4, dingtalk: 5, telegram: 6, msteams: 7, feishu: 8, matrix: 9}
|
||||||
|
|
||||||
|
def response_content_json
|
||||||
|
JSON.parse(response_content)
|
||||||
|
rescue
|
||||||
|
{}
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -11,7 +11,7 @@
|
||||||
# category_id :integer
|
# category_id :integer
|
||||||
# status_id :integer not null
|
# status_id :integer not null
|
||||||
# assigned_to_id :integer
|
# assigned_to_id :integer
|
||||||
# priority_id :integer not null
|
# priority_id :integer
|
||||||
# fixed_version_id :integer
|
# fixed_version_id :integer
|
||||||
# author_id :integer not null
|
# author_id :integer not null
|
||||||
# created_on :datetime
|
# created_on :datetime
|
||||||
|
|
@ -75,7 +75,7 @@ class Issue < ApplicationRecord
|
||||||
scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)}
|
scope :issue_index_includes, ->{includes(:tracker, :priority, :version, :issue_status, :journals,:issue_tags,user: :user_extension)}
|
||||||
scope :closed, ->{where(status_id: 5)}
|
scope :closed, ->{where(status_id: 5)}
|
||||||
after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
|
after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic
|
||||||
after_update :change_versions_count
|
after_save :change_versions_count, :send_update_message_to_notice_system
|
||||||
after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic
|
after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic
|
||||||
|
|
||||||
def incre_project_common
|
def incre_project_common
|
||||||
|
|
@ -153,6 +153,10 @@ class Issue < ApplicationRecord
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_collaborators?
|
||||||
|
self.assigned_to_id.present? ? self.project.member?(self.assigned_to_id) : false
|
||||||
|
end
|
||||||
|
|
||||||
def get_issue_tags_name
|
def get_issue_tags_name
|
||||||
if issue_tags.present?
|
if issue_tags.present?
|
||||||
issue_tags.select(:name).uniq.pluck(:name).join(",")
|
issue_tags.select(:name).uniq.pluck(:name).join(",")
|
||||||
|
|
@ -166,11 +170,25 @@ class Issue < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def change_versions_count
|
def change_versions_count
|
||||||
if self.version.present? && self.saved_change_to_status_id?
|
if self.saved_change_to_fixed_version_id?
|
||||||
|
before_version = Version.find_by_id(self.fixed_version_id_before_last_save)
|
||||||
|
Rails.logger.info self.fixed_version_id_before_last_save
|
||||||
|
if before_version.present?
|
||||||
|
Rails.logger.info self.status_id
|
||||||
|
Rails.logger.info self.status_id_before_last_save
|
||||||
|
# 更改前状态为完成 或者 更改前后都为完成状态
|
||||||
|
if self.status_id_before_last_save == 5
|
||||||
|
percent = before_version.issues_count == 0 ? 0.0 : ((before_version.closed_issues_count - 1).to_f / before_version.issues_count)
|
||||||
|
before_version.update_attributes(closed_issues_count: (before_version.closed_issues_count - 1), percent: percent)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.version.present? && (self.saved_change_to_status_id? || self.saved_change_to_fixed_version_id?)
|
||||||
if self.status_id == 5
|
if self.status_id == 5
|
||||||
percent = self.version.issues_count == 0 ? 0.0 : ((self.version.closed_issues_count + 1).to_f / self.version.issues_count)
|
percent = self.version.issues_count == 0 ? 0.0 : ((self.version.closed_issues_count + 1).to_f / self.version.issues_count)
|
||||||
self.version.update_attributes(closed_issues_count: (self.version.closed_issues_count + 1), percent: percent)
|
self.version.update_attributes(closed_issues_count: (self.version.closed_issues_count + 1), percent: percent)
|
||||||
elsif self.status_id_before_last_save == 5
|
elsif self.status_id_before_last_save == 5 && !self.saved_change_to_fixed_version_id?
|
||||||
percent = self.version.issues_count == 0 ? 0.0 : ((self.version.closed_issues_count - 1).to_f / self.version.issues_count)
|
percent = self.version.issues_count == 0 ? 0.0 : ((self.version.closed_issues_count - 1).to_f / self.version.issues_count)
|
||||||
self.version.update_attributes(closed_issues_count: (self.version.closed_issues_count - 1), percent: percent)
|
self.version.update_attributes(closed_issues_count: (self.version.closed_issues_count - 1), percent: percent)
|
||||||
end
|
end
|
||||||
|
|
@ -178,7 +196,11 @@ class Issue < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def update_closed_issues_count_in_project!
|
def update_closed_issues_count_in_project!
|
||||||
self.project.decrement!(:closed_issues_count)
|
self.project.decrement!(:closed_issues_count) if self.status_id == 5
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_update_message_to_notice_system
|
||||||
|
SendTemplateMessageJob.perform_later('IssueExpire', self.id) if Site.has_notice_menu? && self.due_date == Date.today + 1.days
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@
|
||||||
# journalized_id :integer default("0"), not null
|
# journalized_id :integer default("0"), not null
|
||||||
# journalized_type :string(30) default(""), not null
|
# journalized_type :string(30) default(""), not null
|
||||||
# user_id :integer default("0"), not null
|
# user_id :integer default("0"), not null
|
||||||
# notes :text(65535)
|
# notes :text(4294967295)
|
||||||
# created_on :datetime not null
|
# created_on :datetime not null
|
||||||
# private_notes :boolean default("0"), not null
|
# private_notes :boolean default("0"), not null
|
||||||
# parent_id :integer
|
# parent_id :integer
|
||||||
|
|
|
||||||
|
|
@ -11,23 +11,26 @@
|
||||||
# course_group_id :integer default("0")
|
# course_group_id :integer default("0")
|
||||||
# is_collect :integer default("1")
|
# is_collect :integer default("1")
|
||||||
# graduation_group_id :integer default("0")
|
# graduation_group_id :integer default("0")
|
||||||
|
# team_user_id :integer
|
||||||
#
|
#
|
||||||
# Indexes
|
# Indexes
|
||||||
#
|
#
|
||||||
# index_members_on_course_id (course_id)
|
# index_members_on_course_id (course_id)
|
||||||
# index_members_on_project_id (project_id)
|
# index_members_on_project_id (project_id)
|
||||||
|
# index_members_on_team_user_id (team_user_id)
|
||||||
# index_members_on_user_id (user_id)
|
# index_members_on_user_id (user_id)
|
||||||
# index_members_on_user_id_and_project_id (user_id,project_id,course_id) UNIQUE
|
# index_members_on_user_id_and_project_id (user_id,project_id,course_id) UNIQUE
|
||||||
#
|
#
|
||||||
|
|
||||||
class Member < ApplicationRecord
|
class Member < ApplicationRecord
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
# belongs_to :course, optional: true
|
# belongs_to :course, optional: true
|
||||||
belongs_to :project, optional: true
|
belongs_to :project, optional: true
|
||||||
|
belongs_to :team_user, optional: true
|
||||||
has_many :member_roles, dependent: :destroy
|
|
||||||
has_many :roles, through: :member_roles
|
has_many :member_roles, dependent: :destroy
|
||||||
|
has_many :roles, through: :member_roles
|
||||||
validates :user_id, :project_id, presence: true
|
|
||||||
|
validates :user_id, :project_id, presence: true
|
||||||
end
|
|
||||||
|
end
|
||||||
|
|
|
||||||
|
|
@ -13,59 +13,72 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
class MessageTemplate < ApplicationRecord
|
class MessageTemplate < ApplicationRecord
|
||||||
|
PLATFORM = 'GitLink'
|
||||||
|
|
||||||
def self.build_init_data
|
def self.build_init_data
|
||||||
|
MessageTemplate::IssueAssignerExpire.destroy_all
|
||||||
|
MessageTemplate::IssueCreatorExpire.destroy_all
|
||||||
self.create(type: 'MessageTemplate::FollowedTip', sys_notice: '<b>{nickname}</b> 关注了你', notification_url: '{baseurl}/{login}')
|
self.create(type: 'MessageTemplate::FollowedTip', sys_notice: '<b>{nickname}</b> 关注了你', notification_url: '{baseurl}/{login}')
|
||||||
email_html = File.read("#{email_template_html_dir}/issue_assigned.html")
|
email_html = File.read("#{email_template_html_dir}/issue_assigned.html")
|
||||||
self.create(type: 'MessageTemplate::IssueAssigned', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 指派给你一个易修:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: 'GitLink: {nickname1} 在 {nickname2}/{repository} 指派给你一个易修')
|
self.create(type: 'MessageTemplate::IssueAssigned', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 指派给你一个疑修:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 在 {nickname2}/{repository} 指派给你一个疑修")
|
||||||
self.create(type: 'MessageTemplate::IssueAssignerExpire', sys_notice: '您负责的易修 <b>{title}</b> 已临近截止日期,请尽快处理', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
|
self.create(type: 'MessageTemplate::IssueAtme', sys_notice: '<b>{nickname}</b> 在疑修 <b>{title}</b> 中@我', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
|
||||||
self.create(type: 'MessageTemplate::IssueAtme', sys_notice: '<b>{nickname}</b> 在易修 <b>{title}</b> 中@我', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
|
|
||||||
email_html = File.read("#{email_template_html_dir}/issue_changed.html")
|
email_html = File.read("#{email_template_html_dir}/issue_changed.html")
|
||||||
self.create(type: 'MessageTemplate::IssueChanged', sys_notice: '在项目 <b>{nickname2}/{repository}</b> 的易修 <b>{title}</b> 中:{ifassigner}{nickname1}将负责人从 <b>{assigner1}</b> 修改为 <b>{assigner2}</b> {endassigner}{ifstatus}{nickname1}将状态从 <b>{status1}</b> 修改为 <b>{status2}</b> {endstatus}{iftracker}{nickname1}将类型从 <b>{tracker1}</b> 修改为 <b>{tracker2}</b> {endtracker}{ifpriority}{nickname1}将优先级从 <b>{priority1}</b> 修改为 <b>{priority2}</b> {endpriority}{ifmilestone}{nickname1}将里程碑从 <b>{milestone1}</b> 修改为 <b>{milestone2}</b> {endmilestone}{iftag}{nickname1}将标记从 <b>{tag1}</b> 修改为 <b>{tag2}</b> {endtag}{ifdoneratio}{nickname1}将完成度从 <b>{doneratio1}</b> 修改为 <b>{doneratio2}</b> {enddoneratio}{ifbranch}{nickname1}将指定分支从 <b>{branch1}</b> 修改为 <b>{branch2}</b> {endbranch}{ifstartdate}{nickname1}将开始日期从 <b>{startdate1}</b> 修改为 <b>{startdate2}</b> {endstartdate}{ifduedate}{nickname1}将结束日期从 <b>{duedate1}</b> 修改为 <b>{duedate2}</b> {endduedate}', email: email_html, email_title: 'GitLink: 易修 {title} 有状态变更', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
|
self.create(type: 'MessageTemplate::IssueChanged', sys_notice: '在项目 <b>{nickname2}/{repository}</b> 的疑修 <b>{title}</b> 中:{ifassigner}{nickname1}将负责人从 <b>{assigner1}</b> 修改为 <b>{assigner2}</b> {endassigner}{ifstatus}{nickname1}将状态从 <b>{status1}</b> 修改为 <b>{status2}</b> {endstatus}{iftracker}{nickname1}将类型从 <b>{tracker1}</b> 修改为 <b>{tracker2}</b> {endtracker}{ifpriority}{nickname1}将优先级从 <b>{priority1}</b> 修改为 <b>{priority2}</b> {endpriority}{ifmilestone}{nickname1}将里程碑从 <b>{milestone1}</b> 修改为 <b>{milestone2}</b> {endmilestone}{iftag}{nickname1}将标记从 <b>{tag1}</b> 修改为 <b>{tag2}</b> {endtag}{ifdoneratio}{nickname1}将完成度从 <b>{doneratio1}</b> 修改为 <b>{doneratio2}</b> {enddoneratio}{ifbranch}{nickname1}将指定分支从 <b>{branch1}</b> 修改为 <b>{branch2}</b> {endbranch}{ifstartdate}{nickname1}将开始日期从 <b>{startdate1}</b> 修改为 <b>{startdate2}</b> {endstartdate}{ifduedate}{nickname1}将结束日期从 <b>{duedate1}</b> 修改为 <b>{duedate2}</b> {endduedate}', email: email_html, email_title: "#{PLATFORM}: 疑修 {title} 有状态变更", notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
|
||||||
self.create(type: 'MessageTemplate::IssueCreatorExpire', sys_notice: '您发布的易修 <b>{title}</b> 已临近截止日期,请尽快处理', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
|
email_html = File.read("#{email_template_html_dir}/issue_expire.html")
|
||||||
|
self.create(type: 'MessageTemplate::IssueExpire', sys_notice: '疑修 <b>{title}</b> 已临近截止日期,请尽快处理', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: "#{PLATFORM}: 疑修截止日期到达最后一天")
|
||||||
email_html = File.read("#{email_template_html_dir}/issue_deleted.html")
|
email_html = File.read("#{email_template_html_dir}/issue_deleted.html")
|
||||||
self.create(type: 'MessageTemplate::IssueDeleted', sys_notice: '{nickname}已将易修 <b>{title}</b> 删除', email: email_html, email_title: 'GitLink: 易修 {title} 有状态变更', notification_url: '')
|
self.create(type: 'MessageTemplate::IssueDeleted', sys_notice: '{nickname}已将疑修 <b>{title}</b> 删除', email: email_html, email_title: "#{PLATFORM}: 疑修 {title} 有状态变更", notification_url: '')
|
||||||
self.create(type: 'MessageTemplate::IssueJournal', sys_notice: '{nickname}评论易修{title}:<b>{notes}</b>', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
|
self.create(type: 'MessageTemplate::IssueJournal', sys_notice: '{nickname}评论疑修{title}:<b>{notes}</b>', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}')
|
||||||
self.create(type: 'MessageTemplate::LoginIpTip', sys_notice: '您的账号{nickname}于{login_time)在非常用的IP地址{ip}登录,如非本人操作,请立即修改密码', notification_url: '')
|
self.create(type: 'MessageTemplate::LoginIpTip', sys_notice: '您的账号{nickname}于{login_time)在非常用的IP地址{ip}登录,如非本人操作,请立即修改密码', notification_url: '')
|
||||||
email_html = File.read("#{email_template_html_dir}/organization_joined.html")
|
email_html = File.read("#{email_template_html_dir}/organization_joined.html")
|
||||||
self.create(type: 'MessageTemplate::OrganizationJoined', sys_notice: '你已加入 <b>{organization}</b> 组织', notification_url: '{baseurl}/{login}', email: email_html, email_title: 'GitLink: 你已加入 {organization} 组织')
|
self.create(type: 'MessageTemplate::OrganizationJoined', sys_notice: '你已加入 <b>{organization}</b> 组织', notification_url: '{baseurl}/{login}', email: email_html, email_title: "#{PLATFORM}: 你已加入 {organization} 组织")
|
||||||
email_html = File.read("#{email_template_html_dir}/organization_left.html")
|
email_html = File.read("#{email_template_html_dir}/organization_left.html")
|
||||||
self.create(type: 'MessageTemplate::OrganizationLeft', sys_notice: '你已被移出 <b>{organization}</b> 组织', notification_url: '', email: email_html, email_title: 'GitLink: 你已被移出 {organization} 组织')
|
self.create(type: 'MessageTemplate::OrganizationLeft', sys_notice: '你已被移出 <b>{organization}</b> 组织', notification_url: '', email: email_html, email_title: "#{PLATFORM}: 你已被移出 {organization} 组织")
|
||||||
email_html = File.read("#{email_template_html_dir}/organization_role.html")
|
|
||||||
self.create(type: 'MessageTemplate::OrganizationRole', sys_notice: '组织 <b>{organization}</b> 已把你的角色改为 <b>{role}</b>', email: email_html, email_title: 'GitLink: 在 {organization} 组织你的账号有权限变更', notification_url: '{baseurl}/{login}')
|
|
||||||
self.create(type: 'MessageTemplate::ProjectDeleted', sys_notice: '你关注的仓库{nickname}/{repository}已被删除', notification_url: '')
|
self.create(type: 'MessageTemplate::ProjectDeleted', sys_notice: '你关注的仓库{nickname}/{repository}已被删除', notification_url: '')
|
||||||
self.create(type: 'MessageTemplate::ProjectFollowed', sys_notice: '<b>{nickname}</b> 关注了你管理的仓库', notification_url: '{baseurl}/{login}')
|
self.create(type: 'MessageTemplate::ProjectFollowed', sys_notice: '<b>{nickname}</b> 关注了你管理的仓库', notification_url: '{baseurl}/{login}')
|
||||||
self.create(type: 'MessageTemplate::ProjectForked', sys_notice: '<b>{nickname1}</b> 复刻了你管理的仓库{nickname1}/{repository1}到{nickname2}/{repository2}', notification_url: '{baseurl}/{owner}/{identifier}')
|
self.create(type: 'MessageTemplate::ProjectForked', sys_notice: '<b>{nickname1}</b> 复刻了你管理的仓库 <b>{nickname2}/{repository}</b> 到 <b>{nickname1}/{repository}</b>', notification_url: '{baseurl}/{owner}/{identifier}')
|
||||||
email_html = File.read("#{email_template_html_dir}/project_issue.html")
|
email_html = File.read("#{email_template_html_dir}/project_issue.html")
|
||||||
self.create(type: 'MessageTemplate::ProjectIssue', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 新建易修:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: 'GitLink: {nickname1} 在 {nickname2}/{repository} 新建了一个易修')
|
self.create(type: 'MessageTemplate::ProjectIssue', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 新建疑修:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 在 {nickname2}/{repository} 新建了一个疑修")
|
||||||
email_html = File.read("#{email_template_html_dir}/project_joined.html")
|
email_html = File.read("#{email_template_html_dir}/project_joined.html")
|
||||||
self.create(type: 'MessageTemplate::ProjectJoined', sys_notice: '你已加入 <b>{repository}</b> 项目', notification_url: '{baseurl}/{owner}/{identifier}', email: email_html, email_title: 'GitLink: 你已加入 {repository} 项目')
|
self.create(type: 'MessageTemplate::ProjectJoined', sys_notice: '你已加入 <b>{repository}</b> 项目', notification_url: '{baseurl}/{owner}/{identifier}', email: email_html, email_title: "#{PLATFORM}: 你已加入 {repository} 项目")
|
||||||
email_html = File.read("#{email_template_html_dir}/project_left.html")
|
email_html = File.read("#{email_template_html_dir}/project_left.html")
|
||||||
self.create(type: 'MessageTemplate::ProjectLeft', sys_notice: '你已被移出 <b>{repository}</b> 项目', notification_url: '', email: email_html, email_title: 'GitLink: 你已被移出 {repository} 项目')
|
self.create(type: 'MessageTemplate::ProjectLeft', sys_notice: '你已被移出 <b>{repository}</b> 项目', notification_url: '', email: email_html, email_title: "#{PLATFORM}: 你已被移出 {repository} 项目")
|
||||||
email_html = File.read("#{email_template_html_dir}/project_member_joined.html")
|
email_html = File.read("#{email_template_html_dir}/project_member_joined.html")
|
||||||
self.create(type: 'MessageTemplate::ProjectMemberJoined', sys_notice: '<b>{nickname1}</b> 已加入项目 <b>{nickname2}/{repository}</b>', notification_url: '{baseurl}/{owner}/{identifier}', email: email_html, email_title: 'GitLink: {nickname1} 已加入项目 {nickname2}/{repository}')
|
self.create(type: 'MessageTemplate::ProjectMemberJoined', sys_notice: '<b>{nickname1}</b> 已加入项目 <b>{nickname2}/{repository}</b>', notification_url: '{baseurl}/{owner}/{identifier}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 已加入项目 {nickname2}/{repository}")
|
||||||
email_html = File.read("#{email_template_html_dir}/project_member_left.html")
|
email_html = File.read("#{email_template_html_dir}/project_member_left.html")
|
||||||
self.create(type: 'MessageTemplate::ProjectMemberLeft', sys_notice: '<b>{nickname1}</b> 已被移出项目 <b>{nickname2}/{repository}</b>', notification_url: '{baseurl}/{owner}/{identifier}', email: email_html, email_title: 'GitLink: {nickname1} 已被移出项目 {nickname2}/{repository}')
|
self.create(type: 'MessageTemplate::ProjectMemberLeft', sys_notice: '<b>{nickname1}</b> 已被移出项目 <b>{nickname2}/{repository}</b>', notification_url: '{baseurl}/{owner}/{identifier}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 已被移出项目 {nickname2}/{repository}")
|
||||||
self.create(type: 'MessageTemplate::ProjectMilestone', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 创建了一个里程碑:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/milestones/{id}')
|
email_html = File.read("#{email_template_html_dir}/project_milestone.html")
|
||||||
self.create(type: 'MessageTemplate::ProjectPraised', sys_notice: '<b>{nickname}</b> 点赞了你管理的仓库', notification_url: '{baseurl}/{login}')
|
self.create(type: 'MessageTemplate::ProjectMilestone', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 创建了一个里程碑:<b>{name}</b>', notification_url: '{baseurl}/{owner}/{identifier}/milestones/{id}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 在 {nickname2}/{repository} 新建了一个里程碑")
|
||||||
|
email_html = File.read("#{email_template_html_dir}/project_milestone_completed.html")
|
||||||
|
self.create(type: 'MessageTemplate::ProjectMilestoneCompleted', sys_notice: '在 <b>{nickname}/{repository}</b> 仓库,里程碑 <b>{name}</b> 的完成度已达到100%', notification_url: '{baseurl}/{owner}/{identifier}/milestones/{id}', email: email_html, email_title: "#{PLATFORM}: 仓库 {nickname}/{repository} 有里程碑已完成")
|
||||||
|
self.create(type: 'MessageTemplate::ProjectPraised', sys_notice: '<b>{nickname1}</b> 点赞了你管理的仓库 <b>{nickname2}/{repository}</b>', notification_url: '{baseurl}/{login}')
|
||||||
email_html = File.read("#{email_template_html_dir}/project_pull_request.html")
|
email_html = File.read("#{email_template_html_dir}/project_pull_request.html")
|
||||||
self.create(type: 'MessageTemplate::ProjectPullRequest', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 提交了一个合并请求:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}', email: email_html, email_title: 'GitLink: {nickname1} 在 {nickname2}/{repository} 提交了一个合并请求')
|
self.create(type: 'MessageTemplate::ProjectPullRequest', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 提交了一个合并请求:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 在 {nickname2}/{repository} 提交了一个合并请求")
|
||||||
email_html = File.read("#{email_template_html_dir}/project_role.html")
|
email_html = File.read("#{email_template_html_dir}/project_role.html")
|
||||||
self.create(type: 'MessageTemplate::ProjectRole', sys_notice: '仓库 <b>{nickname}/{repository}</b> 已把你的角色改为 <b>{role}</b>', email: email_html, email_title: 'GitLink: 在 {nickname}/{repository} 项目你的账号有权限变更', notification_url: '{baseurl}/{owner}/{identifier}')
|
self.create(type: 'MessageTemplate::ProjectRole', sys_notice: '仓库 <b>{nickname}/{repository}</b> 已把你的角色改为 <b>{role}</b>', email: email_html, email_title: '#{PLATFORM}: 在 {nickname}/{repository} 项目你的账号有权限变更', notification_url: '{baseurl}/{owner}/{identifier}')
|
||||||
email_html = File.read("#{email_template_html_dir}/project_setting_changed.html")
|
email_html = File.read("#{email_template_html_dir}/project_setting_changed.html")
|
||||||
self.create(type: 'MessageTemplate::ProjectSettingChanged', sys_notice: '{nickname1}更改了 <b>{nickname2}/{repository}</b> 仓库设置:{ifname}更改项目名称为"<b>{name}</b>"{endname}{ifidentifier}更改项目标识为"<b>{identifier}</b>"{endidentifier}{ifdescription}更改项目简介为"<b>{description}</b>"{enddescription}{ifcategory}更改项目类别为"<b>{category}</b>"{endcategory}{iflanguage}更改项目语言为"<b>{language}</b>"{endlanguage}{ifpermission}将仓库设为"<b>{permission}</b>"{endpermission}{ifnavbar}将项目导航更改为"<b>{navbar}</b>"{endnavbar}', notification_url: '{baseurl}/{owner}/{identifier}/settings', email: email_html, email_title: 'GitLink: 您管理的仓库 {nickname2}/{repository} 仓库设置已被更改')
|
self.create(type: 'MessageTemplate::ProjectSettingChanged', sys_notice: '{nickname1}更改了 <b>{nickname2}/{repository}</b> 仓库设置:{ifname}更改项目名称为"<b>{name}</b>"{endname}{ifidentifier}更改项目标识为"<b>{identifier}</b>"{endidentifier}{ifdescription}更改项目简介为"<b>{description}</b>"{enddescription}{ifcategory}更改项目类别为"<b>{category}</b>"{endcategory}{iflanguage}更改项目语言为"<b>{language}</b>"{endlanguage}{ifpermission}将仓库设为"<b>{permission}</b>"{endpermission}{ifnavbar}将项目导航更改为"<b>{navbar}</b>"{endnavbar}', notification_url: '{baseurl}/{owner}/{identifier}/settings', email: email_html, email_title: "#{PLATFORM}: 您管理的仓库 {nickname2}/{repository} 仓库设置已被更改")
|
||||||
self.create(type: 'MessageTemplate::ProjectTransfer', sys_notice: '你关注的仓库{nickname1}/{repository1}已被转移至{nickname2}/{repository2}', notification_url: '{baseurl}/{owner}/{identifier}')
|
self.create(type: 'MessageTemplate::ProjectTransfer', sys_notice: '你关注的仓库{nickname1}/{repository1}已被转移至{nickname2}/{repository2}', notification_url: '{baseurl}/{owner}/{identifier}')
|
||||||
self.create(type: 'MessageTemplate::ProjectVersion', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 创建了发行版:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/releases')
|
self.create(type: 'MessageTemplate::ProjectVersion', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 创建了发行版:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/releases')
|
||||||
email_html = File.read("#{email_template_html_dir}/pull_request_assigned.html")
|
email_html = File.read("#{email_template_html_dir}/pull_request_assigned.html")
|
||||||
self.create(type: 'MessageTemplate::PullRequestAssigned', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 指派给你一个合并请求:<b>{title}<b>', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}', email: email_html, email_title: 'GitLink: {nickname1} 在 {nickname2}/{repository} 指派给你一个合并请求')
|
self.create(type: 'MessageTemplate::PullRequestAssigned', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 指派给你一个合并请求:<b>{title}<b>', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 在 {nickname2}/{repository} 指派给你一个合并请求")
|
||||||
self.create(type: 'MessageTemplate::PullRequestAtme', sys_notice: '<b>{nickname}</b> 在合并请求 <b>{title}</b> 中@我', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}')
|
self.create(type: 'MessageTemplate::PullRequestAtme', sys_notice: '<b>{nickname}</b> 在合并请求 <b>{title}</b> 中@我', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}')
|
||||||
email_html = File.read("#{email_template_html_dir}/pull_request_changed.html")
|
email_html = File.read("#{email_template_html_dir}/pull_request_changed.html")
|
||||||
self.create(type: 'MessageTemplate::PullRequestChanged', sys_notice: '在项目{nickname2}/{repository}的合并请求 <b>{title}</b> 中:{ifassigner}{nickname1}将审查成员从 <b>{assigner1}</b> 修改为 <b>{assigner2}</b> {endassigner}{ifmilestone}{nickname1}将里程碑从 <b>{milestone1}</b> 修改为 <b>{milestone2}</b> {endmilestone}{iftag}{nickname1}将标记从 <b>{tag1}</b> 修改为 <b>{tag2}</b> {endtag}{ifpriority}{nickname1}将优先级从 <b>{priority1}</b> 修改为 <b>{priority2}</b> {endpriority}', email: email_html, email_title: 'GitLink: 合并请求 {title} 有状态变更', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}')
|
self.create(type: 'MessageTemplate::PullRequestChanged', sys_notice: '在项目{nickname2}/{repository}的合并请求 <b>{title}</b> 中:{ifassigner}{nickname1}将审查成员从 <b>{assigner1}</b> 修改为 <b>{assigner2}</b> {endassigner}{ifmilestone}{nickname1}将里程碑从 <b>{milestone1}</b> 修改为 <b>{milestone2}</b> {endmilestone}{iftag}{nickname1}将标记从 <b>{tag1}</b> 修改为 <b>{tag2}</b> {endtag}{ifpriority}{nickname1}将优先级从 <b>{priority1}</b> 修改为 <b>{priority2}</b> {endpriority}', email: email_html, email_title: "#{PLATFORM}: 合并请求 {title} 有状态变更", notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}')
|
||||||
email_html = File.read("#{email_template_html_dir}/pull_request_closed.html")
|
email_html = File.read("#{email_template_html_dir}/pull_request_closed.html")
|
||||||
self.create(type: 'MessageTemplate::PullRequestClosed', sys_notice: '你提交的合并请求:{title} <b>被拒绝</b>', email: email_html, email_title: 'GitLink: 合并请求 {title} 有状态变更', notification_url: '')
|
self.create(type: 'MessageTemplate::PullRequestClosed', sys_notice: '你提交的合并请求:{title} <b>被拒绝</b>', email: email_html, email_title: "#{PLATFORM}: 合并请求 {title} 有状态变更", notification_url: '')
|
||||||
self.create(type: 'MessageTemplate::PullRequestJournal', sys_notice: '{nickname}评论合并请求{title}:<b>{notes}</b>', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}')
|
self.create(type: 'MessageTemplate::PullRequestJournal', sys_notice: '{nickname}评论合并请求{title}:<b>{notes}</b>', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}')
|
||||||
email_html = File.read("#{email_template_html_dir}/pull_request_merged.html")
|
email_html = File.read("#{email_template_html_dir}/pull_request_merged.html")
|
||||||
self.create(type: 'MessageTemplate::PullRequestMerged', sys_notice: '你提交的合并请求:{title} <b>已通过</b>', email: email_html, email_title: 'GitLink: 合并请求 {title} 有状态变更', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}')
|
self.create(type: 'MessageTemplate::PullRequestMerged', sys_notice: '你提交的合并请求:{title} <b>已通过</b>', email: email_html, email_title: "#{PLATFORM}: 合并请求 {title} 有状态变更", notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}')
|
||||||
|
email_html = File.read("#{email_template_html_dir}/team_joined.html")
|
||||||
|
self.create(type: 'MessageTemplate::TeamJoined', sys_notice: '你已被拉入组织 <b>{organization}</b> 的 <b>{team}</b> 团队,拥有<b>{role}</b>权限', email: email_html, email_title: "#{PLATFORM}: 在 {organization} 组织你的账号有权限变更", notification_url: '{baseurl}/{login}')
|
||||||
|
email_html = File.read("#{email_template_html_dir}/team_left.html")
|
||||||
|
self.create(type: 'MessageTemplate::TeamLeft', sys_notice: '你已被移出组织 <b>{organization}</b> 的 <b>{team}</b> 团队', email: email_html, email_title: "#{PLATFORM}: 在 {organization} 组织你的账号有权限变更", notification_url: '{baseurl}/{login}')
|
||||||
|
|
||||||
|
# 竞赛通知
|
||||||
|
self.create(type: 'MessageTemplate::CompetitionBegin', sys_notice: '你报名的竞赛 <b>{competition_name}</b> 已进入比赛进行阶段,可在此期间提交作品', notification_url: '{to_url}')
|
||||||
|
self.create(type: 'MessageTemplate::CompetitionResult', sys_notice: '你报名的竞赛 <b>{competition_name}</b> 已进入成绩公示阶段,可查看排行榜信息', notification_url: '{to_url}')
|
||||||
|
self.create(type: 'MessageTemplate::CompetitionReview', sys_notice: '你报名的竞赛 <b>{competition_name}</b> 距作品提交结束日期仅剩3天,若尚未提交参赛作品,请尽快提交', notification_url: '{to_url}')
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.sys_notice
|
def self.sys_notice
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: message_templates
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# type :string(255)
|
||||||
|
# sys_notice :text(65535)
|
||||||
|
# email :text(65535)
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
# notification_url :string(255)
|
||||||
|
# email_title :string(255)
|
||||||
|
#
|
||||||
|
|
||||||
|
# 报名的竞赛进入比赛进行阶段
|
||||||
|
# 触发场景
|
||||||
|
# 赛队成员报名的竞赛已进入比赛进行阶段
|
||||||
|
# 通知文案格式
|
||||||
|
# 你报名的竞赛 xxx 已进入比赛进行阶段,可在此阶段提交作品
|
||||||
|
# 时间:x分钟/小时/天/月前
|
||||||
|
# 通知文案示例
|
||||||
|
# 你报名的竞赛 代码审查大赛 已进入比赛进行阶段,可在此期间提交作品
|
||||||
|
# 时间:3小时前
|
||||||
|
# 点击通知跳转页面
|
||||||
|
# 点击此通知将跳转到代码审查大赛详情页:
|
||||||
|
# http://117.50.100.12:8080/competitions/lgw7st/home
|
||||||
|
class MessageTemplate::CompetitionBegin < MessageTemplate
|
||||||
|
|
||||||
|
# MessageTemplate::FollowedTip.get_message_content(User.where(login: 'yystopf'), User.last)
|
||||||
|
def self.get_message_content(receivers, competition)
|
||||||
|
return receivers_string(receivers), sys_notice.to_s.gsub('{competition_name}', competition&.name), notification_url.to_s.gsub('{to_url}', "/competitions/#{competition.identifier}/home")
|
||||||
|
# rescue
|
||||||
|
# return '', '', ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: message_templates
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# type :string(255)
|
||||||
|
# sys_notice :text(65535)
|
||||||
|
# email :text(65535)
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
# notification_url :string(255)
|
||||||
|
# email_title :string(255)
|
||||||
|
#
|
||||||
|
|
||||||
|
# 报名的竞赛进入成绩公示阶段
|
||||||
|
# 触发场景
|
||||||
|
# 赛队成员报名的竞赛已进入成绩公示阶段
|
||||||
|
# 通知文案格式
|
||||||
|
# 你报名的竞赛 xxx 已进入成绩公示阶段,可查看排行榜信息
|
||||||
|
# 时间:x分钟/小时/天/月前
|
||||||
|
# 通知文案示例
|
||||||
|
# 你报名的竞赛 代码审查大赛 已进入成绩公示阶段,可查看排行榜信息
|
||||||
|
# 时间:3小时前
|
||||||
|
# 点击通知跳转页面
|
||||||
|
# 点击此通知将跳转到代码审查大赛详情页:
|
||||||
|
# http://117.50.100.12:8080/competitions/lgw7st/home
|
||||||
|
class MessageTemplate::CompetitionResult < MessageTemplate
|
||||||
|
|
||||||
|
# MessageTemplate::FollowedTip.get_message_content(User.where(login: 'yystopf'), User.last)
|
||||||
|
def self.get_message_content(receivers, competition)
|
||||||
|
return receivers_string(receivers), sys_notice.gsub('{competition_name}', competition&.title), notification_url.gsub('{to_url}', "/competitions/#{competition.identifier}/home")
|
||||||
|
rescue
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: message_templates
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# type :string(255)
|
||||||
|
# sys_notice :text(65535)
|
||||||
|
# email :text(65535)
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
# notification_url :string(255)
|
||||||
|
# email_title :string(255)
|
||||||
|
#
|
||||||
|
|
||||||
|
# 报名的竞赛比赛结束时间临近
|
||||||
|
# 触发场景
|
||||||
|
# 赛队成员报名的竞赛阶段处于比赛进行中,且距比赛结束日期仅剩3天
|
||||||
|
# 通知文案格式
|
||||||
|
# 你报名的竞赛 xxx 距作品提交结束日期仅剩3天,若尚未提交参赛作品,请尽快提交
|
||||||
|
# 时间:x分钟/小时/天/月前
|
||||||
|
# 通知文案示例
|
||||||
|
# 你报名的竞赛 代码审查大赛 距作品提交结束日期仅剩3天,若尚未提交参赛作品,请尽快提交
|
||||||
|
# 时间:3小时前
|
||||||
|
# 点击通知跳转页面
|
||||||
|
# 点击此通知将跳转到代码审查大赛详情页:
|
||||||
|
# http://117.50.100.12:8080/competitions/lgw7st/home
|
||||||
|
class MessageTemplate::CompetitionReview < MessageTemplate
|
||||||
|
|
||||||
|
# MessageTemplate::FollowedTip.get_message_content(User.where(login: 'yystopf'), User.last)
|
||||||
|
def self.get_message_content(receivers, competition)
|
||||||
|
return receivers_string(receivers), sys_notice.gsub('{competition_name}', competition&.title), notification_url.gsub('{to_url}', "/competitions/#{competition.identifier}/home")
|
||||||
|
rescue
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
# email_title :string(255)
|
# email_title :string(255)
|
||||||
#
|
#
|
||||||
|
|
||||||
# 有新指派给我的易修
|
# 有新指派给我的疑修
|
||||||
class MessageTemplate::IssueAssigned < MessageTemplate
|
class MessageTemplate::IssueAssigned < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::IssueAssigned.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last)
|
# MessageTemplate::IssueAssigned.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last)
|
||||||
|
|
@ -36,26 +36,29 @@ class MessageTemplate::IssueAssigned < MessageTemplate
|
||||||
def self.get_email_message_content(receiver, operator, issue)
|
def self.get_email_message_content(receiver, operator, issue)
|
||||||
if receiver.user_template_message_setting.present?
|
if receiver.user_template_message_setting.present?
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::IssueAssigned"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::IssueAssigned"]
|
||||||
|
project = issue&.project
|
||||||
|
owner = project&.owner
|
||||||
|
title = email_title
|
||||||
|
title.gsub!('{nickname1}', operator&.real_name)
|
||||||
|
title.gsub!('{nickname2}', owner&.real_name)
|
||||||
|
title.gsub!('{repository}', project&.name)
|
||||||
|
content = email
|
||||||
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
|
content.gsub!('{nickname1}', operator&.real_name)
|
||||||
|
content.gsub!('{login1}', operator&.login)
|
||||||
|
content.gsub!('{nickname2}', owner&.real_name)
|
||||||
|
content.gsub!('{login2}', owner&.login)
|
||||||
|
content.gsub!('{identifier}', project&.identifier)
|
||||||
|
content.gsub!('{repository}', project&.name)
|
||||||
|
content.gsub!('{baseurl}', base_url)
|
||||||
|
content.gsub!('{title}', issue&.subject)
|
||||||
|
content.gsub!('{id}', issue&.id.to_s)
|
||||||
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
end
|
end
|
||||||
project = issue&.project
|
|
||||||
owner = project&.owner
|
|
||||||
title = email_title
|
|
||||||
title.gsub!('{nickname1}', operator&.real_name)
|
|
||||||
title.gsub!('{nickname2}', owner&.real_name)
|
|
||||||
title.gsub!('{repository}', project&.name)
|
|
||||||
content = email
|
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
|
||||||
content.gsub!('{nickname1}', operator&.real_name)
|
|
||||||
content.gsub!('{login1}', operator&.login)
|
|
||||||
content.gsub!('{nickname2}', owner&.real_name)
|
|
||||||
content.gsub!('{login2}', owner&.login)
|
|
||||||
content.gsub!('{identifier}', project&.identifier)
|
|
||||||
content.gsub!('{repository}', project&.name)
|
|
||||||
content.gsub!('{baseurl}', base_url)
|
|
||||||
content.gsub!('{title}', issue&.subject)
|
|
||||||
content.gsub!('{id}', issue&.id.to_s)
|
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::IssueAssigned.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::IssueAssigned.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
# email_title :string(255)
|
# email_title :string(255)
|
||||||
#
|
#
|
||||||
|
|
||||||
# 我负责的易修截止日期到达最后一天
|
# 我负责的疑修截止日期到达最后一天
|
||||||
class MessageTemplate::IssueAssignerExpire < MessageTemplate
|
class MessageTemplate::IssueAssignerExpire < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::IssueAssignerExpire.get_message_content(User.where(login: 'yystopf'), Issue.last)
|
# MessageTemplate::IssueAssignerExpire.get_message_content(User.where(login: 'yystopf'), Issue.last)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
# email_title :string(255)
|
# email_title :string(255)
|
||||||
#
|
#
|
||||||
|
|
||||||
# 在易修中@我
|
# 在疑修中@我
|
||||||
class MessageTemplate::IssueAtme < MessageTemplate
|
class MessageTemplate::IssueAtme < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::IssueAtme.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last)
|
# MessageTemplate::IssueAtme.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last)
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
# email_title :string(255)
|
# email_title :string(255)
|
||||||
#
|
#
|
||||||
|
|
||||||
# 我创建或负责的易修状态变更
|
# 我创建或负责的疑修状态变更
|
||||||
class MessageTemplate::IssueChanged < MessageTemplate
|
class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::IssueChanged.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last, {status_id: [1, 2], assigned_to_id: [nil, 203], tracker_id: [4, 3], priority_id: [2, 4], fixed_version_id: [nil, 5], due_date: ['', '2021-09-11'], done_ratio: [0, 40], issue_tags_value: ["", "7"], branch_name: ["", "master"]})
|
# MessageTemplate::IssueChanged.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last, {status_id: [1, 2], assigned_to_id: [nil, 203], tracker_id: [4, 3], priority_id: [2, 4], fixed_version_id: [nil, 5], due_date: ['', '2021-09-11'], done_ratio: [0, 40], issue_tags_value: ["", "7"], branch_name: ["", "master"]})
|
||||||
|
|
@ -29,7 +29,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
content = MessageTemplate::IssueChanged.sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject)
|
content = MessageTemplate::IssueChanged.sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject)
|
||||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
||||||
change_count = change_params.keys.size
|
change_count = change_params.keys.size
|
||||||
# 易修负责人修改
|
# 疑修负责人修改
|
||||||
if change_params[:assigned_to_id].present?
|
if change_params[:assigned_to_id].present?
|
||||||
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
|
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
|
||||||
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
|
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
|
||||||
|
|
@ -44,7 +44,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
|
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
|
||||||
end
|
end
|
||||||
# 易修状态修改
|
# 疑修状态修改
|
||||||
if change_params[:status_id].present?
|
if change_params[:status_id].present?
|
||||||
status1 = IssueStatus.find_by_id(change_params[:status_id][0])
|
status1 = IssueStatus.find_by_id(change_params[:status_id][0])
|
||||||
status2 = IssueStatus.find_by_id(change_params[:status_id][1])
|
status2 = IssueStatus.find_by_id(change_params[:status_id][1])
|
||||||
|
|
@ -59,7 +59,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifstatus})(.*)({endstatus})/, '')
|
content.gsub!(/({ifstatus})(.*)({endstatus})/, '')
|
||||||
end
|
end
|
||||||
# 易修类型修改
|
# 疑修类型修改
|
||||||
if change_params[:tracker_id].present?
|
if change_params[:tracker_id].present?
|
||||||
tracker1 = Tracker.find_by_id(change_params[:tracker_id][0])
|
tracker1 = Tracker.find_by_id(change_params[:tracker_id][0])
|
||||||
tracker2 = Tracker.find_by_id(change_params[:tracker_id][1])
|
tracker2 = Tracker.find_by_id(change_params[:tracker_id][1])
|
||||||
|
|
@ -74,7 +74,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
else
|
else
|
||||||
content.gsub!(/({iftracker})(.*)({endtracker})/, '')
|
content.gsub!(/({iftracker})(.*)({endtracker})/, '')
|
||||||
end
|
end
|
||||||
# 易修里程碑修改
|
# 疑修里程碑修改
|
||||||
if change_params[:fixed_version_id].present?
|
if change_params[:fixed_version_id].present?
|
||||||
fix_version1 = Version.find_by_id(change_params[:fixed_version_id][0])
|
fix_version1 = Version.find_by_id(change_params[:fixed_version_id][0])
|
||||||
fix_version2 = Version.find_by_id(change_params[:fixed_version_id][1])
|
fix_version2 = Version.find_by_id(change_params[:fixed_version_id][1])
|
||||||
|
|
@ -89,7 +89,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
|
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
|
||||||
end
|
end
|
||||||
# 易修标记修改
|
# 疑修标记修改
|
||||||
if change_params[:issue_tags_value].present?
|
if change_params[:issue_tags_value].present?
|
||||||
issue_tags1 = IssueTag.where(id: change_params[:issue_tags_value][0]).distinct
|
issue_tags1 = IssueTag.where(id: change_params[:issue_tags_value][0]).distinct
|
||||||
issue_tags2 = IssueTag.where(id: change_params[:issue_tags_value][1]).distinct
|
issue_tags2 = IssueTag.where(id: change_params[:issue_tags_value][1]).distinct
|
||||||
|
|
@ -106,7 +106,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
else
|
else
|
||||||
content.gsub!(/({iftag})(.*)({endtag})()/, '')
|
content.gsub!(/({iftag})(.*)({endtag})()/, '')
|
||||||
end
|
end
|
||||||
# 易修优先级修改
|
# 疑修优先级修改
|
||||||
if change_params[:priority_id].present?
|
if change_params[:priority_id].present?
|
||||||
priority1 = IssuePriority.find_by_id(change_params[:priority_id][0])
|
priority1 = IssuePriority.find_by_id(change_params[:priority_id][0])
|
||||||
priority2 = IssuePriority.find_by_id(change_params[:priority_id][1])
|
priority2 = IssuePriority.find_by_id(change_params[:priority_id][1])
|
||||||
|
|
@ -121,7 +121,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
|
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
|
||||||
end
|
end
|
||||||
# 易修完成度修改
|
# 疑修完成度修改
|
||||||
if change_params[:done_ratio].present?
|
if change_params[:done_ratio].present?
|
||||||
doneratio1 = change_params[:done_ratio][0]
|
doneratio1 = change_params[:done_ratio][0]
|
||||||
doneratio2 = change_params[:done_ratio][1]
|
doneratio2 = change_params[:done_ratio][1]
|
||||||
|
|
@ -136,7 +136,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifdoneratio})(.*)({enddoneratio})/, '')
|
content.gsub!(/({ifdoneratio})(.*)({enddoneratio})/, '')
|
||||||
end
|
end
|
||||||
# 易修指定分支修改
|
# 疑修指定分支修改
|
||||||
if change_params[:branch_name].present?
|
if change_params[:branch_name].present?
|
||||||
branch1 = change_params[:branch_name][0].blank? ? '分支未指定' : change_params[:branch_name][0]
|
branch1 = change_params[:branch_name][0].blank? ? '分支未指定' : change_params[:branch_name][0]
|
||||||
branch2 = change_params[:branch_name][1].blank? ? '分支未指定' : change_params[:branch_name][1]
|
branch2 = change_params[:branch_name][1].blank? ? '分支未指定' : change_params[:branch_name][1]
|
||||||
|
|
@ -151,7 +151,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifbranch})(.*)({endbranch})/, '')
|
content.gsub!(/({ifbranch})(.*)({endbranch})/, '')
|
||||||
end
|
end
|
||||||
# 易修开始日期修改
|
# 疑修开始日期修改
|
||||||
if change_params[:start_date].present?
|
if change_params[:start_date].present?
|
||||||
startdate1 = change_params[:start_date][0].blank? ? "未选择开始日期" : change_params[:start_date][0]
|
startdate1 = change_params[:start_date][0].blank? ? "未选择开始日期" : change_params[:start_date][0]
|
||||||
startdate2 = change_params[:start_date][1].blank? ? "未选择开始日期" : change_params[:start_date][1]
|
startdate2 = change_params[:start_date][1].blank? ? "未选择开始日期" : change_params[:start_date][1]
|
||||||
|
|
@ -166,7 +166,7 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifstartdate})(.*)({endstartdate})/, '')
|
content.gsub!(/({ifstartdate})(.*)({endstartdate})/, '')
|
||||||
end
|
end
|
||||||
# 易修结束日期修改
|
# 疑修结束日期修改
|
||||||
if change_params[:due_date].present?
|
if change_params[:due_date].present?
|
||||||
duedate1 = change_params[:due_date][0].blank? ? '未选择结束日期' : change_params[:due_date][0]
|
duedate1 = change_params[:due_date][0].blank? ? '未选择结束日期' : change_params[:due_date][0]
|
||||||
duedate2 = change_params[:due_date][1].blank? ? '未选择结束日期' : change_params[:due_date][1]
|
duedate2 = change_params[:due_date][1].blank? ? '未选择结束日期' : change_params[:due_date][1]
|
||||||
|
|
@ -191,177 +191,181 @@ class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
return '', '', '' if change_params.blank?
|
return '', '', '' if change_params.blank?
|
||||||
if receiver.user_template_message_setting.present?
|
if receiver.user_template_message_setting.present?
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::IssueChanged"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::IssueChanged"]
|
||||||
end
|
project = issue&.project
|
||||||
project = issue&.project
|
owner = project&.owner
|
||||||
owner = project&.owner
|
title = email_title
|
||||||
title = email_title
|
title.gsub!('{title}', issue&.subject)
|
||||||
title.gsub!('{title}', issue&.subject)
|
content = email
|
||||||
content = email
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
content.gsub!('{baseurl}', base_url)
|
||||||
content.gsub!('{baseurl}', base_url)
|
content.gsub!('{login1}', operator&.login)
|
||||||
content.gsub!('{login1}', operator&.login)
|
content.gsub!('{nickname1}', operator&.real_name)
|
||||||
content.gsub!('{nickname1}', operator&.real_name)
|
content.gsub!('{login2}', owner&.login)
|
||||||
content.gsub!('{login2}', owner&.login)
|
content.gsub!('{nickname2}', owner&.real_name)
|
||||||
content.gsub!('{nickname2}', owner&.real_name)
|
content.gsub!('{identifier}', project&.identifier)
|
||||||
content.gsub!('{identifier}', project&.identifier)
|
content.gsub!('{repository}', project&.name)
|
||||||
content.gsub!('{repository}', project&.name)
|
content.gsub!('{title}', issue&.subject)
|
||||||
content.gsub!('{title}', issue&.subject)
|
content.gsub!('{id}', issue&.id.to_s)
|
||||||
content.gsub!('{id}', issue&.id.to_s)
|
change_count = change_params.keys.size
|
||||||
change_count = change_params.keys.size
|
# 疑修负责人修改
|
||||||
# 易修负责人修改
|
if change_params[:assigned_to_id].present?
|
||||||
if change_params[:assigned_to_id].present?
|
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
|
||||||
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
|
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
|
||||||
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
|
if change_count > 1
|
||||||
if change_count > 1
|
content.sub!('{ifassigner}', '<br/>')
|
||||||
content.sub!('{ifassigner}', '<br/>')
|
else
|
||||||
|
content.sub!('{ifassigner}', '')
|
||||||
|
end
|
||||||
|
content.sub!('{endassigner}', '')
|
||||||
|
content.gsub!('{assigner1}', assigner1.present? ? assigner1&.real_name : '未指派成员')
|
||||||
|
content.gsub!('{assigner2}', assigner2.present? ? assigner2&.real_name : '未指派成员')
|
||||||
else
|
else
|
||||||
content.sub!('{ifassigner}', '')
|
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
|
||||||
end
|
end
|
||||||
content.sub!('{endassigner}', '')
|
# 疑修状态修改
|
||||||
content.gsub!('{assigner1}', assigner1.present? ? assigner1&.real_name : '未指派成员')
|
if change_params[:status_id].present?
|
||||||
content.gsub!('{assigner2}', assigner2.present? ? assigner2&.real_name : '未指派成员')
|
status1 = IssueStatus.find_by_id(change_params[:status_id][0])
|
||||||
else
|
status2 = IssueStatus.find_by_id(change_params[:status_id][1])
|
||||||
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
|
if change_count > 1
|
||||||
end
|
content.sub!('{ifstatus}', '<br/>')
|
||||||
# 易修状态修改
|
else
|
||||||
if change_params[:status_id].present?
|
content.sub!('{ifstatus}', '')
|
||||||
status1 = IssueStatus.find_by_id(change_params[:status_id][0])
|
end
|
||||||
status2 = IssueStatus.find_by_id(change_params[:status_id][1])
|
content.sub!('{endstatus}', '')
|
||||||
if change_count > 1
|
content.gsub!('{status1}', status1&.name)
|
||||||
content.sub!('{ifstatus}', '<br/>')
|
content.gsub!('{status2}', status2&.name)
|
||||||
else
|
else
|
||||||
content.sub!('{ifstatus}', '')
|
content.gsub!(/({ifstatus})(.*)({endstatus})/, '')
|
||||||
end
|
end
|
||||||
content.sub!('{endstatus}', '')
|
# 疑修类型修改
|
||||||
content.gsub!('{status1}', status1&.name)
|
if change_params[:tracker_id].present?
|
||||||
content.gsub!('{status2}', status2&.name)
|
tracker1 = Tracker.find_by_id(change_params[:tracker_id][0])
|
||||||
else
|
tracker2 = Tracker.find_by_id(change_params[:tracker_id][1])
|
||||||
content.gsub!(/({ifstatus})(.*)({endstatus})/, '')
|
if change_count > 1
|
||||||
end
|
content.sub!('{iftracker}', '<br/>')
|
||||||
# 易修类型修改
|
else
|
||||||
if change_params[:tracker_id].present?
|
content.sub!('{iftracker}', '')
|
||||||
tracker1 = Tracker.find_by_id(change_params[:tracker_id][0])
|
end
|
||||||
tracker2 = Tracker.find_by_id(change_params[:tracker_id][1])
|
content.sub!('{endtracker}', '')
|
||||||
if change_count > 1
|
content.gsub!('{tracker1}', tracker1&.name)
|
||||||
content.sub!('{iftracker}', '<br/>')
|
content.gsub!('{tracker2}', tracker2&.name)
|
||||||
else
|
else
|
||||||
content.sub!('{iftracker}', '')
|
content.gsub!(/({iftracker})(.*)({endtracker})/, '')
|
||||||
end
|
end
|
||||||
content.sub!('{endtracker}', '')
|
# 疑修里程碑修改
|
||||||
content.gsub!('{tracker1}', tracker1&.name)
|
if change_params[:fixed_version_id].present?
|
||||||
content.gsub!('{tracker2}', tracker2&.name)
|
fix_version1 = Version.find_by_id(change_params[:fixed_version_id][0])
|
||||||
else
|
fix_version2 = Version.find_by_id(change_params[:fixed_version_id][1])
|
||||||
content.gsub!(/({iftracker})(.*)({endtracker})/, '')
|
if change_count > 1
|
||||||
end
|
content.sub!('{ifmilestone}', '<br/>')
|
||||||
# 易修里程碑修改
|
else
|
||||||
if change_params[:fixed_version_id].present?
|
content.sub!('{ifmilestone}', '')
|
||||||
fix_version1 = Version.find_by_id(change_params[:fixed_version_id][0])
|
end
|
||||||
fix_version2 = Version.find_by_id(change_params[:fixed_version_id][1])
|
content.sub!('{endmilestone}', '')
|
||||||
if change_count > 1
|
content.gsub!('{milestone1}', fix_version1.present? ? fix_version1&.name : '未选择里程碑')
|
||||||
content.sub!('{ifmilestone}', '<br/>')
|
content.gsub!('{milestone2}', fix_version2.present? ? fix_version2&.name : '未选择里程碑')
|
||||||
else
|
else
|
||||||
content.sub!('{ifmilestone}', '')
|
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
|
||||||
end
|
end
|
||||||
content.sub!('{endmilestone}', '')
|
# 疑修标记修改
|
||||||
content.gsub!('{milestone1}', fix_version1.present? ? fix_version1&.name : '未选择里程碑')
|
if change_params[:issue_tags_value].present?
|
||||||
content.gsub!('{milestone2}', fix_version2.present? ? fix_version2&.name : '未选择里程碑')
|
issue_tags1 = IssueTag.where(id: change_params[:issue_tags_value][0]).distinct
|
||||||
else
|
issue_tags2 = IssueTag.where(id: change_params[:issue_tags_value][1]).distinct
|
||||||
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
|
tag1 = issue_tags1.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags1.pluck(:name).join(",")
|
||||||
end
|
tag2 = issue_tags2.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags2.pluck(:name).join(",")
|
||||||
# 易修标记修改
|
if change_count > 1
|
||||||
if change_params[:issue_tags_value].present?
|
content.sub!('{iftag}', '<br/>')
|
||||||
issue_tags1 = IssueTag.where(id: change_params[:issue_tags_value][0]).distinct
|
else
|
||||||
issue_tags2 = IssueTag.where(id: change_params[:issue_tags_value][1]).distinct
|
content.sub!('{iftag}', '')
|
||||||
tag1 = issue_tags1.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags1.pluck(:name).join(",")
|
end
|
||||||
tag2 = issue_tags2.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags2.pluck(:name).join(",")
|
content.sub!('{endtag}', '')
|
||||||
if change_count > 1
|
content.gsub!('{tag1}', tag1)
|
||||||
content.sub!('{iftag}', '<br/>')
|
content.gsub!('{tag2}', tag2)
|
||||||
else
|
else
|
||||||
content.sub!('{iftag}', '')
|
content.gsub!(/({iftag})(.*)({endtag})()/, '')
|
||||||
end
|
end
|
||||||
content.sub!('{endtag}', '')
|
# 疑修优先级修改
|
||||||
content.gsub!('{tag1}', tag1)
|
if change_params[:priority_id].present?
|
||||||
content.gsub!('{tag2}', tag2)
|
priority1 = IssuePriority.find_by_id(change_params[:priority_id][0])
|
||||||
else
|
priority2 = IssuePriority.find_by_id(change_params[:priority_id][1])
|
||||||
content.gsub!(/({iftag})(.*)({endtag})()/, '')
|
if change_count > 1
|
||||||
end
|
content.sub!('{ifpriority}', '<br/>')
|
||||||
# 易修优先级修改
|
else
|
||||||
if change_params[:priority_id].present?
|
content.sub!('{ifpriority}', '')
|
||||||
priority1 = IssuePriority.find_by_id(change_params[:priority_id][0])
|
end
|
||||||
priority2 = IssuePriority.find_by_id(change_params[:priority_id][1])
|
content.sub!('{endpriority}', '')
|
||||||
if change_count > 1
|
content.gsub!('{priority1}', priority1&.name)
|
||||||
content.sub!('{ifpriority}', '<br/>')
|
content.gsub!('{priority2}', priority2&.name)
|
||||||
else
|
else
|
||||||
content.sub!('{ifpriority}', '')
|
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
|
||||||
end
|
end
|
||||||
content.sub!('{endpriority}', '')
|
# 疑修完成度修改
|
||||||
content.gsub!('{priority1}', priority1&.name)
|
if change_params[:done_ratio].present?
|
||||||
content.gsub!('{priority2}', priority2&.name)
|
doneratio1 = change_params[:done_ratio][0]
|
||||||
else
|
doneratio2 = change_params[:done_ratio][1]
|
||||||
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
|
if change_count > 1
|
||||||
end
|
content.sub!('{ifdoneratio}', '<br/>')
|
||||||
# 易修完成度修改
|
else
|
||||||
if change_params[:done_ratio].present?
|
content.sub!('{ifdoneratio}', '')
|
||||||
doneratio1 = change_params[:done_ratio][0]
|
end
|
||||||
doneratio2 = change_params[:done_ratio][1]
|
content.sub!('{enddoneratio}', '')
|
||||||
if change_count > 1
|
content.gsub!('{doneratio1}', "#{doneratio1}%")
|
||||||
content.sub!('{ifdoneratio}', '<br/>')
|
content.gsub!('{doneratio2}', "#{doneratio2}%")
|
||||||
else
|
else
|
||||||
content.sub!('{ifdoneratio}', '')
|
content.gsub!(/({ifdoneratio})(.*)({enddoneratio})/, '')
|
||||||
end
|
end
|
||||||
content.sub!('{enddoneratio}', '')
|
# 疑修指定分支修改
|
||||||
content.gsub!('{doneratio1}', "#{doneratio1}%")
|
if change_params[:branch_name].present?
|
||||||
content.gsub!('{doneratio2}', "#{doneratio2}%")
|
branch1 = change_params[:branch_name][0].blank? ? '分支未指定' : change_params[:branch_name][0]
|
||||||
else
|
branch2 = change_params[:branch_name][1].blank? ? '分支未指定' : change_params[:branch_name][1]
|
||||||
content.gsub!(/({ifdoneratio})(.*)({enddoneratio})/, '')
|
if change_count > 1
|
||||||
end
|
content.sub!('{ifbranch}', '<br/>')
|
||||||
# 易修指定分支修改
|
else
|
||||||
if change_params[:branch_name].present?
|
content.sub!('{ifbranch}', '')
|
||||||
branch1 = change_params[:branch_name][0].blank? ? '分支未指定' : change_params[:branch_name][0]
|
end
|
||||||
branch2 = change_params[:branch_name][1].blank? ? '分支未指定' : change_params[:branch_name][1]
|
content.sub!('{endbranch}', '')
|
||||||
if change_count > 1
|
content.gsub!('{branch1}', branch1)
|
||||||
content.sub!('{ifbranch}', '<br/>')
|
content.gsub!('{branch2}', branch2)
|
||||||
else
|
else
|
||||||
content.sub!('{ifbranch}', '')
|
content.gsub!(/({ifbranch})(.*)({endbranch})/, '')
|
||||||
end
|
end
|
||||||
content.sub!('{endbranch}', '')
|
# 疑修开始日期修改
|
||||||
content.gsub!('{branch1}', branch1)
|
if change_params[:start_date].present?
|
||||||
content.gsub!('{branch2}', branch2)
|
startdate1 = change_params[:start_date][0].blank? ? "未选择开始日期" : change_params[:start_date][0]
|
||||||
else
|
startdate2 = change_params[:start_date][1].blank? ? "未选择开始日期" : change_params[:start_date][1]
|
||||||
content.gsub!(/({ifbranch})(.*)({endbranch})/, '')
|
if change_count > 1
|
||||||
end
|
content.sub!('{ifstartdate}', '<br/>')
|
||||||
# 易修开始日期修改
|
else
|
||||||
if change_params[:start_date].present?
|
content.sub!('{ifstartdate}', '')
|
||||||
startdate1 = change_params[:start_date][0].blank? ? "未选择开始日期" : change_params[:start_date][0]
|
end
|
||||||
startdate2 = change_params[:start_date][1].blank? ? "未选择开始日期" : change_params[:start_date][1]
|
content.sub!('{endstartdate}', '')
|
||||||
if change_count > 1
|
content.gsub!('{startdate1}', startdate1 )
|
||||||
content.sub!('{ifstartdate}', '<br/>')
|
content.gsub!('{startdate2}', startdate2)
|
||||||
else
|
else
|
||||||
content.sub!('{ifstartdate}', '')
|
content.gsub!(/({ifstartdate})(.*)({endstartdate})/, '')
|
||||||
end
|
end
|
||||||
content.sub!('{endstartdate}', '')
|
# 疑修结束日期修改
|
||||||
content.gsub!('{startdate1}', startdate1 )
|
if change_params[:due_date].present?
|
||||||
content.gsub!('{startdate2}', startdate2)
|
duedate1 = change_params[:due_date][0].blank? ? '未选择结束日期' : change_params[:due_date][0]
|
||||||
else
|
duedate2 = change_params[:due_date][1].blank? ? '未选择结束日期' : change_params[:due_date][1]
|
||||||
content.gsub!(/({ifstartdate})(.*)({endstartdate})/, '')
|
if change_count > 1
|
||||||
end
|
content.sub!('{ifduedate}', '<br/>')
|
||||||
# 易修结束日期修改
|
else
|
||||||
if change_params[:due_date].present?
|
content.sub!('{ifduedate}', '')
|
||||||
duedate1 = change_params[:due_date][0].blank? ? '未选择结束日期' : change_params[:due_date][0]
|
end
|
||||||
duedate2 = change_params[:due_date][1].blank? ? '未选择结束日期' : change_params[:due_date][1]
|
content.sub!('{endduedate}', '')
|
||||||
if change_count > 1
|
content.gsub!('{duedate1}', duedate1)
|
||||||
content.sub!('{ifduedate}', '<br/>')
|
content.gsub!('{duedate2}', duedate2)
|
||||||
else
|
else
|
||||||
content.sub!('{ifduedate}', '')
|
content.gsub!(/({ifduedate})(.*)({endduedate})/, '')
|
||||||
end
|
end
|
||||||
content.sub!('{endduedate}', '')
|
content.gsub!('{platform}', PLATFORM)
|
||||||
content.gsub!('{duedate1}', duedate1)
|
|
||||||
content.gsub!('{duedate2}', duedate2)
|
|
||||||
else
|
|
||||||
content.gsub!(/({ifduedate})(.*)({endduedate})/, '')
|
|
||||||
end
|
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
|
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::IssueChanged.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::IssueChanged.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,3 @@
|
||||||
# == Schema Information
|
|
||||||
#
|
|
||||||
# Table name: message_templates
|
|
||||||
#
|
|
||||||
# id :integer not null, primary key
|
|
||||||
# type :string(255)
|
|
||||||
# sys_notice :text(65535)
|
|
||||||
# email :text(65535)
|
|
||||||
# created_at :datetime not null
|
|
||||||
# updated_at :datetime not null
|
|
||||||
# notification_url :string(255)
|
|
||||||
# email_title :string(255)
|
|
||||||
#
|
|
||||||
|
|
||||||
# 我创建的易修截止日期到达最后一天
|
|
||||||
class MessageTemplate::IssueCreatorExpire < MessageTemplate
|
class MessageTemplate::IssueCreatorExpire < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::IssueCreatorExpire.get_message_content(User.where(login: 'yystopf'), Issue.last)
|
end
|
||||||
def self.get_message_content(receivers, issue)
|
|
||||||
project = issue&.project
|
|
||||||
owner = project&.owner
|
|
||||||
content = sys_notice.gsub('{title}', issue&.subject)
|
|
||||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
|
||||||
return receivers_string(receivers), content, url
|
|
||||||
rescue => e
|
|
||||||
Rails.logger.info("MessageTemplate::IssueAssignerExpire.get_message_content [ERROR] #{e}")
|
|
||||||
return '', '', ''
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
# email_title :string(255)
|
# email_title :string(255)
|
||||||
#
|
#
|
||||||
|
|
||||||
# 我创建或负责的易修删除
|
# 我创建或负责的疑修删除
|
||||||
class MessageTemplate::IssueDeleted < MessageTemplate
|
class MessageTemplate::IssueDeleted < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::IssueDeleted.get_message_content(User.where(login: 'yystopf'), User.last, "hahah")
|
# MessageTemplate::IssueDeleted.get_message_content(User.where(login: 'yystopf'), User.last, "hahah")
|
||||||
|
|
@ -33,17 +33,20 @@ class MessageTemplate::IssueDeleted < MessageTemplate
|
||||||
def self.get_email_message_content(receiver, operator, issue_title)
|
def self.get_email_message_content(receiver, operator, issue_title)
|
||||||
if receiver.user_template_message_setting.present?
|
if receiver.user_template_message_setting.present?
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::IssueChanged"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::IssueChanged"]
|
||||||
end
|
title = email_title
|
||||||
title = email_title
|
title.gsub!('{title}', issue_title)
|
||||||
title.gsub!('{title}', issue_title)
|
content = email
|
||||||
content = email
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
content.gsub!('{nickname}', operator&.real_name)
|
||||||
content.gsub!('{nickname}', operator&.real_name)
|
content.gsub!('{login}', operator&.login)
|
||||||
content.gsub!('{login}', operator&.login)
|
content.gsub!('{baseurl}', base_url)
|
||||||
content.gsub!('{baseurl}', base_url)
|
content.gsub!('{title}', issue_title)
|
||||||
content.gsub!('{title}', issue_title)
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::IssueDeleted.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::IssueDeleted.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,67 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: message_templates
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# type :string(255)
|
||||||
|
# sys_notice :text(65535)
|
||||||
|
# email :text(65535)
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
# notification_url :string(255)
|
||||||
|
# email_title :string(255)
|
||||||
|
#
|
||||||
|
|
||||||
|
# 我创建或负责的疑修截止日期到达最后一天
|
||||||
|
class MessageTemplate::IssueExpire < MessageTemplate
|
||||||
|
|
||||||
|
# MessageTemplate::IssueCreatorExpire.get_message_content(User.where(login: 'yystopf'), Issue.last)
|
||||||
|
def self.get_message_content(receivers, issue)
|
||||||
|
receivers.each do |receiver|
|
||||||
|
if receiver.user_template_message_setting.present?
|
||||||
|
send_setting = receiver.user_template_message_setting.notification_body["CreateOrAssign::IssueExpire"]
|
||||||
|
send_setting = send_setting.nil? ? UserTemplateMessageSetting.init_notification_body["CreateOrAssign::IssueExpire"] : send_setting
|
||||||
|
receivers = receivers.where.not(id: receiver.id) unless send_setting
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return '', '', '' if receivers.blank?
|
||||||
|
project = issue&.project
|
||||||
|
owner = project&.owner
|
||||||
|
content = sys_notice.gsub('{title}', issue&.subject)
|
||||||
|
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
||||||
|
|
||||||
|
return receivers_string(receivers), content, url
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.info("MessageTemplate::IssueExpire.get_message_content [ERROR] #{e}")
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get_email_message_content(receiver, issue)
|
||||||
|
if receiver.user_template_message_setting.present?
|
||||||
|
send_setting = receiver.user_template_message_setting.email_body["CreateOrAssign::IssueExpire"]
|
||||||
|
send_setting = send_setting.nil? ? UserTemplateMessageSetting.init_email_body["CreateOrAssign::IssueExpire"] : send_setting
|
||||||
|
return '', '', '' unless send_setting
|
||||||
|
project = issue&.project
|
||||||
|
owner = project&.owner
|
||||||
|
title = email_title
|
||||||
|
|
||||||
|
content = email
|
||||||
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
|
content.gsub!('{nickname}', owner&.real_name)
|
||||||
|
content.gsub!('{login}', owner&.login)
|
||||||
|
content.gsub!('{identifier}', project&.identifier)
|
||||||
|
content.gsub!('{repository}', project&.name)
|
||||||
|
content.gsub!('{baseurl}', base_url)
|
||||||
|
content.gsub!('{title}', issue&.subject)
|
||||||
|
content.gsub!('{id}', issue&.id.to_s)
|
||||||
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.info("MessageTemplate::IssueExpire.get_email_message_content [ERROR] #{e}")
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
# email_title :string(255)
|
# email_title :string(255)
|
||||||
#
|
#
|
||||||
|
|
||||||
# TODO 我创建或负责的易修有新的评论
|
# TODO 我创建或负责的疑修有新的评论
|
||||||
class MessageTemplate::IssueJournal < MessageTemplate
|
class MessageTemplate::IssueJournal < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::IssueJournal.get_message_content(User.where(login: 'yystopf'))
|
# MessageTemplate::IssueJournal.get_message_content(User.where(login: 'yystopf'))
|
||||||
|
|
|
||||||
|
|
@ -34,16 +34,20 @@ class MessageTemplate::OrganizationJoined < MessageTemplate
|
||||||
def self.get_email_message_content(receiver, organization)
|
def self.get_email_message_content(receiver, organization)
|
||||||
if receiver.user_template_message_setting.present?
|
if receiver.user_template_message_setting.present?
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Organization"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Organization"]
|
||||||
|
title = email_title
|
||||||
|
title.gsub!('{organization}', organization&.real_name)
|
||||||
|
content = email
|
||||||
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
|
content.gsub!('{baseurl}', base_url)
|
||||||
|
content.gsub!('{login}', organization&.login)
|
||||||
|
content.gsub!('{organization}', organization&.real_name)
|
||||||
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
end
|
end
|
||||||
title = email_title
|
|
||||||
title.gsub!('{organization}', organization&.real_name)
|
|
||||||
content = email
|
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
|
||||||
content.gsub!('{baseurl}', base_url)
|
|
||||||
content.gsub!('{login}', organization&.login)
|
|
||||||
content.gsub!('{organization}', organization&.real_name)
|
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::OrganizationJoined.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::OrganizationJoined.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
|
|
@ -34,16 +34,20 @@ class MessageTemplate::OrganizationLeft < MessageTemplate
|
||||||
def self.get_email_message_content(receiver, organization)
|
def self.get_email_message_content(receiver, organization)
|
||||||
if receiver.user_template_message_setting.present?
|
if receiver.user_template_message_setting.present?
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Organization"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Organization"]
|
||||||
|
title = email_title
|
||||||
|
title.gsub!('{organization}', organization&.real_name)
|
||||||
|
content = email
|
||||||
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
|
content.gsub!('{baseurl}', base_url)
|
||||||
|
content.gsub!('{login}', organization&.login)
|
||||||
|
content.gsub!('{organization}', organization&.real_name)
|
||||||
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
end
|
end
|
||||||
title = email_title
|
|
||||||
title.gsub!('{organization}', organization&.real_name)
|
|
||||||
content = email
|
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
|
||||||
content.gsub!('{baseurl}', base_url)
|
|
||||||
content.gsub!('{login}', organization&.login)
|
|
||||||
content.gsub!('{organization}', organization&.real_name)
|
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::OrganizationLeft.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::OrganizationLeft.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
|
|
@ -34,18 +34,22 @@ class MessageTemplate::OrganizationRole < MessageTemplate
|
||||||
def self.get_email_message_content(receiver, organization, role)
|
def self.get_email_message_content(receiver, organization, role)
|
||||||
if receiver.user_template_message_setting.present?
|
if receiver.user_template_message_setting.present?
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Permission"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Permission"]
|
||||||
|
title = email_title
|
||||||
|
title.gsub!('{organization}', organization&.real_name)
|
||||||
|
title.gsub!('{role}', role)
|
||||||
|
content = email
|
||||||
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
|
content.gsub!('{baseurl}', base_url)
|
||||||
|
content.gsub!('{login}', organization&.login)
|
||||||
|
content.gsub!('{organization}', organization&.real_name)
|
||||||
|
content.gsub!('{role}', role)
|
||||||
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
end
|
end
|
||||||
title = email_title
|
|
||||||
title.gsub!('{organization}', organization&.real_name)
|
|
||||||
title.gsub!('{role}', role)
|
|
||||||
content = email
|
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
|
||||||
content.gsub!('{baseurl}', base_url)
|
|
||||||
content.gsub!('{login}', organization&.login)
|
|
||||||
content.gsub!('{organization}', organization&.real_name)
|
|
||||||
content.gsub!('{role}', role)
|
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::OrganizationRole.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::OrganizationRole.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
|
|
@ -12,11 +12,21 @@
|
||||||
# email_title :string(255)
|
# email_title :string(255)
|
||||||
#
|
#
|
||||||
|
|
||||||
# TODO 我管理的仓库被复刻
|
# 我管理的仓库被复刻
|
||||||
class MessageTemplate::ProjectForked < MessageTemplate
|
class MessageTemplate::ProjectForked < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::ProjectForked.get_message_content(User.where(login: 'yystopf'))
|
# MessageTemplate::ProjectForked.get_message_content(User.where(login: 'yystopf'))
|
||||||
def self.get_message_content(receivers)
|
def self.get_message_content(receivers, user, project)
|
||||||
|
receivers.each do |receiver|
|
||||||
|
if receiver.user_template_message_setting.present?
|
||||||
|
send_setting = receiver.user_template_message_setting.notification_body["ManageProject::Forked"]
|
||||||
|
send_setting = send_setting.nil? ? UserTemplateMessageSetting.init_notification_body["ManageProject::Forked"] : send_setting
|
||||||
|
receivers = receivers.where.not(id: receiver.id) unless send_setting
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return '', '', '' if receivers.blank?
|
||||||
|
content = sys_notice.gsub('{nickname1}', user&.real_name).gsub('{nickname2}', project&.owner&.real_name).gsub('{repository}', project&.name)
|
||||||
|
url = notification_url.gsub('{owner}', user&.login).gsub('{identifier}', project&.identifier)
|
||||||
return receivers_string(receivers), content, url
|
return receivers_string(receivers), content, url
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::ProjectForked.get_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::ProjectForked.get_message_content [ERROR] #{e}")
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
# email_title :string(255)
|
# email_title :string(255)
|
||||||
#
|
#
|
||||||
|
|
||||||
# TODO 我管理/关注的仓库有新的易修
|
# TODO 我管理/关注的仓库有新的疑修
|
||||||
class MessageTemplate::ProjectIssue < MessageTemplate
|
class MessageTemplate::ProjectIssue < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::ProjectIssue.get_message_content(User.where(login: 'yystopf'), User.where(login: 'forgetest1'), User.last, Issue.last)
|
# MessageTemplate::ProjectIssue.get_message_content(User.where(login: 'yystopf'), User.where(login: 'forgetest1'), User.last, Issue.last)
|
||||||
|
|
@ -38,27 +38,31 @@ class MessageTemplate::ProjectIssue < MessageTemplate
|
||||||
def self.get_email_message_content(receiver, is_manager, operator, issue)
|
def self.get_email_message_content(receiver, is_manager, operator, issue)
|
||||||
if receiver.user_template_message_setting.present? && is_manager
|
if receiver.user_template_message_setting.present? && is_manager
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::Issue"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::Issue"]
|
||||||
|
project = issue&.project
|
||||||
|
owner = project&.owner
|
||||||
|
title = email_title
|
||||||
|
title.gsub!('{nickname1}', operator&.real_name)
|
||||||
|
title.gsub!('{nickname2}', owner&.real_name)
|
||||||
|
title.gsub!('{repository}', project&.name)
|
||||||
|
|
||||||
|
content = email
|
||||||
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
|
content.gsub!('{baseurl}', base_url)
|
||||||
|
content.gsub!('{login1}', operator&.login)
|
||||||
|
content.gsub!('{nickname1}', operator&.real_name)
|
||||||
|
content.gsub!('{nickname2}', owner&.real_name)
|
||||||
|
content.gsub!('{repository}', project&.name)
|
||||||
|
content.gsub!('{login2}', owner&.login)
|
||||||
|
content.gsub!('{identifier}', project&.identifier)
|
||||||
|
content.gsub!('{id}', issue&.id.to_s)
|
||||||
|
content.gsub!('{title}', issue&.subject)
|
||||||
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
end
|
end
|
||||||
project = issue&.project
|
|
||||||
owner = project&.owner
|
|
||||||
title = email_title
|
|
||||||
title.gsub!('{nickname1}', operator&.real_name)
|
|
||||||
title.gsub!('{nickname2}', owner&.real_name)
|
|
||||||
title.gsub!('{repository}', project&.name)
|
|
||||||
|
|
||||||
content = email
|
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
|
||||||
content.gsub!('{baseurl}', base_url)
|
|
||||||
content.gsub!('{login1}', operator&.login)
|
|
||||||
content.gsub!('{nickname1}', operator&.real_name)
|
|
||||||
content.gsub!('{nickname2}', owner&.real_name)
|
|
||||||
content.gsub!('{repository}', project&.name)
|
|
||||||
content.gsub!('{login2}', owner&.login)
|
|
||||||
content.gsub!('{identifier}', project&.identifier)
|
|
||||||
content.gsub!('{id}', issue&.id.to_s)
|
|
||||||
content.gsub!('{title}', issue&.subject)
|
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::ProjectIssue.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::ProjectIssue.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
|
|
@ -34,19 +34,23 @@ class MessageTemplate::ProjectJoined < MessageTemplate
|
||||||
def self.get_email_message_content(receiver, project)
|
def self.get_email_message_content(receiver, project)
|
||||||
if receiver.user_template_message_setting.present?
|
if receiver.user_template_message_setting.present?
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Project"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Project"]
|
||||||
end
|
title = email_title
|
||||||
title = email_title
|
title.gsub!('{repository}', project&.name)
|
||||||
title.gsub!('{repository}', project&.name)
|
|
||||||
|
content = email
|
||||||
content = email
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
content.gsub!('{baseurl}', base_url)
|
||||||
content.gsub!('{baseurl}', base_url)
|
content.gsub!('{login}', project&.owner&.login)
|
||||||
content.gsub!('{login}', project&.owner&.login)
|
content.gsub!('{identifier}', project&.identifier)
|
||||||
content.gsub!('{identifier}', project&.identifier)
|
content.gsub!('{nickname}', project&.owner&.real_name)
|
||||||
content.gsub!('{nickname}', project&.owner&.real_name)
|
content.gsub!('{repository}', project&.name)
|
||||||
content.gsub!('{repository}', project&.name)
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
|
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::ProjectJoined.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::ProjectJoined.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
|
|
@ -33,19 +33,23 @@ class MessageTemplate::ProjectLeft < MessageTemplate
|
||||||
def self.get_email_message_content(receiver, project)
|
def self.get_email_message_content(receiver, project)
|
||||||
if receiver.user_template_message_setting.present?
|
if receiver.user_template_message_setting.present?
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Project"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Project"]
|
||||||
end
|
title = email_title
|
||||||
title = email_title
|
title.gsub!('{repository}', project&.name)
|
||||||
title.gsub!('{repository}', project&.name)
|
|
||||||
|
content = email
|
||||||
content = email
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
content.gsub!('{baseurl}', base_url)
|
||||||
content.gsub!('{baseurl}', base_url)
|
content.gsub!('{login}', project&.owner&.login)
|
||||||
content.gsub!('{login}', project&.owner&.login)
|
content.gsub!('{identifier}', project&.identifier)
|
||||||
content.gsub!('{identifier}', project&.identifier)
|
content.gsub!('{nickname}', project&.owner&.real_name)
|
||||||
content.gsub!('{nickname}', project&.owner&.real_name)
|
content.gsub!('{repository}', project&.name)
|
||||||
content.gsub!('{repository}', project&.name)
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
|
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::ProjectLeft.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::ProjectLeft.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
|
|
@ -34,23 +34,26 @@ class MessageTemplate::ProjectMemberJoined < MessageTemplate
|
||||||
def self.get_email_message_content(receiver, user, project)
|
def self.get_email_message_content(receiver, user, project)
|
||||||
if receiver.user_template_message_setting.present?
|
if receiver.user_template_message_setting.present?
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::Member"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::Member"]
|
||||||
end
|
title = email_title
|
||||||
title = email_title
|
title.gsub!('{nickname1}', user&.real_name)
|
||||||
title.gsub!('{nickname1}', user&.real_name)
|
title.gsub!('{nickname2}', project&.owner&.real_name)
|
||||||
title.gsub!('{nickname2}', project&.owner&.real_name)
|
title.gsub!('{repository}', project&.name)
|
||||||
title.gsub!('{repository}', project&.name)
|
|
||||||
|
content = email
|
||||||
content = email
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
content.gsub!('{baseurl}', base_url)
|
||||||
content.gsub!('{baseurl}', base_url)
|
content.gsub!('{login1}', user&.login)
|
||||||
content.gsub!('{login1}', user&.login)
|
content.gsub!('{login2}', project&.owner&.login)
|
||||||
content.gsub!('{login2}', project&.owner&.login)
|
content.gsub!('{identifier}', project&.identifier)
|
||||||
content.gsub!('{identifier}', project&.identifier)
|
content.gsub!('{nickname1}', user&.real_name)
|
||||||
content.gsub!('{nickname1}', user&.real_name)
|
content.gsub!('{nickname2}', project&.owner&.real_name)
|
||||||
content.gsub!('{nickname2}', project&.owner&.real_name)
|
content.gsub!('{repository}', project&.name)
|
||||||
content.gsub!('{repository}', project&.name)
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::ProjectMemberJoined.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::ProjectMemberJoined.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
|
|
@ -34,23 +34,27 @@ class MessageTemplate::ProjectMemberLeft < MessageTemplate
|
||||||
def self.get_email_message_content(receiver, user, project)
|
def self.get_email_message_content(receiver, user, project)
|
||||||
if receiver.user_template_message_setting.present?
|
if receiver.user_template_message_setting.present?
|
||||||
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::Member"]
|
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::Member"]
|
||||||
|
title = email_title
|
||||||
|
title.gsub!('{nickname1}', user&.real_name)
|
||||||
|
title.gsub!('{nickname2}', project&.owner&.real_name)
|
||||||
|
title.gsub!('{repository}', project&.name)
|
||||||
|
|
||||||
|
content = email
|
||||||
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
|
content.gsub!('{baseurl}', base_url)
|
||||||
|
content.gsub!('{login1}', user&.login)
|
||||||
|
content.gsub!('{login2}', project&.owner&.login)
|
||||||
|
content.gsub!('{identifier}', project&.identifier)
|
||||||
|
content.gsub!('{nickname1}', user&.real_name)
|
||||||
|
content.gsub!('{nickname2}', project&.owner&.real_name)
|
||||||
|
content.gsub!('{repository}', project&.name)
|
||||||
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
|
return receiver&.mail, title, content
|
||||||
|
else
|
||||||
|
return '', '', ''
|
||||||
end
|
end
|
||||||
title = email_title
|
|
||||||
title.gsub!('{nickname1}', user&.real_name)
|
|
||||||
title.gsub!('{nickname2}', project&.owner&.real_name)
|
|
||||||
title.gsub!('{repository}', project&.name)
|
|
||||||
|
|
||||||
content = email
|
|
||||||
content.gsub!('{receiver}', receiver&.real_name)
|
|
||||||
content.gsub!('{baseurl}', base_url)
|
|
||||||
content.gsub!('{login1}', user&.login)
|
|
||||||
content.gsub!('{login2}', project&.owner&.login)
|
|
||||||
content.gsub!('{identifier}', project&.identifier)
|
|
||||||
content.gsub!('{nickname1}', user&.real_name)
|
|
||||||
content.gsub!('{nickname2}', project&.owner&.real_name)
|
|
||||||
content.gsub!('{repository}', project&.name)
|
|
||||||
|
|
||||||
return receiver&.mail, title, content
|
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::ProjectMemberLeft.get_email_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::ProjectMemberLeft.get_email_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
return '', '', ''
|
||||||
|
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue