diff --git a/app/assets/javascripts/admins/system_notifications/index.js b/app/assets/javascripts/admins/system_notifications/index.js new file mode 100644 index 000000000..90809b344 --- /dev/null +++ b/app/assets/javascripts/admins/system_notifications/index.js @@ -0,0 +1,76 @@ +/* + * @Description: Do not edit + * @Date: 2021-08-31 11:16:45 + * @LastEditors: viletyy + * @Author: viletyy + * @LastEditTime: 2021-08-31 14:19:46 + * @FilePath: /forgeplus/app/assets/javascripts/admins/system_notifications/index.js + */ +$(document).on('turbolinks:load', function(){ + + var showSuccessNotify = function() { + $.notify({ + message: '操作成功' + },{ + type: 'success' + }); + } + + // close user + $('.system-notification-list-container').on('click', '.close-action', function(){ + var $closeAction = $(this); + var $uncloseAction = $closeAction.siblings('.unclose-action'); + + var keywordID = $closeAction.data('id'); + customConfirm({ + content: '确认取消置顶吗?', + ok: function(){ + $.ajax({ + url: '/admins/system_notifications/' + keywordID, + method: 'PUT', + dataType: 'json', + data: { + system_notification: { + is_top: false + } + }, + success: function() { + showSuccessNotify(); + $closeAction.hide(); + $uncloseAction.show(); + $(".system-notification-item-"+keywordID).children('td').eq(3).text("") + } + }); + } + }); + }); + + // unclose user + $('.system-notification-list-container').on('click', '.unclose-action', function(){ + var $uncloseAction = $(this); + var $closeAction = $uncloseAction.siblings('.close-action'); + + var keywordID = $uncloseAction.data('id'); + customConfirm({ + content: '确认置顶吗?', + ok: function () { + $.ajax({ + url: '/admins/system_notifications/' + keywordID, + method: 'PUT', + dataType: 'json', + data: { + system_notification: { + is_top: true + } + }, + success: function() { + showSuccessNotify(); + $closeAction.show(); + $uncloseAction.hide(); + $(".system-notification-item-"+keywordID).children('td').eq(3).text("√") + } + }); + } + }) + }); +}) \ No newline at end of file diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb new file mode 100644 index 000000000..0dc7dd2a2 --- /dev/null +++ b/app/controllers/admins/system_notifications_controller.rb @@ -0,0 +1,71 @@ +class Admins::SystemNotificationsController < Admins::BaseController + before_action :get_notification, only: [:history, :edit,:update, :destroy] + # before_action :validate_identifer, only: [:create, :update] + + def index + sort_by = SystemNotification.column_names.include?(params[:sort_by]) ? params[:sort_by] : 'created_at' + sort_direction = %w(desc asc).include?(params[:sort_direction]) ? params[:sort_direction] : 'desc' + q = SystemNotification.ransack(subject_cont: params[:search]) + notifications = q.result(distinct: true).reorder("#{sort_by} #{sort_direction},created_at desc") + @notifications = paginate(notifications) + end + + def new + @notification = SystemNotification.new + end + + def edit + end + + def create + @notification = SystemNotification.new(notification_params) + if @notification.save + redirect_to admins_system_notifications_path + flash[:success] = '系统消息创建成功' + else + redirect_to admins_system_notifications_path + flash[:danger] = @notification.errors.full_messages.join(",") + end + end + + def update + respond_to do |format| + if @notification.update_attributes(notification_params) + format.html do + redirect_to admins_system_notifications_path + flash[:success] = '系统消息更新成功' + end + format.js {render_ok} + else + format.html do + redirect_to admins_system_notifications_path + flash[:danger] = @notification.errors.full_messages.join(",") + end + format.js {render_js_error} + end + end + end + + def destroy + if @notification.destroy + redirect_to admins_system_notifications_path + flash[:success] = "系统消息删除成功" + else + redirect_to admins_system_notifications_path + flash[:danger] = "系统消息删除失败" + end + end + + private + def notification_params + params.require(:system_notification).permit! + end + + def get_notification + @notification = SystemNotification.find_by(id: params[:id]) + unless @notification.present? + redirect_to admins_system_notifications_path + flash[:danger] = "系统消息不存在" + end + end +end \ No newline at end of file diff --git a/app/controllers/compare_controller.rb b/app/controllers/compare_controller.rb index 6dc9baade..8e8e3ec91 100644 --- a/app/controllers/compare_controller.rb +++ b/app/controllers/compare_controller.rb @@ -24,7 +24,7 @@ class CompareController < ApplicationController @exist_pullrequest = @project.pull_requests.where(is_original: false, head: @base, base: @head, status: 0).take end if @exist_pullrequest.present? - return -2, "在这些分支之间的合并请求已存在:#{@exist_pullrequest.try(:title)}" + return -2, "在这些分支之间的合并请求已存在:#{@exist_pullrequest.try(:title)}" else if @compare_result["Commits"].blank? && @compare_result["Diff"].blank? return -2, "分支内容相同,无需创建合并请求" diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index bfa15aa50..446c699e2 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -111,8 +111,8 @@ class IssuesController < ApplicationController Issues::CreateForm.new({subject:issue_params[:subject]}).validate! @issue = Issue.new(issue_params) if @issue.save! - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) - SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id) if Site.has_notice_menu? if params[:attachment_ids].present? params[:attachment_ids].each do |id| attachment = Attachment.select(:id, :container_id, :container_type)&.find_by_id(id) @@ -206,8 +206,8 @@ class IssuesController < ApplicationController Issues::UpdateForm.new({subject:issue_params[:subject]}).validate! 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? + SendTemplateMessageJob.perform_later('PullRequestChanged', current_user.id, @issue&.pull_request&.id, @issue.previous_changes.slice(:assigned_to_id, :priority_id, :fixed_version_id, :issue_tags_value)) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @issue&.pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? 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? @@ -216,8 +216,14 @@ class IssuesController < ApplicationController 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? + if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][1] == 5 + @issue.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) + end + if @issue.previous_changes[:status_id].present? && @issue.previous_changes[:status_id][0] == 5 + @issue.project_trends.where(action_type: ProjectTrend::CLOSE).destroy_all + end + SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_changes) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? end if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时 @issue.issue_times.update_all(end_time: Time.now) @@ -270,7 +276,7 @@ class IssuesController < ApplicationController status_id = @issue.status_id token = @issue.token login = @issue.user.try(:login) - SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigned_to_id, @issue.author_id) + SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigned_to_id, @issue.author_id) if Site.has_notice_menu? if @issue.destroy if issue_type == "2" && status_id != 5 post_to_chain("add", token, login) @@ -293,7 +299,7 @@ class IssuesController < ApplicationController issues = Issue.where(id: issue_ids, issue_type: "1") if issues.present? issues.find_each do |i| - SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, i&.subject, i.assigned_to_id, i.author_id) + SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, i&.subject, i.assigned_to_id, i.author_id) if Site.has_notice_menu? end if issues.destroy_all normal_status(0, "删除成功") @@ -338,8 +344,14 @@ class IssuesController < ApplicationController if i.previous_changes[:due_date].present? previous_changes.merge!(due_date: [i.previous_changes[:due_date][0].to_s, i.previous_changes[:due_date][1].to_s]) end - SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, i&.id, previous_changes) - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? + if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][1] == 5 + i.project_trends.create(user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE) + end + if i.previous_changes[:status_id].present? && i.previous_changes[:status_id][0] == 5 + i.project_trends.where(action_type: ProjectTrend::CLOSE).destroy_all + end + SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, i&.id, previous_changes) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? end normal_status(0, "批量更新成功") else @@ -354,8 +366,8 @@ class IssuesController < ApplicationController @new_issue = @issue.dup @new_issue.author_id = current_user.id if @new_issue.save - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @new_issue&.id) - SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @new_issue&.id) + SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @new_issue&.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @new_issue&.id) if Site.has_notice_menu? issue_tags = @issue.issue_tags.pluck(:id) if issue_tags.present? issue_tags.each do |tag| diff --git a/app/controllers/members_controller.rb b/app/controllers/members_controller.rb index 0af4898fc..77087770a 100644 --- a/app/controllers/members_controller.rb +++ b/app/controllers/members_controller.rb @@ -9,8 +9,8 @@ class MembersController < ApplicationController def create interactor = Projects::AddMemberInteractor.call(@project.owner, @project, @user) - SendTemplateMessageJob.perform_later('ProjectJoined', current_user.id, @user.id, @project.id) - SendTemplateMessageJob.perform_later('ProjectMemberJoined', current_user.id, @user.id, @project.id) + SendTemplateMessageJob.perform_later('ProjectJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectMemberJoined', current_user.id, @user.id, @project.id) if Site.has_notice_menu? render_response(interactor) rescue Exception => e uid_logger_error(e.message) @@ -30,8 +30,8 @@ class MembersController < ApplicationController def remove interactor = Projects::DeleteMemberInteractor.call(@project.owner, @project, @user) - SendTemplateMessageJob.perform_later('ProjectLeft', current_user.id, @user.id, @project.id) - SendTemplateMessageJob.perform_later('ProjectMemberLeft', current_user.id, @user.id, @project.id) + SendTemplateMessageJob.perform_later('ProjectLeft', current_user.id, @user.id, @project.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectMemberLeft', current_user.id, @user.id, @project.id) if Site.has_notice_menu? render_response(interactor) rescue Exception => e uid_logger_error(e.message) @@ -40,7 +40,7 @@ class MembersController < ApplicationController def change_role interactor = Projects::ChangeMemberRoleInteractor.call(@project.owner, @project, @user, params[:role]) - SendTemplateMessageJob.perform_later('ProjectRole', current_user.id, @user.id, @project.id, message_role_name) + SendTemplateMessageJob.perform_later('ProjectRole', current_user.id, @user.id, @project.id, message_role_name) if Site.has_notice_menu? render_response(interactor) rescue Exception => e uid_logger_error(e.message) diff --git a/app/controllers/organizations/team_users_controller.rb b/app/controllers/organizations/team_users_controller.rb index c63005260..0a5ff28a1 100644 --- a/app/controllers/organizations/team_users_controller.rb +++ b/app/controllers/organizations/team_users_controller.rb @@ -18,7 +18,7 @@ class Organizations::TeamUsersController < Organizations::BaseController ActiveRecord::Base.transaction do @team_user = TeamUser.build(@organization.id, @operate_user.id, @team.id) @organization_user = OrganizationUser.build(@organization.id, @operate_user.id) - SendTemplateMessageJob.perform_later('OrganizationRole', @operate_user.id, @organization.id, @team.authorize_name) + SendTemplateMessageJob.perform_later('OrganizationRole', @operate_user.id, @organization.id, @team.authorize_name) if Site.has_notice_menu? Gitea::Organization::TeamUser::CreateService.call(@organization.gitea_token, @team.gtid, @operate_user.login) end rescue Exception => e diff --git a/app/controllers/project_trends_controller.rb b/app/controllers/project_trends_controller.rb index dc1ffbdb4..66702608d 100644 --- a/app/controllers/project_trends_controller.rb +++ b/app/controllers/project_trends_controller.rb @@ -3,7 +3,7 @@ class ProjectTrendsController < ApplicationController before_action :check_project_public def index - project_trends = @project.project_trends.includes(:user, trend: :user) + project_trends = @project.project_trends.preload(:user, trend: :user) check_time = params[:time] #时间的筛选 check_type = params[:type] #动态类型的筛选,目前已知的有 Issue, PullRequest, Version @@ -14,20 +14,25 @@ class ProjectTrendsController < ApplicationController project_trends = project_trends.where("created_at between ? and ?",(Time.now.beginning_of_day - check_time.days), Time.now.end_of_day) end - @project_open_issues_count = project_trends.where(trend_type: "Issue", action_type: "create").size @project_close_issues_count = project_trends.where(trend_type: "Issue", action_type: "close").size - @project_issues_count = @project_open_issues_count + @project_close_issues_count - - @project_pr_count = project_trends.where(trend_type: "PullRequest", action_type: "close").size - @project_new_pr_count = project_trends.where(trend_type: "PullRequest", action_type: "create").size - @project_pr_all_count = @project_pr_count + @project_new_pr_count + @project_issues_count = project_trends.where(trend_type: "Issue", action_type: "create").size + @project_open_issues_count = @project_issues_count - @project_close_issues_count + @project_pr_count = project_trends.where(trend_type: "PullRequest", action_type: ["close", "merge"]).size + @project_pr_all_count = project_trends.where(trend_type: "PullRequest", action_type: "create").size + @project_new_pr_count = @project_pr_all_count - @project_pr_count if check_type.present? project_trends = project_trends.where(trend_type: check_type.to_s.strip) end if check_status.present? - project_trends = project_trends.where(action_type: check_status.to_s.strip) + if check_status == "delay" || check_status == "close" + project_trends = project_trends.where(action_type: ["close", "merge"]) + else + project_trends = project_trends.where(action_type: ["create"]).where.not(trend_id: project_trends.where(action_type: ["close", "merge"]).pluck(:trend_id)) + end + else + project_trends = project_trends.where(action_type: "create") end project_trends = project_trends.order("created_at desc") diff --git a/app/controllers/projects/project_units_controller.rb b/app/controllers/projects/project_units_controller.rb index e8b8f67a1..52cd857d1 100644 --- a/app/controllers/projects/project_units_controller.rb +++ b/app/controllers/projects/project_units_controller.rb @@ -7,7 +7,7 @@ class Projects::ProjectUnitsController < Projects::BaseController if current_user.admin? || @project.manager?(current_user) ActiveRecord::Base.transaction do 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) + SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, {navbar: true}) unless before_units.eql?(after_units) if Site.has_notice_menu? render_ok end else diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index bea2b429c..1c6e9868c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -127,9 +127,9 @@ class ProjectsController < ApplicationController Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) else validate_params = project_params.slice(:name, :description, - :project_category_id, :project_language_id, :private) + :project_category_id, :project_language_id, :private, :identifier) - Projects::UpdateForm.new(validate_params).validate! + Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id, project_identifier: @project.identifier)).validate! private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false @@ -139,14 +139,13 @@ class ProjectsController < ApplicationController gitea_params = { private: private, default_branch: @project.default_branch, - website: @project.website + website: @project.website, + name: @project.identifier } - if [true, false].include? private - Gitea::Repository::UpdateService.call(@owner, @project.identifier, gitea_params) - @project.repository.update_column(:hidden, private) - end + gitea_repo = Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params) + @project.repository.update_attributes({hidden: gitea_repo["private"], identifier: gitea_repo["name"]}) end - SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, @project.previous_changes.slice(:name, :description, :project_category_id, :project_language_id, :is_public)) + SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, @project.previous_changes.slice(:name, :description, :project_category_id, :project_language_id, :is_public, :identifier)) if Site.has_notice_menu? end rescue Exception => e uid_logger_error(e.message) @@ -229,7 +228,7 @@ class ProjectsController < ApplicationController private def project_params - params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, + params.permit(:user_id, :name, :description, :repository_name, :website, :lesson_url, :default_branch, :identifier, :project_category_id, :project_language_id, :license_id, :ignore_id, :private) end diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index d646efb0c..342f063d2 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -59,8 +59,8 @@ class PullRequestsController < ApplicationController @pull_request, @gitea_pull_request = PullRequests::CreateService.call(current_user, @owner, @project, params) if @gitea_pull_request[:status] == :success @pull_request.bind_gitea_pull_request!(@gitea_pull_request[:body]["number"], @gitea_pull_request[:body]["id"]) - SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id) - SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) + SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectPullRequest', current_user.id, @pull_request&.id) if Site.has_notice_menu? else render_error("create pull request error: #{@gitea_pull_request[:status]}") raise ActiveRecord::Rollback @@ -69,9 +69,9 @@ class PullRequestsController < ApplicationController end def edit - @fork_project_user_name = @project&.fork_project&.owner.try(:show_real_name) - @fork_project_user = @project&.fork_project&.owner.try(:login) - @fork_project_identifier = @project&.fork_project&.repository.try(:identifier) + @fork_project_user_name = @pull_request&.fork_project&.owner.try(:show_real_name) + @fork_project_user = @pull_request&.fork_project&.owner.try(:login) + @fork_project_identifier = @pull_request&.fork_project&.repository.try(:identifier) end def update @@ -118,8 +118,8 @@ class PullRequestsController < ApplicationController normal_status(-1, e.message) raise ActiveRecord::Rollback end - 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? + 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)) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('PullRequestAssigned', current_user.id, @pull_request&.id ) if @issue.previous_changes[:assigned_to_id].present? && Site.has_notice_menu? end end @@ -130,7 +130,8 @@ class PullRequestsController < ApplicationController begin colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user) if colsed === true - SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) + @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE) + SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) if Site.has_notice_menu? normal_status(1, "已拒绝") else normal_status(-1, '合并失败') @@ -171,9 +172,10 @@ class PullRequestsController < ApplicationController end if success_condition && @pull_request.merge! - @pull_request.project_trend_status! + # @pull_request.project_trend_status! + @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::MERGE) @issue&.custom_journal_detail("merge", "", "该合并请求已被合并", current_user&.id) - SendTemplateMessageJob.perform_later('PullRequestMerged', current_user.id, @pull_request.id) + SendTemplateMessageJob.perform_later('PullRequestMerged', current_user.id, @pull_request.id) if Site.has_notice_menu? normal_status(1, "合并成功") else normal_status(-1, result.message) diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index b03edb1fc..3a68ff7ba 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -5,6 +5,7 @@ class SettingsController < ApplicationController get_common_menu get_personal_menu get_third_party + get_top_system_notification end private @@ -47,6 +48,10 @@ class SettingsController < ApplicationController url: EducoderOauth.oauth_url } end + + def get_top_system_notification + @top_system_notification = SystemNotification.is_top.first + end def get_site_url(key, value) key.to_s === "url" ? append_http(reset_site_url(value)) : reset_site_url(value) diff --git a/app/controllers/template_message_settings_controller.rb b/app/controllers/template_message_settings_controller.rb new file mode 100644 index 000000000..967481f2a --- /dev/null +++ b/app/controllers/template_message_settings_controller.rb @@ -0,0 +1,8 @@ +class TemplateMessageSettingsController < ApplicationController + before_action :require_login + + def index + @group_settings = TemplateMessageSetting.group(:type).count + end + +end \ No newline at end of file diff --git a/app/controllers/users/messages_controller.rb b/app/controllers/users/messages_controller.rb index 035441ccb..5116f580f 100644 --- a/app/controllers/users/messages_controller.rb +++ b/app/controllers/users/messages_controller.rb @@ -18,16 +18,16 @@ class Users::MessagesController < Users::BaseController Notice::Write::CreateAtmeForm.new(atme_params).validate! case atme_params[:atmeable_type] when 'Issue' - SendTemplateMessageJob.perform_now('IssueAtme', @receivers, current_user.id, atme_params[:atmeable_id]) + SendTemplateMessageJob.perform_now('IssueAtme', @receivers, current_user.id, atme_params[:atmeable_id]) if Site.has_notice_menu? when 'PullRequest' - SendTemplateMessageJob.perform_now('PullRequestAtme', @receivers, current_user.id, atme_params[:atmeable_id]) + SendTemplateMessageJob.perform_now('PullRequestAtme', @receivers, current_user.id, atme_params[:atmeable_id]) if Site.has_notice_menu? 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]) + SendTemplateMessageJob.perform_now('PullRequestAtme', @receivers, current_user.id, atme_params[:atmeable_id]) if Site.has_notice_menu? else - SendTemplateMessageJob.perform_now('IssueAtme', @receivers, current_user.id, atme_params[:atmeable_id]) + SendTemplateMessageJob.perform_now('IssueAtme', @receivers, current_user.id, atme_params[:atmeable_id]) if Site.has_notice_menu? end end end diff --git a/app/controllers/users/template_message_settings_controller.rb b/app/controllers/users/template_message_settings_controller.rb new file mode 100644 index 000000000..2234e7301 --- /dev/null +++ b/app/controllers/users/template_message_settings_controller.rb @@ -0,0 +1,36 @@ +class Users::TemplateMessageSettingsController < Users::BaseController + before_action :check_auth + before_action :get_current_setting + + def current_setting + + end + + def update_setting + Rails.logger.info setting_params[:notification_body] + Rails.logger.info setting_params[:email_body] + + @current_setting.notification_body = setting_params[:notification_body].to_hash + @current_setting.email_body = setting_params[:email_body].to_hash + return render_error("保存失败") unless @current_setting.save! + end + + private + def check_auth + return render_forbidden unless current_user.admin? || observed_logged_user? + end + + def get_current_setting + @current_setting = @_observed_user.user_template_message_setting + @current_setting = UserTemplateMessageSetting.build(@_observed_user.id) if @current_setting.nil? + end + + def setting_params + params.require(:setting).permit(notification_body: {}, email_body: {}) + end + + def valid_setting_params + setting_params[:notification_body].keys.equal?(UserTemplateMessageSetting.init_notification_body.keys) && setting_params[:email_body].keys.equal?(UserTemplateMessageSetting.init_email_body) + end + +end \ No newline at end of file diff --git a/app/docs/slate/source/includes/_users.md b/app/docs/slate/source/includes/_users.md index 9d6b80927..be2728d0b 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -372,6 +372,290 @@ await octokit.request('PATCH/PUT /api/users/:login.json') "message": "success" } ``` + +## 获取平台消息设置配置信息 +获取平台消息设置配置信息 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/template_message_settings.json +``` + +```javascript +await octokit.request('GET /api/template_message_settings.json') +``` + +### HTTP 请求 +`GET /api/template_message_settings.json` + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|type |string |消息配置类型 | +|type_name |string |消息配置类型含义| +|total_settings_count |int |配置条数| +|settings.name |string |配置名称| +|settings.key |string |配置标识| +|settings.notification_disabled |boolean |站内信设置是否禁用| +|settings.email_disabled |boolean |邮件设置是否禁用| + + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "响应成功", + "setting_types": [ + { + "type": "TemplateMessageSetting::Normal", + "type_name": "", + "total_settings_count": 3, + "settings": [ + { + "name": "被拉入或移出组织", + "key": "Organization", + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "被拉入或移出项目", + "key": "Project", + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "有权限变更", + "key": "Permission", + "notification_disabled": true, + "email_disabled": false + } + ] + }, + { + "type": "TemplateMessageSetting::CreateOrAssign", + "type_name": "我创建的或负责的", + "total_settings_count": 4, + "settings": [ + { + "name": "易修被指派", + "key": "IssueAssigned", + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "合并请求被指派", + "key": "PullRequestAssigned", + "notification_disabled": true, + "email_disabled": false + } + ] + }, + { + "type": "TemplateMessageSetting::ManageProject", + "type_name": "我管理的仓库", + "total_settings_count": 4, + "settings": [ + { + "name": "有新的易修", + "key": "Issue", + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "有新的合并请求", + "key": "PullRequest", + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "有成员变动", + "key": "Member", + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "设置更改", + "key": "SettingChanged", + "notification_disabled": true, + "email_disabled": false + } + ] + } + ] +} +``` + + +## 获取用户消息设置配置信息 +获取用户消息设置配置信息 + +> 示例: + +```shell +curl -X GET http://localhost:3000/api/users/yystopf/template_message_settings.json +``` + +```javascript +await octokit.request('GET /api/uses/yystopf/template_message_settings.json') +``` + +### HTTP 请求 +`GET /api/users/:user_id/template_message_settings.json` + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|notification_body |string |站内信配置 | +|email_body |string |邮件配置| + + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "响应成功", + "user": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "notification_body": { + "CreateOrAssign::IssueAssigned": true, + "CreateOrAssign::PullRequestAssigned": true, + "ManageProject::Issue": true, + "ManageProject::PullRequest": true, + "ManageProject::Member": true, + "ManageProject::SettingChanged": true, + "Normal::Organization": true, + "Normal::Project": true, + "Normal::Permission": true + }, + "email_body": { + "CreateOrAssign::IssueAssigned": false, + "CreateOrAssign::PullRequestAssigned": false, + "ManageProject::Issue": false, + "ManageProject::PullRequest": false, + "ManageProject::Member": false, + "ManageProject::SettingChanged": true, + "Normal::Organization": false, + "Normal::Project": true, + "Normal::Permission": false + } +} +``` + + +## 重新设置用户消息设置配置信息 +重新设置用户消息设置配置信息 + +> 示例: + +```shell +curl -X POST http://localhost:3000/api/users/yystopf/template_message_settings/update_setting.json +``` + +```javascript +await octokit.request('POST /api/uses/yystopf/template_message_settings/update_setting.json') +``` + +### HTTP 请求 +`POST /api/users/:user_id/template_message_settings/update_setting.json` + +### 请求字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|notification_body |string |站内信配置 | +|email_body |string |邮件配置| + + +> 请求的JSON示例: + +```json +{ + "setting": { + "notification_body": { + "CreateOrAssign::IssueAssigned": true, + "CreateOrAssign::PullRequestAssigned": true, + "ManageProject::Issue": true, + "ManageProject::PullRequest": true, + "ManageProject::Member": true, + "ManageProject::SettingChanged": true, + "Normal::Organization": true, + "Normal::Project": true, + "Normal::Permission": true + }, + "email_body": { + "CreateOrAssign::IssueAssigned": false, + "CreateOrAssign::PullRequestAssigned": false, + "ManageProject::Issue": false, + "ManageProject::PullRequest": false, + "ManageProject::Member": false, + "ManageProject::SettingChanged": true, + "Normal::Organization": false, + "Normal::Project": "t", + "Normal::Permission": false + } + } +} +``` + +### 返回字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|notification_body |string |站内信配置 | +|email_body |string |邮件配置| + + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "响应成功", + "user": { + "id": 2, + "type": "User", + "name": "heh", + "login": "yystopf", + "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" + }, + "notification_body": { + "CreateOrAssign::IssueAssigned": true, + "CreateOrAssign::PullRequestAssigned": true, + "ManageProject::Issue": true, + "ManageProject::PullRequest": true, + "ManageProject::Member": true, + "ManageProject::SettingChanged": true, + "Normal::Organization": true, + "Normal::Project": true, + "Normal::Permission": true + }, + "email_body": { + "CreateOrAssign::IssueAssigned": false, + "CreateOrAssign::PullRequestAssigned": false, + "ManageProject::Issue": false, + "ManageProject::PullRequest": false, + "ManageProject::Member": false, + "ManageProject::SettingChanged": true, + "Normal::Organization": false, + "Normal::Project": true, + "Normal::Permission": false + } +} +``` + + ## 获取用户星标项目 获取用户星标项目 diff --git a/app/forms/issues/create_form.rb b/app/forms/issues/create_form.rb index 7dde8ecda..602775ff4 100644 --- a/app/forms/issues/create_form.rb +++ b/app/forms/issues/create_form.rb @@ -5,7 +5,7 @@ class Issues::CreateForm validates :subject, presence: { message: "不能为空" } - validates :subject, length: { maximum: 80, too_long: "不能超过80个字符" } + validates :subject, length: { maximum: 200, too_long: "不能超过200个字符" } end diff --git a/app/forms/issues/update_form.rb b/app/forms/issues/update_form.rb index 7447c8cc0..64acdfb5c 100644 --- a/app/forms/issues/update_form.rb +++ b/app/forms/issues/update_form.rb @@ -5,6 +5,6 @@ class Issues::UpdateForm validates :subject, presence: { message: "不能为空" } - validates :subject, length: { maximum: 80, too_long: "不能超过80个字符" } + validates :subject, length: { maximum: 200, too_long: "不能超过200个字符" } end \ No newline at end of file diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index 0cd2c9459..ae93abf30 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -1,11 +1,14 @@ class Projects::UpdateForm < BaseForm - attr_accessor :name, :description, :project_category_id, :project_language_id, :private + attr_accessor :name, :description, :project_category_id, :project_language_id, :private, :identifier, :user_id, :project_identifier validates :name, presence: true validates :name, length: { maximum: 50 } validates :description, length: { maximum: 200 } validate do check_project_category(project_category_id) check_project_language(project_language_id) + Rails.logger.info project_identifier + Rails.logger.info identifier + check_repository_name(user_id, identifier) unless identifier.blank? || identifier == project_identifier end end diff --git a/app/jobs/delay_expired_issue_job.rb b/app/jobs/delay_expired_issue_job.rb index 4633a953d..bf0e1d2e4 100644 --- a/app/jobs/delay_expired_issue_job.rb +++ b/app/jobs/delay_expired_issue_job.rb @@ -3,8 +3,8 @@ class DelayExpiredIssueJob < ApplicationJob def perform Issue.where(due_date: Date.today + 1.days).find_each do |issue| - SendTemplateMessageJob.perform_later('IssueAssignerExpire', issue.id) - SendTemplateMessageJob.perform_later('IssueCreatorExpire', issue.id) + SendTemplateMessageJob.perform_later('IssueAssignerExpire', issue.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('IssueCreatorExpire', issue.id) if Site.has_notice_menu? end end diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb index 2c463d705..a0191cee3 100644 --- a/app/jobs/send_template_message_job.rb +++ b/app/jobs/send_template_message_job.rb @@ -45,8 +45,12 @@ class SendTemplateMessageJob < ApplicationJob issue = Issue.find_by_id(issue_id) return unless operator.present? && issue.present? receivers = User.where(id: [issue&.assigned_to_id, issue&.author_id]).where.not(id: operator&.id) - receivers_string, content, notification_url = MessageTemplate::IssueChanged.get_message_content(receivers, operator, issue, change_params) + receivers_string, content, notification_url = MessageTemplate::IssueChanged.get_message_content(receivers, operator, issue, change_params.symbolize_keys) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, issue_id: issue.id, change_params: change_params.symbolize_keys}) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::IssueChanged.get_email_message_content(receiver, operator, issue, change_params) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'IssueCreatorExpire' issue_id = args[0] issue = Issue.find_by_id(issue_id) @@ -61,6 +65,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: [issue_assigned_to_id, issue_author_id]).where.not(id: operator&.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}) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::IssueDeleted.get_email_message_content(receiver, operator, issue_title) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'OrganizationJoined' user_id, organization_id = args[0], args[1] user = User.find_by_id(user_id) @@ -193,7 +201,7 @@ class SendTemplateMessageJob < ApplicationJob receivers_string, content, notification_url = MessageTemplate::ProjectRole.get_message_content(receivers, project, role) Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, user_id: user.id, project_id: project.id, role: role}) receivers.find_each do |receiver| - receivers_email_string, email_title, email_content = MessageTemplate::ProjectRole.get_email_message_content(receivers, project, role) + receivers_email_string, email_title, email_content = MessageTemplate::ProjectRole.get_email_message_content(receiver, project, role) Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) end when 'ProjectSettingChanged' @@ -203,7 +211,7 @@ class SendTemplateMessageJob < ApplicationJob return unless operator.present? && project.present? receivers = project.all_managers.where.not(id: operator&.id) 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}) + Notice::Write::CreateService.call(receivers_string, content, notification_url, source, {operator_id: operator.id, project_id: project.id, change_params: change_params.symbolize_keys}) receivers.find_each do |receiver| receivers_email_string, email_title, email_content = MessageTemplate::ProjectSettingChanged.get_email_message_content(receiver, operator, project, change_params.symbolize_keys) Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) @@ -238,6 +246,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: [issue&.assigned_to_id, pull_request&.user_id]).where.not(id: operator&.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}) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::PullRequestChanged.get_email_message_content(receiver, operator, pull_request, change_params.symbolize_keys) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'PullRequestClosed' operator_id, pull_request_id = args[0], args[1] operator = User.find_by_id(operator_id) @@ -246,6 +258,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: [pull_request&.issue&.assigned_to_id, pull_request&.user_id]).where.not(id: operator&.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}) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::PullRequestClosed.get_email_message_content(receiver, operator, pull_request) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end when 'PullRequestMerged' operator_id, pull_request_id = args[0], args[1] operator = User.find_by_id(operator_id) @@ -254,6 +270,10 @@ class SendTemplateMessageJob < ApplicationJob receivers = User.where(id: [pull_request&.issue&.assigned_to_id, pull_request&.user_id]).where.not(id: operator&.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}) + receivers.find_each do |receiver| + receivers_email_string, email_title, email_content = MessageTemplate::PullRequestMerged.get_email_message_content(receiver, operator, pull_request) + Notice::Write::EmailCreateService.call(receivers_email_string, email_title, email_content) + end end end end \ No newline at end of file diff --git a/app/models/message_template.rb b/app/models/message_template.rb index 2c8c96869..bd2c68bdd 100644 --- a/app/models/message_template.rb +++ b/app/models/message_template.rb @@ -20,16 +20,19 @@ class MessageTemplate < ApplicationRecord self.create(type: 'MessageTemplate::IssueAssigned', sys_notice: '{nickname1}在 {nickname2}/{repository} 指派给你一个易修:{title}', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}', email: email_html, email_title: '{nickname1} 在 {nickname2}/{repository} 指派给你一个易修') self.create(type: 'MessageTemplate::IssueAssignerExpire', sys_notice: '您负责的易修 {title} 已临近截止日期,请尽快处理', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') self.create(type: 'MessageTemplate::IssueAtme', sys_notice: '{nickname} 在易修 {title} 中@我', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') - self.create(type: 'MessageTemplate::IssueChanged', sys_notice: '在项目 {nickname2}/{repository} 的易修 {title} 中:{ifassigner}{nickname1}将负责人从 {assigner1} 修改为 {assigner2} {endassigner}{ifstatus}{nickname1}将状态从 {status1} 修改为 {status2} {endstatus}{iftracker}{nickname1}将类型从 {tracker1} 修改为 {tracker2} {endtracker}{ifpriority}{nickname1}将优先级从 {priority1} 修改为 {priority2} {endpriority}{ifmilestone}{nickname1}将里程碑从 {milestone1} 修改为 {milestone2} {endmilestone}{iftag}{nickname1}将标记从 {tag1} 修改为 {tag2} {endtag}{ifdoneratio}{nickname1}将完成度从 {doneratio1} 修改为 {doneratio2} {enddoneratio}{ifbranch}{nickname1}将指定分支从 {branch1} 修改为 {branch2} {endbranch}{ifstartdate}{nickname1}将开始日期从 {startdate1} 修改为 {startdate2} {endstartdate}{ifduedate}{nickname1}将结束日期从 {duedate1} 修改为 {duedate2} {endduedate}', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') + email_html = File.read("#{email_template_html_dir}/issue_changed.html") + self.create(type: 'MessageTemplate::IssueChanged', sys_notice: '在项目 {nickname2}/{repository} 的易修 {title} 中:{ifassigner}{nickname1}将负责人从 {assigner1} 修改为 {assigner2} {endassigner}{ifstatus}{nickname1}将状态从 {status1} 修改为 {status2} {endstatus}{iftracker}{nickname1}将类型从 {tracker1} 修改为 {tracker2} {endtracker}{ifpriority}{nickname1}将优先级从 {priority1} 修改为 {priority2} {endpriority}{ifmilestone}{nickname1}将里程碑从 {milestone1} 修改为 {milestone2} {endmilestone}{iftag}{nickname1}将标记从 {tag1} 修改为 {tag2} {endtag}{ifdoneratio}{nickname1}将完成度从 {doneratio1} 修改为 {doneratio2} {enddoneratio}{ifbranch}{nickname1}将指定分支从 {branch1} 修改为 {branch2} {endbranch}{ifstartdate}{nickname1}将开始日期从 {startdate1} 修改为 {startdate2} {endstartdate}{ifduedate}{nickname1}将结束日期从 {duedate1} 修改为 {duedate2} {endduedate}', email: email_html, email_title: '易修 {title} 有状态变更', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') self.create(type: 'MessageTemplate::IssueCreatorExpire', sys_notice: '您发布的易修 {title} 已临近截止日期,请尽快处理', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') - self.create(type: 'MessageTemplate::IssueDeleted', sys_notice: '{nickname}已将易修 {title} 删除', notification_url: '') + email_html = File.read("#{email_template_html_dir}/issue_deleted.html") + self.create(type: 'MessageTemplate::IssueDeleted', sys_notice: '{nickname}已将易修 {title} 删除', email: email_html, email_title: '易修 {title} 有状态变更', notification_url: '') self.create(type: 'MessageTemplate::IssueJournal', sys_notice: '{nickname}评论易修{title}:{notes}', notification_url: '{baseurl}/{owner}/{identifier}/issues/{id}') self.create(type: 'MessageTemplate::LoginIpTip', sys_notice: '您的账号{nickname}于{login_time)在非常用的IP地址{ip}登录,如非本人操作,请立即修改密码', notification_url: '') email_html = File.read("#{email_template_html_dir}/organization_joined.html") self.create(type: 'MessageTemplate::OrganizationJoined', sys_notice: '你已加入 {organization} 组织', notification_url: '{baseurl}/{login}', email: email_html, email_title: '你已加入 {organization} 组织') email_html = File.read("#{email_template_html_dir}/organization_left.html") self.create(type: 'MessageTemplate::OrganizationLeft', sys_notice: '你已被移出 {organization} 组织', notification_url: '', email: email_html, email_title: '你已被移出 {organization} 组织') - self.create(type: 'MessageTemplate::OrganizationRole', sys_notice: '组织 {organization} 已把你的角色改为 {role}', notification_url: '{baseurl}/{login}') + email_html = File.read("#{email_template_html_dir}/organization_role.html") + self.create(type: 'MessageTemplate::OrganizationRole', sys_notice: '组织 {organization} 已把你的角色改为 {role}', email: email_html, email_title: '在 {organization} 组织你的账号有权限变更', notification_url: '{baseurl}/{login}') self.create(type: 'MessageTemplate::ProjectDeleted', sys_notice: '你关注的仓库{nickname}/{repository}已被删除', notification_url: '') self.create(type: 'MessageTemplate::ProjectFollowed', sys_notice: '{nickname} 关注了你管理的仓库', notification_url: '{baseurl}/{login}') self.create(type: 'MessageTemplate::ProjectForked', sys_notice: '{nickname1} 复刻了你管理的仓库{nickname1}/{repository1}到{nickname2}/{repository2}', notification_url: '{baseurl}/{owner}/{identifier}') @@ -46,19 +49,23 @@ class MessageTemplate < ApplicationRecord self.create(type: 'MessageTemplate::ProjectMilestone', sys_notice: '{nickname1}在 {nickname2}/{repository} 创建了一个里程碑:{title}', notification_url: '{baseurl}/{owner}/{identifier}/milestones/{id}') self.create(type: 'MessageTemplate::ProjectPraised', sys_notice: '{nickname} 点赞了你管理的仓库', notification_url: '{baseurl}/{login}') email_html = File.read("#{email_template_html_dir}/project_pull_request.html") - self.create(type: 'MessageTemplate::ProjectPullRequest', sys_notice: '{nickname1}在 {nickname2}/{repository} 提交了一个合并请求:{title}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount', email: email_html, email_title: '{nickname1} 在 {nickname2}/{repository} 提交了一个合并请求') - self.create(type: 'MessageTemplate::ProjectRole', sys_notice: '仓库 {repository} 已把你的角色改为 {role}', notification_url: '{baseurl}/{owner}/{identifier}') + self.create(type: 'MessageTemplate::ProjectPullRequest', sys_notice: '{nickname1}在 {nickname2}/{repository} 提交了一个合并请求:{title}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}', email: email_html, email_title: '{nickname1} 在 {nickname2}/{repository} 提交了一个合并请求') + email_html = File.read("#{email_template_html_dir}/project_role.html") + self.create(type: 'MessageTemplate::ProjectRole', sys_notice: '仓库 {nickname}/{repository} 已把你的角色改为 {role}', email: email_html, email_title: '在 {nickname}/{repository} 项目你的账号有权限变更', notification_url: '{baseurl}/{owner}/{identifier}') email_html = File.read("#{email_template_html_dir}/project_setting_changed.html") - self.create(type: 'MessageTemplate::ProjectSettingChanged', sys_notice: '{nickname1}更改了 {nickname2}/{repository} 仓库设置:{ifname}更改项目名称为"{name}"{endname}{ifdescription}更改项目简介为"{description}"{enddescription}{ifcategory}更改项目类别为"{category}"{endcategory}{iflanguage}更改项目语言为"{language}"{endlanguage}{ifpermission}将仓库设为"{permission}"{endpermission}{ifnavbar}将项目导航更改为"{navbar}"{endnavbar}', notification_url: '{baseurl}/{owner}/{identifier}/settings', email: email_html, email_title: '您管理的仓库 {nickname2}/{repository} 仓库设置已被更改') + self.create(type: 'MessageTemplate::ProjectSettingChanged', sys_notice: '{nickname1}更改了 {nickname2}/{repository} 仓库设置:{ifname}更改项目名称为"{name}"{endname}{ifidentifier}更改项目标识为"{identifier}"{endidentifier}{ifdescription}更改项目简介为"{description}"{enddescription}{ifcategory}更改项目类别为"{category}"{endcategory}{iflanguage}更改项目语言为"{language}"{endlanguage}{ifpermission}将仓库设为"{permission}"{endpermission}{ifnavbar}将项目导航更改为"{navbar}"{endnavbar}', notification_url: '{baseurl}/{owner}/{identifier}/settings', email: email_html, email_title: '您管理的仓库 {nickname2}/{repository} 仓库设置已被更改') self.create(type: 'MessageTemplate::ProjectTransfer', sys_notice: '你关注的仓库{nickname1}/{repository1}已被转移至{nickname2}/{repository2}', notification_url: '{baseurl}/{owner}/{identifier}') self.create(type: 'MessageTemplate::ProjectVersion', sys_notice: '{nickname1}在 {nickname2}/{repository} 创建了发行版:{title}', notification_url: '{baseurl}/{owner}/{identifier}/releases') email_html = File.read("#{email_template_html_dir}/pull_request_assigned.html") - self.create(type: 'MessageTemplate::PullRequestAssigned', sys_notice: '{nickname1}在 {nickname2}/{repository} 指派给你一个合并请求:{title}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount', email: email_html, email_title: '{nickname1} 在 {nickname2}/{repository} 指派给你一个合并请求') - self.create(type: 'MessageTemplate::PullRequestAtme', sys_notice: '{nickname} 在合并请求 {title} 中@我', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount') - self.create(type: 'MessageTemplate::PullRequestChanged', sys_notice: '在项目{nickname2}/{repository}的合并请求 {title} 中:{ifassigner}{nickname1}将审查成员从 {assigner1} 修改为 {assigner2} {endassigner}{ifmilestone}{nickname1}将里程碑从 {milestone1} 修改为 {milestone2} {endmilestone}{iftag}{nickname1}将标记从 {tag1} 修改为 {tag2} {endtag}{ifpriority}{nickname1}将优先级从 {priority1} 修改为 {priority2} {endpriority}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount') - self.create(type: 'MessageTemplate::PullRequestClosed', sys_notice: '你提交的合并请求:{title} 被拒绝', notification_url: '') - self.create(type: 'MessageTemplate::PullRequestJournal', sys_notice: '{nickname}评论合并请求{title}:{notes}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount') - self.create(type: 'MessageTemplate::PullRequestMerged', sys_notice: '你提交的合并请求:{title} 已通过', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}/Messagecount') + self.create(type: 'MessageTemplate::PullRequestAssigned', sys_notice: '{nickname1}在 {nickname2}/{repository} 指派给你一个合并请求:{title}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}', email: email_html, email_title: '{nickname1} 在 {nickname2}/{repository} 指派给你一个合并请求') + self.create(type: 'MessageTemplate::PullRequestAtme', sys_notice: '{nickname} 在合并请求 {title} 中@我', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}') + email_html = File.read("#{email_template_html_dir}/pull_request_changed.html") + self.create(type: 'MessageTemplate::PullRequestChanged', sys_notice: '在项目{nickname2}/{repository}的合并请求 {title} 中:{ifassigner}{nickname1}将审查成员从 {assigner1} 修改为 {assigner2} {endassigner}{ifmilestone}{nickname1}将里程碑从 {milestone1} 修改为 {milestone2} {endmilestone}{iftag}{nickname1}将标记从 {tag1} 修改为 {tag2} {endtag}{ifpriority}{nickname1}将优先级从 {priority1} 修改为 {priority2} {endpriority}', email: email_html, email_title: '合并请求 {title} 有状态变更', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}') + email_html = File.read("#{email_template_html_dir}/pull_request_closed.html") + self.create(type: 'MessageTemplate::PullRequestClosed', sys_notice: '你提交的合并请求:{title} 被拒绝', email: email_html, email_title: '合并请求 {title} 有状态变更', notification_url: '') + self.create(type: 'MessageTemplate::PullRequestJournal', sys_notice: '{nickname}评论合并请求{title}:{notes}', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}') + email_html = File.read("#{email_template_html_dir}/pull_request_merged.html") + self.create(type: 'MessageTemplate::PullRequestMerged', sys_notice: '你提交的合并请求:{title} 已通过', email: email_html, email_title: '合并请求 {title} 有状态变更', notification_url: '{baseurl}/{owner}/{identifier}/pulls/{id}') end def self.sys_notice diff --git a/app/models/message_template/issue_assigned.rb b/app/models/message_template/issue_assigned.rb index 91daa8dcc..23632c3ef 100644 --- a/app/models/message_template/issue_assigned.rb +++ b/app/models/message_template/issue_assigned.rb @@ -17,6 +17,12 @@ class MessageTemplate::IssueAssigned < MessageTemplate # MessageTemplate::IssueAssigned.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last) def self.get_message_content(receivers, operator, issue) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["Normal::IssueAssigned"] + end + end + return '', '', '' if receivers.blank? project = issue&.project owner = project&.owner content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject) @@ -28,6 +34,9 @@ class MessageTemplate::IssueAssigned < MessageTemplate end 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"] + end project = issue&.project owner = project&.owner title = email_title diff --git a/app/models/message_template/issue_changed.rb b/app/models/message_template/issue_changed.rb index 6b9e79763..7edc8f05d 100644 --- a/app/models/message_template/issue_changed.rb +++ b/app/models/message_template/issue_changed.rb @@ -17,6 +17,12 @@ class MessageTemplate::IssueChanged < MessageTemplate # MessageTemplate::IssueChanged.get_message_content(User.where(login: 'yystopf'), User.last, Issue.last, {status_id: [1, 2], assigned_to_id: [nil, 203], tracker_id: [4, 3], priority_id: [2, 4], fixed_version_id: [nil, 5], due_date: ['', '2021-09-11'], done_ratio: [0, 40], issue_tags_value: ["", "7"], branch_name: ["", "master"]}) def self.get_message_content(receivers, operator, issue, change_params) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["CreateOrAssign::IssueChanged"] + end + end + return '', '', '' if receivers.blank? return '', '', '' if change_params.blank? project = issue&.project owner = project&.owner @@ -180,4 +186,183 @@ class MessageTemplate::IssueChanged < MessageTemplate Rails.logger.info("MessageTemplate::IssueAssigned.get_message_content [ERROR] #{e}") return '', '', '' end + + def self.get_email_message_content(receiver, operator, issue, change_params) + if receiver.user_template_message_setting.present? + return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::IssueChanged"] + 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}', '
') + 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}', '
') + 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}', '
') + 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}', '
') + 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}', '
') + 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}', '
') + 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}', '
') + 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}', '
') + 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}', '
') + 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}', '
') + 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 '', '', '' + end end diff --git a/app/models/message_template/issue_deleted.rb b/app/models/message_template/issue_deleted.rb index 8c4145716..c08ee0439 100644 --- a/app/models/message_template/issue_deleted.rb +++ b/app/models/message_template/issue_deleted.rb @@ -17,10 +17,35 @@ class MessageTemplate::IssueDeleted < MessageTemplate # MessageTemplate::IssueDeleted.get_message_content(User.where(login: 'yystopf'), User.last, "hahah") def self.get_message_content(receivers, operator, issue_title) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["CreateOrAssign::IssueChanged"] + end + end + return '', '', '' if receivers.blank? content = sys_notice.gsub('{nickname}', operator&.real_name).gsub('{title}', issue_title) return receivers_string(receivers), content, notification_url rescue => e - Rails.logger.info("MessageTemplate::IssueAtme.get_message_content [ERROR] #{e}") + Rails.logger.info("MessageTemplate::IssueDeleted.get_message_content [ERROR] #{e}") + return '', '', '' + end + + 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"] + 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 '', '', '' end end diff --git a/app/models/message_template/organization_joined.rb b/app/models/message_template/organization_joined.rb index 9045ac424..22cfb48d0 100644 --- a/app/models/message_template/organization_joined.rb +++ b/app/models/message_template/organization_joined.rb @@ -17,6 +17,12 @@ class MessageTemplate::OrganizationJoined < MessageTemplate # MessageTemplate::OrganizationJoined.get_message_content(User.where(login: 'yystopf'), Organization.last) def self.get_message_content(receivers, organization) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["Normal::Organization"] + end + end + return '', '', '' if receivers.blank? content = sys_notice.gsub('{organization}', organization&.real_name) url = notification_url.gsub('{login}', organization&.name) return receivers_string(receivers), content, url @@ -26,6 +32,9 @@ class MessageTemplate::OrganizationJoined < MessageTemplate end 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"] + end title = email_title title.gsub!('{organization}', organization&.real_name) content = email diff --git a/app/models/message_template/organization_left.rb b/app/models/message_template/organization_left.rb index edf8b32ec..eee752f05 100644 --- a/app/models/message_template/organization_left.rb +++ b/app/models/message_template/organization_left.rb @@ -17,6 +17,12 @@ class MessageTemplate::OrganizationLeft < MessageTemplate # MessageTemplate::OrganizationLeft.get_message_content(User.where(login: 'yystopf'), Organization.last) def self.get_message_content(receivers, organization) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["Normal::Organization"] + end + end + return '', '', '' if receivers.blank? content = sys_notice.gsub('{organization}', organization&.real_name) url = notification_url.gsub('{login}', organization&.name) return receivers_string(receivers), content, url @@ -26,6 +32,9 @@ class MessageTemplate::OrganizationLeft < MessageTemplate end 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"] + end title = email_title title.gsub!('{organization}', organization&.real_name) content = email diff --git a/app/models/message_template/organization_role.rb b/app/models/message_template/organization_role.rb index 4bc96a63e..b6024f614 100644 --- a/app/models/message_template/organization_role.rb +++ b/app/models/message_template/organization_role.rb @@ -17,6 +17,12 @@ class MessageTemplate::OrganizationRole < MessageTemplate # MessageTemplate::OrganizationRole.get_message_content(User.where(login: 'yystopf'), Organization.last, '管理员') def self.get_message_content(receivers, organization, role) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["Normal::Permission"] + end + end + return '', '', '' if receivers.blank? content = sys_notice.gsub('{organization}', organization&.real_name).gsub('{role}', role) url = notification_url.gsub('{login}', organization&.login) return receivers_string(receivers), content, url @@ -26,6 +32,9 @@ class MessageTemplate::OrganizationRole < MessageTemplate end 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"] + end title = email_title title.gsub!('{organization}', organization&.real_name) title.gsub!('{role}', role) diff --git a/app/models/message_template/project_issue.rb b/app/models/message_template/project_issue.rb index 8e319bf3b..9106bcc8f 100644 --- a/app/models/message_template/project_issue.rb +++ b/app/models/message_template/project_issue.rb @@ -17,9 +17,15 @@ class MessageTemplate::ProjectIssue < MessageTemplate # MessageTemplate::ProjectIssue.get_message_content(User.where(login: 'yystopf'), User.where(login: 'forgetest1'), User.last, Issue.last) def self.get_message_content(managers, followers, operator, issue) + managers.each do |receiver| + if receiver.user_template_message_setting.present? + managers = managers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["ManageProject::Issue"] + end + end project = issue&.project owner = project&.owner receivers = managers + followers + return '', '', '' if receivers.blank? content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', issue&.subject) url = notification_url.gsub('{owner}', owner&.login).gsub('{identifier}', project&.identifier).gsub('{id}', issue&.id.to_s) @@ -30,6 +36,9 @@ class MessageTemplate::ProjectIssue < MessageTemplate end 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"] + end project = issue&.project owner = project&.owner title = email_title diff --git a/app/models/message_template/project_joined.rb b/app/models/message_template/project_joined.rb index 3ff1d23d7..b46dc51a7 100644 --- a/app/models/message_template/project_joined.rb +++ b/app/models/message_template/project_joined.rb @@ -17,6 +17,12 @@ class MessageTemplate::ProjectJoined < MessageTemplate # MessageTemplate::ProjectJoined.get_message_content(User.where(login: 'yystopf'), Project.last) def self.get_message_content(receivers, project) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["Normal::Project"] + end + end + return '', '', '' if receivers.blank? content = sys_notice.gsub('{repository}', project&.name) url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) return receivers_string(receivers), content, url @@ -26,6 +32,9 @@ class MessageTemplate::ProjectJoined < MessageTemplate end 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"] + end title = email_title title.gsub!('{repository}', project&.name) diff --git a/app/models/message_template/project_left.rb b/app/models/message_template/project_left.rb index 3244e59a0..3dfa7bb61 100644 --- a/app/models/message_template/project_left.rb +++ b/app/models/message_template/project_left.rb @@ -17,6 +17,11 @@ class MessageTemplate::ProjectLeft < MessageTemplate # MessageTemplate::ProjectLeft.get_message_content(User.where(login: 'yystopf'), Project.last) def self.get_message_content(receivers, project) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["Normal::Project"] + end + end content = sys_notice.gsub('{repository}', project&.name) url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) return receivers_string(receivers), content, url @@ -26,6 +31,9 @@ class MessageTemplate::ProjectLeft < MessageTemplate end 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"] + end title = email_title title.gsub!('{repository}', project&.name) diff --git a/app/models/message_template/project_member_joined.rb b/app/models/message_template/project_member_joined.rb index e2ab7d610..7a781750c 100644 --- a/app/models/message_template/project_member_joined.rb +++ b/app/models/message_template/project_member_joined.rb @@ -17,6 +17,12 @@ class MessageTemplate::ProjectMemberJoined < MessageTemplate # MessageTemplate::ProjectMemberJoined.get_message_content(User.where(login: 'yystopf')) def self.get_message_content(receivers, user, project) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["ManageProject::Member"] + end + end + return '', '', '' if receivers.blank? content = sys_notice.gsub('{nickname1}', user&.real_name).gsub('{nickname2}', project&.owner&.real_name).gsub('{repository}', project&.name) url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) return receivers_string(receivers), content, url @@ -26,6 +32,9 @@ class MessageTemplate::ProjectMemberJoined < MessageTemplate end 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"] + end title = email_title title.gsub!('{nickname1}', user&.real_name) title.gsub!('{nickname2}', project&.owner&.real_name) diff --git a/app/models/message_template/project_member_left.rb b/app/models/message_template/project_member_left.rb index a7d9911d6..f41791233 100644 --- a/app/models/message_template/project_member_left.rb +++ b/app/models/message_template/project_member_left.rb @@ -17,6 +17,12 @@ class MessageTemplate::ProjectMemberLeft < MessageTemplate # MessageTemplate::ProjectMemberLeft.get_message_content(User.where(login: 'yystopf'), User.last, Project.last) def self.get_message_content(receivers, user, project) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["ManageProject::Member"] + end + end + return '', '', '' if receivers.blank? content = sys_notice.gsub('{nickname1}', user&.real_name).gsub('{nickname2}', project&.owner&.real_name).gsub('{repository}', project&.name) url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) return receivers_string(receivers), content, url @@ -26,6 +32,9 @@ class MessageTemplate::ProjectMemberLeft < MessageTemplate end 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"] + end title = email_title title.gsub!('{nickname1}', user&.real_name) title.gsub!('{nickname2}', project&.owner&.real_name) diff --git a/app/models/message_template/project_pull_request.rb b/app/models/message_template/project_pull_request.rb index 704936f54..ac04651ef 100644 --- a/app/models/message_template/project_pull_request.rb +++ b/app/models/message_template/project_pull_request.rb @@ -17,9 +17,15 @@ class MessageTemplate::ProjectPullRequest < MessageTemplate # MessageTemplate::ProjectPullRequest.get_message_content(User.where(login: 'yystopf'), User.where(login: 'testforge2'), User.last, PullRequest.last) def self.get_message_content(managers, followers, operator, pull_request) + managers.each do |receiver| + if receiver.user_template_message_setting.present? + managers = managers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["ManageProject::PullRequest"] + end + end project = pull_request&.project owner = project&.owner receivers = managers + followers + return '', '', '' if receivers.blank? content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).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) @@ -30,6 +36,9 @@ class MessageTemplate::ProjectPullRequest < MessageTemplate end 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"] + end project = pull_request&.project owner = project&.owner title = email_title diff --git a/app/models/message_template/project_role.rb b/app/models/message_template/project_role.rb index 4db81ab47..e306f5c02 100644 --- a/app/models/message_template/project_role.rb +++ b/app/models/message_template/project_role.rb @@ -17,7 +17,13 @@ class MessageTemplate::ProjectRole < MessageTemplate # MessageTemplate::ProjectRole.get_message_content(User.where(login: 'yystopf'), Project.last, '管理员') def self.get_message_content(receivers, project, role) - content = sys_notice.gsub('{repository}', project&.name).gsub('{role}', role) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["Normal::Permission"] + end + end + return '', '', '' if receivers.blank? + content = sys_notice.gsub('{nickname}', project&.owner&.real_name).gsub('{repository}', project&.name).gsub('{role}', role) url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) return receivers_string(receivers), content, url rescue => e @@ -25,14 +31,19 @@ class MessageTemplate::ProjectRole < MessageTemplate return '', '', '' end - def self.get_email_message_content(receivers, project, role) + 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"] + 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) diff --git a/app/models/message_template/project_setting_changed.rb b/app/models/message_template/project_setting_changed.rb index 3a8df5ffc..457ab9207 100644 --- a/app/models/message_template/project_setting_changed.rb +++ b/app/models/message_template/project_setting_changed.rb @@ -17,6 +17,12 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate # 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) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["ManageProject::SettingChanged"] + end + end + return '', '', '' if receivers.blank? return '', '', '' if change_params.blank? owner = project&.owner content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name) @@ -34,6 +40,18 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate else content.gsub!(/({ifname})(.*)({endname})/, '') end + # 项目标识更改 + if change_params[:identifier].present? + if change_count > 1 + content.sub!('{ifidentifier}', '
') + 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? @@ -141,6 +159,9 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate end def self.get_email_message_content(receiver, operator, project, change_params) + if receiver.user_template_message_setting.present? + return '', '', '' unless receiver.user_template_message_setting.email_body["ManageProject::SettingChanged"] + end return '', '', '' if change_params.blank? owner = project&.owner title = email_title @@ -169,6 +190,18 @@ class MessageTemplate::ProjectSettingChanged < MessageTemplate else content.gsub!(/({ifname})(.*)({endname})/, '') end + # 项目标识更改 + if change_params[:identifier].present? + if change_count > 1 + content.sub!('{ifidentifier}', '
') + 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? diff --git a/app/models/message_template/pull_request_assigned.rb b/app/models/message_template/pull_request_assigned.rb index 54d51f3f3..1101ca46b 100644 --- a/app/models/message_template/pull_request_assigned.rb +++ b/app/models/message_template/pull_request_assigned.rb @@ -17,6 +17,12 @@ class MessageTemplate::PullRequestAssigned < MessageTemplate # MessageTemplate::PullRequestAssigned.get_message_content(User.where(login: 'yystopf'), User.last, PullRequest.last) def self.get_message_content(receivers, operator, pull_request) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["Normal::PullRequestAssigned"] + end + end + return '', '', '' if receivers.blank? project = pull_request&.project owner = project&.owner content = sys_notice.gsub('{nickname1}', operator&.real_name).gsub('{nickname2}', owner&.real_name).gsub('{repository}', project&.name).gsub('{title}', pull_request&.title) @@ -28,6 +34,9 @@ class MessageTemplate::PullRequestAssigned < MessageTemplate end 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"] + end project = pull_request&.project owner = project&.owner title = email_title diff --git a/app/models/message_template/pull_request_changed.rb b/app/models/message_template/pull_request_changed.rb index 099607fbe..729e12060 100644 --- a/app/models/message_template/pull_request_changed.rb +++ b/app/models/message_template/pull_request_changed.rb @@ -17,6 +17,12 @@ class MessageTemplate::PullRequestChanged < MessageTemplate # 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) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["CreateOrAssign::PullRequestChanged"] + end + end + return '', '', '' if receivers.blank? return '', '', '' if change_params.blank? project = pull_request&.project owner = project&.owner @@ -92,4 +98,95 @@ class MessageTemplate::PullRequestChanged < MessageTemplate Rails.logger.info("MessageTemplate::PullRequestChanged.get_message_content [ERROR] #{e}") return '', '', '' end + + def self.get_email_message_content(receiver, operator, pull_request, change_params) + if receiver.user_template_message_setting.present? + return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::PullRequestChanged"] + 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}', '
') + 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[: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}', '
') + 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}', '
') + 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}', '
') + 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 '', '', '' + end end diff --git a/app/models/message_template/pull_request_closed.rb b/app/models/message_template/pull_request_closed.rb index 6ebb23a63..f160ebf20 100644 --- a/app/models/message_template/pull_request_closed.rb +++ b/app/models/message_template/pull_request_closed.rb @@ -17,6 +17,12 @@ class MessageTemplate::PullRequestClosed < MessageTemplate # MessageTemplate::PullRequestClosed.get_message_content(User.where(login: 'yystopf'), User.last, PullRequest.last) def self.get_message_content(receivers, operator, pull_request) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["CreateOrAssign::PullRequestChanged"] + end + end + return '', '', '' if receivers.blank? project = pull_request&.project owner = project&.owner content = sys_notice.gsub('{title}', pull_request&.title) @@ -26,4 +32,30 @@ class MessageTemplate::PullRequestClosed < MessageTemplate Rails.logger.info("MessageTemplate::PullRequestClosed.get_message_content [ERROR] #{e}") return '', '', '' end + + 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"] + 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 '', '', '' + end end diff --git a/app/models/message_template/pull_request_merged.rb b/app/models/message_template/pull_request_merged.rb index 8df4255a0..3dccffdd7 100644 --- a/app/models/message_template/pull_request_merged.rb +++ b/app/models/message_template/pull_request_merged.rb @@ -17,6 +17,12 @@ class MessageTemplate::PullRequestMerged < MessageTemplate # MessageTemplate::PullRequestMerged.get_message_content(User.where(login: 'yystopf'), User.last, PullRequest.last) def self.get_message_content(receivers, operator, pull_request) + receivers.each do |receiver| + if receiver.user_template_message_setting.present? + receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["CreateOrAssign::PullRequestChanged"] + end + end + return '', '', '' if receivers.blank? project = pull_request&.project owner = project&.owner content = sys_notice.gsub('{title}', pull_request&.title) @@ -26,4 +32,30 @@ class MessageTemplate::PullRequestMerged < MessageTemplate Rails.logger.info("MessageTemplate::PullRequestMerged.get_message_content [ERROR] #{e}") return '', '', '' end + + 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"] + 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 '', '', '' + end end diff --git a/app/models/organization_user.rb b/app/models/organization_user.rb index 1ad2abd9a..4ff6946b7 100644 --- a/app/models/organization_user.rb +++ b/app/models/organization_user.rb @@ -36,10 +36,10 @@ class OrganizationUser < ApplicationRecord end def send_create_message_to_notice_system - SendTemplateMessageJob.perform_later('OrganizationJoined', self.user_id, self.organization_id) + SendTemplateMessageJob.perform_later('OrganizationJoined', self.user_id, self.organization_id) if Site.has_notice_menu? end def send_destroy_message_to_notice_system - SendTemplateMessageJob.perform_later('OrganizationLeft', self.user_id, self.organization_id) + SendTemplateMessageJob.perform_later('OrganizationLeft', self.user_id, self.organization_id) if Site.has_notice_menu? end end diff --git a/app/models/project_trend.rb b/app/models/project_trend.rb index 8c55c4f94..7642e1dfb 100644 --- a/app/models/project_trend.rb +++ b/app/models/project_trend.rb @@ -20,7 +20,8 @@ class ProjectTrend < ApplicationRecord CLOSE = 'close' CREATE = 'create' - + MERGE = 'merge' + belongs_to :project belongs_to :trend, polymorphic: true, optional: true belongs_to :user diff --git a/app/models/site.rb b/app/models/site.rb index de352dcc5..af5e78169 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -26,6 +26,10 @@ class Site < ApplicationRecord set_common_menu! end + def self.has_notice_menu? + self.common.where(key: 'notice').present? + end + private def self.set_add_menu! adds= [ diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb new file mode 100644 index 000000000..6f901b3fd --- /dev/null +++ b/app/models/system_notification.rb @@ -0,0 +1,20 @@ +# == Schema Information +# +# Table name: system_notifications +# +# id :integer not null, primary key +# subject :string(255) +# sub_subject :string(255) +# content :text(65535) +# is_top :boolean +# created_at :datetime not null +# updated_at :datetime not null +# + +class SystemNotification < ApplicationRecord + + default_scope { order(created_at: :desc)} + + scope :is_top, lambda { where(is_top: true) } + +end diff --git a/app/models/template_message_setting.rb b/app/models/template_message_setting.rb new file mode 100644 index 000000000..a9c81500b --- /dev/null +++ b/app/models/template_message_setting.rb @@ -0,0 +1,30 @@ +# == Schema Information +# +# Table name: template_message_settings +# +# id :integer not null, primary key +# type :string(255) +# name :string(255) +# key :string(255) +# openning :boolean +# notification_disabled :boolean +# email_disabled :boolean +# created_at :datetime not null +# updated_at :datetime not null +# + +class TemplateMessageSetting < ApplicationRecord + + scope :openning, ->() {where(openning: true)} + + def self.type_name + "" + end + + def self.build_init_data + TemplateMessageSetting::CreateOrAssign.build_init_data + TemplateMessageSetting::ManageProject.build_init_data + TemplateMessageSetting::Normal.build_init_data + TemplateMessageSetting::WatchProject.build_init_data + end +end diff --git a/app/models/template_message_setting/create_or_assign.rb b/app/models/template_message_setting/create_or_assign.rb new file mode 100644 index 000000000..2c9fa2076 --- /dev/null +++ b/app/models/template_message_setting/create_or_assign.rb @@ -0,0 +1,31 @@ +# == Schema Information +# +# Table name: template_message_settings +# +# id :integer not null, primary key +# type :string(255) +# name :string(255) +# key :string(255) +# openning :boolean +# notification_disabled :boolean +# email_disabled :boolean +# created_at :datetime not null +# updated_at :datetime not null +# + +#我创建的或负责的 +class TemplateMessageSetting::CreateOrAssign < TemplateMessageSetting + + def self.type_name + "我创建的或负责的" + end + + def self.order_index + 20 + end + + def self.build_init_data + self.find_or_create_by(name: "易修状态变更", key: "IssueChanged") + self.find_or_create_by(name: "合并请求状态变更", key: "PullRequestChanged") + end +end diff --git a/app/models/template_message_setting/manage_project.rb b/app/models/template_message_setting/manage_project.rb new file mode 100644 index 000000000..2aa9e4883 --- /dev/null +++ b/app/models/template_message_setting/manage_project.rb @@ -0,0 +1,33 @@ +# == Schema Information +# +# Table name: template_message_settings +# +# id :integer not null, primary key +# type :string(255) +# name :string(255) +# key :string(255) +# openning :boolean +# notification_disabled :boolean +# email_disabled :boolean +# created_at :datetime not null +# updated_at :datetime not null +# + +#我管理的 +class TemplateMessageSetting::ManageProject < TemplateMessageSetting + + def self.type_name + "我管理的仓库" + end + + def self.order_index + 30 + end + + def self.build_init_data + self.find_or_create_by(name: "有新的易修", key: "Issue") + self.find_or_create_by(name: "有新的合并请求", key: "PullRequest") + self.find_or_create_by(name: "有成员变动", key: "Member") + self.find_or_create_by(name: "仓库设置被更改", key: "SettingChanged") + end +end diff --git a/app/models/template_message_setting/normal.rb b/app/models/template_message_setting/normal.rb new file mode 100644 index 000000000..9090196d5 --- /dev/null +++ b/app/models/template_message_setting/normal.rb @@ -0,0 +1,33 @@ +# == Schema Information +# +# Table name: template_message_settings +# +# id :integer not null, primary key +# type :string(255) +# name :string(255) +# key :string(255) +# openning :boolean +# notification_disabled :boolean +# email_disabled :boolean +# created_at :datetime not null +# updated_at :datetime not null +# + +class TemplateMessageSetting::Normal < TemplateMessageSetting + + def self.type_name + "我的状态" + end + + def self.order_index + 10 + end + + def self.build_init_data + self.find_or_create_by(name: "账号有权限变更", key: "Permission") + self.find_or_create_by(name: "被拉入或移出组织", key: "Organization") + self.find_or_create_by(name: "被拉入或移出项目", key: "Project") + self.find_or_create_by(name: "有新的易修指派给我", key: "IssueAssigned") + self.find_or_create_by(name: "有新的合并请求指派给我", key: "PullRequestAssigned") + end +end diff --git a/app/models/template_message_setting/watch_project.rb b/app/models/template_message_setting/watch_project.rb new file mode 100644 index 000000000..35dfef6db --- /dev/null +++ b/app/models/template_message_setting/watch_project.rb @@ -0,0 +1,29 @@ +# == Schema Information +# +# Table name: template_message_settings +# +# id :integer not null, primary key +# type :string(255) +# name :string(255) +# key :string(255) +# openning :boolean +# notification_disabled :boolean +# email_disabled :boolean +# created_at :datetime not null +# updated_at :datetime not null +# + +#我关注的 +class TemplateMessageSetting::WatchProject < TemplateMessageSetting + + def self.type_name + "我关注的仓库" + end + + def self.order_index + 40 + end + + def self.build_init_data + end +end diff --git a/app/models/user.rb b/app/models/user.rb index e2b82e6df..15c760a3f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -172,6 +172,8 @@ class User < Owner has_many :pull_requests, dependent: :destroy has_many :public_keys, class_name: "Gitea::PublicKey",primary_key: :gitea_uid, foreign_key: :owner_id, dependent: :destroy + has_one :user_template_message_setting, dependent: :destroy + # Groups and active users scope :active, lambda { where(status: [STATUS_ACTIVE, STATUS_EDIT_INFO]) } scope :like, lambda { |keywords| diff --git a/app/models/user_template_message_setting.rb b/app/models/user_template_message_setting.rb new file mode 100644 index 000000000..c581e626e --- /dev/null +++ b/app/models/user_template_message_setting.rb @@ -0,0 +1,72 @@ +# == Schema Information +# +# Table name: user_template_message_settings +# +# id :integer not null, primary key +# user_id :integer +# notification_body :text(65535) +# email_body :text(65535) +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_user_template_message_settings_on_user_id (user_id) +# + +class UserTemplateMessageSetting < ApplicationRecord + serialize :notification_body, Hash + serialize :email_body, Hash + + belongs_to :user + + before_update :set_body_value + + def self.build(user_id) + self.create!(user_id: user_id, notification_body: init_notification_body, email_body: init_email_body) + end + + def self.init_notification_body + { + "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 + + def self.init_email_body + { + "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 + + private + + def set_body_value + self.notification_body.each do |k, v| + self.notification_body[k] = ActiveModel::Type::Boolean.new.cast(v).nil? ? false : ActiveModel::Type::Boolean.new.cast(v) + end + + self.email_body.each do |k, v| + self.email_body[k] = ActiveModel::Type::Boolean.new.cast(v).nil? ? false : ActiveModel::Type::Boolean.new.cast(v) + end + end +end diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 7ff20943e..6a8c94fcc 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -37,7 +37,7 @@ class Watcher < ApplicationRecord end def send_create_message_to_notice_system - SendTemplateMessageJob.perform_later('FollowTip', self.id) if self.watchable.is_a?(User) + SendTemplateMessageJob.perform_later('FollowTip', self.id) if self.watchable.is_a?(User) if Site.has_notice_menu? end end diff --git a/app/services/gitea/repository/get_branch_and_tag_total_num_service.rb b/app/services/gitea/repository/get_branch_and_tag_total_num_service.rb new file mode 100644 index 000000000..0b8a52467 --- /dev/null +++ b/app/services/gitea/repository/get_branch_and_tag_total_num_service.rb @@ -0,0 +1,37 @@ + +module Gitea + module Repository + class GetBranchAndTagTotalNumService < Gitea::ClientService + attr_reader :owner, :repo, :token + + def initialize(owner, repo, token=nil) + @owner = owner + @repo = repo + @token = token + end + + def call + response = get(url, params) + render_result(response) + end + + private + def params + Hash.new.merge(token: token) + end + + def url + "/repos/#{owner}/#{repo}/branch_tag_count".freeze + end + + def render_result(response) + case response.status + when 200 + JSON.parse(response.body) + else + {} + end + end + end + end +end diff --git a/app/services/gitea/repository/update_service.rb b/app/services/gitea/repository/update_service.rb index 0d27922b8..6c4eff1b3 100644 --- a/app/services/gitea/repository/update_service.rb +++ b/app/services/gitea/repository/update_service.rb @@ -19,7 +19,8 @@ class Gitea::Repository::UpdateService < Gitea::ClientService end def call - patch(url, data_params) + response = patch(url, data_params) + render_200_response(response) end private diff --git a/app/services/projects/accept_join_service.rb b/app/services/projects/accept_join_service.rb index b1a996fd8..2bbacad69 100644 --- a/app/services/projects/accept_join_service.rb +++ b/app/services/projects/accept_join_service.rb @@ -53,8 +53,8 @@ class Projects::AcceptJoinService < ApplicationService def operate_project_member Projects::AddMemberInteractor.call(@project.owner, @project, @applied_project.user, permission) - SendTemplateMessageJob.perform_later('ProjectJoined', @user.id, @applied_project.user_id, @project.id) - SendTemplateMessageJob.perform_later('ProjectMemberJoined', @user.id, @applied_project.user_id, @project.id) + SendTemplateMessageJob.perform_later('ProjectJoined', @user.id, @applied_project.user_id, @project.id) if Site.has_notice_menu? + SendTemplateMessageJob.perform_later('ProjectMemberJoined', @user.id, @applied_project.user_id, @project.id) if Site.has_notice_menu? end def send_apply_message diff --git a/app/services/repositories/detail_service.rb b/app/services/repositories/detail_service.rb index 4b29d50a7..b2e7a69e6 100644 --- a/app/services/repositories/detail_service.rb +++ b/app/services/repositories/detail_service.rb @@ -10,11 +10,9 @@ class Repositories::DetailService < ApplicationService def call return { repo: repo_suitable, - release: release_suitable, - branch: branch_suitable, - tag: tag_suitable, contributor: contributor_suitable, - language: language_suitable + language: language_suitable, + branch_tag_total_count: branch_tag_total_count } rescue return { @@ -30,25 +28,14 @@ class Repositories::DetailService < ApplicationService end private + def branch_tag_total_count + Gitea::Repository::GetBranchAndTagTotalNumService.call(@owner.login, @repo.identifier, @owner.gitea_token) + end + def repo_suitable Gitea::Repository::GetService.call(@owner, @repo.identifier) end - def release_suitable - releases = Gitea::Versions::ListService.call(@owner.gitea_token, @owner.try(:login), @repo.try(:identifier), {page: 1, limit: 1}) - releases.is_a?(Hash) && releases[:status] == -1 ? [] : releases - end - - def branch_suitable - branches = Gitea::Repository::Branches::ListService.call(@owner, @repo.identifier) - branches.is_a?(Hash) && branches.key?(:status) ? [] : branches - end - - def tag_suitable - tags = Gitea::Repository::Tags::ListService.call(@owner&.gitea_token, @owner.login, @repo.identifier) - tags.is_a?(Hash) && tags[:status] == -1 ? [] : tags - end - def contributor_suitable contributors = Gitea::Repository::Contributors::GetService.call(@owner, @repo.identifier) contributors.is_a?(Hash) && contributors.key?(:status) ? [] : contributors diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb index 402449b3b..75abbc124 100644 --- a/app/views/admins/shared/_sidebar.html.erb +++ b/app/views/admins/shared/_sidebar.html.erb @@ -30,8 +30,6 @@
  • <%= sidebar_item(admins_reversed_keywords_path, '系统保留关键词', icon: 'key', controller: 'admins-reversed_keywords') %>
  • -
  • <%= sidebar_item(admins_message_templates_path, '消息模版', icon: 'folder', controller: 'admins-message_templates') %>
  • -
  • <%= sidebar_item(admins_laboratories_path, '云上实验室', icon: 'cloud', controller: 'admins-laboratories') %>
  • @@ -48,6 +46,8 @@ <%= sidebar_item_group('#setting-system', '系统配置', icon: 'wrench') do %>
  • <%= sidebar_item(admins_sites_path, 'setting接口配置', icon: 'deaf', controller: 'admins-sites') %>
  • <%= sidebar_item(admins_edu_settings_path, '全局变量配置', icon: 'pencil-square', controller: 'admins-edu_settings') %>
  • +
  • <%= sidebar_item(admins_system_notifications_path, '系统通知配置', icon: 'bell', controller: 'admins-system_notifications') %>
  • +
  • <%= sidebar_item(admins_message_templates_path, '消息模版配置', icon: 'folder', controller: 'admins-message_templates') %>
  • <% end %>
  • diff --git a/app/views/admins/system_notifications/_form.html.erb b/app/views/admins/system_notifications/_form.html.erb new file mode 100644 index 000000000..33c35747a --- /dev/null +++ b/app/views/admins/system_notifications/_form.html.erb @@ -0,0 +1,57 @@ +
    +
    <%= type == "create" ? "新建" : "编辑" %>系统通知
    + <%= link_to "返回", admins_system_notifications_path, class: "btn btn-default pull-right" %> +
    + +
    + <%= form_for @notification, url: {controller: "system_notifications", action: "#{type}"} do |p| %> +
    + +
    + <%= p.text_field :subject, class: "form-control input-lg", placeholder: "请输入系统通知标题" %> +
    + +
    +
    + +
    + <%= p.text_field :sub_subject, class: "form-control input-lg", placeholder: "请输入系统通知副标题" %> +
    + +
    +
    + +
    + <%= p.text_area :content, class:"form-control", style: 'display: none;', rows: "10", cols: "20", placeholer: "请输入系统通知正文" %> +
    + +
    + +
    +
    + <%= p.check_box :is_top, class: "form-check-input", value:"true"%> + +
    +
    +
    + <%= p.submit "确认", class: "btn btn-primary submit-btn" %> +
    + <% end %> +
    \ No newline at end of file diff --git a/app/views/admins/system_notifications/_form_modal.html.erb b/app/views/admins/system_notifications/_form_modal.html.erb new file mode 100644 index 000000000..658bbc9c0 --- /dev/null +++ b/app/views/admins/system_notifications/_form_modal.html.erb @@ -0,0 +1,40 @@ + \ No newline at end of file diff --git a/app/views/admins/system_notifications/_list.html.erb b/app/views/admins/system_notifications/_list.html.erb new file mode 100644 index 000000000..0d86ab035 --- /dev/null +++ b/app/views/admins/system_notifications/_list.html.erb @@ -0,0 +1,35 @@ + + + + + + + + + + + + + <% if notifications.present? %> + <% notifications.each_with_index do |notification, index| %> + + + + + + + + + <% end %> + <% else %> + <%= render 'admins/shared/no_data_for_table' %> + <% end %> + +
    序号标题副标题<%= sort_tag('是否置顶', name: 'is_top', path: admins_system_notifications_path) %><%= sort_tag('创建时间', name: 'created_at', path: admins_system_notifications_path) %>操作
    <%= list_index_no((params[:page] || 1).to_i, index) %><%= notification.subject %><%= notification.sub_subject %><%= notification.is_top ? '√' : '' %><%= notification.created_at&.strftime('%Y-%m-%d %H:%M') %> + <%= javascript_void_link '置顶', class: 'action unclose-action', data: { id: notification.id }, style: notification.is_top ? 'display: none;' : '' %> + <%= javascript_void_link '取消置顶', class: 'action close-action', data: { id: notification.id }, style: notification.is_top ? '' : 'display: none;' %> + <%= link_to "编辑", edit_admins_system_notification_path(notification), remote: true, class: "action" %> + <%= link_to "删除", admins_system_notification_path(notification), method: :delete, data:{confirm: "确认删除的吗?"}, class: "action" %> +
    + +<%= render partial: 'admins/shared/paginate', locals: { objects: notifications } %> \ No newline at end of file diff --git a/app/views/admins/system_notifications/edit.js.erb b/app/views/admins/system_notifications/edit.js.erb new file mode 100644 index 000000000..e5929f876 --- /dev/null +++ b/app/views/admins/system_notifications/edit.js.erb @@ -0,0 +1,2 @@ +$("#admins-system-notification-content").html("<%= j render(partial: 'admins/system_notifications/form', locals: {type: 'update'}) %>") +createMDEditor('system-notification-content-editor', { height: 500, placeholder: '请输入邮件模版' }); \ No newline at end of file diff --git a/app/views/admins/system_notifications/index.html.erb b/app/views/admins/system_notifications/index.html.erb new file mode 100644 index 000000000..01a35f216 --- /dev/null +++ b/app/views/admins/system_notifications/index.html.erb @@ -0,0 +1,21 @@ +<% define_admin_breadcrumbs do %> + <% add_admin_breadcrumb('系统通知模版') %> +<% end %> + +
    +
    + <%= form_tag(admins_system_notifications_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': '搜索中...') %> + + <% end %> + <%= link_to "新增", new_admins_system_notification_path, remote: true, class: "btn btn-primary pull-right", "data-disabled-with":"...新增" %> +
    + +
    +
    + +
    + <%= render partial: 'admins/system_notifications/list', locals: { notifications: @notifications } %> +
    +
    \ No newline at end of file diff --git a/app/views/admins/system_notifications/index.js.erb b/app/views/admins/system_notifications/index.js.erb new file mode 100644 index 000000000..a5cfec841 --- /dev/null +++ b/app/views/admins/system_notifications/index.js.erb @@ -0,0 +1 @@ +$('.system-notification-list-container').html("<%= j( render partial: 'admins/system_notifications/list', locals: { notifications: @notifications } ) %>"); \ No newline at end of file diff --git a/app/views/admins/system_notifications/new.js.erb b/app/views/admins/system_notifications/new.js.erb new file mode 100644 index 000000000..885357b5a --- /dev/null +++ b/app/views/admins/system_notifications/new.js.erb @@ -0,0 +1,2 @@ +$("#admins-system-notification-content").html("<%= j render(partial: 'admins/system_notifications/form', locals: {type: 'create'}) %>") +createMDEditor('system-notification-content-editor', { height: 500, placeholder: '请输入邮件模版' }); diff --git a/app/views/pull_requests/show.json.jbuilder b/app/views/pull_requests/show.json.jbuilder index 5c30bd172..ee6563965 100644 --- a/app/views/pull_requests/show.json.jbuilder +++ b/app/views/pull_requests/show.json.jbuilder @@ -3,8 +3,8 @@ json.project_name @project.name json.identifier @project.identifier json.project_identifier @project.identifier json.pr_time time_from_now(@pull_request.updated_at) -json.commits_count @pull_request.commits_count -json.files_count @pull_request.files_count +json.commits_count @gitea_pull["commit_num"] +json.files_count @gitea_pull["changed_files"] json.comments_count @issue.journals.parent_journals.size json.comments_total_count @issue.get_journals_size diff --git a/app/views/repositories/detail.json.jbuilder b/app/views/repositories/detail.json.jbuilder index c08077088..c489cf47a 100644 --- a/app/views/repositories/detail.json.jbuilder +++ b/app/views/repositories/detail.json.jbuilder @@ -51,28 +51,8 @@ if @result[:repo] json.private @result[:repo]['private'] end json.license_name @project.license_name -json.release_versions do - json.list @result[:release].each do |release| - forge_version = VersionRelease.find_by(version_gid: release["id"]) - json.id forge_version&.id - json.name release["name"] - json.tag_name release["tag_name"] - json.created_at format_time(release["created_at"].to_time) - end - json.total_count @repository&.version_releases.size -end -json.branches do - json.list @result[:branch].each do |branch| - json.name branch["name"] - end - json.total_count @result[:branch].size -end -json.tags do - json.list @result[:tag].each do |tag| - json.name tag["name"] - end - json.total_count @result[:tag].size -end +json.branches_count @result[:branch_tag_total_count]['branch_count'] || 0 +json.tags_count @result[:branch_tag_total_count]['tag_count'] || 0 json.contributors do total_count = @result[:contributor].size json.list @result[:contributor].each do |contributor| diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index ea42f20b4..93347c1d6 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -57,4 +57,12 @@ json.setting do json.common @common json.third_party @third_party + + if @top_system_notification.present? + json.system_notification do + json.(@top_system_notification, :id, :subject, :sub_subject, :content) + end + else + json.system_notification nil + end end diff --git a/app/views/template_message_settings/_detail.json.jbuilder b/app/views/template_message_settings/_detail.json.jbuilder new file mode 100644 index 000000000..d85a4c4ea --- /dev/null +++ b/app/views/template_message_settings/_detail.json.jbuilder @@ -0,0 +1,8 @@ +json.type type +json.type_name type.constantize.type_name +json.total_settings_count count +json.settings do + json.array! type.constantize.openning.limit(100).each do |setting| + json.(setting, :name, :key, :notification_disabled, :email_disabled) + end +end \ No newline at end of file diff --git a/app/views/template_message_settings/index.json.jbuilder b/app/views/template_message_settings/index.json.jbuilder new file mode 100644 index 000000000..4f863ce0f --- /dev/null +++ b/app/views/template_message_settings/index.json.jbuilder @@ -0,0 +1,11 @@ +json.partial! "commons/success" +json.setting_types do + + json.array! @group_settings.keys.sort_by{|i| i.constantize.order_index}.each do |k| + json.partial! "detail", type: k, count: @group_settings[k] + end + + # json.array! @group_settings, partial: 'detail', as: :type + + +end \ No newline at end of file diff --git a/app/views/users/template_message_settings/_detail.json.jbuilder b/app/views/users/template_message_settings/_detail.json.jbuilder new file mode 100644 index 000000000..18a3e31ed --- /dev/null +++ b/app/views/users/template_message_settings/_detail.json.jbuilder @@ -0,0 +1,5 @@ +json.user do + json.partial! 'users/user_simple', locals: { user: setting.user } +end +json.notification_body setting.notification_body +json.email_body setting.email_body \ No newline at end of file diff --git a/app/views/users/template_message_settings/current_setting.json.jbuilder b/app/views/users/template_message_settings/current_setting.json.jbuilder new file mode 100644 index 000000000..514aadb7c --- /dev/null +++ b/app/views/users/template_message_settings/current_setting.json.jbuilder @@ -0,0 +1,2 @@ +json.partial! "commons/success" +json.partial! "detail", locals: {setting: @current_setting} \ No newline at end of file diff --git a/app/views/users/template_message_settings/update_setting.json.jbuilder b/app/views/users/template_message_settings/update_setting.json.jbuilder new file mode 100644 index 000000000..514aadb7c --- /dev/null +++ b/app/views/users/template_message_settings/update_setting.json.jbuilder @@ -0,0 +1,2 @@ +json.partial! "commons/success" +json.partial! "detail", locals: {setting: @current_setting} \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 005bd926a..35fea39c7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -150,6 +150,8 @@ Rails.application.routes.draw do resources :issue_depends, only: [:create, :destroy] end + resources :template_message_settings, only: [:index] + resources :applied_projects, only: [:create] resources :project_categories, only: [:index, :show] do @@ -263,6 +265,8 @@ Rails.application.routes.draw do end scope module: :users do + get 'template_message_settings', to: 'template_message_settings#current_setting' + post 'template_message_settings/update_setting', to: 'template_message_settings#update_setting' resources :applied_messages, only: [:index] resources :applied_transfer_projects, only: [:index] do member do @@ -670,6 +674,7 @@ Rails.application.routes.draw do resources :project_licenses resources :project_ignores resources :reversed_keywords + resources :system_notifications resources :message_templates, only: [:index, :edit, :update] do collection do get :init_data diff --git a/db/migrate/20211012060724_create_system_notifications.rb b/db/migrate/20211012060724_create_system_notifications.rb new file mode 100644 index 000000000..2dcade417 --- /dev/null +++ b/db/migrate/20211012060724_create_system_notifications.rb @@ -0,0 +1,13 @@ +class CreateSystemNotifications < ActiveRecord::Migration[5.2] + def change + # 系统消息 + create_table :system_notifications do |t| + t.string :subject, comment: "标题" + t.string :sub_subject, comment: "副标题" + t.string :content, comment: "正文" + t.boolean :is_top, comment: "是否置顶" + + t.timestamps + end + end +end diff --git a/db/migrate/20211013081221_create_template_message_settings.rb b/db/migrate/20211013081221_create_template_message_settings.rb new file mode 100644 index 000000000..a3140493e --- /dev/null +++ b/db/migrate/20211013081221_create_template_message_settings.rb @@ -0,0 +1,17 @@ +class CreateTemplateMessageSettings < ActiveRecord::Migration[5.2] + def change + # 平台的通知设置 + create_table :template_message_settings do |t| + t.string :type + t.string :name + t.string :key + t.boolean :openning, default: true + t.boolean :notification_disabled, default: true + t.boolean :email_disabled, default: false + + t.timestamps + end + + TemplateMessageSetting.build_init_data + end +end diff --git a/db/migrate/20211013081713_create_user_template_message_settings.rb b/db/migrate/20211013081713_create_user_template_message_settings.rb new file mode 100644 index 000000000..47964d3f7 --- /dev/null +++ b/db/migrate/20211013081713_create_user_template_message_settings.rb @@ -0,0 +1,12 @@ +class CreateUserTemplateMessageSettings < ActiveRecord::Migration[5.2] + def change + # 用户对系统通知的设置 + create_table :user_template_message_settings do |t| + t.references :user + t.text :notification_body + t.text :email_body + + t.timestamps + end + end +end diff --git a/db/migrate/20211013090556_change_system_notification_content_column.rb b/db/migrate/20211013090556_change_system_notification_content_column.rb new file mode 100644 index 000000000..1e0e80927 --- /dev/null +++ b/db/migrate/20211013090556_change_system_notification_content_column.rb @@ -0,0 +1,5 @@ +class ChangeSystemNotificationContentColumn < ActiveRecord::Migration[5.2] + def change + change_column :system_notifications, :content, :text + end +end diff --git a/lib/tasks/refactor_project_trend.rake b/lib/tasks/refactor_project_trend.rake new file mode 100644 index 000000000..e2092d028 --- /dev/null +++ b/lib/tasks/refactor_project_trend.rake @@ -0,0 +1,30 @@ +namespace :refactor_project_trend do + desc "refactor project trend data record" + + task issue_and_pull_request: :environment do + puts "========DELETE all old data begin========" + old_data_count = ProjectTrend.where(trend_type: ["PullRequest","Issue"]).destroy_all.size + puts "========DELETE all old data #{old_data_count}========" + puts "========DELETE all old data end========" + puts "========CREATE new issue data begin========" + issue_count = 0 + Issue.issue_issue.find_each do |issue| + issue_count += 1 + issue.project_trends.create(user_id: issue.assigned_to_id || issue.author_id, project_id: issue.project_id, action_type: ProjectTrend::CLOSE, created_at: issue.updated_on) if issue.status_id == 5 + issue.project_trends.create(user_id: issue.author_id, project_id: issue.project_id, action_type: ProjectTrend::CREATE, created_at: issue.created_on) + end + puts "========CREATE new issue data #{issue_count}========" + puts "========CREATE new issue data end========" + puts "========CREATE new pull_request data begin========" + pull_request_count = 0 + PullRequest.find_each do |pull_request| + pull_request_count += 1 + pull_request.project_trends.create(user_id: pull_request.user_id, project_id: pull_request.project_id, action_type: ProjectTrend::MERGE, created_at: pull_request.updated_at) if pull_request.status == PullRequest::MERGED + pull_request.project_trends.create(user_id: pull_request.user_id, project_id: pull_request.project_id, action_type: ProjectTrend::CLOSE, created_at: pull_request.updated_at) if pull_request.status == PullRequest::CLOSED + pull_request.project_trends.create(user_id: pull_request.user_id, project_id: pull_request.project_id, action_type: ProjectTrend::CREATE, created_at: pull_request.created_at) + end + puts "========CREATE new pull_request data #{pull_request_count}========" + puts "========CREATE new pull_request data end========" + + end +end \ No newline at end of file diff --git a/public/docs/api.html b/public/docs/api.html index 8368e8fae..5df230a28 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -360,6 +360,15 @@
  • 更改用户信息
  • +
  • + 获取平台消息设置配置信息 +
  • +
  • + 获取用户消息设置配置信息 +
  • +
  • + 重新设置用户消息设置配置信息 +
  • 获取用户星标项目
  • @@ -1569,7 +1578,339 @@ Success — a happy kitten is an authenticated kitten! "status": 0, "message": "success" } -

    获取用户星标项目

    +

    获取平台消息设置配置信息

    +

    获取平台消息设置配置信息

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/template_message_settings.json
    +
    await octokit.request('GET /api/template_message_settings.json')
    +

    HTTP 请求

    +

    GET /api/template_message_settings.json

    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    typestring消息配置类型
    type_namestring消息配置类型含义
    total_settings_countint配置条数
    settings.namestring配置名称
    settings.keystring配置标识
    settings.notification_disabledboolean站内信设置是否禁用
    settings.email_disabledboolean邮件设置是否禁用
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "响应成功",
    +    "setting_types": [
    +        {
    +            "type": "TemplateMessageSetting::Normal",
    +            "type_name": "",
    +            "total_settings_count": 3,
    +            "settings": [
    +                {
    +                    "name": "被拉入或移出组织",
    +                    "key": "Organization",
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "被拉入或移出项目",
    +                    "key": "Project",
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "有权限变更",
    +                    "key": "Permission",
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                }
    +            ]
    +        },
    +        {
    +            "type": "TemplateMessageSetting::CreateOrAssign",
    +            "type_name": "我创建的或负责的",
    +            "total_settings_count": 4,
    +            "settings": [
    +                {
    +                    "name": "易修被指派",
    +                    "key": "IssueAssigned",
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "合并请求被指派",
    +                    "key": "PullRequestAssigned",
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                }
    +            ]
    +        },
    +        {
    +            "type": "TemplateMessageSetting::ManageProject",
    +            "type_name": "我管理的仓库",
    +            "total_settings_count": 4,
    +            "settings": [
    +                {
    +                    "name": "有新的易修",
    +                    "key": "Issue",
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "有新的合并请求",
    +                    "key": "PullRequest",
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "有成员变动",
    +                    "key": "Member",
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "设置更改",
    +                    "key": "SettingChanged",
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                }
    +            ]
    +        }
    +    ]
    +}
    +
    + +

    获取用户消息设置配置信息

    +

    获取用户消息设置配置信息

    + +
    +

    示例:

    +
    +
    curl -X GET http://localhost:3000/api/users/yystopf/template_message_settings.json
    +
    await octokit.request('GET /api/uses/yystopf/template_message_settings.json')
    +

    HTTP 请求

    +

    GET /api/users/:user_id/template_message_settings.json

    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    notification_bodystring站内信配置
    email_bodystring邮件配置
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "响应成功",
    +    "user": {
    +        "id": 2,
    +        "type": "User",
    +        "name": "heh",
    +        "login": "yystopf",
    +        "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +    },
    +    "notification_body": {
    +        "CreateOrAssign::IssueAssigned": true,
    +        "CreateOrAssign::PullRequestAssigned": true,
    +        "ManageProject::Issue": true,
    +        "ManageProject::PullRequest": true,
    +        "ManageProject::Member": true,
    +        "ManageProject::SettingChanged": true,
    +        "Normal::Organization": true,
    +        "Normal::Project": true,
    +        "Normal::Permission": true
    +    },
    +    "email_body": {
    +        "CreateOrAssign::IssueAssigned": false,
    +        "CreateOrAssign::PullRequestAssigned": false,
    +        "ManageProject::Issue": false,
    +        "ManageProject::PullRequest": false,
    +        "ManageProject::Member": false,
    +        "ManageProject::SettingChanged": true,
    +        "Normal::Organization": false,
    +        "Normal::Project": true,
    +        "Normal::Permission": false
    +    }
    +}
    +
    + +

    重新设置用户消息设置配置信息

    +

    重新设置用户消息设置配置信息

    + +
    +

    示例:

    +
    +
    curl -X POST http://localhost:3000/api/users/yystopf/template_message_settings/update_setting.json
    +
    await octokit.request('POST /api/uses/yystopf/template_message_settings/update_setting.json')
    +

    HTTP 请求

    +

    POST /api/users/:user_id/template_message_settings/update_setting.json

    +

    请求字段说明:

    + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    notification_bodystring站内信配置
    email_bodystring邮件配置
    + +
    +

    请求的JSON示例:

    +
    +
    {
    +    "setting": {
    +        "notification_body": {
    +            "CreateOrAssign::IssueAssigned": true,
    +            "CreateOrAssign::PullRequestAssigned": true,
    +            "ManageProject::Issue": true,
    +            "ManageProject::PullRequest": true,
    +            "ManageProject::Member": true,
    +            "ManageProject::SettingChanged": true,
    +            "Normal::Organization": true,
    +            "Normal::Project": true,
    +            "Normal::Permission": true
    +        },
    +        "email_body": {
    +            "CreateOrAssign::IssueAssigned": false,
    +            "CreateOrAssign::PullRequestAssigned": false,
    +            "ManageProject::Issue": false,
    +            "ManageProject::PullRequest": false,
    +            "ManageProject::Member": false,
    +            "ManageProject::SettingChanged": true,
    +            "Normal::Organization": false,
    +            "Normal::Project": "t",
    +            "Normal::Permission": false
    +        }
    +   }
    +}
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    notification_bodystring站内信配置
    email_bodystring邮件配置
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "响应成功",
    +    "user": {
    +        "id": 2,
    +        "type": "User",
    +        "name": "heh",
    +        "login": "yystopf",
    +        "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
    +    },
    +    "notification_body": {
    +        "CreateOrAssign::IssueAssigned": true,
    +        "CreateOrAssign::PullRequestAssigned": true,
    +        "ManageProject::Issue": true,
    +        "ManageProject::PullRequest": true,
    +        "ManageProject::Member": true,
    +        "ManageProject::SettingChanged": true,
    +        "Normal::Organization": true,
    +        "Normal::Project": true,
    +        "Normal::Permission": true
    +    },
    +    "email_body": {
    +        "CreateOrAssign::IssueAssigned": false,
    +        "CreateOrAssign::PullRequestAssigned": false,
    +        "ManageProject::Issue": false,
    +        "ManageProject::PullRequest": false,
    +        "ManageProject::Member": false,
    +        "ManageProject::SettingChanged": true,
    +        "Normal::Organization": false,
    +        "Normal::Project": true,
    +        "Normal::Permission": false
    +    }
    +}
    +
    + +

    获取用户星标项目

    获取用户星标项目

    @@ -1577,9 +1918,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/is_pinned_projects.json
     
    await octokit.request('GET /api/users/:login/is_pinned_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/is_pinned_projects.json

    -

    返回字段说明:

    +

    返回字段说明:

    @@ -1764,9 +2105,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/is_pinned_projects/pin.json
     
    await octokit.request('GET /api/users/:login/is_pinned_projects/pin.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST /api/users/:login/is_pinned_projects/pin.json

    -

    请求字段说明:

    同时设定多个星标项目

    +

    请求字段说明:

    同时设定多个星标项目

    参数
    @@ -1810,9 +2151,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X PATCH http://localhost:3000/api/users/yystopf/is_pinned_projects/11.json
     
    await octokit.request('PATCH/PUT /api/users/:login/is_pinned_projects/:id.json')
    -

    HTTP 请求

    +

    HTTP 请求

    PATCH/PUT /api/users/:login/is_pinned_projects/:id.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1851,9 +2192,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/activity.json
     
    await octokit.request('GET /api/users/:login/statistics/activity.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/activity.json

    -

    返回字段说明:

    +

    返回字段说明:

    参数
    @@ -1940,9 +2281,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/headmaps.json
     
    await octokit.request('GET /api/users/:login/headmaps.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/headmaps.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1956,7 +2297,7 @@ Success — a happy kitten is an authenticated kitten!
    参数年份
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2085,9 +2426,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/project_trends.json
     
    await octokit.request('GET /api/users/:login/project_trends.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET api/users/:login/project_trends.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2101,7 +2442,7 @@ Success — a happy kitten is an authenticated kitten!
    参数日期,格式: 2021-05-28
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2402,9 +2743,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/develop.json
     
    await octokit.request('GET /api/users/:login/statistics/develop.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/develop.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2423,7 +2764,7 @@ Success — a happy kitten is an authenticated kitten!
    参数时间戳,结束时间,格式:1622131200
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2545,9 +2886,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/role.json
     
    await octokit.request('GET /api/users/:login/statistics/role.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/role.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2566,7 +2907,7 @@ Success — a happy kitten is an authenticated kitten!
    参数时间戳,结束时间,格式:1622131200
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2627,9 +2968,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/statistics/major.json
     
    await octokit.request('GET /api/users/:login/statistics/major.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/statistics/major.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2648,7 +2989,7 @@ Success — a happy kitten is an authenticated kitten!
    参数时间戳,结束时间,格式:1622131200
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2688,9 +3029,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_messages.json
     
    await octokit.request('GET /api/users/:login/applied_messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2704,7 +3045,7 @@ Success — a happy kitten is an authenticated kitten!
    参数用户标识
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2967,9 +3308,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_transfer_projects.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2983,7 +3324,7 @@ Success — a happy kitten is an authenticated kitten!
    参数用户标识
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -3159,9 +3500,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/accept.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects/:id/accept.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects/:id/accept.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3180,7 +3521,7 @@ Success — a happy kitten is an authenticated kitten!
    参数迁移id
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -3350,9 +3691,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_transfer_projects/2/refuse.json
     
    await octokit.request('GET /api/users/:login/applied_transfer_projects/:id/refuse.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_transfer_projects/:id/refuse.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3371,7 +3712,7 @@ Success — a happy kitten is an authenticated kitten!
    参数迁移id
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -3541,9 +3882,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X GET http://localhost:3000/api/users/yystopf/applied_projects.json
     
    await octokit.request('GET /api/users/:login/applied_projects.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3557,7 +3898,7 @@ Success — a happy kitten is an authenticated kitten!
    参数用户标识
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -3701,9 +4042,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_projects/2/accept.json
     
    await octokit.request('GET /api/users/:login/applied_projects/:id/accept.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects/:id/accept.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3722,7 +4063,7 @@ Success — a happy kitten is an authenticated kitten!
    参数申请id
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -3860,9 +4201,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/yystopf/applied_projects/2/refuse.json
     
    await octokit.request('GET /api/users/:login/applied_projects/:id/refuse.json')
    -

    HTTP 请求

    +

    HTTP 请求

    GET /api/users/:login/applied_projects/:id/refuse.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3881,7 +4222,7 @@ Success — a happy kitten is an authenticated kitten!
    参数申请id
    -

    返回字段说明:

    +

    返回字段说明:

    diff --git a/public/message_template/issue_changed.html b/public/message_template/issue_changed.html new file mode 100755 index 000000000..5f8d796b4 --- /dev/null +++ b/public/message_template/issue_changed.html @@ -0,0 +1,62 @@ + + + 有新的易修指派给我 + + + + +
    +
    +
    + +

    确实让创新更美好

    +
    +
    +
    +

    + {receiver},您好!
    + 在项目 {nickname2}/{repository} 的易修 {title} 中: + {ifassigner}{nickname1}将负责人从 {assigner1} 修改为 {assigner2}{endassigner} + {ifstatus}{nickname1}将状态从 {status1} 修改为 {status2}{endstatus} + {iftracker}{nickname1}将类型从 {tracker1} 修改为 {tracker2}{endtracker} + {ifpriority}{nickname1}将优先级从 {priority1} 修改为 {priority2}{endpriority} + {ifmilestone}{nickname1}将里程碑从 {milestone1} 修改为 {milestone2}{endmilestone} + {iftag}{nickname1}将标记从 {tag1} 修改为 {tag2}{endtag} + {ifdoneratio}{nickname1}将完成度从 {doneratio1} 修改为 {doneratio2}{enddoneratio} + {ifbranch}{nickname1}将指定分支从 {branch1} 修改为 {branch2}{endbranch} + {ifstartdate}{nickname1}将开始日期从 {startdate1} 修改为 {startdate2}{endstartdate} + {ifduedate}{nickname1}将结束日期从 {duedate1} 修改为 {duedate2}{endduedate} +

    +
    + +

    + 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
    + 想了解更多信息,请访问 www.trustie.net +

    +
    +
    +

    如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
    + QQ群:1071514693

    +

    Trustie团队

    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/public/message_template/issue_deleted.html b/public/message_template/issue_deleted.html new file mode 100755 index 000000000..1eb40c81c --- /dev/null +++ b/public/message_template/issue_deleted.html @@ -0,0 +1,52 @@ + + + 易修状态改变 + + + + +
    +
    +
    + +

    确实让创新更美好

    +
    +
    +
    +

    + {receiver},您好!
    + {nickname}已将易修 {title} 删除 +

    +
    + +

    + 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
    + 想了解更多信息,请访问 www.trustie.net +

    +
    +
    +

    如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
    + QQ群:1071514693

    +

    Trustie团队

    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/public/message_template/organization_role.html b/public/message_template/organization_role.html new file mode 100755 index 000000000..661698b8a --- /dev/null +++ b/public/message_template/organization_role.html @@ -0,0 +1,52 @@ + + + 组织权限被更改 + + + + +
    +
    +
    + +

    确实让创新更美好

    +
    +
    +
    +

    + {receiver},您好!
    + 组织 {organization} 已把你的角色修改为 {role} +

    +
    + +

    + 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
    + 想了解更多信息,请访问 www.trustie.net +

    +
    +
    +

    如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
    + QQ群:1071514693

    +

    Trustie团队

    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/public/message_template/project_pull_request.html b/public/message_template/project_pull_request.html index 0f75e0b8c..c342894b0 100755 --- a/public/message_template/project_pull_request.html +++ b/public/message_template/project_pull_request.html @@ -31,7 +31,7 @@

    {receiver},您好!
    - {nickname1}在 {nickname2}/{repository} 提交了一个合并请求:{title}
    + {nickname1}在 {nickname2}/{repository} 提交了一个合并请求:{title}

    diff --git a/public/message_template/project_role.html b/public/message_template/project_role.html new file mode 100755 index 000000000..db64a4f76 --- /dev/null +++ b/public/message_template/project_role.html @@ -0,0 +1,52 @@ + + + 移出项目 + + + + +
    +
    +
    + +

    确实让创新更美好

    +
    +
    +
    +

    + {receiver},您好!
    + 项目 {nickname}/{repository} 已把你的角色修改为 {role} +

    +
    + +

    + 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
    + 想了解更多信息,请访问 www.trustie.net +

    +
    +
    +

    如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
    + QQ群:1071514693

    +

    Trustie团队

    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/public/message_template/project_setting_changed.html b/public/message_template/project_setting_changed.html index ca51e262c..ef5af71fd 100755 --- a/public/message_template/project_setting_changed.html +++ b/public/message_template/project_setting_changed.html @@ -33,6 +33,7 @@ {receiver},您好!
    {nickname1} 更改 {nickname2}/{repository} 的仓库设置: {ifname}更改项目名称为"{name}"{endname} + {ifidentifier}更改项目标识为"{identifier}"{endidentifier} {ifdescription}更改项目简介为"{description}"{enddescription} {ifcategory}更改项目类别为"{category}"{endcategory} {iflanguage}更改项目语言为"{language}"{endlanguage} diff --git a/public/message_template/pull_request_assigned.html b/public/message_template/pull_request_assigned.html index 3898336e4..fe139ec1b 100755 --- a/public/message_template/pull_request_assigned.html +++ b/public/message_template/pull_request_assigned.html @@ -31,7 +31,7 @@

    {receiver},您好!
    - {nickname1}在 {nickname2}/{repository} 指派给你一个合并请求:{title}
    + {nickname1}在 {nickname2}/{repository} 指派给你一个合并请求:{title}

    diff --git a/public/message_template/pull_request_changed.html b/public/message_template/pull_request_changed.html new file mode 100755 index 000000000..5cafdc47e --- /dev/null +++ b/public/message_template/pull_request_changed.html @@ -0,0 +1,56 @@ + + + 合并请求被更改 + + + + +
    +
    +
    + +

    确实让创新更美好

    +
    +
    +
    +

    + {receiver},您好!
    + 在项目 {nickname2}/{repository} 的合并请求 {title} 中: + {ifassigner}{nickname1}将负责人从 {assigner1} 修改为 {assigner2}{endassigner} + {ifmilestone}{nickname1}将里程碑从 {milestone1} 修改为 {milestone2}{endmilestone} + {iftag}{nickname1}将标记从 {tag1} 修改为 {tag2}{endtag} + {ifpriority}{nickname1}将优先级从 {priority1} 修改为 {priority2}{endpriority} +

    +
    + +

    + 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
    + 想了解更多信息,请访问 www.trustie.net +

    +
    +
    +

    如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
    + QQ群:1071514693

    +

    Trustie团队

    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/public/message_template/pull_request_closed.html b/public/message_template/pull_request_closed.html new file mode 100755 index 000000000..d0828c19a --- /dev/null +++ b/public/message_template/pull_request_closed.html @@ -0,0 +1,52 @@ + + + 合并请求被关闭 + + + + +
    +
    +
    + +

    确实让创新更美好

    +
    +
    +
    +

    + {receiver},您好!
    + 你提交的合并请求:{title} 被拒绝; +

    +
    + +

    + 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
    + 想了解更多信息,请访问 www.trustie.net +

    +
    +
    +

    如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
    + QQ群:1071514693

    +

    Trustie团队

    +
    +
    +
    +
    + + \ No newline at end of file diff --git a/public/message_template/pull_request_merged.html b/public/message_template/pull_request_merged.html new file mode 100755 index 000000000..e1f028a7e --- /dev/null +++ b/public/message_template/pull_request_merged.html @@ -0,0 +1,52 @@ + + + 合并请求被合并 + + + + +
    +
    +
    + +

    确实让创新更美好

    +
    +
    +
    +

    + {receiver},您好!
    + 你提交的合并请求:{title} 已通过; +

    +
    + +

    + 扫一扫,关注trustie微信公众号,更方便获取平台动态,消息推送等提醒
    + 想了解更多信息,请访问 www.trustie.net +

    +
    +
    +

    如果您在使用中有任何的疑问和建议,欢迎您给我们反馈意见
    + QQ群:1071514693

    +

    Trustie团队

    +
    +
    +
    +
    + + \ No newline at end of file
    参数