This commit is contained in:
chenyh 2021-11-22 13:23:10 +08:00
parent 2cfc4e719b
commit 80a1c0e173
1018 changed files with 109257 additions and 783 deletions

2
.gitignore vendored
View File

@ -37,13 +37,11 @@ public/react/yarn.lock
# Ignore react node_modules
public/system/*
public/react/*
/public/react/.cache
/public/react/node_modules/
/public/react/config/stats.json
/public/react/stats.json
/public/react/.idea/*
/public/react/build/*
/public/h5build
/public/npm-debug.log

View File

@ -115,7 +115,7 @@ rails db:migrate RAILS_ENV=development
git clone -b standalone https://git.trustie.net/jasder/build.git
```
#### 12. 启动redis(此处已mac系统为例)
#### 12. 启动redis(此处以macOS系统为例)
```bash
redis-server&
```

View File

@ -1,8 +1,6 @@
class AccountsController < ApplicationController
include ApplicationHelper
#skip_before_action :check_account, :only => [:logout]
def index
render json: session
end
@ -139,15 +137,17 @@ class AccountsController < ApplicationController
tip_exception(-1, interactor.error)
end
rescue Register::BaseForm::EmailError => e
render_error(-2, e.message)
render_result(-2, e.message)
rescue Register::BaseForm::LoginError => e
render_error(-3, e.message)
render_result(-3, e.message)
rescue Register::BaseForm::PhoneError => e
render_error(-4, e.message)
render_result(-4, e.message)
rescue Register::BaseForm::PasswordFormatError => e
render_error(-5, e.message)
render_result(-5, e.message)
rescue Register::BaseForm::PasswordConfirmationError => e
render_result(-7, e.message)
rescue Register::BaseForm::VerifiCodeError => e
render_error(-6, e.message)
render_result(-6, e.message)
rescue Exception => e
Gitea::User::DeleteService.call(user.login) unless user.nil?
uid_logger_error(e.message)
@ -157,7 +157,7 @@ class AccountsController < ApplicationController
# 用户登录
def login
Users::LoginForm.new(account_params).validate!
Users::LoginForm.new(login_params).validate!
@user = User.try_to_login(params[:login], params[:password])
return normal_status(-2, "错误的账号或密码") if @user.blank?
@ -206,28 +206,27 @@ class AccountsController < ApplicationController
# 忘记密码
def reset_password
begin
code = params[:code]
login_type = phone_mail_type(params[:login].strip)
# 获取验证码
if login_type == 1
phone = params[:login]
verifi_code = VerificationCode.where(phone: phone, code: code, code_type: 2).last
user = User.find_by_phone(phone)
else
email = params[:login]
verifi_code = VerificationCode.where(email: email, code: code, code_type: 3).last
user = User.find_by_mail(email) #这里有问题应该是为email,而不是mail 6.13-hs
end
return normal_status(-2, "验证码不正确") if verifi_code.try(:code) != code.strip
return normal_status(-2, "验证码已失效") if !verifi_code&.effective?
return normal_status(-1, "8~16位密码支持字母数字和符号") unless params[:new_password] =~ CustomRegexp::PASSWORD
Accounts::ResetPasswordForm.new(reset_password_params).validate!
user.password, user.password_confirmation = params[:new_password], params[:new_password_confirmation]
ActiveRecord::Base.transaction do
user.save!
LimitForbidControl::UserLogin.new(user).clear
end
sucess_status
user = find_user
return render_error('未找到相关账号') if user.blank?
user = Accounts::ResetPasswordService.call(user, reset_password_params)
LimitForbidControl::UserLogin.new(user).clear if user.save!
render_ok
rescue Register::BaseForm::EmailError => e
render_result(-2, e.message)
rescue Register::BaseForm::PhoneError => e
render_result(-4, e.message)
rescue Register::BaseForm::PasswordFormatError => e
render_result(-5, e.message)
rescue Register::BaseForm::PasswordConfirmationError => e
render_result(-7, e.message)
rescue Register::BaseForm::VerifiCodeError => e
render_result(-6, e.message)
rescue ActiveRecord::Rollback => e
render_result(-1, "服务器异常")
rescue Exception => e
uid_logger_error(e.message)
tip_exception(e.message)
@ -356,7 +355,7 @@ class AccountsController < ApplicationController
params.require(:user).permit(:login, :email, :phone)
end
def account_params
def login_params
params.require(:account).permit(:login, :password)
end
@ -365,7 +364,16 @@ class AccountsController < ApplicationController
end
def register_params
params.permit(:login, :namespace, :password, :code)
params.permit(:login, :namespace, :password, :password_confirmation, :code)
end
def reset_password_params
params.permit(:login, :password, :password_confirmation, :code)
end
def find_user
phone_or_mail = strip(reset_password_params[:login])
User.where("phone = :search OR mail = :search", search: phone_or_mail).last
end
end

View File

@ -0,0 +1,57 @@
class Admins::Topic::ActivityForumsController < Admins::Topic::BaseController
before_action :find_activity_forum, only: [:edit, :update, :destroy]
def index
q = ::Topic::ActivityForum.ransack(title_cont: params[:search])
activity_forums = q.result(distinct: true)
@activity_forums = paginate(activity_forums)
end
def new
@activity_forum = ::Topic::ActivityForum.new
end
def create
@activity_forum = ::Topic::ActivityForum.new(activity_forum_params)
if @activity_forum.save
redirect_to admins_topic_activity_forums_path
flash[:success] = "新增平台动态成功"
else
redirect_to admins_topic_activity_forums_path
flash[:danger] = "新增平台动态失败"
end
end
def edit
end
def update
@activity_forum.attributes = activity_forum_params
if @activity_forum.save
redirect_to admins_topic_activity_forums_path
flash[:success] = "更新平台动态成功"
else
redirect_to admins_topic_activity_forums_path
flash[:danger] = "更新平台动态失败"
end
end
def destroy
if @activity_forum.destroy
redirect_to admins_topic_activity_forums_path
flash[:success] = "删除平台动态成功"
else
redirect_to admins_topic_activity_forums_path
flash[:danger] = "删除平台动态失败"
end
end
private
def find_activity_forum
@activity_forum = ::Topic::ActivityForum.find_by_id(params[:id])
end
def activity_forum_params
params.require(:topic_activity_forum).permit(:title, :uuid, :url, :order_index)
end
end

View File

@ -0,0 +1,57 @@
class Admins::Topic::BannersController < Admins::Topic::BaseController
before_action :find_banner, only: [:edit, :update, :destroy]
def index
@banners = paginate(::Topic::Banner)
end
def new
@banner = ::Topic::Banner.new
end
def create
@banner = ::Topic::Banner.new(banner_params)
if @banner.save
save_image_file(params[:image], @banner)
redirect_to admins_topic_banners_path
flash[:success] = "新增banner成功"
else
redirect_to admins_topic_banners_path
flash[:danger] = "新增banner失败"
end
end
def edit
end
def update
@banner.attributes = banner_params
if @banner.save
save_image_file(params[:image], @banner)
redirect_to admins_topic_banners_path
flash[:success] = "更新banner成功"
else
redirect_to admins_topic_banners_path
flash[:danger] = "更新banner失败"
end
end
def destroy
if @banner.destroy
redirect_to admins_topic_banners_path
flash[:success] = "删除banner成功"
else
redirect_to admins_topic_banners_path
flash[:danger] = "删除banner失败"
end
end
private
def find_banner
@banner = ::Topic::Banner.find_by_id(params[:id])
end
def banner_params
params.require(:topic_banner).permit(:title, :order_index)
end
end

View File

@ -0,0 +1,11 @@
class Admins::Topic::BaseController < Admins::BaseController
protected
def save_image_file(file, topic)
return unless file.present? && file.is_a?(ActionDispatch::Http::UploadedFile)
file_path = Util::FileManage.source_disk_filename(topic, 'image')
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
Util.write_file(file, file_path)
end
end

View File

@ -0,0 +1,57 @@
class Admins::Topic::CardsController < Admins::Topic::BaseController
before_action :find_card, only: [:edit, :update, :destroy]
def index
q = ::Topic::Card.ransack(title_cont: params[:search])
cards = q.result(distinct: true)
@cards = paginate(cards)
end
def new
@card = ::Topic::Card.new
end
def create
@card = ::Topic::Card.new(card_params)
if @card.save
redirect_to admins_topic_cards_path
flash[:success] = "新增合作单位成功"
else
redirect_to admins_topic_cards_path
flash[:danger] = "新增合作单位失败"
end
end
def edit
end
def update
@card.attributes = card_params
if @card.save
redirect_to admins_topic_cards_path
flash[:success] = "更新合作单位成功"
else
redirect_to admins_topic_cards_path
flash[:danger] = "更新合作单位失败"
end
end
def destroy
if @card.destroy
redirect_to admins_topic_cards_path
flash[:success] = "删除合作单位成功"
else
redirect_to admins_topic_cards_path
flash[:danger] = "删除合作单位失败"
end
end
private
def find_card
@card = ::Topic::Card.find_by_id(params[:id])
end
def card_params
params.require(:topic_card).permit(:title, :url, :order_index)
end
end

View File

@ -0,0 +1,57 @@
class Admins::Topic::CooperatorsController < Admins::Topic::BaseController
before_action :find_cooperator, only: [:edit, :update, :destroy]
def index
@cooperators = paginate(::Topic::Cooperator)
end
def new
@cooperator = ::Topic::Cooperator.new
end
def create
@cooperator = ::Topic::Cooperator.new(cooperator_params)
if @cooperator.save
save_image_file(params[:image], @cooperator)
redirect_to admins_topic_cooperators_path
flash[:success] = "新增合作单位成功"
else
redirect_to admins_topic_cooperators_path
flash[:danger] = "新增合作单位失败"
end
end
def edit
end
def update
@cooperator.attributes = cooperator_params
if @cooperator.save
save_image_file(params[:image], @cooperator)
redirect_to admins_topic_cooperators_path
flash[:success] = "更新合作单位成功"
else
redirect_to admins_topic_cooperators_path
flash[:danger] = "更新合作单位失败"
end
end
def destroy
if @cooperator.destroy
redirect_to admins_topic_cooperators_path
flash[:success] = "删除合作单位成功"
else
redirect_to admins_topic_cooperators_path
flash[:danger] = "删除合作单位失败"
end
end
private
def find_cooperator
@cooperator = ::Topic::Cooperator.find_by_id(params[:id])
end
def cooperator_params
params.require(:topic_cooperator).permit(:title, :url, :order_index)
end
end

View File

@ -0,0 +1,57 @@
class Admins::Topic::ExcellentProjectsController < Admins::Topic::BaseController
before_action :find_excellent_project, only: [:edit, :update, :destroy]
def index
q = ::Topic::ExcellentProject.ransack(title_cont: params[:search])
excellent_projects = q.result(distinct: true)
@excellent_projects = paginate(excellent_projects)
end
def new
@excellent_project = ::Topic::ExcellentProject.new
end
def create
@excellent_project = ::Topic::ExcellentProject.new(excellent_project_params)
if @excellent_project.save
redirect_to admins_topic_excellent_projects_path
flash[:success] = "新增优秀仓库成功"
else
redirect_to admins_topic_excellent_projects_path
flash[:danger] = "新增优秀仓库失败"
end
end
def edit
end
def update
@excellent_project.attributes = excellent_project_params
if @excellent_project.save
redirect_to admins_topic_excellent_projects_path
flash[:success] = "更新优秀仓库成功"
else
redirect_to admins_topic_excellent_projects_path
flash[:danger] = "更新优秀仓库失败"
end
end
def destroy
if @excellent_project.destroy
redirect_to admins_topic_excellent_projects_path
flash[:success] = "删除优秀仓库成功"
else
redirect_to admins_topic_excellent_projects_path
flash[:danger] = "删除优秀仓库失败"
end
end
private
def find_excellent_project
@excellent_project = ::Topic::ExcellentProject.find_by_id(params[:id])
end
def excellent_project_params
params.require(:topic_excellent_project).permit(:title, :uuid, :url, :order_index)
end
end

View File

@ -0,0 +1,57 @@
class Admins::Topic::ExperienceForumsController < Admins::Topic::BaseController
before_action :find_experience_forum, only: [:edit, :update, :destroy]
def index
q = ::Topic::ExperienceForum.ransack(title_cont: params[:search])
experience_forums = q.result(distinct: true)
@experience_forums = paginate(experience_forums)
end
def new
@experience_forum = ::Topic::ExperienceForum.new
end
def create
@experience_forum = ::Topic::ExperienceForum.new(experience_forum_params)
if @experience_forum.save
redirect_to admins_topic_experience_forums_path
flash[:success] = "新增经验分享成功"
else
redirect_to admins_topic_experience_forums_path
flash[:danger] = "新增经验分享失败"
end
end
def edit
end
def update
@experience_forum.attributes = experience_forum_params
if @experience_forum.save
redirect_to admins_topic_experience_forums_path
flash[:success] = "更新经验分享成功"
else
redirect_to admins_topic_experience_forums_path
flash[:danger] = "更新经验分享失败"
end
end
def destroy
if @experience_forum.destroy
redirect_to admins_topic_experience_forums_path
flash[:success] = "删除经验分享成功"
else
redirect_to admins_topic_experience_forums_path
flash[:danger] = "删除经验分享失败"
end
end
private
def find_experience_forum
@experience_forum = ::Topic::ExperienceForum.find_by_id(params[:id])
end
def experience_forum_params
params.require(:topic_experience_forum).permit(:title, :uuid, :url, :order_index)
end
end

View File

@ -0,0 +1,57 @@
class Admins::Topic::PinnedForumsController < Admins::Topic::BaseController
before_action :find_pinned_forum, only: [:edit, :update, :destroy]
def index
q = ::Topic::PinnedForum.ransack(title_cont: params[:search])
pinned_forums = q.result(distinct: true)
@pinned_forums = paginate(pinned_forums)
end
def new
@pinned_forum = ::Topic::PinnedForum.new
end
def create
@pinned_forum = ::Topic::PinnedForum.new(pinned_forum_params)
if @pinned_forum.save
redirect_to admins_topic_pinned_forums_path
flash[:success] = "新增精选文章成功"
else
redirect_to admins_topic_pinned_forums_path
flash[:danger] = "新增精选文章失败"
end
end
def edit
end
def update
@pinned_forum.attributes = pinned_forum_params
if @pinned_forum.save
redirect_to admins_topic_pinned_forums_path
flash[:success] = "更新精选文章成功"
else
redirect_to admins_topic_pinned_forums_path
flash[:danger] = "更新精选文章失败"
end
end
def destroy
if @pinned_forum.destroy
redirect_to admins_topic_pinned_forums_path
flash[:success] = "删除精选文章成功"
else
redirect_to admins_topic_pinned_forums_path
flash[:danger] = "删除精选文章失败"
end
end
private
def find_pinned_forum
@pinned_forum = ::Topic::PinnedForum.find_by_id(params[:id])
end
def pinned_forum_params
params.require(:topic_pinned_forum).permit(:title, :uuid, :url, :order_index)
end
end

View File

@ -26,7 +26,8 @@ class ApplicationController < ActionController::Base
end
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)
OPENKEY = "79e33abd4b6588941ab7622aed1e67e8"
OPENKEY = Rails.application.config_for(:configuration)['sign_key'] || "79e33abd4b6588941ab7622aed1e67e8"
helper_method :current_user, :base_url
@ -264,7 +265,6 @@ class ApplicationController < ActionController::Base
User.current = user
end
end
# if !User.current.logged? && Rails.env.development?
# User.current = User.find 1
# end
@ -336,11 +336,6 @@ class ApplicationController < ActionController::Base
@message = message
end
# 实训等对应的仓库地址
def repo_ip_url(repo_path)
"#{edu_setting('git_address_ip')}/#{repo_path}"
end
def repo_url(repo_path)
"#{edu_setting('git_address_domain')}/#{repo_path}"
end
@ -609,7 +604,7 @@ class ApplicationController < ActionController::Base
def kaminari_paginate(relation)
limit = params[:limit] || params[:per_page]
limit = (limit.to_i.zero? || limit.to_i > 15) ? 15 : limit.to_i
limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
relation.page(page).per(limit)
@ -617,7 +612,7 @@ class ApplicationController < ActionController::Base
def kaminari_array_paginate(relation)
limit = params[:limit] || params[:per_page]
limit = (limit.to_i.zero? || limit.to_i > 15) ? 15 : limit.to_i
limit = (limit.to_i.zero? || limit.to_i > 20) ? 20 : limit.to_i
page = params[:page].to_i.zero? ? 1 : params[:page].to_i
Kaminari.paginate_array(relation).page(page).per(limit)
@ -742,37 +737,10 @@ class ApplicationController < ActionController::Base
render json: exception.tip_json
end
def render_parameter_missing
render json: { status: -1, message: '参数缺失' }
end
def set_export_cookies
cookies[:fileDownload] = true
end
# 149课程的评审用户数据创建包含创建课堂学生
def open_class_user
user = User.find_by(login: "OpenClassUser")
unless user
ActiveRecord::Base.transaction do
user_params = {status: 1, login: "OpenClassUser", lastname: "开放课程",
nickname: "开放课程", professional_certification: 1, certification: 1, grade: 0,
password: "12345678", phone: "11122223333", profile_completed: 1}
user = User.create!(user_params)
UserExtension.create!(user_id: user.id, gender: 0, school_id: 3396, :identity => 1, :student_id => "openclassuser") # 3396
subject = Subject.find_by(id: 149)
if subject
subject.courses.each do |course|
CourseMember.create!(course_id: course.id, role: 3, user_id: user.id) if !course.course_members.exists?(user_id: user.id)
end
end
end
end
user
end
# 记录热门搜索关键字
def record_search_keyword
keyword = params[:keyword].to_s.strip

View File

@ -1,13 +1,17 @@
module RegisterHelper
extend ActiveSupport::Concern
def autologin_register(username, email, password, platform= 'forge')
def autologin_register(username, email, password, platform= 'forge', need_edit_info = false)
result = {message: nil, user: nil}
user = User.new(admin: false, login: username, mail: email, type: "User")
user.password = password
user.platform = platform
user.activate
if need_edit_info
user.need_edit_info
else
user.activate
end
return unless user.valid?
@ -27,4 +31,31 @@ module RegisterHelper
result
end
def autosync_register_trustie(username, password, email, lastname="")
config = Rails.application.config_for(:configuration).symbolize_keys!
api_host = config[:sync_url]
return if api_host.blank?
url = "#{api_host}/api/v1/users/common"
sync_json = {
"mail": email,
"password": password,
"login": username,
"lastname": lastname
}.compact
uri = URI.parse(url)
if api_host
http = Net::HTTP.new(uri.hostname, uri.port)
if api_host.include?("https://")
http.use_ssl = true
end
http.send_request('POST', uri.path, sync_json.to_json, {'Content-Type' => 'application/json'})
end
end
end

View File

@ -3,8 +3,8 @@ module RenderHelper
render json: { status: 0, message: 'success' }.merge(data)
end
def render_error(status = -1, message = '')
render json: { status: status, message: message }
def render_error(message = '')
render json: { status: -1, message: message }
end
def render_not_acceptable(message = '请求已拒绝')
@ -28,4 +28,8 @@ module RenderHelper
def render_result(status=1, message='success')
render json: { status: status, message: message }
end
def render_parameter_missing
render json: { status: -1, message: '参数缺失' }
end
end

View File

@ -2,6 +2,7 @@ class Oauth::BaseController < ActionController::Base
include RenderHelper
include LoginHelper
include ControllerRescueHandler
include LoggerHelper
# include LaboratoryHelper
skip_before_action :verify_authenticity_token
@ -11,6 +12,18 @@ class Oauth::BaseController < ActionController::Base
end
private
def tip_exception(status = -1, message)
raise Educoder::TipException.new(status, message)
end
def tip_show_exception(status = -2, message)
raise Educoder::TipException.new(status, message)
end
def tip_show(exception)
uid_logger("Tip show status is #{exception.status}, message is #{exception.message}")
render json: exception.tip_json
end
def session_user_id
# session[:user_id]
@ -48,4 +61,13 @@ class Oauth::BaseController < ActionController::Base
Rails.logger.info("[wechat] set session unionid: #{unionid}")
session[:unionid] = unionid
end
def session_edulogin
session[:edulogin]
end
def set_session_edulogin(login)
Rails.logger.info("[educoder] set sesstion edulogin: #{login}")
session[:edulogin] = login
end
end

View File

@ -1,4 +1,6 @@
class Oauth::EducoderController < Oauth::BaseController
include RegisterHelper
def bind
begin
login = params[:login]
@ -32,4 +34,41 @@ class Oauth::EducoderController < Oauth::BaseController
render_error(ex.message)
end
end
# 需要educoder那边设置回调地址
def create
begin
code = params['code'].to_s.strip
tip_exception("code不能为空") if code.blank?
new_user = false
result = EducoderOauth::Service.access_token(code)
result = EducoderOauth::Service.user_info(result[:access_token])
# 存在该用户
open_user = OpenUsers::Educoder.find_by(uid: result['login'])
if open_user.present? && open_user.user.present?
successful_authentication(open_user.user)
else
if current_user.blank? || !current_user.logged?
new_user = true
login = User.generate_login('E')
reg_result = autologin_register(login,"#{login}@forge.com", "Ec#{login}2021#", 'educoder', true)
if reg_result[:message].blank?
open_user = OpenUsers::Educoder.create!(user_id: reg_result[:user][:id], uid: result['login'], extra: result)
autosync_register_trustie(login, "Ec#{login}2021#", "#{login}@forge.com")
successful_authentication(open_user.user)
else
render_error(reg_result[:message])
end
else
OpenUsers::Educoder.create!(user: current_user, uid: result['login'], extra: result)
end
end
redirect_to root_path(new_user: new_user)
rescue Exception => ex
render_error(ex.message)
end
end
end

View File

@ -61,6 +61,7 @@ class OauthController < ApplicationController
login = params[:login]
email = params[:mail]
password = params[:password]
lastname = params[:lastname]
callback_url = params[:callback_url]
platform = params[:plathform] || 'educoder'
@ -72,8 +73,11 @@ class OauthController < ApplicationController
if result[:message].blank?
logger.info "[Oauth educoer] ====auto_register success"
user = User.find result[:user][:id]
successful_authentication(user)
user.update_column(:lastname, params[:lastname])
autosync_register_trustie(login, password, email, lastname)
OpenUsers::Educoder.create!(user: user, uid: user.login)
successful_authentication(user)
render json: { callback_url: callback_url }
# redirect_to callback_url

View File

@ -347,7 +347,7 @@ class RepositoriesController < ApplicationController
local_requests = PullRequest.new(local_params.merge(user_id: current_user.try(:id), project_id: @project.id, issue_id: @pull_issue.id))
if local_requests.save
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")
end
end

View File

@ -4,6 +4,7 @@ class SettingsController < ApplicationController
get_add_menu
get_common_menu
get_personal_menu
get_third_party
get_top_system_notification
end
@ -40,6 +41,14 @@ class SettingsController < ApplicationController
end
end
def get_third_party
@third_party = []
@third_party << {
name: 'educoder',
url: EducoderOauth.oauth_url
}
end
def get_top_system_notification
@top_system_notification = SystemNotification.is_top.first
end

View File

@ -0,0 +1,9 @@
class TopicsController < ApplicationController
def index
return render_not_found("请输入正确的数据类型") unless params[:topic_type].present?
scope = Topic.with_single_type(params[:topic_type])
@topics = kaminari_paginate(scope)
end
end

View File

@ -275,7 +275,7 @@ class UsersController < ApplicationController
interactor = Gitea::User::UpdateInteractor.call(user.login, sync_params)
if interactor.success?
user.update!(password: params[:password], mail: params[:email], status: User::STATUS_EDIT_INFO)
user.update!(password: params[:password], mail: params[:email], status: User::STATUS_ACTIVE)
render_ok
else
render_error(interactor.error)

View File

@ -0,0 +1,41 @@
module Accounts
class ResetPasswordForm < ::BaseForm
# login 邮箱、手机号
# code 验证码
# type: 1手机号注册2邮箱注册
attr_accessor :login, :password, :password_confirmation, :code
validates :login, :code, :password, :password_confirmation, presence: true, allow_blank: false
validate :check!
def check!
Rails.logger.info "ResetPasswordForm params: code: #{code} login: #{login}
password: #{password} password_confirmation: #{password_confirmation}"
type = phone_mail_type(login)
db_verifi_code =
if type == 1
check_phone_format(login)
VerificationCode.where(phone: login, code: code, code_type: 2).last
elsif type == 0
check_email_format(login)
VerificationCode.where(email: login, code: code, code_type: 3).last
end
check_password(password)
check_password_confirmation(password, password_confirmation)
check_verifi_code(db_verifi_code, code)
end
def check_phone_format(phone)
phone = strip(phone)
raise LoginError, "登录名格式有误" unless phone =~ CustomRegexp::LOGIN
end
def check_email_format(mail)
mail = strip(mail)
raise EmailError, "邮件格式有误" unless mail =~ CustomRegexp::EMAIL
end
end
end

View File

@ -1,6 +1,14 @@
class BaseForm
include ActiveModel::Model
Error = Class.new(StandardError)
EmailError = Class.new(Error)
LoginError = Class.new(Error)
PhoneError = Class.new(Error)
PasswordFormatError = Class.new(Error)
VerifiCodeError = Class.new(Error)
PasswordConfirmationError = Class.new(Error)
def check_project_category(project_category_id)
unless project_category_id == ''
raise "project_category_id参数值无效." if project_category_id && !ProjectCategory.exists?(project_category_id)
@ -26,8 +34,35 @@ class BaseForm
raise "项目标识已被占用." if ReversedKeyword.check_exists?(repository_name)
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&.code != code
raise VerifiCodeError, "验证码已失效" if !verifi_code&.effective?
end
private
def strip(str)
str.to_s.strip.presence
end
# 1 手机类型0 邮箱类型
# 注意新版的login是自动名生成的
def phone_mail_type value
value =~ /^1\d{10}$/ ? 1 : 0
end
end

View File

@ -2,13 +2,6 @@ module Register
class BaseForm < ::BaseForm
include ActiveModel::Model
Error = Class.new(StandardError)
EmailError = Class.new(Error)
LoginError = Class.new(Error)
PhoneError = Class.new(Error)
PasswordFormatError = Class.new(Error)
VerifiCodeError = Class.new(Error)
private
def check_login(login)
login = strip(login)
@ -33,19 +26,5 @@ module Register
phone_exist = Owner.exists?(phone: phone)
raise PhoneError, '手机号已被使用' if phone_exist
end
def check_password(password)
password = strip(password)
raise PasswordFormatError, "8~16位密码支持字母数字和符号" unless password =~ CustomRegexp::PASSWORD
end
def check_verifi_code(verifi_code, code)
code = strip(code)
# return if code == "123123" # TODO 万能验证码,用于测试
raise VerifiCodeError, "验证码不正确" if verifi_code&.code != code
raise VerifiCodeError, "验证码已失效" if !verifi_code&.effective?
end
end
end

View File

@ -3,13 +3,16 @@ module Register
# login 登陆方式,支持邮箱、登陆、手机号等
# namespace 用户空间地址
# type: 1手机号注册2邮箱注册
attr_accessor :login, :namespace, :password, :code, :type
attr_accessor :login, :namespace, :password, :password_confirmation, :code, :type
validates :login, :code, :password, :namespace, presence: true
validates :login, :code, :password, :password_confirmation, :namespace, presence: true, allow_blank: false
validate :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}; password_confirmation: #{password_confirmation}"
type = phone_mail_type(strip(login))
db_verifi_code =
if type == 1
check_phone(login)
@ -22,6 +25,7 @@ module Register
check_login(namespace)
check_verifi_code(db_verifi_code, code)
check_password(password)
check_password_confirmation(password, password_confirmation)
end
end
end

View File

@ -469,5 +469,9 @@ module ApplicationHelper
def phone_mail_type value
value =~ /^1\d{10}$/ ? 1 : 0
end
def strip(str)
str.to_s.strip.presence
end
end

View File

@ -0,0 +1,18 @@
module EducoderOauth
class << self
attr_accessor :client_id, :client_secret, :base_url, :redirect_uri
def logger
@_logger ||= STDOUT
end
def logger=(l)
@_logger = l
end
def oauth_url
"#{base_url}/oauth2?call_url=/oauth/authorize?client_id=#{client_id}&redirect_uri=#{URI.encode_www_form_component(redirect_uri)}&response_type=code"
end
end
end

View File

@ -0,0 +1,37 @@
require 'oauth2'
module EducoderOauth::Service
module_function
def request(method, url, params)
begin
Rails.logger.info("[EducoderOauth] [#{method.to_s.upcase}] #{url} || #{params}")
client = Faraday.new(url: EducoderOauth.base_url)
response = client.public_send(method, url, params)
result = JSON.parse(response.body)
Rails.logger.info("[EducoderOauth] [#{response.status}] #{result}")
result
rescue Exception => e
raise Educoder::TipException.new(e.message)
end
end
def access_token(code)
begin
Rails.logger.info("[EducoderOauth] [code] #{code} ")
Rails.logger.info("[EducoderOauth] [redirect_uri] #{EducoderOauth.redirect_uri} ")
client = OAuth2::Client.new(EducoderOauth.client_id, EducoderOauth.client_secret, site: EducoderOauth.base_url)
result = client.auth_code.get_token(code, redirect_uri: EducoderOauth.redirect_uri).to_hash
return result
rescue Exception => e
raise Educoder::TipException.new(e.message)
end
end
def user_info(access_token)
request(:get, '/api/users/info.json', {access_token: access_token})
end
end

20
app/libs/forum.rb Normal file
View File

@ -0,0 +1,20 @@
module Forum
class << self
def forum_config
forum_config = {}
begin
config = Rails.application.config_for(:configuration).symbolize_keys!
forum_config = config[:forum].symbolize_keys!
raise 'forum config missing' if forum_config.blank?
rescue => ex
raise ex if Rails.env.production?
puts %Q{\033[33m [warning] forum config or configuration.yml missing,
please add it or execute 'cp config/configuration.yml.example config/configuration.yml' \033[0m}
forum_config = {}
end
forum_config
end
end
end

View File

@ -39,6 +39,6 @@ class Gitea::Pull < Gitea::Base
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

View File

@ -36,28 +36,26 @@ class MessageTemplate::IssueAssigned < MessageTemplate
def self.get_email_message_content(receiver, operator, issue)
if receiver.user_template_message_setting.present?
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)
return receiver&.mail, title, content
else
return '', '', ''
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
Rails.logger.info("MessageTemplate::IssueAssigned.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -191,180 +191,177 @@ class MessageTemplate::IssueChanged < MessageTemplate
return '', '', '' if change_params.blank?
if receiver.user_template_message_setting.present?
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::IssueChanged"]
project = issue&.project
owner = project&.owner
title = email_title
title.gsub!('{title}', issue&.subject)
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!('{login2}', owner&.login)
content.gsub!('{nickname2}', owner&.real_name)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{repository}', project&.name)
content.gsub!('{title}', issue&.subject)
content.gsub!('{id}', issue&.id.to_s)
change_count = change_params.keys.size
# 易修负责人修改
if change_params[:assigned_to_id].present?
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
if change_count > 1
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
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
end
# 易修状态修改
if change_params[:status_id].present?
status1 = IssueStatus.find_by_id(change_params[:status_id][0])
status2 = IssueStatus.find_by_id(change_params[:status_id][1])
if change_count > 1
content.sub!('{ifstatus}', '<br/>')
else
content.sub!('{ifstatus}', '')
end
content.sub!('{endstatus}', '')
content.gsub!('{status1}', status1&.name)
content.gsub!('{status2}', status2&.name)
else
content.gsub!(/({ifstatus})(.*)({endstatus})/, '')
end
# 易修类型修改
if change_params[:tracker_id].present?
tracker1 = Tracker.find_by_id(change_params[:tracker_id][0])
tracker2 = Tracker.find_by_id(change_params[:tracker_id][1])
if change_count > 1
content.sub!('{iftracker}', '<br/>')
else
content.sub!('{iftracker}', '')
end
content.sub!('{endtracker}', '')
content.gsub!('{tracker1}', tracker1&.name)
content.gsub!('{tracker2}', tracker2&.name)
else
content.gsub!(/({iftracker})(.*)({endtracker})/, '')
end
# 易修里程碑修改
if change_params[:fixed_version_id].present?
fix_version1 = Version.find_by_id(change_params[:fixed_version_id][0])
fix_version2 = Version.find_by_id(change_params[:fixed_version_id][1])
if change_count > 1
content.sub!('{ifmilestone}', '<br/>')
else
content.sub!('{ifmilestone}', '')
end
content.sub!('{endmilestone}', '')
content.gsub!('{milestone1}', fix_version1.present? ? fix_version1&.name : '未选择里程碑')
content.gsub!('{milestone2}', fix_version2.present? ? fix_version2&.name : '未选择里程碑')
else
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
end
# 易修标记修改
if change_params[:issue_tags_value].present?
issue_tags1 = IssueTag.where(id: change_params[:issue_tags_value][0]).distinct
issue_tags2 = IssueTag.where(id: change_params[:issue_tags_value][1]).distinct
tag1 = issue_tags1.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags1.pluck(:name).join(",")
tag2 = issue_tags2.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags2.pluck(:name).join(",")
if change_count > 1
content.sub!('{iftag}', '<br/>')
else
content.sub!('{iftag}', '')
end
content.sub!('{endtag}', '')
content.gsub!('{tag1}', tag1)
content.gsub!('{tag2}', tag2)
else
content.gsub!(/({iftag})(.*)({endtag})()/, '')
end
# 易修优先级修改
if change_params[:priority_id].present?
priority1 = IssuePriority.find_by_id(change_params[:priority_id][0])
priority2 = IssuePriority.find_by_id(change_params[:priority_id][1])
if change_count > 1
content.sub!('{ifpriority}', '<br/>')
else
content.sub!('{ifpriority}', '')
end
content.sub!('{endpriority}', '')
content.gsub!('{priority1}', priority1&.name)
content.gsub!('{priority2}', priority2&.name)
else
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
end
# 易修完成度修改
if change_params[:done_ratio].present?
doneratio1 = change_params[:done_ratio][0]
doneratio2 = change_params[:done_ratio][1]
if change_count > 1
content.sub!('{ifdoneratio}', '<br/>')
else
content.sub!('{ifdoneratio}', '')
end
content.sub!('{enddoneratio}', '')
content.gsub!('{doneratio1}', "#{doneratio1}%")
content.gsub!('{doneratio2}', "#{doneratio2}%")
else
content.gsub!(/({ifdoneratio})(.*)({enddoneratio})/, '')
end
# 易修指定分支修改
if change_params[:branch_name].present?
branch1 = change_params[:branch_name][0].blank? ? '分支未指定' : change_params[:branch_name][0]
branch2 = change_params[:branch_name][1].blank? ? '分支未指定' : change_params[:branch_name][1]
if change_count > 1
content.sub!('{ifbranch}', '<br/>')
else
content.sub!('{ifbranch}', '')
end
content.sub!('{endbranch}', '')
content.gsub!('{branch1}', branch1)
content.gsub!('{branch2}', branch2)
else
content.gsub!(/({ifbranch})(.*)({endbranch})/, '')
end
# 易修开始日期修改
if change_params[:start_date].present?
startdate1 = change_params[:start_date][0].blank? ? "未选择开始日期" : change_params[:start_date][0]
startdate2 = change_params[:start_date][1].blank? ? "未选择开始日期" : change_params[:start_date][1]
if change_count > 1
content.sub!('{ifstartdate}', '<br/>')
else
content.sub!('{ifstartdate}', '')
end
content.sub!('{endstartdate}', '')
content.gsub!('{startdate1}', startdate1 )
content.gsub!('{startdate2}', startdate2)
else
content.gsub!(/({ifstartdate})(.*)({endstartdate})/, '')
end
# 易修结束日期修改
if change_params[:due_date].present?
duedate1 = change_params[:due_date][0].blank? ? '未选择结束日期' : change_params[:due_date][0]
duedate2 = change_params[:due_date][1].blank? ? '未选择结束日期' : change_params[:due_date][1]
if change_count > 1
content.sub!('{ifduedate}', '<br/>')
else
content.sub!('{ifduedate}', '')
end
content.sub!('{endduedate}', '')
content.gsub!('{duedate1}', duedate1)
content.gsub!('{duedate2}', duedate2)
else
content.gsub!(/({ifduedate})(.*)({endduedate})/, '')
end
return receiver&.mail, title, content
else
return '', '', ''
end
project = issue&.project
owner = project&.owner
title = email_title
title.gsub!('{title}', issue&.subject)
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!('{login2}', owner&.login)
content.gsub!('{nickname2}', owner&.real_name)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{repository}', project&.name)
content.gsub!('{title}', issue&.subject)
content.gsub!('{id}', issue&.id.to_s)
change_count = change_params.keys.size
# 易修负责人修改
if change_params[:assigned_to_id].present?
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
if change_count > 1
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
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
end
# 易修状态修改
if change_params[:status_id].present?
status1 = IssueStatus.find_by_id(change_params[:status_id][0])
status2 = IssueStatus.find_by_id(change_params[:status_id][1])
if change_count > 1
content.sub!('{ifstatus}', '<br/>')
else
content.sub!('{ifstatus}', '')
end
content.sub!('{endstatus}', '')
content.gsub!('{status1}', status1&.name)
content.gsub!('{status2}', status2&.name)
else
content.gsub!(/({ifstatus})(.*)({endstatus})/, '')
end
# 易修类型修改
if change_params[:tracker_id].present?
tracker1 = Tracker.find_by_id(change_params[:tracker_id][0])
tracker2 = Tracker.find_by_id(change_params[:tracker_id][1])
if change_count > 1
content.sub!('{iftracker}', '<br/>')
else
content.sub!('{iftracker}', '')
end
content.sub!('{endtracker}', '')
content.gsub!('{tracker1}', tracker1&.name)
content.gsub!('{tracker2}', tracker2&.name)
else
content.gsub!(/({iftracker})(.*)({endtracker})/, '')
end
# 易修里程碑修改
if change_params[:fixed_version_id].present?
fix_version1 = Version.find_by_id(change_params[:fixed_version_id][0])
fix_version2 = Version.find_by_id(change_params[:fixed_version_id][1])
if change_count > 1
content.sub!('{ifmilestone}', '<br/>')
else
content.sub!('{ifmilestone}', '')
end
content.sub!('{endmilestone}', '')
content.gsub!('{milestone1}', fix_version1.present? ? fix_version1&.name : '未选择里程碑')
content.gsub!('{milestone2}', fix_version2.present? ? fix_version2&.name : '未选择里程碑')
else
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
end
# 易修标记修改
if change_params[:issue_tags_value].present?
issue_tags1 = IssueTag.where(id: change_params[:issue_tags_value][0]).distinct
issue_tags2 = IssueTag.where(id: change_params[:issue_tags_value][1]).distinct
tag1 = issue_tags1.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags1.pluck(:name).join(",")
tag2 = issue_tags2.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags2.pluck(:name).join(",")
if change_count > 1
content.sub!('{iftag}', '<br/>')
else
content.sub!('{iftag}', '')
end
content.sub!('{endtag}', '')
content.gsub!('{tag1}', tag1)
content.gsub!('{tag2}', tag2)
else
content.gsub!(/({iftag})(.*)({endtag})()/, '')
end
# 易修优先级修改
if change_params[:priority_id].present?
priority1 = IssuePriority.find_by_id(change_params[:priority_id][0])
priority2 = IssuePriority.find_by_id(change_params[:priority_id][1])
if change_count > 1
content.sub!('{ifpriority}', '<br/>')
else
content.sub!('{ifpriority}', '')
end
content.sub!('{endpriority}', '')
content.gsub!('{priority1}', priority1&.name)
content.gsub!('{priority2}', priority2&.name)
else
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
end
# 易修完成度修改
if change_params[:done_ratio].present?
doneratio1 = change_params[:done_ratio][0]
doneratio2 = change_params[:done_ratio][1]
if change_count > 1
content.sub!('{ifdoneratio}', '<br/>')
else
content.sub!('{ifdoneratio}', '')
end
content.sub!('{enddoneratio}', '')
content.gsub!('{doneratio1}', "#{doneratio1}%")
content.gsub!('{doneratio2}', "#{doneratio2}%")
else
content.gsub!(/({ifdoneratio})(.*)({enddoneratio})/, '')
end
# 易修指定分支修改
if change_params[:branch_name].present?
branch1 = change_params[:branch_name][0].blank? ? '分支未指定' : change_params[:branch_name][0]
branch2 = change_params[:branch_name][1].blank? ? '分支未指定' : change_params[:branch_name][1]
if change_count > 1
content.sub!('{ifbranch}', '<br/>')
else
content.sub!('{ifbranch}', '')
end
content.sub!('{endbranch}', '')
content.gsub!('{branch1}', branch1)
content.gsub!('{branch2}', branch2)
else
content.gsub!(/({ifbranch})(.*)({endbranch})/, '')
end
# 易修开始日期修改
if change_params[:start_date].present?
startdate1 = change_params[:start_date][0].blank? ? "未选择开始日期" : change_params[:start_date][0]
startdate2 = change_params[:start_date][1].blank? ? "未选择开始日期" : change_params[:start_date][1]
if change_count > 1
content.sub!('{ifstartdate}', '<br/>')
else
content.sub!('{ifstartdate}', '')
end
content.sub!('{endstartdate}', '')
content.gsub!('{startdate1}', startdate1 )
content.gsub!('{startdate2}', startdate2)
else
content.gsub!(/({ifstartdate})(.*)({endstartdate})/, '')
end
# 易修结束日期修改
if change_params[:due_date].present?
duedate1 = change_params[:due_date][0].blank? ? '未选择结束日期' : change_params[:due_date][0]
duedate2 = change_params[:due_date][1].blank? ? '未选择结束日期' : change_params[:due_date][1]
if change_count > 1
content.sub!('{ifduedate}', '<br/>')
else
content.sub!('{ifduedate}', '')
end
content.sub!('{endduedate}', '')
content.gsub!('{duedate1}', duedate1)
content.gsub!('{duedate2}', duedate2)
else
content.gsub!(/({ifduedate})(.*)({endduedate})/, '')
end
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::IssueChanged.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -33,19 +33,17 @@ class MessageTemplate::IssueDeleted < MessageTemplate
def self.get_email_message_content(receiver, operator, issue_title)
if receiver.user_template_message_setting.present?
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::IssueChanged"]
title = email_title
title.gsub!('{title}', issue_title)
content = email
content.gsub!('{receiver}', receiver&.real_name)
content.gsub!('{nickname}', operator&.real_name)
content.gsub!('{login}', operator&.login)
content.gsub!('{baseurl}', base_url)
content.gsub!('{title}', issue_title)
return receiver&.mail, title, content
else
return '', '', ''
end
title = email_title
title.gsub!('{title}', issue_title)
content = email
content.gsub!('{receiver}', receiver&.real_name)
content.gsub!('{nickname}', operator&.real_name)
content.gsub!('{login}', operator&.login)
content.gsub!('{baseurl}', base_url)
content.gsub!('{title}', issue_title)
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::IssueDeleted.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -34,19 +34,16 @@ class MessageTemplate::OrganizationJoined < MessageTemplate
def self.get_email_message_content(receiver, organization)
if receiver.user_template_message_setting.present?
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)
return receiver&.mail, title, content
else
return '', '', ''
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
Rails.logger.info("MessageTemplate::OrganizationJoined.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -34,19 +34,16 @@ class MessageTemplate::OrganizationLeft < MessageTemplate
def self.get_email_message_content(receiver, organization)
if receiver.user_template_message_setting.present?
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)
return receiver&.mail, title, content
else
return '', '', ''
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
Rails.logger.info("MessageTemplate::OrganizationLeft.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -34,21 +34,18 @@ class MessageTemplate::OrganizationRole < MessageTemplate
def self.get_email_message_content(receiver, organization, role)
if receiver.user_template_message_setting.present?
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)
return receiver&.mail, title, content
else
return '', '', ''
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
Rails.logger.info("MessageTemplate::OrganizationRole.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -38,30 +38,27 @@ class MessageTemplate::ProjectIssue < MessageTemplate
def self.get_email_message_content(receiver, is_manager, operator, issue)
if receiver.user_template_message_setting.present? && is_manager
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)
return receiver&.mail, title, content
else
return '', '', ''
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
Rails.logger.info("MessageTemplate::ProjectIssue.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -34,22 +34,19 @@ class MessageTemplate::ProjectJoined < MessageTemplate
def self.get_email_message_content(receiver, project)
if receiver.user_template_message_setting.present?
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Project"]
title = email_title
title.gsub!('{repository}', project&.name)
content = email
content.gsub!('{receiver}', receiver&.real_name)
content.gsub!('{baseurl}', base_url)
content.gsub!('{login}', project&.owner&.login)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{nickname}', project&.owner&.real_name)
content.gsub!('{repository}', project&.name)
return receiver&.mail, title, content
else
return '', '', ''
end
title = email_title
title.gsub!('{repository}', project&.name)
content = email
content.gsub!('{receiver}', receiver&.real_name)
content.gsub!('{baseurl}', base_url)
content.gsub!('{login}', project&.owner&.login)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{nickname}', project&.owner&.real_name)
content.gsub!('{repository}', project&.name)
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::ProjectJoined.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -33,22 +33,19 @@ class MessageTemplate::ProjectLeft < MessageTemplate
def self.get_email_message_content(receiver, project)
if receiver.user_template_message_setting.present?
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Project"]
title = email_title
title.gsub!('{repository}', project&.name)
content = email
content.gsub!('{receiver}', receiver&.real_name)
content.gsub!('{baseurl}', base_url)
content.gsub!('{login}', project&.owner&.login)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{nickname}', project&.owner&.real_name)
content.gsub!('{repository}', project&.name)
return receiver&.mail, title, content
else
return '', '', ''
end
title = email_title
title.gsub!('{repository}', project&.name)
content = email
content.gsub!('{receiver}', receiver&.real_name)
content.gsub!('{baseurl}', base_url)
content.gsub!('{login}', project&.owner&.login)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{nickname}', project&.owner&.real_name)
content.gsub!('{repository}', project&.name)
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::ProjectLeft.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -34,25 +34,23 @@ class MessageTemplate::ProjectMemberJoined < MessageTemplate
def self.get_email_message_content(receiver, user, project)
if receiver.user_template_message_setting.present?
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)
return receiver&.mail, title, content
else
return '', '', ''
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
Rails.logger.info("MessageTemplate::ProjectMemberJoined.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -34,26 +34,23 @@ class MessageTemplate::ProjectMemberLeft < MessageTemplate
def self.get_email_message_content(receiver, user, project)
if receiver.user_template_message_setting.present?
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)
return receiver&.mail, title, content
else
return '', '', ''
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
Rails.logger.info("MessageTemplate::ProjectMemberLeft.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -38,29 +38,27 @@ class MessageTemplate::ProjectPullRequest < MessageTemplate
def self.get_email_message_content(receiver, is_manager, operator, pull_request)
if receiver.user_template_message_setting.present? && is_manager
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::PullRequest"]
project = pull_request&.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}', pull_request&.id.to_s)
content.gsub!('{title}', pull_request&.title)
return receiver&.mail, title, content
else
return '', '', ''
end
project = pull_request&.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}', pull_request&.id.to_s)
content.gsub!('{title}', pull_request&.title)
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::ProjectPullRequest.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -34,24 +34,21 @@ class MessageTemplate::ProjectRole < MessageTemplate
def self.get_email_message_content(receiver, project, role)
if receiver.user_template_message_setting.present?
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::Permission"]
title = email_title
title.gsub!('{repository}', project&.name)
title.gsub!('{role}', role)
title.gsub!('{nickname}', project&.owner&.real_name)
content = email
content.gsub!('{receiver}', receiver&.real_name)
content.gsub!('{baseurl}', base_url)
content.gsub!('{login}', project&.owner&.login)
content.gsub!('{nickname}', project&.owner&.real_name)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{repository}', project&.name)
content.gsub!('{role}', role)
return receiver&.mail, title, content
else
return '', '', ''
end
title = email_title
title.gsub!('{repository}', project&.name)
title.gsub!('{role}', role)
title.gsub!('{nickname}', project&.owner&.real_name)
content = email
content.gsub!('{receiver}', receiver&.real_name)
content.gsub!('{baseurl}', base_url)
content.gsub!('{login}', project&.owner&.login)
content.gsub!('{nickname}', project&.owner&.real_name)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{repository}', project&.name)
content.gsub!('{role}', role)
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::ProjectRole.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -159,152 +159,150 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate
end
def self.get_email_message_content(receiver, operator, project, change_params)
return '', '', '' if change_params.blank?
if receiver.user_template_message_setting.present?
return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::SettingChanged"]
owner = project&.owner
title = email_title
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!('{login2}', owner&.login)
content.gsub!('{nickname2}', owner&.real_name)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{repository}', project&.name)
change_count = change_params.keys.size
# 项目名称更改
if change_params[:name].present?
if change_count > 1
content.sub!('{ifname}', '<br/>')
else
content.sub!('{ifname}', '')
end
content.sub!('{endname}', '')
content.gsub!('{name}', change_params[:name][1])
else
content.gsub!(/({ifname})(.*)({endname})/, '')
end
# 项目标识更改
if change_params[:identifier].present?
if change_count > 1
content.sub!('{ifidentifier}', '<br/>')
else
content.sub!('{ifidentifier}', '')
end
content.sub!('{endidentifier}', '')
content.gsub!('{identifier}', change_params[:identifier][1])
else
content.gsub!(/({ifidentifier})(.*)({endidentifier})/, '')
end
# 项目简介更改
if change_params[:description].present?
if change_params[:description][1].blank?
if change_count > 1
content.gsub!(/({ifdescription})(.*)({enddescription})/, '<br/>删除了项目简介')
else
content.gsub!(/({ifdescription})(.*)({enddescription})/, '删除了项目简介')
end
else
if change_count > 1
content.sub!('{ifdescription}', '<br/>')
else
content.sub!('{ifdescription}', '')
end
content.sub!('{enddescription}', '')
content.gsub!('{description}', change_params[:description][1])
end
else
content.gsub!(/({ifdescription})(.*)({enddescription})/, '')
end
# 项目类别更改
if change_params[:project_category_id].present?
category = ProjectCategory.find_by_id(change_params[:project_category_id][1])
if category.present?
if change_count > 1
content.sub!('{ifcategory}', '<br/>')
else
content.sub!('{ifcategory}', '')
end
content.sub!('{endcategory}', '')
content.gsub!('{category}', category&.name)
else
if change_count > 1
content.gsub!(/({ifcategory})(.*)({endcategory})/, '<br/>删除了项目类别')
else
content.gsub!(/({ifcategory})(.*)({endcategory})/, '删除了项目类别')
end
end
else
content.gsub!(/({ifcategory})(.*)({endcategory})/, '')
end
# 项目语言更改
if change_params[:project_language_id].present?
language = ProjectLanguage.find_by_id(change_params[:project_language_id][1])
if language.present?
if change_count > 1
content.sub!('{iflanguage}', '<br/>')
else
content.sub!('{iflanguage}', '')
end
content.sub!('{endlanguage}', '')
content.gsub!('{language}', language&.name)
else
if change_count > 1
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '<br/>删除了项目语言')
else
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '删除了项目语言')
end
end
else
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '')
end
# 项目公私有更改
if change_params[:is_public].present?
permission = change_params[:is_public][1] ? '公有' : '私有'
if change_count > 1
content.sub!('{ifpermission}', '<br/>')
else
content.sub!('{ifpermission}', '')
end
content.sub!('{endpermission}', '')
content.gsub!('{permission}', permission)
else
content.gsub!(/({ifpermission})(.*)({endpermission})/, '')
end
# 项目导航更改
if change_params[:navbar].present?
unit_types = project.project_units.order(unit_type: :asc).pluck(:unit_type)
unit_types.delete('code')
unit_types.unshift('代码库')
unit_types.unshift('主页')
unit_types.append('动态')
navbar = unit_types.join('')
navbar.gsub!('issues', '易修')
navbar.gsub!('pulls', '合并请求')
navbar.gsub!('wiki', 'Wiki')
navbar.gsub!('devops', '工作流')
navbar.gsub!('versions', '里程碑')
navbar.gsub!('resources', '资源库')
if change_count > 1
content.sub!('{ifnavbar}', '<br/>')
else
content.sub!('{ifnavbar}', '')
end
content.sub!('{endnavbar}', '')
content.gsub!('{navbar}', navbar)
else
content.gsub!(/({ifnavbar})(.*)({endnavbar})/, '')
end
return receiver&.mail, title, content
else
return '', '', ''
end
return '', '', '' if change_params.blank?
owner = project&.owner
title = email_title
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!('{login2}', owner&.login)
content.gsub!('{nickname2}', owner&.real_name)
content.gsub!('{identifier}', project&.identifier)
content.gsub!('{repository}', project&.name)
change_count = change_params.keys.size
# 项目名称更改
if change_params[:name].present?
if change_count > 1
content.sub!('{ifname}', '<br/>')
else
content.sub!('{ifname}', '')
end
content.sub!('{endname}', '')
content.gsub!('{name}', change_params[:name][1])
else
content.gsub!(/({ifname})(.*)({endname})/, '')
end
# 项目标识更改
if change_params[:identifier].present?
if change_count > 1
content.sub!('{ifidentifier}', '<br/>')
else
content.sub!('{ifidentifier}', '')
end
content.sub!('{endidentifier}', '')
content.gsub!('{identifier}', change_params[:identifier][1])
else
content.gsub!(/({ifidentifier})(.*)({endidentifier})/, '')
end
# 项目简介更改
if change_params[:description].present?
if change_params[:description][1].blank?
if change_count > 1
content.gsub!(/({ifdescription})(.*)({enddescription})/, '<br/>删除了项目简介')
else
content.gsub!(/({ifdescription})(.*)({enddescription})/, '删除了项目简介')
end
else
if change_count > 1
content.sub!('{ifdescription}', '<br/>')
else
content.sub!('{ifdescription}', '')
end
content.sub!('{enddescription}', '')
content.gsub!('{description}', change_params[:description][1])
end
else
content.gsub!(/({ifdescription})(.*)({enddescription})/, '')
end
# 项目类别更改
if change_params[:project_category_id].present?
category = ProjectCategory.find_by_id(change_params[:project_category_id][1])
if category.present?
if change_count > 1
content.sub!('{ifcategory}', '<br/>')
else
content.sub!('{ifcategory}', '')
end
content.sub!('{endcategory}', '')
content.gsub!('{category}', category&.name)
else
if change_count > 1
content.gsub!(/({ifcategory})(.*)({endcategory})/, '<br/>删除了项目类别')
else
content.gsub!(/({ifcategory})(.*)({endcategory})/, '删除了项目类别')
end
end
else
content.gsub!(/({ifcategory})(.*)({endcategory})/, '')
end
# 项目语言更改
if change_params[:project_language_id].present?
language = ProjectLanguage.find_by_id(change_params[:project_language_id][1])
if language.present?
if change_count > 1
content.sub!('{iflanguage}', '<br/>')
else
content.sub!('{iflanguage}', '')
end
content.sub!('{endlanguage}', '')
content.gsub!('{language}', language&.name)
else
if change_count > 1
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '<br/>删除了项目语言')
else
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '删除了项目语言')
end
end
else
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '')
end
# 项目公私有更改
if change_params[:is_public].present?
permission = change_params[:is_public][1] ? '公有' : '私有'
if change_count > 1
content.sub!('{ifpermission}', '<br/>')
else
content.sub!('{ifpermission}', '')
end
content.sub!('{endpermission}', '')
content.gsub!('{permission}', permission)
else
content.gsub!(/({ifpermission})(.*)({endpermission})/, '')
end
# 项目导航更改
if change_params[:navbar].present?
unit_types = project.project_units.order(unit_type: :asc).pluck(:unit_type)
unit_types.delete('code')
unit_types.unshift('代码库')
unit_types.unshift('主页')
unit_types.append('动态')
navbar = unit_types.join('')
navbar.gsub!('issues', '易修')
navbar.gsub!('pulls', '合并请求')
navbar.gsub!('wiki', 'Wiki')
navbar.gsub!('devops', '工作流')
navbar.gsub!('versions', '里程碑')
navbar.gsub!('resources', '资源库')
if change_count > 1
content.sub!('{ifnavbar}', '<br/>')
else
content.sub!('{ifnavbar}', '')
end
content.sub!('{endnavbar}', '')
content.gsub!('{navbar}', navbar)
else
content.gsub!(/({ifnavbar})(.*)({endnavbar})/, '')
end
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::ProjectSettingChanged.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -36,28 +36,26 @@ class MessageTemplate::PullRequestAssigned < MessageTemplate
def self.get_email_message_content(receiver, operator, pull_request)
if receiver.user_template_message_setting.present?
return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::PullRequestAssigned"]
project = pull_request&.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}', pull_request&.title)
content.gsub!('{id}', pull_request&.id.to_s)
return receiver&.mail, title, content
else
return '', '', ''
end
project = pull_request&.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}', pull_request&.title)
content.gsub!('{id}', pull_request&.id.to_s)
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::PullRequestAssigned.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -103,92 +103,89 @@ class MessageTemplate::PullRequestChanged < MessageTemplate
return '', '', '' if change_params.blank?
if receiver.user_template_message_setting.present?
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::PullRequestChanged"]
project = pull_request&.project
owner = project&.owner
title = email_title
title.gsub!('{title}', pull_request&.title)
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}', pull_request&.title)
content.gsub!('{id}', pull_request&.id.to_s)
change_count = change_params.keys.size
# 合并请求审查成员修改
if change_params[:assigned_to_id].present?
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
if change_count > 1
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 : '未指派成员')
end
project = pull_request&.project
owner = project&.owner
title = email_title
title.gsub!('{title}', pull_request&.title)
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}', pull_request&.title)
content.gsub!('{id}', pull_request&.id.to_s)
change_count = change_params.keys.size
# 合并请求审查成员修改
if change_params[:assigned_to_id].present?
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
if change_count > 1
content.sub!('{ifassigner}', '<br/>')
else
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
content.sub!('{ifassigner}', '')
end
# 合并请求里程碑修改
if change_params[:fixed_version_id].present?
fix_version1 = Version.find_by_id(change_params[:fixed_version_id][0])
fix_version2 = Version.find_by_id(change_params[:fixed_version_id][1])
if change_count > 1
content.sub!('{ifmilestone}', '<br/>')
else
content.sub!('{ifmilestone}', '')
end
content.sub!('{endmilestone}', '')
content.gsub!('{milestone1}', fix_version1.present? ? fix_version1&.name : '未选择里程碑')
content.gsub!('{milestone2}', fix_version2.present? ? fix_version2&.name : '未选择里程碑')
else
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
end
# 合并请求标记修改
if change_params[:issue_tags_value].present?
issue_tags1 = IssueTag.where(id: change_params[:issue_tags_value][0]).distinct
issue_tags2 = IssueTag.where(id: change_params[:issue_tags_value][1]).distinct
tag1 = issue_tags1.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags1.pluck(:name).join(",")
tag2 = issue_tags2.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags2.pluck(:name).join(",")
if change_count > 1
content.sub!('{iftag}', '<br/>')
else
content.sub!('{iftag}', '')
end
content.sub!('{endtag}', '')
content.gsub!('{tag1}', tag1)
content.gsub!('{tag2}', tag2)
else
content.gsub!(/({iftag})(.*)({endtag})()/, '')
end
# 合并请求优先级修改
if change_params[:priority_id].present?
priority1 = IssuePriority.find_by_id(change_params[:priority_id][0])
priority2 = IssuePriority.find_by_id(change_params[:priority_id][1])
if change_count > 1
content.sub!('{ifpriority}', '<br/>')
else
content.sub!('{ifpriority}', '')
end
content.sub!('{ifpriority}', '')
content.sub!('{endpriority}', '')
content.gsub!('{priority1}', priority1&.name)
content.gsub!('{priority2}', priority2&.name)
else
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
end
return receiver&.mail, title, content
content.sub!('{endassigner}', '')
content.gsub!('{assigner1}', assigner1.present? ? assigner1&.real_name : '未指派成员')
content.gsub!('{assigner2}', assigner2.present? ? assigner2&.real_name : '未指派成员')
else
return '', '', ''
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
end
# 合并请求里程碑修改
if change_params[:fixed_version_id].present?
fix_version1 = Version.find_by_id(change_params[:fixed_version_id][0])
fix_version2 = Version.find_by_id(change_params[:fixed_version_id][1])
if change_count > 1
content.sub!('{ifmilestone}', '<br/>')
else
content.sub!('{ifmilestone}', '')
end
content.sub!('{endmilestone}', '')
content.gsub!('{milestone1}', fix_version1.present? ? fix_version1&.name : '未选择里程碑')
content.gsub!('{milestone2}', fix_version2.present? ? fix_version2&.name : '未选择里程碑')
else
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
end
# 合并请求标记修改
if change_params[:issue_tags_value].present?
issue_tags1 = IssueTag.where(id: change_params[:issue_tags_value][0]).distinct
issue_tags2 = IssueTag.where(id: change_params[:issue_tags_value][1]).distinct
tag1 = issue_tags1.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags1.pluck(:name).join(",")
tag2 = issue_tags2.pluck(:name).join(",").blank? ? '未选择标记' : issue_tags2.pluck(:name).join(",")
if change_count > 1
content.sub!('{iftag}', '<br/>')
else
content.sub!('{iftag}', '')
end
content.sub!('{endtag}', '')
content.gsub!('{tag1}', tag1)
content.gsub!('{tag2}', tag2)
else
content.gsub!(/({iftag})(.*)({endtag})()/, '')
end
# 合并请求优先级修改
if change_params[:priority_id].present?
priority1 = IssuePriority.find_by_id(change_params[:priority_id][0])
priority2 = IssuePriority.find_by_id(change_params[:priority_id][1])
if change_count > 1
content.sub!('{ifpriority}', '<br/>')
else
content.sub!('{ifpriority}', '')
end
content.sub!('{ifpriority}', '')
content.sub!('{endpriority}', '')
content.gsub!('{priority1}', priority1&.name)
content.gsub!('{priority2}', priority2&.name)
else
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
end
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::PullRequestChanged.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -36,27 +36,24 @@ class MessageTemplate::PullRequestClosed < MessageTemplate
def self.get_email_message_content(receiver, operator, pull_request)
if receiver.user_template_message_setting.present?
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::PullRequestChanged"]
project = pull_request&.project
owner = project&.owner
title = email_title
title.gsub!('{title}', pull_request&.title)
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}', pull_request&.title)
content.gsub!('{id}', pull_request&.id.to_s)
return receiver&.mail, title, content
else
return '', '', ''
end
project = pull_request&.project
owner = project&.owner
title = email_title
title.gsub!('{title}', pull_request&.title)
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}', pull_request&.title)
content.gsub!('{id}', pull_request&.id.to_s)
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::PullRequestClosed.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -36,26 +36,24 @@ class MessageTemplate::PullRequestMerged < MessageTemplate
def self.get_email_message_content(receiver, operator, pull_request)
if receiver.user_template_message_setting.present?
return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::PullRequestChanged"]
project = pull_request&.project
owner = project&.owner
title = email_title
title.gsub!('{title}', pull_request&.title)
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}', pull_request&.title)
content.gsub!('{id}', pull_request&.id.to_s)
return receiver&.mail, title, content
else
return '', '', ''
end
project = pull_request&.project
owner = project&.owner
title = email_title
title.gsub!('{title}', pull_request&.title)
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}', pull_request&.title)
content.gsub!('{id}', pull_request&.id.to_s)
return receiver&.mail, title, content
rescue => e
Rails.logger.info("MessageTemplate::PullRequestMerged.get_email_message_content [ERROR] #{e}")
return '', '', ''

View File

@ -1,4 +1,3 @@
# == Schema Information
#
# Table name: projects
@ -38,8 +37,6 @@
# rep_identifier :string(255)
# project_category_id :integer
# project_language_id :integer
# license_id :integer
# ignore_id :integer
# praises_count :integer default("0")
# watchers_count :integer default("0")
# issues_count :integer default("0")
@ -53,6 +50,8 @@
# open_devops_count :integer default("0")
# recommend :boolean default("0")
# platform :integer default("0")
# license_id :integer
# ignore_id :integer
# default_branch :string(255) default("master")
# website :string(255)
# lesson_url :string(255)

View File

@ -37,7 +37,7 @@ class PullRequest < ApplicationRecord
has_many :pull_request_tags, foreign_key: :pull_request_id
has_many :project_trends, as: :trend, dependent: :destroy
has_many :attachments, as: :container, dependent: :destroy
has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_number, class_name: 'Gitea::Pull'
has_one :gitea_pull, foreign_key: :id, primary_key: :gitea_id, class_name: 'Gitea::Pull'
scope :merged_and_closed, ->{where.not(status: 0)}
scope :opening, -> {where(status: 0)}

View File

@ -65,7 +65,7 @@ class Site < ApplicationRecord
commons = [
{name: '通知', key: 'notice', url: '/users/current_user/user_messages'},
{name: '找回密码', key: 'lost_password', url: '/account/lost_password'},
{name: '注册', key: 'register', url: '/login?login=false'}
{name: '注册', key: 'register', url: '/register'}
]
commons.each { |ele|

View File

@ -76,7 +76,7 @@ class Token < ActiveRecord::Base
# Returns the active user who owns the key for the given action
def self.find_active_user(action, key, validity_days=nil)
user = find_user(action, key, validity_days)
if user && user.active?
if user && (user.active? || user.need_edit_info?)
user
end
end

50
app/models/topic.rb Normal file
View File

@ -0,0 +1,50 @@
# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#
class Topic < ApplicationRecord
default_scope { order(order_index: :desc)}
scope :with_single_type, ->(type){where(type: trans_simpletype_to_classtype(type))}
def image
image_url('image')
end
def self.trans_simpletype_to_classtype(type)
case type
when 'activity_forum'
'Topic::ActivityForum'
when 'banner'
'Topic::Banner'
when 'card'
'Topic::Card'
when 'cooperator'
'Topic::Cooperator'
when 'excellent_project'
'Topic::ExcellentProject'
when 'experience_forum'
'Topic::ExperienceForum'
when 'pinned_forum'
'Topic::PinnedForum'
end
end
private
def image_url(type)
return nil unless Util::FileManage.exists?(self, type)
Util::FileManage.source_disk_file_url(self, type)
end
end

View File

@ -0,0 +1,17 @@
# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#
# 首页平台动态
class Topic::ActivityForum < Topic
end

View File

@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#
# 首页banner
class Topic::Banner < Topic
end

16
app/models/topic/card.rb Normal file
View File

@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#
# 首页卡片内容
class Topic::Card < Topic
end

View File

@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#
# 首页合作伙伴
class Topic::Cooperator < Topic
end

View File

@ -0,0 +1,17 @@
# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#
# 首页优秀项目
class Topic::ExcellentProject < Topic
end

View File

@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#
# 首页经验分享
class Topic::ExperienceForum < Topic
end

View File

@ -0,0 +1,16 @@
# == Schema Information
#
# Table name: topics
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# uuid :integer
# image_url :string(255)
# url :string(255)
# order_index :integer
#
# 首页精选文章
class Topic::PinnedForum < Topic
end

View File

@ -83,6 +83,7 @@ class User < Owner
STATUS_ACTIVE = 1
STATUS_REGISTERED = 2
STATUS_LOCKED = 3
STATUS_EDIT_INFO = 4
# tpi tpm权限控制
EDU_ADMIN = 1 # 超级管理员
@ -175,7 +176,7 @@ class User < Owner
has_many :system_notifications, through: :system_notification_histories
# Groups and active users
scope :active, lambda { where(status: STATUS_ACTIVE) }
scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) }
scope :like, lambda { |keywords|
sql = "CONCAT(lastname, firstname) LIKE :search OR nickname LIKE :search OR login LIKE :search OR mail LIKE :search OR nickname LIKE :search"
where(sql, :search => "%#{keywords.split(" ").join('|')}%") unless keywords.blank?
@ -418,6 +419,10 @@ class User < Owner
status == STATUS_LOCKED
end
def need_edit_info?
status == STATUS_EDIT_INFO
end
def activate
self.status = STATUS_ACTIVE
end
@ -430,6 +435,10 @@ class User < Owner
self.status = STATUS_LOCKED
end
def need_edit_info
self.status = STATUS_EDIT_INFO
end
def activate!
update_attribute(:status, STATUS_ACTIVE)
prohibit_gitea_user_login!(false)
@ -449,6 +458,10 @@ class User < Owner
{email: self.mail, prohibit_login: prohibit_login})
end
def need_edit_info!
update_attribute(:status, STATUS_EDIT_INFO)
end
# 课程用户身份
def course_identity(course)
if !logged?

View File

@ -44,17 +44,17 @@ class UserTemplateMessageSetting < ApplicationRecord
def self.init_email_body
{
"Normal::Permission": false,
"Normal::Project": false,
"Normal::Organization": false,
"Normal::IssueAssigned": false,
"Normal::PullRequestAssigned": false,
"CreateOrAssign::IssueChanged": false,
"CreateOrAssign::PullRequestChanged": false,
"ManageProject::Issue": false,
"ManageProject::PullRequest": false,
"ManageProject::Member": false,
"ManageProject::SettingChanged": false,
"Normal::Permission": true,
"Normal::Project": true,
"Normal::Organization": true,
"Normal::IssueAssigned": true,
"Normal::PullRequestAssigned": true,
"CreateOrAssign::IssueChanged": true,
"CreateOrAssign::PullRequestChanged": true,
"ManageProject::Issue": true,
"ManageProject::PullRequest": true,
"ManageProject::Member": true,
"ManageProject::SettingChanged": true,
}.stringify_keys!
end

View File

@ -0,0 +1,30 @@
module Accounts
class ResetPasswordService < ApplicationService
# login、code、password、password_confirmation
def initialize(user, params)
@user = user
@password = params[:password]
@password_confirmation = params[:password_confirmation]
end
def call
return if @user.blank?
password = strip(@password)
password_confirmation = strip(@password_confirmation)
Rails.logger.info "Accounts::ResetPasswordService params:
##### password: #{@password} password_confirmation: #{@password_confirmation}"
@user.password, @user.password_confirmation = password, password_confirmation
sync_params = {
password: password,
email: @user.mail
}
interactor = Gitea::User::UpdateInteractor.call(@user.login, sync_params)
raise ActiveRecord::Rollback unless interactor.success?
@user
end
end
end

View File

@ -18,4 +18,9 @@ class ApplicationService
def str_to_boolean str
ActiveModel::Type::Boolean.new.cast str
end
def phone_mail_type value
value =~ /^1\d{10}$/ ? 1 : 0
end
end

View File

@ -196,7 +196,6 @@ class Cache::V2::ProjectCommonService < ApplicationService
def reset_project_common
load_project
return unless @project.present?
return unless @project.is_full_public
$redis_cache.del(project_common_key)
reset_project_owner_id

View File

@ -0,0 +1,94 @@
class Forum::ClientService < ApplicationService
attr_reader :url, :params
PAGINATE_DEFAULT_PAGE = 1
PAGINATE_DEFAULT_LIMIT = 20
def initialize(options={})
@url = options[:url]
@params = options[:params]
end
def get(url, params={})
conn(params).get do |req|
req.url full_url(url, 'get')
params.except(:token).each_pair do |key, value|
req.params["#{key}"] = value
end
end
# response.headers.each do |k,v|
# puts "#{k}:#{v}"
# end #=> 响应头
end
private
def conn(auth={})
@client ||= begin
Faraday.new(url: domain) do |req|
req.request :url_encoded
req.headers['Content-Type'] = 'application/json'
req.response :logger # 显示日志
req.adapter Faraday.default_adapter
end
end
@client
end
def base_url
Forum.forum_config[:base_url]
end
def domain
Forum.forum_config[:domain]
end
def api_url
[domain, base_url].join('')
end
def full_url(api_rest, action='post')
url = [api_url, api_rest].join('').freeze
url = action === 'get' ? url : URI.escape(url)
url = URI.escape(url) unless url.ascii_only?
puts "[forum] request url: #{url}"
return url
end
def render_response(response)
status = response.status
body = response&.body
# log_error(status, body)
body, message = get_body_by_status(status, body)
[status, message, body]
end
def get_body_by_status(status, body)
body, message =
case status
when 401 then [nil, "401"]
when 404 then [nil, "404"]
when 403 then [nil, "403"]
when 500 then [nil, "500"]
else
if body.present?
body = JSON.parse(body)
fix_body(body)
else
nil
end
end
[body, message]
end
def fix_body(body)
return [body, nil] if body.is_a?(Array) || body.is_a?(Hash)
body['message'].blank? ? [body, nil] : [nil, body['message']]
end
end

View File

@ -0,0 +1,21 @@
class Forum::Memos::GetService < Forum::ClientService
attr_reader :memo_id
def initialize(memo_id)
@memo_id = memo_id
end
def call
response = get(url)
code, message, body = render_response(response)
if code == 200 && body["status"] == 0
return body
else
return nil
end
end
def url
"/memos/#{memo_id}.json".freeze
end
end

View File

@ -12,7 +12,8 @@ class Users::RegisterService < ApplicationService
namespace = strip(@namespace)
password = strip(@password)
Rails.logger.info "Users::RegisterService params: ##### #{params} "
Rails.logger.info "Users::RegisterService params:
##### code: #{code} login: #{login} namespace: #{namespace} password: #{password} "
email, phone =
if register_type == 1
@ -50,9 +51,4 @@ class Users::RegisterService < ApplicationService
def register_type
phone_mail_type(@login)
end
def phone_mail_type value
value =~ /^1\d{10}$/ ? 1 : 0
end
end

View File

@ -31,7 +31,18 @@
<li><%= sidebar_item(admins_reversed_keywords_path, '系统保留关键词', icon: 'key', controller: 'admins-reversed_keywords') %></li>
<li><%= sidebar_item(admins_laboratories_path, '云上实验室', icon: 'cloud', controller: 'admins-laboratories') %></li>
<li>
<%= sidebar_item_group('#setting-index', '首页配置', icon: 'file') do %>
<li><%= sidebar_item(admins_topic_banners_path, 'banner管理', icon: 'image', controller: 'admins-topic-banners') %></li>
<li><%= sidebar_item(admins_topic_cards_path, '卡片管理', icon: 'archive', controller: 'admins-topic-cards') %></li>
<li><%= sidebar_item(admins_topic_activity_forums_path, '平台动态管理', icon: 'bell', controller: 'admins-topic-activity_forums') %></li>
<li><%= sidebar_item(admins_topic_excellent_projects_path, '优秀仓库管理', icon: 'git', controller: 'admins-topic-excellent_projects') %></li>
<li><%= sidebar_item(admins_topic_pinned_forums_path, '精选文章管理', icon: 'edit', controller: 'admins-topic-pinned_forums') %></li>
<li><%= sidebar_item(admins_topic_experience_forums_path, '经验分享管理', icon: 'edit', controller: 'admins-topic-experience_forums') %></li>
<li><%= sidebar_item(admins_topic_cooperators_path, '合作伙伴管理', icon: 'user', controller: 'admins-topic-cooperators') %></li>
<% end %>
</li>
<li>
<%= sidebar_item_group('#setting-submenu', '网站建设', icon: 'cogs') do %>
<li><%= sidebar_item(admins_faqs_path, 'FAQ', icon: 'question-circle', controller: 'admins-faqs') %></li>

View File

@ -0,0 +1,44 @@
<div class="modal fade activity-forum-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<%= form_for @activity_forum, url: {controller: "topic/activity_forums", action: "#{type}"} do |p| %>
<div class="modal-body">
<div class="form-group">
<label>
标题 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :title,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
跳转地址 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :url,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
帖子ID <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :uuid,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
排序等级
</label>
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
</div>
<% end %>
</div>
</div>
</div>

View File

@ -0,0 +1,33 @@
<table class="table table-hover text-center subject-list-table">
<thead class="thead-light">
<tr>
<th width="5%">序号</th>
<th width="20%">标题</th>
<th width="20%">跳转地址</th>
<th width="10%">帖子ID</th>
<th width="20%">排序等级</th>
<th width="25%">操作</th>
</tr>
</thead>
<tbody>
<% if activity_forums.present? %>
<% activity_forums.each_with_index do |activity_forum, index| %>
<tr class="activity-forum-item-<%= activity_forum.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td><%= activity_forum.title %></td>
<td><%= activity_forum.url %></td>
<td><%= activity_forum.uuid %></td>
<td><%= activity_forum.order_index %></td>
<td class="action-container">
<%= link_to "编辑", edit_admins_topic_activity_forum_path(activity_forum), remote: true, class: "action" %>
<%= link_to "删除", admins_topic_activity_forum_path(activity_forum), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: activity_forums } %>

View File

@ -0,0 +1,2 @@
$("#activity-forum-modals").html("<%= j render(partial: 'admins/topic/activity_forums/form_modal', locals: {type: 'update'}) %>")
$(".activity-forum-change-modal").modal('show');

View File

@ -0,0 +1,18 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('平台动态管理') %>
<% end %>
<div class="box search-form-container project-list-form">
<%= form_tag(admins_topic_activity_forums_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
<% end %>
<%= link_to "新增", new_admins_topic_activity_forum_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
</div>
<div class="box admin-list-container activity-forum-list-container">
<%= render partial: 'admins/topic/activity_forums/list', locals: { activity_forums: @activity_forums } %>
</div>
<div id="activity-forum-modals">
</div>

View File

@ -0,0 +1 @@
$('.activity-forum-list-container').html("<%= j( render partial: 'admins/topic/activity_forums/list', locals: { activity_forums: @activity_forums } ) %>");

View File

@ -0,0 +1,2 @@
$("#activity-forum-modals").html("<%= j render(partial: 'admins/topic/activity_forums/form_modal', locals: {type: 'create'}) %>")
$(".activity-forum-change-modal").modal('show');

View File

@ -0,0 +1,45 @@
<div class="modal fade banner-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<%= form_for @banner, url: {controller: "topic/banners", action: "#{type}"}, html: { enctype: 'multipart/form-data' } do |p| %>
<div class="modal-body">
<div class="form-group">
<label>
标题 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :title,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
排序等级
</label>
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
</div>
<div class="logo-item">
<% logo_img = @banner.image %>
<div class="logo-item-left mr-3 <%= logo_img ? 'has-img' : '' %>">
<img class="logo-item-img nav-logo-img" src="<%= logo_img %>" style="<%= logo_img.present? ? '' : 'display: none' %>"/>
<%= file_field_tag(:image, accept: 'image/png,image/jpg,image/jpeg',style: "display: none", value: params[:image]) %>
<label for="image" class="logo-item-upload" data-toggle="tooltip" data-title="选择图片"></label>
</div>
<div class="logo-item-right">
<div class="logo-item-title flex-1">logo</div>
<div>格式PNG、JPG</div>
<div>尺寸高度38px以内宽等比例缩放</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
</div>
<% end %>
</div>
</div>
</div>

View File

@ -0,0 +1,31 @@
<table class="table table-hover text-center subject-list-table">
<thead class="thead-light">
<tr>
<th width="5%">序号</th>
<th width="20%">标题</th>
<th width="20%">图片</th>
<th width="20%">排序等级</th>
<th width="25%">操作</th>
</tr>
</thead>
<tbody>
<% if banners.present? %>
<% banners.each_with_index do |banner, index| %>
<tr class="banner-item-<%= banner.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td><%= banner.title %></td>
<td><img style="width:150px" src="<%= banner.image %>" /></td>
<td><%= banner.order_index %></td>
<td class="action-container">
<%= link_to "编辑", edit_admins_topic_banner_path(banner), remote: true, class: "action" %>
<%= link_to "删除", admins_topic_banner_path(banner), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: banners } %>

View File

@ -0,0 +1,18 @@
$("#banner-modals").html("<%= j render(partial: 'admins/topic/banners/form_modal', locals: {type: 'update'}) %>")
$(".banner-change-modal").modal('show');
$('.logo-item-left').on("change", 'input[type="file"]', function () {
var $fileInput = $(this);
var file = this.files[0];
var imageType = /image.*/;
if (file && file.type.match(imageType)) {
var reader = new FileReader();
reader.onload = function () {
var $box = $fileInput.parent();
$box.find('img').attr('src', reader.result).css('display', 'block');
$box.addClass('has-img');
};
reader.readAsDataURL(file);
} else {
}
});

