Merge branch 'pre_trustie_server' into trustie_server
This commit is contained in:
commit
b3dfc72546
|
@ -2,8 +2,24 @@ class Admins::MessageTemplatesController < Admins::BaseController
|
||||||
before_action :get_template, only: [:edit, :update, :destroy]
|
before_action :get_template, only: [:edit, :update, :destroy]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
message_templates = MessageTemplate.group(:type).count.keys
|
message_templates = MessageTemplate.ransack(sys_notice_or_email_or_email_title_cont: params[:search]).result
|
||||||
@message_templates = kaminari_array_paginate(message_templates)
|
@message_templates = kaminari_paginate(message_templates)
|
||||||
|
end
|
||||||
|
|
||||||
|
def new
|
||||||
|
@message_template = MessageTemplate::CustomTip.new
|
||||||
|
end
|
||||||
|
|
||||||
|
def create
|
||||||
|
@message_template = MessageTemplate::CustomTip.new(ignore_params)
|
||||||
|
|
||||||
|
if @message_template.save!
|
||||||
|
redirect_to admins_message_templates_path
|
||||||
|
flash[:success] = "创建消息模板成功"
|
||||||
|
else
|
||||||
|
render :new
|
||||||
|
flash[:danger] = "创建消息模板失败"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def edit
|
def edit
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class NoticesController < ApplicationController
|
class NoticesController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
tip_exception("参数有误") if params["source"].blank?
|
return tip_exception("参数有误") if params["source"].blank?
|
||||||
user_id = params[:user_id]
|
user_id = params[:user_id]
|
||||||
|
|
||||||
if params["source"] == "CompetitionBegin"
|
if params["source"] == "CompetitionBegin"
|
||||||
|
@ -13,9 +13,21 @@ class NoticesController < ApplicationController
|
||||||
elsif params["source"] == "CompetitionReview"
|
elsif params["source"] == "CompetitionReview"
|
||||||
competition_id = params[:competition_id]
|
competition_id = params[:competition_id]
|
||||||
SendTemplateMessageJob.perform_later('CompetitionReview', user_id, competition_id)
|
SendTemplateMessageJob.perform_later('CompetitionReview', user_id, competition_id)
|
||||||
|
elsif params["source"] == "CustomTip"
|
||||||
|
users_id = params[:users_id]
|
||||||
|
props = params[:props].to_unsafe_hash
|
||||||
|
return tip_exception("参数有误") unless props.is_a?(Hash) && users_id.is_a?(Array)
|
||||||
|
template_id = params[:template_id]
|
||||||
|
SendTemplateMessageJob.perform_later('CustomTip', users_id, template_id, props)
|
||||||
else
|
else
|
||||||
tip_exception("#{params["source"]}未配置")
|
tip_exception("#{params["source"]}未配置")
|
||||||
end
|
end
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
private
|
||||||
|
def params_props
|
||||||
|
params.require(:notice).permit(:props)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,6 +4,24 @@ class SendTemplateMessageJob < ApplicationJob
|
||||||
def perform(source, *args)
|
def perform(source, *args)
|
||||||
Rails.logger.info "SendTemplateMessageJob [args] #{args}"
|
Rails.logger.info "SendTemplateMessageJob [args] #{args}"
|
||||||
case source
|
case source
|
||||||
|
when 'CustomTip'
|
||||||
|
receivers_id, template_id, props = args[0], args[1], args[2]
|
||||||
|
template = MessageTemplate.find_by_id(template_id)
|
||||||
|
return unless template.present?
|
||||||
|
receivers = User.where(id: receivers_id).or(User.where(mail: receivers_id))
|
||||||
|
not_exists_receivers = receivers_id - receivers.pluck(:id) - receivers.pluck(:mail)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::CustomTip.get_message_content(receivers, template, props)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {receivers_id: receivers_id, template_id: template_id, props: props})
|
||||||
|
receivers.find_each do |receiver|
|
||||||
|
receivers_email_string, email_title, email_content = MessageTemplate::CustomTip.get_email_message_content(receiver, template, props)
|
||||||
|
Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content)
|
||||||
|
end
|
||||||
|
not_exists_receivers.each do |mail|
|
||||||
|
valid_email_regex = /^[a-zA-Z0-9]+([.\-_\\]*[a-zA-Z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/i
|
||||||
|
next unless (mail =~ valid_email_regex)
|
||||||
|
email_title, email_content = MessageTemplate::CustomTip.get_email_content(template, props)
|
||||||
|
Notice::Write::EmailCreateService.call(mail, email_title, email_content)
|
||||||
|
end
|
||||||
when 'FollowTip'
|
when 'FollowTip'
|
||||||
watcher_id = args[0]
|
watcher_id = args[0]
|
||||||
watcher = Watcher.find_by_id(watcher_id)
|
watcher = Watcher.find_by_id(watcher_id)
|
||||||
|
|
|
@ -16,8 +16,7 @@ class MessageTemplate < ApplicationRecord
|
||||||
PLATFORM = 'GitLink'
|
PLATFORM = 'GitLink'
|
||||||
|
|
||||||
def self.build_init_data
|
def self.build_init_data
|
||||||
MessageTemplate::IssueAssignerExpire.destroy_all
|
MessageTemplate.where.not(type: 'MessageTemplate::CustomTip').destroy_all
|
||||||
MessageTemplate::IssueCreatorExpire.destroy_all
|
|
||||||
self.create(type: 'MessageTemplate::FollowedTip', sys_notice: '<b>{nickname}</b> 关注了你', notification_url: '{baseurl}/{login}')
|
self.create(type: 'MessageTemplate::FollowedTip', sys_notice: '<b>{nickname}</b> 关注了你', notification_url: '{baseurl}/{login}')
|
||||||
email_html = File.read("#{email_template_html_dir}/issue_assigned.html")
|
email_html = File.read("#{email_template_html_dir}/issue_assigned.html")
|
||||||
self.create(type: 'MessageTemplate::IssueAssigned', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 指派给你一个疑修:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 在 {nickname2}/{repository} 指派给你一个疑修")
|
self.create(type: 'MessageTemplate::IssueAssigned', sys_notice: '{nickname1}在 <b>{nickname2}/{repository}</b> 指派给你一个疑修:<b>{title}</b>', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: "#{PLATFORM}: {nickname1} 在 {nickname2}/{repository} 指派给你一个疑修")
|
||||||
|
|
|
@ -0,0 +1,70 @@
|
||||||
|
# == Schema Information
|
||||||
|
#
|
||||||
|
# Table name: message_templates
|
||||||
|
#
|
||||||
|
# id :integer not null, primary key
|
||||||
|
# type :string(255)
|
||||||
|
# sys_notice :text(65535)
|
||||||
|
# email :text(65535)
|
||||||
|
# created_at :datetime not null
|
||||||
|
# updated_at :datetime not null
|
||||||
|
# notification_url :string(255)
|
||||||
|
# email_title :string(255)
|
||||||
|
#
|
||||||
|
|
||||||
|
# 统一模板(
|
||||||
|
|
||||||
|
class MessageTemplate::CustomTip < MessageTemplate
|
||||||
|
|
||||||
|
# MessageTemplate::CustomTip.get_message_content(User.where(login: 'yystopf'), "hahah")
|
||||||
|
def self.get_message_content(receivers, template, props={})
|
||||||
|
return '', '', '' if receivers.blank? || template.blank?
|
||||||
|
content = template.sys_notice
|
||||||
|
notification_url = template.notification_url
|
||||||
|
props.each do |k, v|
|
||||||
|
content.gsub!("{#{k}}", v)
|
||||||
|
notification_url.gsub!("{#{k}}", v)
|
||||||
|
end
|
||||||
|
notification_url.gsub!('{baseurl}', base_url)
|
||||||
|
return receivers_string(receivers), content, notification_url
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.info("MessageTemplate::CustomTip.get_message_content [ERROR] #{e}")
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get_email_message_content(receiver, template, props={})
|
||||||
|
return '', '', '' if receiver.blank? || template.blank?
|
||||||
|
title = template.email_title
|
||||||
|
content = template.email
|
||||||
|
props.each do |k, v|
|
||||||
|
title.gsub!("{#{k}}", v)
|
||||||
|
content.gsub!("{#{k}}", v)
|
||||||
|
end
|
||||||
|
content.gsub!('{receiver}', receiver&.real_name)
|
||||||
|
title.gsub!('{platform}', PLATFORM)
|
||||||
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
content.gsub!('{baseurl}', base_url)
|
||||||
|
|
||||||
|
return receiver&.mail, title, content
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.info("MessageTemplate::CustomTip.get_email_message_content [ERROR] #{e}")
|
||||||
|
return '', '', ''
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.get_email_content(template, props = {})
|
||||||
|
return '', '', '' if template.blank?
|
||||||
|
title = template.email_title
|
||||||
|
content = template.email
|
||||||
|
props.each do |k, v|
|
||||||
|
title.gsub!("{#{k}}", v)
|
||||||
|
content.gsub!("{#{k}}", v)
|
||||||
|
end
|
||||||
|
title.gsub!('{platform}', PLATFORM)
|
||||||
|
content.gsub!('{platform}', PLATFORM)
|
||||||
|
|
||||||
|
return title, content
|
||||||
|
rescue => e
|
||||||
|
Rails.logger.info("MessageTemplate::CustomTip.get_email_content [ERROR] #{e}")
|
||||||
|
return '', ''
|
||||||
|
end
|
||||||
|
end
|
|
@ -37,6 +37,8 @@
|
||||||
# rep_identifier :string(255)
|
# rep_identifier :string(255)
|
||||||
# project_category_id :integer
|
# project_category_id :integer
|
||||||
# project_language_id :integer
|
# project_language_id :integer
|
||||||
|
# license_id :integer
|
||||||
|
# ignore_id :integer
|
||||||
# praises_count :integer default("0")
|
# praises_count :integer default("0")
|
||||||
# watchers_count :integer default("0")
|
# watchers_count :integer default("0")
|
||||||
# issues_count :integer default("0")
|
# issues_count :integer default("0")
|
||||||
|
@ -50,8 +52,6 @@
|
||||||
# open_devops_count :integer default("0")
|
# open_devops_count :integer default("0")
|
||||||
# recommend :boolean default("0")
|
# recommend :boolean default("0")
|
||||||
# platform :integer default("0")
|
# platform :integer default("0")
|
||||||
# license_id :integer
|
|
||||||
# ignore_id :integer
|
|
||||||
# default_branch :string(255) default("master")
|
# default_branch :string(255) default("master")
|
||||||
# website :string(255)
|
# website :string(255)
|
||||||
# lesson_url :string(255)
|
# lesson_url :string(255)
|
||||||
|
@ -138,6 +138,8 @@ class Project < ApplicationRecord
|
||||||
delegate :content, to: :project_detail, allow_nil: true
|
delegate :content, to: :project_detail, allow_nil: true
|
||||||
delegate :name, to: :license, prefix: true, allow_nil: true
|
delegate :name, to: :license, prefix: true, allow_nil: true
|
||||||
|
|
||||||
|
validate :validate_sensitive_string
|
||||||
|
|
||||||
def self.all_visible(user_id=nil)
|
def self.all_visible(user_id=nil)
|
||||||
user_projects_sql = Project.joins(:owner).where(users: {type: 'User'}).to_sql
|
user_projects_sql = Project.joins(:owner).where(users: {type: 'User'}).to_sql
|
||||||
org_public_projects_sql = Project.joins(:owner).merge(Organization.joins(:organization_extension).where(organization_extensions: {visibility: 'common'})).to_sql
|
org_public_projects_sql = Project.joins(:owner).merge(Organization.joins(:organization_extension).where(organization_extensions: {visibility: 'common'})).to_sql
|
||||||
|
@ -371,6 +373,7 @@ class Project < ApplicationRecord
|
||||||
logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} "
|
logger.info "########namespace_path: #{namespace_path} ########identifier: #{identifier} "
|
||||||
|
|
||||||
user = Owner.find_by_login namespace_path
|
user = Owner.find_by_login namespace_path
|
||||||
|
user = Owner.new(login: namespace_path) if user.nil?
|
||||||
project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}")
|
project = user&.projects&.find_by(identifier: identifier) || Project.find_by(identifier: "#{namespace_path}/#{identifier}")
|
||||||
return nil if project.blank?
|
return nil if project.blank?
|
||||||
|
|
||||||
|
@ -409,4 +412,9 @@ class Project < ApplicationRecord
|
||||||
def is_transfering
|
def is_transfering
|
||||||
applied_transfer_project&.common? ? true : false
|
applied_transfer_project&.common? ? true : false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def validate_sensitive_string
|
||||||
|
raise("项目名称包含敏感词汇,请重新输入") if name && !HarmoniousDictionary.clean?(name)
|
||||||
|
raise("项目描述包含敏感词汇,请重新输入") if description && !HarmoniousDictionary.clean?(description)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,8 +11,8 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<% if message_templates.present? %>
|
<% if message_templates.present? %>
|
||||||
<% message_templates.each_with_index do |message_template_type, index| %>
|
<% message_templates.each_with_index do |message_template, index| %>
|
||||||
<% message_template = message_template_type.constantize.last%>
|
<%# message_template = message_template_type.constantize.last%>
|
||||||
<tr class="project-language-item-<%= message_template.id %>">
|
<tr class="project-language-item-<%= message_template.id %>">
|
||||||
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
<td><%= list_index_no((params[:page] || 1).to_i, index) %></td>
|
||||||
<td><%= message_template.simple_type %></td>
|
<td><%= message_template.simple_type %></td>
|
||||||
|
|
|
@ -3,7 +3,13 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<div id="admins-message-templates-content">
|
<div id="admins-message-templates-content">
|
||||||
<div class="box search-form-container project-list-form">
|
<div class="box search-form-container project-list-form">
|
||||||
<%= link_to "初始化数据", init_data_admins_message_templates_path, class: "btn btn-primary pull-right", "data-disabled-with":"...初始化数据" %>
|
<%= form_tag(admins_message_templates_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 "初始化数据", init_data_admins_message_templates_path, class: "btn btn-primary mr-3 pull-right", "data-disabled-with":"...初始化数据" %>
|
||||||
|
<%= link_to "新增", new_admins_message_template_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %>
|
||||||
</div>
|
</div>
|
||||||
<div class="box admin-list-container message-templates-list-container">
|
<div class="box admin-list-container message-templates-list-container">
|
||||||
<%= render partial: 'admins/message_templates/list', locals: { message_templates: @message_templates } %>
|
<%= render partial: 'admins/message_templates/list', locals: { message_templates: @message_templates } %>
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
$("#admins-message-templates-content").html("<%= j render partial: 'admins/message_templates/form', locals:{type: 'create'} %>")
|
||||||
|
createMDEditor('message-template-email-editor', { height: 500, placeholder: '请输入邮件模版' });
|
|
@ -1,6 +1,6 @@
|
||||||
json.total_count @projects.total_count
|
json.total_count @projects.total_count
|
||||||
json.projects @projects.each do |project|
|
json.projects @projects.each do |project|
|
||||||
json.(project, :id, :name, :identifier, :description, :forked_count, :praises_count, :forked_from_project_id)
|
json.(project, :id, :name, :identifier, :description, :forked_count, :praises_count, :forked_from_project_id, :is_public)
|
||||||
json.mirror_url project.repository&.mirror_url
|
json.mirror_url project.repository&.mirror_url
|
||||||
json.type project.numerical_for_project_type
|
json.type project.numerical_for_project_type
|
||||||
json.praised project.praised_by?(current_user)
|
json.praised project.praised_by?(current_user)
|
||||||
|
|
|
@ -729,7 +729,7 @@ Rails.application.routes.draw do
|
||||||
get :history
|
get :history
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :message_templates, only: [:index, :edit, :update] do
|
resources :message_templates, only: [:index, :new, :create, :edit, :update] do
|
||||||
collection do
|
collection do
|
||||||
get :init_data
|
get :init_data
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue