add: message touch condition
This commit is contained in:
parent
fa0021b504
commit
88bc5f29ff
|
@ -111,6 +111,7 @@ class IssuesController < ApplicationController
|
||||||
Issues::CreateForm.new({subject:issue_params[:subject]}).validate!
|
Issues::CreateForm.new({subject:issue_params[:subject]}).validate!
|
||||||
@issue = Issue.new(issue_params)
|
@issue = Issue.new(issue_params)
|
||||||
if @issue.save!
|
if @issue.save!
|
||||||
|
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id)
|
||||||
if params[:attachment_ids].present?
|
if params[:attachment_ids].present?
|
||||||
params[:attachment_ids].each do |id|
|
params[:attachment_ids].each do |id|
|
||||||
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id)
|
||||||
|
@ -202,6 +203,20 @@ class IssuesController < ApplicationController
|
||||||
issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id)
|
issue_params = issue_send_params(params).except(:issue_classify, :author_id, :project_id)
|
||||||
Issues::UpdateForm.new({subject:issue_params[:subject]}).validate!
|
Issues::UpdateForm.new({subject:issue_params[:subject]}).validate!
|
||||||
if @issue.update_attributes(issue_params)
|
if @issue.update_attributes(issue_params)
|
||||||
|
if @issue&.pull_request.present?
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @issue&.pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value))
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @issue&.pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present?
|
||||||
|
else
|
||||||
|
previous_changes = @issue.previous_changes.slice(:status_id, :assigned_to_id, :tracker_id, :priority_id, :fixed_version_id, :done_ratio, :issue_tags_value, :branch_name)
|
||||||
|
if @issue.previous_changes[:start_date].present?
|
||||||
|
previous_changes.merge!(start_date: [@issue.previous_changes[:start_date][0].to_s, @issue.previous_changes[:start_date][1].to_s])
|
||||||
|
end
|
||||||
|
if @issue.previous_changes[:due_date].present?
|
||||||
|
previous_changes.merge!(due_date: [@issue.previous_changes[:due_date][0].to_s, @issue.previous_changes[:due_date][1].to_s])
|
||||||
|
end
|
||||||
|
SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes)
|
||||||
|
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present?
|
||||||
|
end
|
||||||
if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时
|
if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时
|
||||||
@issue.issue_times.update_all(end_time: Time.now)
|
@issue.issue_times.update_all(end_time: Time.now)
|
||||||
@issue.update_closed_issues_count_in_project!
|
@issue.update_closed_issues_count_in_project!
|
||||||
|
@ -253,6 +268,7 @@ class IssuesController < ApplicationController
|
||||||
status_id = @issue.status_id
|
status_id = @issue.status_id
|
||||||
token = @issue.token
|
token = @issue.token
|
||||||
login = @issue.user.try(:login)
|
login = @issue.user.try(:login)
|
||||||
|
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigned_to_id, @issue.author_id)
|
||||||
if @issue.destroy
|
if @issue.destroy
|
||||||
if issue_type == "2" && status_id != 5
|
if issue_type == "2" && status_id != 5
|
||||||
post_to_chain("add", token, login)
|
post_to_chain("add", token, login)
|
||||||
|
|
|
@ -9,6 +9,7 @@ class MembersController < ApplicationController
|
||||||
|
|
||||||
def create
|
def create
|
||||||
interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user)
|
interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user)
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectJoined', @user.id, @project.id)
|
||||||
render_response(interactor)
|
render_response(interactor)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
@ -28,6 +29,7 @@ class MembersController < ApplicationController
|
||||||
|
|
||||||
def remove
|
def remove
|
||||||
interactor = Projects::DeleteMemberInteractor.call(@project.owner, @project, @user)
|
interactor = Projects::DeleteMemberInteractor.call(@project.owner, @project, @user)
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectLeft', @user.id, @project.id)
|
||||||
render_response(interactor)
|
render_response(interactor)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
@ -36,6 +38,7 @@ class MembersController < ApplicationController
|
||||||
|
|
||||||
def change_role
|
def change_role
|
||||||
interactor = Projects::ChangeMemberRoleInteractor.call(@project.owner, @project, @user, params[:role])
|
interactor = Projects::ChangeMemberRoleInteractor.call(@project.owner, @project, @user, params[:role])
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectRole', @user.id, @project.id, message_role_name)
|
||||||
render_response(interactor)
|
render_response(interactor)
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
@ -66,4 +69,14 @@ class MembersController < ApplicationController
|
||||||
def check_user_profile_completed
|
def check_user_profile_completed
|
||||||
require_user_profile_completed(@user)
|
require_user_profile_completed(@user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def message_role_name
|
||||||
|
case params[:role]
|
||||||
|
when 'Manager' then '管理员'
|
||||||
|
when 'Developer' then '开发者'
|
||||||
|
when 'Reporter' then '报告者'
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,7 @@ class Organizations::TeamUsersController < Organizations::BaseController
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
@team_user = TeamUser.build(@organization.id, @operate_user.id, @team.id)
|
@team_user = TeamUser.build(@organization.id, @operate_user.id, @team.id)
|
||||||
@organization_user = OrganizationUser.build(@organization.id, @operate_user.id)
|
@organization_user = OrganizationUser.build(@organization.id, @operate_user.id)
|
||||||
|
SendTemplateMessageJob.perform_later('OrganizationRole', @operate_user.id, @organization.id, @team.authorize_name)
|
||||||
Gitea::Organization::TeamUser::CreateService.call(@organization.gitea_token, @team.gtid, @operate_user.login)
|
Gitea::Organization::TeamUser::CreateService.call(@organization.gitea_token, @team.gtid, @operate_user.login)
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
|
@ -6,7 +6,8 @@ class Projects::ProjectUnitsController < Projects::BaseController
|
||||||
def create
|
def create
|
||||||
if current_user.admin? || @project.manager?(current_user)
|
if current_user.admin? || @project.manager?(current_user)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
ProjectUnit.update_by_unit_types!(@project, unit_types)
|
before_units, after_units = ProjectUnit.update_by_unit_types!(@project, unit_types)
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, {navbar: true}) unless before_units.eql?(after_units)
|
||||||
render_ok
|
render_ok
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -139,6 +139,7 @@ class ProjectsController < ApplicationController
|
||||||
@project.repository.update_column(:hidden, private)
|
@project.repository.update_column(:hidden, private)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, @project.previous_changes.slice(:name, :description, :project_category_id, :project_language_id, :is_public))
|
||||||
end
|
end
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
uid_logger_error(e.message)
|
uid_logger_error(e.message)
|
||||||
|
|
|
@ -59,6 +59,7 @@ class PullRequestsController < ApplicationController
|
||||||
@pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params)
|
@pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params)
|
||||||
if @gitea_pull_request[:status] == :success
|
if @gitea_pull_request[:status] == :success
|
||||||
@pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"])
|
@pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"])
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id)
|
||||||
render_ok
|
render_ok
|
||||||
else
|
else
|
||||||
render_error("create pull request error: #{@gitea_pull_request[:status]}")
|
render_error("create pull request error: #{@gitea_pull_request[:status]}")
|
||||||
|
@ -91,6 +92,8 @@ class PullRequestsController < ApplicationController
|
||||||
end
|
end
|
||||||
|
|
||||||
if @issue.update_attributes(@issue_params)
|
if @issue.update_attributes(@issue_params)
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value))
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present?
|
||||||
if @pull_request.update_attributes(@local_params.compact)
|
if @pull_request.update_attributes(@local_params.compact)
|
||||||
gitea_pull = Gitea::PullRequest::UpdateService.call(@owner.login, @repository.identifier,
|
gitea_pull = Gitea::PullRequest::UpdateService.call(@owner.login, @repository.identifier,
|
||||||
@pull_request.gitea_number, @requests_params, current_user.gitea_token)
|
@pull_request.gitea_number, @requests_params, current_user.gitea_token)
|
||||||
|
@ -125,7 +128,12 @@ class PullRequestsController < ApplicationController
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
begin
|
begin
|
||||||
colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user)
|
colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user)
|
||||||
colsed === true ? normal_status(1, "已拒绝") : normal_status(-1, '合并失败')
|
if colsed === true
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id)
|
||||||
|
normal_status(1, "已拒绝")
|
||||||
|
else
|
||||||
|
normal_status(-1, '合并失败')
|
||||||
|
end
|
||||||
rescue => e
|
rescue => e
|
||||||
normal_status(-1, e.message)
|
normal_status(-1, e.message)
|
||||||
raise ActiveRecord::Rollback
|
raise ActiveRecord::Rollback
|
||||||
|
@ -164,6 +172,7 @@ class PullRequestsController < ApplicationController
|
||||||
if success_condition && @pull_request.merge!
|
if success_condition && @pull_request.merge!
|
||||||
@pull_request.project_trend_status!
|
@pull_request.project_trend_status!
|
||||||
@issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)
|
@issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id)
|
||||||
|
SendTemplateMessageJob.perform_later('PullRequestMerged', current_user.id, @pull_request.id)
|
||||||
normal_status(1, "合并成功")
|
normal_status(1, "合并成功")
|
||||||
else
|
else
|
||||||
normal_status(-1, result.message)
|
normal_status(-1, result.message)
|
||||||
|
|
|
@ -16,8 +16,21 @@ class Users::MessagesController < Users::BaseController
|
||||||
case params[:type]
|
case params[:type]
|
||||||
when 'atme'
|
when 'atme'
|
||||||
Notice::Write::CreateAtmeForm.new(atme_params).validate!
|
Notice::Write::CreateAtmeForm.new(atme_params).validate!
|
||||||
result = Notice::Write::CreateService.call(@receivers.pluck(:id), '发送了一个@我消息', base_url, "IssueAtme", 2, {}, current_user.id)
|
case atme_params[:atmeable_type]
|
||||||
return render_error if result.nil?
|
when 'Issue'
|
||||||
|
SendTemplateMessageJob.perform_now('IssueAtme', @receivers, current_user.id, atme_params[:atmeable_id])
|
||||||
|
when 'PullRequest'
|
||||||
|
SendTemplateMessageJob.perform_now('PullRequestAtme', @receivers, current_user.id, atme_params[:atmeable_id])
|
||||||
|
when 'Journal'
|
||||||
|
journal = Journal.find_by_id(atme_params[:atmeable_id])
|
||||||
|
if journal.present?
|
||||||
|
if journal&.issue&.pull_request.present?
|
||||||
|
SendTemplateMessageJob.perform_now('PullRequestAtme', @receivers, current_user.id, atme_params[:atmeable_id])
|
||||||
|
else
|
||||||
|
SendTemplateMessageJob.perform_now('IssueAtme', @receivers, current_user.id, atme_params[:atmeable_id])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
render_ok
|
render_ok
|
||||||
rescue Exception => e
|
rescue Exception => e
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
<!--
|
<!--
|
||||||
* @Date: 2021-03-01 10:35:21
|
* @Date: 2021-03-01 10:35:21
|
||||||
* @LastEditors: viletyy
|
* @LastEditors: viletyy
|
||||||
* @LastEditTime: 2021-09-14 17:34:40
|
* @LastEditTime: 2021-09-15 18:00:10
|
||||||
* @FilePath: /forgeplus/app/docs/slate/source/includes/_users.md
|
* @FilePath: /forgeplus/app/docs/slate/source/includes/_users.md
|
||||||
-->
|
-->
|
||||||
# Users
|
# Users
|
||||||
|
@ -219,8 +219,8 @@ await octokit.request('POST /api/users/:login/messages.json')
|
||||||
参数 | 类型 | 字段说明
|
参数 | 类型 | 字段说明
|
||||||
--------- | ----------- | -----------
|
--------- | ----------- | -----------
|
||||||
|type | string | 消息类型 |
|
|type | string | 消息类型 |
|
||||||
|recervers_login | array | 需要发送消息的用户名数组|
|
|receivers_login | array | 需要发送消息的用户名数组|
|
||||||
|atmeable_type | string | atme消息对象,是从哪里@我的,比如评论:Journal |
|
|atmeable_type | string | atme消息对象,是从哪里@我的,比如评论:Journal、易修:Issue、合并请求:PullRequest |
|
||||||
|atmeable_id | integer | atme消息对象id |
|
|atmeable_id | integer | atme消息对象id |
|
||||||
|
|
||||||
> 请求的JSON示例:
|
> 请求的JSON示例:
|
||||||
|
|
|
@ -5,8 +5,152 @@ class SendTemplateMessageJob < ApplicationJob
|
||||||
Rails.logger.info "SendTemplateMessageJob [args] #{args}"
|
Rails.logger.info "SendTemplateMessageJob [args] #{args}"
|
||||||
case source
|
case source
|
||||||
when 'FollowTip'
|
when 'FollowTip'
|
||||||
receivers, followeder = args
|
watcher_id = args[0]
|
||||||
Rails.logger.info "#{receivers} #{followeder}"
|
watcher = Watcher.find_by_id(watcher_id)
|
||||||
|
return unless watcher.present?
|
||||||
|
receivers = User.where(id: watcher.watchable_id)
|
||||||
|
followeder = User.find_by_id(watcher.user_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::FollowedTip.get_message_content(receivers, followeder)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {watcher_id: watcher.id})
|
||||||
|
when 'IssueAssigned'
|
||||||
|
operator_id, issue_id = args[0], args[1]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
issue = Issue.find_by_id(issue_id)
|
||||||
|
return unless operator.present? && issue.present?
|
||||||
|
receivers = User.where(id: issue&.assigned_to_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::IssueAssigned.get_message_content(receivers, operator, issue)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id})
|
||||||
|
when 'IssueAssignerExpire'
|
||||||
|
issue_id = args[0]
|
||||||
|
issue = Issue.find_by_id(issue_id)
|
||||||
|
return unless issue.present?
|
||||||
|
receivers = User.where(id: issue&.assigned_to_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::IssueAssignerExpire.get_message_content(receivers, issue)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {issue_id: issue.id})
|
||||||
|
when 'IssueAtme'
|
||||||
|
receivers, operator_id, issue_id = args[0], args[1], args[2]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
issue = Issue.find_by_id(issue_id)
|
||||||
|
return unless operator.present? && issue.present?
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::IssueAtme.get_message_content(receivers, operator, issue)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id}, 2)
|
||||||
|
when 'IssueChanged'
|
||||||
|
operator_id, issue_id, change_params = args[0], args[1], args[2]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
issue = Issue.find_by_id(issue_id)
|
||||||
|
return unless operator.present? && issue.present?
|
||||||
|
receivers = User.where(id: [issue&.assigned_to_id, issue&.author_id])
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::IssueChanged.get_message_content(receivers, operator, issue, change_params)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id, change_params: change_params.symbolize_keys})
|
||||||
|
when 'IssueCreatorExpire'
|
||||||
|
issue_id = args[0]
|
||||||
|
issue = Issue.find_by_id(issue_id)
|
||||||
|
return unless issue.present?
|
||||||
|
receivers = User.where(id: issue&.author_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::IssueCreatorExpire.get_message_content(receivers, issue)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {issue_id: issue.id})
|
||||||
|
when 'IssueDeleted'
|
||||||
|
operator_id, issue_title, issue_assigned_to_id, issue_author_id = args[0], args[1], args[2], args[3]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
return unless operator.present?
|
||||||
|
receivers = User.where(id: [issue_assigned_to_id, issue_author_id])
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::IssueDeleted.get_message_content(receivers, operator, issue_title)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_title: issue_title})
|
||||||
|
when 'OrganizationJoined'
|
||||||
|
user_id, organization_id = args[0], args[1]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
organization = Organization.find_by_id(organization_id)
|
||||||
|
return unless user.present? && organization.present?
|
||||||
|
receivers = User.where(id: user.id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::OrganizationJoined.get_message_content(receivers, organization)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id})
|
||||||
|
when 'OrganizationLeft'
|
||||||
|
user_id, organization_id = args[0], args[1]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
organization = Organization.find_by_id(organization_id)
|
||||||
|
return unless user.present? && organization.present?
|
||||||
|
receivers = User.where(id: user.id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::OrganizationLeft.get_message_content(receivers, organization)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id})
|
||||||
|
when 'OrganizationRole'
|
||||||
|
user_id, organization_id, role = args[0], args[1], args[2]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
organization = Organization.find_by_id(organization_id)
|
||||||
|
return unless user.present? && organization.present?
|
||||||
|
receivers = User.where(id: user.id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::OrganizationRole.get_message_content(receivers, organization, role)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, organization_id: organization.id, role: role})
|
||||||
|
when 'ProjectJoined'
|
||||||
|
user_id, project_id = args[0], args[1]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
project = Project.find_by_id(project_id)
|
||||||
|
return unless user.present? && project.present?
|
||||||
|
receivers = User.where(id: user.user_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::ProjectJoined.get_message_content(receivers, project)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, project_id: project.id})
|
||||||
|
when 'ProjectLeft'
|
||||||
|
user_id, project_id = args[0], args[1]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
project = Project.find_by_id(project_id)
|
||||||
|
return unless user.present? && project.present?
|
||||||
|
receivers = User.where(id: user.user_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::ProjectJoined.get_message_content(receivers, project)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, project_id: project.id})
|
||||||
|
when 'ProjectRole'
|
||||||
|
user_id, project_id, role = args[0], args[1], args[2]
|
||||||
|
user = User.find_by_id(user_id)
|
||||||
|
project = Project.find_by_id(project_id)
|
||||||
|
return unless user.present? && project.present?
|
||||||
|
receivers = User.where(id: user.user_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::ProjectRole.get_message_content(receivers, project, role)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {user_id: user.id, project_id: project.id, role: role})
|
||||||
|
when 'ProjectSettingChanged'
|
||||||
|
operator_id, project_id, change_params = args[0], args[1], args[2]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
project = Project.find_by_id(project_id)
|
||||||
|
return unless operator.present? && project.present?
|
||||||
|
receivers = project.all_managers
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::ProjectSettingChanged.get_message_content(receivers, operator, project, change_params.symbolize_keys)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, project_id: project.id, change_params: change_params})
|
||||||
|
when 'PullRequestAssigned'
|
||||||
|
operator_id, pull_request_id = args[0], args[1]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
pull_request = PullRequest.find_by_id(pull_request_id)
|
||||||
|
return unless operator.present? && pull_request.present?
|
||||||
|
receivers = User.where(id: pull_request&.issue&.assigned_to_id)
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::PullRequestAssigned.get_message_content(receivers, operator, pull_request)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id})
|
||||||
|
when 'PullRequestAtme'
|
||||||
|
receivers, operator_id, pull_request_id = args[0], args[1], args[2]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
pull_request = PullRequest.find_by_id(pull_request_id)
|
||||||
|
return unless operator.present? && pull_request.present?
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::PullRequestAtme.get_message_content(receivers, operator, pull_request)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id}, 2)
|
||||||
|
when 'PullRequestChanged'
|
||||||
|
operator_id, pull_request_id, change_params = args[0], args[1], args[2]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
pull_request = PullRequest.find_by_id(pull_request_id)
|
||||||
|
return unless operator.present? && pull_request.present?
|
||||||
|
receivers = User.where(id: [pull_request&.issue&.assigned_to_id, pull_request&.user_id])
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::PullRequestChanged.get_message_content(receivers, operator, pull_request, change_params.symbolize_keys)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id, change_params: change_params})
|
||||||
|
when 'PullRequestClosed'
|
||||||
|
operator_id, pull_request_id = args[0], args[1]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
pull_request = PullRequest.find_by_id(pull_request_id)
|
||||||
|
return unless operator.present? && pull_request.present?
|
||||||
|
receivers = User.where(id: [pull_request&.issue&.assigned_to_id, pull_request&.user_id])
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::PullRequestClosed.get_message_content(receivers, operator, pull_request)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id})
|
||||||
|
when 'PullRequestMerged'
|
||||||
|
operator_id, pull_request_id = args[0], args[1]
|
||||||
|
operator = User.find_by_id(operator_id)
|
||||||
|
pull_request = PullRequest.find_by_id(pull_request_id)
|
||||||
|
return unless operator.present? && pull_request.present?
|
||||||
|
receivers = User.where(id: [pull_request&.issue&.assigned_to_id, pull_request&.user_id])
|
||||||
|
receivers_string, content, notification_url = MessageTemplate::PullRequestMerged.get_message_content(receivers, operator, pull_request)
|
||||||
|
Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, pull_request_id: pull_request.id})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
|
@ -19,7 +19,7 @@ class MessageTemplate::IssueAtme < MessageTemplate
|
||||||
project = issue&.project
|
project = issue&.project
|
||||||
owner = project&.owner
|
owner = project&.owner
|
||||||
content = sys_notice.gsub('{nickname}', operator&.nickname).gsub('{title}', issue&.subject)
|
content = sys_notice.gsub('{nickname}', operator&.nickname).gsub('{title}', issue&.subject)
|
||||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifer}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
||||||
return receivers_string(receivers), content, url
|
return receivers_string(receivers), content, url
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::IssueAtme.get_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::IssueAtme.get_message_content [ERROR] #{e}")
|
||||||
|
|
|
@ -14,116 +14,132 @@
|
||||||
# 我创建或负责的易修状态变更
|
# 我创建或负责的易修状态变更
|
||||||
class MessageTemplate::IssueChanged < MessageTemplate
|
class MessageTemplate::IssueChanged < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::IssueChanged.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last, {assigner: 'testforge2', milestone: '里程碑', tag: '标签', priority: '低', tracker: '支持', doneratio: '70', branch: 'master', startdate: Date.today, duedate: Date.today + 1.days})
|
# MessageTemplate::IssueChanged.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last, {status_id: [1, 2], assigned_to_id: [nil, 203], tracker_id: [4, 3], priority_id: [2, 4], fixed_version_id: [nil, 5], due_date: ['', '2021-09-11'], done_ratio: [0, 40], issue_tags_value: ["", "7"], branch_name: ["", "master"]})
|
||||||
def self.get_message_content(receivers, operator, issue, change_params)
|
def self.get_message_content(receivers, operator, issue, change_params)
|
||||||
|
return '', '', '' if change_params.blank?
|
||||||
project = issue&.project
|
project = issue&.project
|
||||||
owner = project&.owner
|
owner = project&.owner
|
||||||
content = MessageTemplate::IssueChanged.sys_notice.gsub('{nickname1}', operator&.nickname).gsub('{nickname2}', owner&.nickname).gsub('{repository}', project&.name).gsub('{title}', issue&.subject)
|
content = MessageTemplate::IssueChanged.sys_notice.gsub('{nickname1}', operator&.nickname).gsub('{nickname2}', owner&.nickname).gsub('{repository}', project&.name).gsub('{title}', issue&.subject)
|
||||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s)
|
||||||
# 易修负责人修改
|
# 易修负责人修改
|
||||||
if change_params[:assigner].present?
|
if change_params[:assigned_to_id].present?
|
||||||
assigner = issue&.get_assign_user&.nickname || '未指派成员'
|
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
|
||||||
|
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
|
||||||
content.sub!('{ifassigner}', '')
|
content.sub!('{ifassigner}', '')
|
||||||
content.sub!('{endassigner}', '')
|
content.sub!('{endassigner}', '')
|
||||||
content.gsub!('{assigner1}', assigner)
|
content.gsub!('{assigner1}', assigner1.present? ? assigner1&.nickname || assigner1.login : '未指派成员')
|
||||||
content.gsub!('{assigner2}', change_params[:assigner])
|
content.gsub!('{assigner2}', assigner2.present? ? assigner2&.nickname || assigner2.login : '未指派成员')
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
|
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
|
||||||
end
|
end
|
||||||
# 易修状态修改
|
# 易修状态修改
|
||||||
if change_params[:status].present?
|
if change_params[:status_id].present?
|
||||||
status = issue&.issue_status&.name
|
status1 = IssueStatus.find_by_id(change_params[:status_id][0])
|
||||||
|
status2 = IssueStatus.find_by_id(change_params[:status_id][1])
|
||||||
content.sub!('{ifstatus}', '')
|
content.sub!('{ifstatus}', '')
|
||||||
content.sub!('{endstatus}', '')
|
content.sub!('{endstatus}', '')
|
||||||
content.gsub!('{status1}', status)
|
content.gsub!('{status1}', status1&.name)
|
||||||
content.gsub!('{status2}', change_params[:status])
|
content.gsub!('{status2}', status2&.name)
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifstatus})(.*)({endstatus})/, '')
|
content.gsub!(/({ifstatus})(.*)({endstatus})/, '')
|
||||||
end
|
end
|
||||||
# 易修类型修改
|
# 易修类型修改
|
||||||
if change_params[:tracker].present?
|
if change_params[:tracker_id].present?
|
||||||
tracker = issue&.tracker&.name
|
tracker1 = Tracker.find_by_id(change_params[:tracker_id][0])
|
||||||
|
tracker2 = Tracker.find_by_id(change_params[:tracker_id][1])
|
||||||
content.sub!('{iftracker}', '')
|
content.sub!('{iftracker}', '')
|
||||||
content.sub!('{endtracker}', '')
|
content.sub!('{endtracker}', '')
|
||||||
content.gsub!('{tracker1}', tracker)
|
content.gsub!('{tracker1}', tracker1&.name)
|
||||||
content.gsub!('{tracker2}', change_params[:tracker])
|
content.gsub!('{tracker2}', tracker2&.name)
|
||||||
else
|
else
|
||||||
content.gsub!(/({iftracker})(.*)({endtracker})/, '')
|
content.gsub!(/({iftracker})(.*)({endtracker})/, '')
|
||||||
end
|
end
|
||||||
# 合并请求里程碑修改
|
# 易修里程碑修改
|
||||||
if change_params[:milestone].present?
|
if change_params[:fixed_version_id].present?
|
||||||
milestone = issue&.version&.name || '未选择里程碑'
|
fix_version1 = Version.find_by_id(change_params[:fixed_version_id][0])
|
||||||
|
fix_version2 = Version.find_by_id(change_params[:fixed_version_id][1])
|
||||||
content.sub!('{ifmilestone}', '')
|
content.sub!('{ifmilestone}', '')
|
||||||
content.sub!('{endmilestone}', '')
|
content.sub!('{endmilestone}', '')
|
||||||
content.gsub!('{milestone1}', milestone)
|
content.gsub!('{milestone1}', fix_version1.present? ? fix_version1&.name : '未选择里程碑')
|
||||||
content.gsub!('{milestone2}', change_params[:milestone])
|
content.gsub!('{milestone2}', fix_version2.present? ? fix_version2&.name : '未选择里程碑')
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
|
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
|
||||||
end
|
end
|
||||||
# 合并请求标签修改
|
# 易修标签修改
|
||||||
if change_params[:tag].present?
|
if change_params[:issue_tags_value].present?
|
||||||
tag = issue&.issue_tags.distinct.pluck(:name).join(",")
|
issue_tags1 = IssueTag.where(id: change_params[:issue_tags_value][0]).distinct
|
||||||
tag = '未选择标签' if tag == ''
|
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(",")
|
||||||
content.sub!('{iftag}', '')
|
content.sub!('{iftag}', '')
|
||||||
content.sub!('{endtag}', '')
|
content.sub!('{endtag}', '')
|
||||||
content.gsub!('{tag1}', tag)
|
content.gsub!('{tag1}', tag1)
|
||||||
content.gsub!('{tag2}', change_params[:tag])
|
content.gsub!('{tag2}', tag2)
|
||||||
else
|
else
|
||||||
content.gsub!(/({iftag})(.*)({endtag})()/, '')
|
content.gsub!(/({iftag})(.*)({endtag})()/, '')
|
||||||
end
|
end
|
||||||
# 合并请求优先级修改
|
# 易修优先级修改
|
||||||
if change_params[:priority].present?
|
if change_params[:priority_id].present?
|
||||||
priority = issue&.priority&.name
|
priority1 = IssuePriority.find_by_id(change_params[:priority_id][0])
|
||||||
|
priority2 = IssuePriority.find_by_id(change_params[:priority_id][1])
|
||||||
|
|
||||||
content.sub!('{ifpriority}', '')
|
content.sub!('{ifpriority}', '')
|
||||||
content.sub!('{endpriority}', '')
|
content.sub!('{endpriority}', '')
|
||||||
content.gsub!('{priority1}', priority)
|
content.gsub!('{priority1}', priority1&.name)
|
||||||
content.gsub!('{priority2}', change_params[:priority])
|
content.gsub!('{priority2}', priority2&.name)
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
|
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
|
||||||
end
|
end
|
||||||
# 易修完成度修改
|
# 易修完成度修改
|
||||||
if change_params[:doneratio].present?
|
if change_params[:done_ratio].present?
|
||||||
doneratio = issue&.done_ratio
|
doneratio1 = change_params[:done_ratio][0]
|
||||||
|
doneratio2 = change_params[:done_ratio][1]
|
||||||
|
|
||||||
content.sub!('{ifdoneratio}', '')
|
content.sub!('{ifdoneratio}', '')
|
||||||
content.sub!('{enddoneratio}', '')
|
content.sub!('{enddoneratio}', '')
|
||||||
content.gsub!('{doneratio1}', "#{doneratio}%")
|
content.gsub!('{doneratio1}', "#{doneratio1}%")
|
||||||
content.gsub!('{doneratio2}', "#{change_params[:doneratio]}%")
|
content.gsub!('{doneratio2}', "#{doneratio2}%")
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifdoneratio})(.*)({enddoneratio})/, '')
|
content.gsub!(/({ifdoneratio})(.*)({enddoneratio})/, '')
|
||||||
end
|
end
|
||||||
# 易修指定分支修改
|
# 易修指定分支修改
|
||||||
if change_params[:branch].present?
|
if change_params[:branch_name].present?
|
||||||
branch = issue&.branch_name || '分支未指定'
|
branch1 = change_params[:branch_name][0].blank? ? '分支未指定' : change_params[:branch_name][0]
|
||||||
|
branch2 = change_params[:branch_name][1].blank? ? '分支未指定' : change_params[:branch_name][1]
|
||||||
|
|
||||||
content.sub!('{ifbranch}', '')
|
content.sub!('{ifbranch}', '')
|
||||||
content.sub!('{endbranch}', '')
|
content.sub!('{endbranch}', '')
|
||||||
content.gsub!('{branch1}', branch )
|
content.gsub!('{branch1}', branch1)
|
||||||
content.gsub!('{branch2}', change_params[:branch])
|
content.gsub!('{branch2}', branch2)
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifbranch})(.*)({endbranch})/, '')
|
content.gsub!(/({ifbranch})(.*)({endbranch})/, '')
|
||||||
end
|
end
|
||||||
# 易修开始日期修改
|
# 易修开始日期修改
|
||||||
if change_params[:startdate].present?
|
if change_params[:start_date].present?
|
||||||
startdate = issue&.start_date || "未选择开始日期"
|
startdate1 = change_params[:start_date][0].blank? ? "未选择开始日期" : change_params[:start_date][0]
|
||||||
|
startdate2 = change_params[:start_date][1].blank? ? "未选择开始日期" : change_params[:start_date][1]
|
||||||
|
|
||||||
content.sub!('{ifstartdate}', '')
|
content.sub!('{ifstartdate}', '')
|
||||||
content.sub!('{endstartdate}', '')
|
content.sub!('{endstartdate}', '')
|
||||||
content.gsub!('{startdate1}', startdate.to_s )
|
content.gsub!('{startdate1}', startdate1 )
|
||||||
content.gsub!('{startdate2}', change_params[:startdate].to_s)
|
content.gsub!('{startdate2}', startdate2)
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifstartdate})(.*)({endstartdate})/, '')
|
content.gsub!(/({ifstartdate})(.*)({endstartdate})/, '')
|
||||||
end
|
end
|
||||||
# 易修结束日期修改
|
# 易修结束日期修改
|
||||||
if change_params[:duedate].present?
|
if change_params[:due_date].present?
|
||||||
duedate = issue&.due_date || '未选择结束日期'
|
duedate1 = change_params[:due_date][0].blank? ? '未选择结束日期' : change_params[:due_date][0]
|
||||||
|
duedate2 = change_params[:due_date][1].blank? ? '未选择结束日期' : change_params[:due_date][1]
|
||||||
content.sub!('{ifduedate}', '')
|
content.sub!('{ifduedate}', '')
|
||||||
content.sub!('{endduedate}', '')
|
content.sub!('{endduedate}', '')
|
||||||
content.gsub!('{duedate1}', duedate.to_s)
|
content.gsub!('{duedate1}', duedate1)
|
||||||
content.gsub!('{duedate2}', change_params[:duedate].to_s)
|
content.gsub!('{duedate2}', duedate2)
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifduedate})(.*)({endduedate})/, '')
|
content.gsub!(/({ifduedate})(.*)({endduedate})/, '')
|
||||||
end
|
end
|
||||||
return receivers_string(receivers), content, url
|
return receivers_string(receivers), content, url
|
||||||
# rescue => e
|
rescue => e
|
||||||
# Rails.logger.info("MessageTemplate::IssueAssigned.get_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::IssueAssigned.get_message_content [ERROR] #{e}")
|
||||||
# return '', '', ''
|
return '', '', ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,11 +14,9 @@
|
||||||
# 我创建或负责的易修删除
|
# 我创建或负责的易修删除
|
||||||
class MessageTemplate::IssueDeleted < MessageTemplate
|
class MessageTemplate::IssueDeleted < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::IssueDeleted.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last)
|
# MessageTemplate::IssueDeleted.get_message_content(User.where(login: 'yystopf'), User.last, "hahah")
|
||||||
def self.get_message_content(receivers, operator, issue)
|
def self.get_message_content(receivers, operator, issue_title)
|
||||||
project = issue&.project
|
content = sys_notice.gsub('{nickname}', operator&.nickname).gsub('{title}', issue_title)
|
||||||
owner = project&.owner
|
|
||||||
content = sys_notice.gsub('{nickname}', operator&.nickname).gsub('{title}', issue&.subject)
|
|
||||||
return receivers_string(receivers), content, notification_url
|
return receivers_string(receivers), content, notification_url
|
||||||
rescue => e
|
rescue => e
|
||||||
Rails.logger.info("MessageTemplate::IssueAtme.get_message_content [ERROR] #{e}")
|
Rails.logger.info("MessageTemplate::IssueAtme.get_message_content [ERROR] #{e}")
|
||||||
|
|
|
@ -16,6 +16,7 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::ProjectSettingChanged.get_message_content(User.where(login: 'yystopf'), User.last, Project.last, {description: '测试修改项目简介', category: '大数据', language: 'Ruby', permission: '公有', navbar: '易修, 合并请求'})
|
# MessageTemplate::ProjectSettingChanged.get_message_content(User.where(login: 'yystopf'), User.last, Project.last, {description: '测试修改项目简介', category: '大数据', language: 'Ruby', permission: '公有', navbar: '易修, 合并请求'})
|
||||||
def self.get_message_content(receivers, operator, project, change_params)
|
def self.get_message_content(receivers, operator, project, change_params)
|
||||||
|
return '', '', '' if change_params.blank?
|
||||||
owner = project&.owner
|
owner = project&.owner
|
||||||
content = sys_notice.gsub('{nickname1}', operator&.nickname).gsub('{nickname2}', owner&.nickname).gsub('{repository}', project&.name)
|
content = sys_notice.gsub('{nickname1}', operator&.nickname).gsub('{nickname2}', owner&.nickname).gsub('{repository}', project&.name)
|
||||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier)
|
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier)
|
||||||
|
@ -23,7 +24,7 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate
|
||||||
if change_params[:name].present?
|
if change_params[:name].present?
|
||||||
content.sub!('{ifname}', '')
|
content.sub!('{ifname}', '')
|
||||||
content.sub!('{endname}', '')
|
content.sub!('{endname}', '')
|
||||||
content.gsub!('{name}', change_params[:name])
|
content.gsub!('{name}', change_params[:name][1])
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifname})(.*)({endname})/, '')
|
content.gsub!(/({ifname})(.*)({endname})/, '')
|
||||||
end
|
end
|
||||||
|
@ -31,46 +32,57 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate
|
||||||
if change_params[:description].present?
|
if change_params[:description].present?
|
||||||
content.sub!('{ifdescription}', '')
|
content.sub!('{ifdescription}', '')
|
||||||
content.sub!('{enddescription}', '')
|
content.sub!('{enddescription}', '')
|
||||||
content.gsub!('{description}', change_params[:description])
|
content.gsub!('{description}', change_params[:description][1])
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifdescription})(.*)({enddescription})/, '')
|
content.gsub!(/({ifdescription})(.*)({enddescription})/, '')
|
||||||
end
|
end
|
||||||
# 项目类别更改
|
# 项目类别更改
|
||||||
if change_params[:category].present?
|
if change_params[:project_category_id].present?
|
||||||
|
category = ProjectCategory.find_by_id(change_params[:project_category_id][1])
|
||||||
content.sub!('{ifcategory}', '')
|
content.sub!('{ifcategory}', '')
|
||||||
content.sub!('{endcategory}', '')
|
content.sub!('{endcategory}', '')
|
||||||
content.gsub!('{category}', change_params[:category])
|
content.gsub!('{category}', category&.name)
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifcategory})(.*)({endcategory})/, '')
|
content.gsub!(/({ifcategory})(.*)({endcategory})/, '')
|
||||||
end
|
end
|
||||||
# 项目语言更改
|
# 项目语言更改
|
||||||
if change_params[:language].present?
|
if change_params[:project_language_id].present?
|
||||||
|
language = ProjectLanguage.find_by_id(change_params[:project_language_id][1])
|
||||||
content.sub!('{iflanguage}', '')
|
content.sub!('{iflanguage}', '')
|
||||||
content.sub!('{endlanguage}', '')
|
content.sub!('{endlanguage}', '')
|
||||||
content.gsub!('{language}', change_params[:language])
|
content.gsub!('{language}', language&.name)
|
||||||
else
|
else
|
||||||
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '')
|
content.gsub!(/({iflanguage})(.*)({endlanguage})/, '')
|
||||||
end
|
end
|
||||||
# 项目公私有更改
|
# 项目公私有更改
|
||||||
if change_params[:permission].present?
|
if change_params[:is_public].present?
|
||||||
|
permission = change_params[:is_public][1] ? '公有' : '私有'
|
||||||
content.sub!('{ifpermission}', '')
|
content.sub!('{ifpermission}', '')
|
||||||
content.sub!('{endpermission}', '')
|
content.sub!('{endpermission}', '')
|
||||||
content.gsub!('{permission}', change_params[:permission])
|
content.gsub!('{permission}', permission)
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifpermission})(.*)({endpermission})/, '')
|
content.gsub!(/({ifpermission})(.*)({endpermission})/, '')
|
||||||
end
|
end
|
||||||
# 项目导航更改
|
# 项目导航更改
|
||||||
if change_params[:navbar].present?
|
if change_params[:navbar].present? || navbar_is_changed_by_time
|
||||||
|
navbar = project.project_units.order(unit_type: :asc).pluck(:unit_type).join(',')
|
||||||
|
navbar.gsub!('code,', '')
|
||||||
|
navbar.gsub!('issues', '易修')
|
||||||
|
navbar.gsub!('pulls', '合并请求')
|
||||||
|
navbar.gsub!('wiki', 'Wiki')
|
||||||
|
navbar.gsub!('devops', '工作流')
|
||||||
|
navbar.gsub!('versions', '里程碑')
|
||||||
|
navbar.gsub!('resources', '资源库')
|
||||||
content.sub!('{ifnavbar}', '')
|
content.sub!('{ifnavbar}', '')
|
||||||
content.sub!('{endnavbar}', '')
|
content.sub!('{endnavbar}', '')
|
||||||
content.gsub!('{navbar}', change_params[:navbar])
|
content.gsub!('{navbar}', navbar)
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifnavbar})(.*)({endnavbar})/, '')
|
content.gsub!(/({ifnavbar})(.*)({endnavbar})/, '')
|
||||||
end
|
end
|
||||||
|
|
||||||
return receivers_string(receivers.where.not(id: operator.id)), content, url
|
return receivers_string(receivers.where.not(id: operator.id)), content, url
|
||||||
rescue => e
|
# rescue => e
|
||||||
Rails.logger.info("MessageTemplate::ProjectSettingChanged.get_message_content [ERROR] #{e}")
|
# Rails.logger.info("MessageTemplate::ProjectSettingChanged.get_message_content [ERROR] #{e}")
|
||||||
return '', '', ''
|
# return '', '', ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,51 +14,57 @@
|
||||||
# 我创建或负责的合并请求状态变更
|
# 我创建或负责的合并请求状态变更
|
||||||
class MessageTemplate::PullRequestChanged < MessageTemplate
|
class MessageTemplate::PullRequestChanged < MessageTemplate
|
||||||
|
|
||||||
# MessageTemplate::PullRequestChanged.get_message_content(User.where(login: 'yystopf'), User.last, PullRequest.last, {assigner: 'testforge2', tag: '标签', priority: '低'})
|
# MessageTemplate::PullRequestChanged.get_message_content(User.where(login: 'yystopf'), User.last, PullRequest.last, {assigned_to_id: [nil, 203], priority_id: [2, 4], fixed_version_id: [nil, 5], issue_tags_value: ["", "7"]})
|
||||||
def self.get_message_content(receivers, operator, pull_request, change_params)
|
def self.get_message_content(receivers, operator, pull_request, change_params)
|
||||||
|
return '', '', '' if change_params.blank?
|
||||||
project = pull_request&.project
|
project = pull_request&.project
|
||||||
owner = project&.owner
|
owner = project&.owner
|
||||||
issue = pull_request&.issue
|
issue = pull_request&.issue
|
||||||
content = sys_notice.gsub('{nickname1}', operator&.nickname).gsub('{nickname2}', owner&.nickname).gsub('{repository}', project&.name)
|
content = sys_notice.gsub('{nickname1}', operator&.nickname).gsub('{nickname2}', owner&.nickname).gsub('{repository}', project&.name).gsub("{title}", pull_request&.title)
|
||||||
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', pull_request&.id.to_s)
|
url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', pull_request&.id.to_s)
|
||||||
# 合并请求审查成员修改
|
# 合并请求审查成员修改
|
||||||
if change_params[:assigner].present?
|
if change_params[:assigned_to_id].present?
|
||||||
assigner = issue&.get_assign_user&.nickname || '未指派成员'
|
assigner1 = User.find_by_id(change_params[:assigned_to_id][0])
|
||||||
|
assigner2 = User.find_by_id(change_params[:assigned_to_id][1])
|
||||||
content.sub!('{ifassigner}', '')
|
content.sub!('{ifassigner}', '')
|
||||||
content.sub!('{endassigner}', '')
|
content.sub!('{endassigner}', '')
|
||||||
content.gsub!('{assigner1}', assigner)
|
content.gsub!('{assigner1}', assigner1.present? ? assigner1&.nickname || assigner1.login : '未指派成员')
|
||||||
content.gsub!('{assigner2}', change_params[:assigner])
|
content.gsub!('{assigner2}', assigner2.present? ? assigner2&.nickname || assigner2.login : '未指派成员')
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
|
content.gsub!(/({ifassigner})(.*)({endassigner})/, '')
|
||||||
end
|
end
|
||||||
# 合并请求里程碑修改
|
# 合并请求里程碑修改
|
||||||
if change_params[:milestone].present?
|
if change_params[:fixed_version_id].present?
|
||||||
milestone = issue&.version&.name || '未选择里程碑'
|
fix_version1 = Version.find_by_id(change_params[:fixed_version_id][0])
|
||||||
|
fix_version2 = Version.find_by_id(change_params[:fixed_version_id][1])
|
||||||
content.sub!('{ifmilestone}', '')
|
content.sub!('{ifmilestone}', '')
|
||||||
content.sub!('{endmilestone}', '')
|
content.sub!('{endmilestone}', '')
|
||||||
content.gsub!('{milestone1}', milestone)
|
content.gsub!('{milestone1}', fix_version1.present? ? fix_version1&.name : '未选择里程碑')
|
||||||
content.gsub!('{milestone2}', change_params[:milestone])
|
content.gsub!('{milestone2}', fix_version2.present? ? fix_version2&.name : '未选择里程碑')
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
|
content.gsub!(/({ifmilestone})(.*)({endmilestone})/, '')
|
||||||
end
|
end
|
||||||
# 合并请求标签修改
|
# 合并请求标签修改
|
||||||
if change_params[:tag].present?
|
if change_params[:issue_tags_value].present?
|
||||||
tag = issue&.issue_tags.distinct.pluck(:name).join(",")
|
issue_tags1 = IssueTag.where(id: change_params[:issue_tags_value][0]).distinct
|
||||||
tag = '未选择标签' if tag == ''
|
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(",")
|
||||||
content.sub!('{iftag}', '')
|
content.sub!('{iftag}', '')
|
||||||
content.sub!('{endtag}', '')
|
content.sub!('{endtag}', '')
|
||||||
content.gsub!('{tag1}', tag)
|
content.gsub!('{tag1}', tag1)
|
||||||
content.gsub!('{tag2}', change_params[:tag])
|
content.gsub!('{tag2}', tag2)
|
||||||
else
|
else
|
||||||
content.gsub!(/({iftag})(.*)({endtag})()/, '')
|
content.gsub!(/({iftag})(.*)({endtag})()/, '')
|
||||||
end
|
end
|
||||||
# 合并请求优先级修改
|
# 合并请求优先级修改
|
||||||
if change_params[:priority].present?
|
if change_params[:priority_id].present?
|
||||||
priority = issue&.priority&.name
|
priority1 = IssuePriority.find_by_id(change_params[:priority_id][0])
|
||||||
|
priority2 = IssuePriority.find_by_id(change_params[:priority_id][1])
|
||||||
content.sub!('{ifpriority}', '')
|
content.sub!('{ifpriority}', '')
|
||||||
content.sub!('{endpriority}', '')
|
content.sub!('{endpriority}', '')
|
||||||
content.gsub!('{priority1}', priority)
|
content.gsub!('{priority1}', priority1&.name)
|
||||||
content.gsub!('{priority2}', change_params[:priority])
|
content.gsub!('{priority2}', priority2&.name)
|
||||||
else
|
else
|
||||||
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
|
content.gsub!(/({ifpriority})(.*)({endpriority})/, '')
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,9 @@ class OrganizationUser < ApplicationRecord
|
||||||
|
|
||||||
validates :user_id, uniqueness: {scope: :organization_id}
|
validates :user_id, uniqueness: {scope: :organization_id}
|
||||||
|
|
||||||
|
after_create :send_create_message_to_notice_system
|
||||||
|
after_destroy :send_destroy_message_to_notice_system
|
||||||
|
|
||||||
def self.build(organization_id, user_id)
|
def self.build(organization_id, user_id)
|
||||||
org_user = self.find_by(organization_id: organization_id, user_id: user_id)
|
org_user = self.find_by(organization_id: organization_id, user_id: user_id)
|
||||||
return org_user unless org_user.nil?
|
return org_user unless org_user.nil?
|
||||||
|
@ -31,4 +34,12 @@ class OrganizationUser < ApplicationRecord
|
||||||
def teams
|
def teams
|
||||||
organization.teams.joins(:team_users).where(team_users: {user_id: user_id})
|
organization.teams.joins(:team_users).where(team_users: {user_id: user_id})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def send_create_message_to_notice_system
|
||||||
|
SendTemplateMessageJob.perform_later('OrganizationJoined', self.user_id, self.organization_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
def send_destroy_message_to_notice_system
|
||||||
|
SendTemplateMessageJob.perform_later('OrganizationLeft', self.user_id, self.organization_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -32,9 +32,13 @@ class ProjectUnit < ApplicationRecord
|
||||||
types.delete("pulls") if project.sync_mirror?
|
types.delete("pulls") if project.sync_mirror?
|
||||||
# 默认code类型自动创建
|
# 默认code类型自动创建
|
||||||
types << "code"
|
types << "code"
|
||||||
|
before_units = project.project_units.pluck(:unit_type).sort
|
||||||
project.project_units.where.not(unit_type: types).each(&:destroy!)
|
project.project_units.where.not(unit_type: types).each(&:destroy!)
|
||||||
types.each do |type|
|
types.each do |type|
|
||||||
project.project_units.find_or_create_by!(unit_type: type)
|
project.project_units.find_or_create_by!(unit_type: type)
|
||||||
end
|
end
|
||||||
|
after_units = project.project_units.pluck(:unit_type).sort
|
||||||
|
return before_units, after_units
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -54,4 +54,15 @@ class Team < ApplicationRecord
|
||||||
team_users.where(user_id: user_id).present?
|
team_users.where(user_id: user_id).present?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def authorize_name
|
||||||
|
case self.authorize
|
||||||
|
when 'read' then '报告者'
|
||||||
|
when 'write' then '开发者'
|
||||||
|
when 'admin' then '管理员'
|
||||||
|
when 'owner' then '管理员'
|
||||||
|
else
|
||||||
|
''
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -24,6 +24,7 @@ class Watcher < ApplicationRecord
|
||||||
|
|
||||||
after_save :reset_cache_data
|
after_save :reset_cache_data
|
||||||
after_destroy :reset_cache_data
|
after_destroy :reset_cache_data
|
||||||
|
after_create :send_create_message_to_notice_system
|
||||||
|
|
||||||
def reset_cache_data
|
def reset_cache_data
|
||||||
if self.watchable.is_a?(User)
|
if self.watchable.is_a?(User)
|
||||||
|
@ -35,4 +36,8 @@ class Watcher < ApplicationRecord
|
||||||
self.reset_platform_cache_async_job
|
self.reset_platform_cache_async_job
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def send_create_message_to_notice_system
|
||||||
|
SendTemplateMessageJob.perform_later('FollowTip', self.id) if self.watchable.is_a?(User)
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
class Notice::Write::CreateService < Notice::Write::ClientService
|
class Notice::Write::CreateService < Notice::Write::ClientService
|
||||||
attr_accessor :receivers, :sender, :content, :notification_url, :source, :extra, :type
|
attr_accessor :receivers, :sender, :content, :notification_url, :source, :extra, :type
|
||||||
|
|
||||||
def initialize(receivers, content, notification_url, source, type=1, extra={},sender=-1)
|
def initialize(receivers, content, notification_url, source, extra={}, type=1, sender=-1)
|
||||||
@receivers = receivers
|
@receivers = receivers
|
||||||
@sender = sender
|
@sender = sender
|
||||||
@content = content
|
@content = content
|
||||||
|
@ -12,6 +12,7 @@ class Notice::Write::CreateService < Notice::Write::ClientService
|
||||||
end
|
end
|
||||||
|
|
||||||
def call
|
def call
|
||||||
|
return nil if request_receivers.blank?
|
||||||
result = post("", request_params)
|
result = post("", request_params)
|
||||||
response = render_response(result)
|
response = render_response(result)
|
||||||
end
|
end
|
||||||
|
@ -19,7 +20,7 @@ class Notice::Write::CreateService < Notice::Write::ClientService
|
||||||
private
|
private
|
||||||
|
|
||||||
def request_receivers
|
def request_receivers
|
||||||
receivers.join(",")
|
receivers.is_a?(Array) ? receivers.join(",") : receivers
|
||||||
end
|
end
|
||||||
|
|
||||||
def request_params
|
def request_params
|
||||||
|
|
|
@ -921,7 +921,7 @@ Success — a happy kitten is an authenticated kitten!
|
||||||
<!--
|
<!--
|
||||||
* @Date: 2021-03-01 10:35:21
|
* @Date: 2021-03-01 10:35:21
|
||||||
* @LastEditors: viletyy
|
* @LastEditors: viletyy
|
||||||
* @LastEditTime: 2021-09-14 17:34:40
|
* @LastEditTime: 2021-09-15 18:00:10
|
||||||
* @FilePath: /forgeplus/app/docs/slate/source/includes/_users.md
|
* @FilePath: /forgeplus/app/docs/slate/source/includes/_users.md
|
||||||
-->
|
-->
|
||||||
<h1 id='users'>Users</h1><h2 id='1ae74893b1'>获取当前登陆用户信息</h2>
|
<h1 id='users'>Users</h1><h2 id='1ae74893b1'>获取当前登陆用户信息</h2>
|
||||||
|
@ -1326,14 +1326,14 @@ Success — a happy kitten is an authenticated kitten!
|
||||||
<td>消息类型</td>
|
<td>消息类型</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>recervers_login</td>
|
<td>receivers_login</td>
|
||||||
<td>array</td>
|
<td>array</td>
|
||||||
<td>需要发送消息的用户名数组</td>
|
<td>需要发送消息的用户名数组</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>atmeable_type</td>
|
<td>atmeable_type</td>
|
||||||
<td>string</td>
|
<td>string</td>
|
||||||
<td>atme消息对象,是从哪里@我的,比如评论:Journal</td>
|
<td>atme消息对象,是从哪里@我的,比如评论:Journal、易修:Issue、合并请求:PullRequest</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td>atmeable_id</td>
|
<td>atmeable_id</td>
|
||||||
|
|
Loading…
Reference in New Issue