View File

@ -0,0 +1,18 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('卡片管理') %>
<% end %>
<div class="box search-form-container project-list-form">
<%= form_tag(admins_topic_banners_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
<% end %>
<%= link_to "新增", new_admins_topic_banner_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
</div>
<div class="box admin-list-container banner-list-container">
<%= render partial: 'admins/topic/banners/list', locals: { banners: @banners } %>
</div>
<div id="banner-modals">
</div>

View File

@ -0,0 +1 @@
$('.banner-list-container').html("<%= j( render partial: 'admins/topic/banners/list', locals: { banners: @banners } ) %>");

View File

@ -0,0 +1,18 @@
$("#banner-modals").html("<%= j render(partial: 'admins/topic/banners/form_modal', locals: {type: 'create'}) %>")
$(".banner-change-modal").modal('show');
$('.logo-item-left').on("change", 'input[type="file"]', function () {
var $fileInput = $(this);
var file = this.files[0];
var imageType = /image.*/;
if (file && file.type.match(imageType)) {
var reader = new FileReader();
reader.onload = function () {
var $box = $fileInput.parent();
$box.find('img').attr('src', reader.result).css('display', 'block');
$box.addClass('has-img');
};
reader.readAsDataURL(file);
} else {
}
});

View File

@ -0,0 +1,38 @@
<div class="modal fade card-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<%= form_for @card, url: {controller: "topic/cards", action: "#{type}"} do |p| %>
<div class="modal-body">
<div class="form-group">
<label>
标题 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :title,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
跳转地址 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :url,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
排序等级
</label>
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
</div>
<% end %>
</div>
</div>
</div>

View File

@ -0,0 +1,31 @@
<table class="table table-hover text-center subject-list-table">
<thead class="thead-light">
<tr>
<th width="5%">序号</th>
<th width="20%">标题</th>
<th width="20%">跳转地址</th>
<th width="20%">排序等级</th>
<th width="25%">操作</th>
</tr>
</thead>
<tbody>
<% if cards.present? %>
<% cards.each_with_index do |card, index| %>
<tr class="card-item-<%= card.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td><%= card.title %></td>
<td><%= card.url %></td>
<td><%= card.order_index %></td>
<td class="action-container">
<%= link_to "编辑", edit_admins_topic_card_path(card), remote: true, class: "action" %>
<%= link_to "删除", admins_topic_card_path(card), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: cards } %>

View File

@ -0,0 +1,2 @@
$("#card-modals").html("<%= j render(partial: 'admins/topic/cards/form_modal', locals: {type: 'update'}) %>")
$(".card-change-modal").modal('show');

View File

@ -0,0 +1,18 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('卡片管理') %>
<% end %>
<div class="box search-form-container project-list-form">
<%= form_tag(admins_topic_cards_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
<% end %>
<%= link_to "新增", new_admins_topic_card_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
</div>
<div class="box admin-list-container card-list-container">
<%= render partial: 'admins/topic/cards/list', locals: { cards: @cards } %>
</div>
<div id="card-modals">
</div>

View File

@ -0,0 +1 @@
$('.card-list-container').html("<%= j( render partial: 'admins/topic/cards/list', locals: { cards: @cards } ) %>");

View File

@ -0,0 +1,2 @@
$("#card-modals").html("<%= j render(partial: 'admins/topic/cards/form_modal', locals: {type: 'create'}) %>")
$(".card-change-modal").modal('show');

View File

@ -0,0 +1,51 @@
<div class="modal fade cooperator-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<%= form_for @cooperator, url: {controller: "topic/cooperators", action: "#{type}"}, html: { enctype: 'multipart/form-data' } do |p| %>
<div class="modal-body">
<div class="form-group">
<label>
标题 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :title,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
跳转地址 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :url,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
排序等级
</label>
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
</div>
<div class="logo-item">
<% logo_img = @cooperator.image %>
<div class="logo-item-left mr-3 <%= logo_img ? 'has-img' : '' %>">
<img class="logo-item-img nav-logo-img" src="<%= logo_img %>" style="<%= logo_img.present? ? '' : 'display: none' %>"/>
<%= file_field_tag(:image, accept: 'image/png,image/jpg,image/jpeg',style: "display: none", value: params[:image]) %>
<label for="image" class="logo-item-upload" data-toggle="tooltip" data-title="选择图片"></label>
</div>
<div class="logo-item-right">
<div class="logo-item-title flex-1">logo</div>
<div>格式PNG、JPG</div>
<div>尺寸高度38px以内宽等比例缩放</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
</div>
<% end %>
</div>
</div>
</div>

View File

@ -0,0 +1,33 @@
<table class="table table-hover text-center subject-list-table">
<thead class="thead-light">
<tr>
<th width="5%">序号</th>
<th width="20%">标题</th>
<th width="20%">跳转地址</th>
<th width="20%">图片</th>
<th width="20%">排序等级</th>
<th width="25%">操作</th>
</tr>
</thead>
<tbody>
<% if cooperators.present? %>
<% cooperators.each_with_index do |cooperator, index| %>
<tr class="cooperator-item-<%= cooperator.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td><%= cooperator.title %></td>
<td><%= cooperator.url %></td>
<td><img style="width:150px" src="<%= cooperator.image %>" /></td>
<td><%= cooperator.order_index %></td>
<td class="action-container">
<%= link_to "编辑", edit_admins_topic_cooperator_path(cooperator), remote: true, class: "action" %>
<%= link_to "删除", admins_topic_cooperator_path(cooperator), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: cooperators } %>

View File

@ -0,0 +1,18 @@
$("#cooperator-modals").html("<%= j render(partial: 'admins/topic/cooperators/form_modal', locals: {type: 'update'}) %>")
$(".cooperator-change-modal").modal('show');
$('.logo-item-left').on("change", 'input[type="file"]', function () {
var $fileInput = $(this);
var file = this.files[0];
var imageType = /image.*/;
if (file && file.type.match(imageType)) {
var reader = new FileReader();
reader.onload = function () {
var $box = $fileInput.parent();
$box.find('img').attr('src', reader.result).css('display', 'block');
$box.addClass('has-img');
};
reader.readAsDataURL(file);
} else {
}
});

View File

@ -0,0 +1,18 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('卡片管理') %>
<% end %>
<div class="box search-form-container project-list-form">
<%= form_tag(admins_topic_cooperators_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
<% end %>
<%= link_to "新增", new_admins_topic_cooperator_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
</div>
<div class="box admin-list-container cooperator-list-container">
<%= render partial: 'admins/topic/cooperators/list', locals: { cooperators: @cooperators } %>
</div>
<div id="cooperator-modals">
</div>

View File

@ -0,0 +1 @@
$('.cooperator-list-container').html("<%= j( render partial: 'admins/topic/cooperators/list', locals: { cooperators: @cooperators } ) %>");

View File

@ -0,0 +1,18 @@
$("#cooperator-modals").html("<%= j render(partial: 'admins/topic/cooperators/form_modal', locals: {type: 'create'}) %>")
$(".cooperator-change-modal").modal('show');
$('.logo-item-left').on("change", 'input[type="file"]', function () {
var $fileInput = $(this);
var file = this.files[0];
var imageType = /image.*/;
if (file && file.type.match(imageType)) {
var reader = new FileReader();
reader.onload = function () {
var $box = $fileInput.parent();
$box.find('img').attr('src', reader.result).css('display', 'block');
$box.addClass('has-img');
};
reader.readAsDataURL(file);
} else {
}
});

View File

@ -0,0 +1,44 @@
<div class="modal fade excellent-project-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<%= form_for @excellent_project, url: {controller: "topic/excellent_projects", action: "#{type}"} do |p| %>
<div class="modal-body">
<div class="form-group">
<label>
标题 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :title,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
跳转地址 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :url,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
项目ID <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.number_field :uuid,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
排序等级
</label>
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
</div>
<% end %>
</div>
</div>
</div>

View File

@ -0,0 +1,33 @@
<table class="table table-hover text-center subject-list-table">
<thead class="thead-light">
<tr>
<th width="5%">序号</th>
<th width="20%">标题</th>
<th width="20%">跳转地址</th>
<th width="10%">项目ID</th>
<th width="20%">排序等级</th>
<th width="25%">操作</th>
</tr>
</thead>
<tbody>
<% if excellent_projects.present? %>
<% excellent_projects.each_with_index do |excellent_project, index| %>
<tr class="excellent-project-item-<%= excellent_project.id %>">
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
<td><%= excellent_project.title %></td>
<td><%= excellent_project.url %></td>
<td><%= excellent_project.uuid %></td>
<td><%= excellent_project.order_index %></td>
<td class="action-container">
<%= link_to "编辑", edit_admins_topic_excellent_project_path(excellent_project), remote: true, class: "action" %>
<%= link_to "删除", admins_topic_excellent_project_path(excellent_project), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %>
</td>
</tr>
<% end %>
<% else %>
<%= render 'admins/shared/no_data_for_table' %>
<% end %>
</tbody>
</table>
<%= render partial: 'admins/shared/paginate', locals: { objects: excellent_projects } %>

View File

@ -0,0 +1,2 @@
$("#excellent-project-modals").html("<%= j render(partial: 'admins/topic/excellent_projects/form_modal', locals: {type: 'update'}) %>")
$(".excellent-project-change-modal").modal('show');

View File

@ -0,0 +1,18 @@
<% define_admin_breadcrumbs do %>
<% add_admin_breadcrumb('优秀仓库管理') %>
<% end %>
<div class="box search-form-container project-list-form">
<%= form_tag(admins_topic_excellent_projects_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
<%= text_field_tag(:search, params[:search], class: 'form-control col-12 col-md-2 mr-3', placeholder: '标题检索') %>
<%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
<input type="reset" class="btn btn-secondary clear-btn" value="清空"/>
<% end %>
<%= link_to "新增", new_admins_topic_excellent_project_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
</div>
<div class="box admin-list-container excellent-project-list-container">
<%= render partial: 'admins/topic/excellent_projects/list', locals: { excellent_projects: @excellent_projects } %>
</div>
<div id="excellent-project-modals">
</div>

View File

@ -0,0 +1 @@
$('.excellent-project-list-container').html("<%= j( render partial: 'admins/topic/excellent_projects/list', locals: { excellent_projects: @excellent_projects } ) %>");

View File

@ -0,0 +1,2 @@
$("#excellent-project-modals").html("<%= j render(partial: 'admins/topic/excellent_projects/form_modal', locals: {type: 'create'}) %>")
$(".excellent-project-change-modal").modal('show');

View File

@ -0,0 +1,44 @@
<div class="modal fade experience-forum-change-modal" tabindex="-1" role="dialog" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title"><%= type == "create" ? "新增" : "编辑" %></h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<%= form_for @experience_forum, url: {controller: "topic/experience_forums", action: "#{type}"} do |p| %>
<div class="modal-body">
<div class="form-group">
<label>
标题 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :title,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
跳转地址 <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.text_field :url,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
帖子ID <span class="ml10 color-orange mr20">*</span>
</label>
<%= p.number_field :uuid,class: "form-control input-lg",required: true%>
</div>
<div class="form-group">
<label>
排序等级
</label>
<%= p.number_field :order_index, class: "form-control",placeholder: ""%>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
<%= p.submit "确认", class: "btn btn-primary submit-btn" %>
</div>
<% end %>
</div>
</div>
</div>

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