From 2587ccea2810ea6d7cbe8aa85ae277f5d8d1a940 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Oct 2021 11:23:43 +0800 Subject: [PATCH 01/37] add: pr compare exist pr --- app/controllers/compare_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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, "分支内容相同,无需创建合并请求" From 8ba1198b4ac8543d5c8b0b784165f8b8b533219c Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 16:38:12 +0800 Subject: [PATCH 02/37] fix: pr files commits count --- app/views/pull_requests/show.json.jbuilder | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 From 3d8b19fa7379638ab5dff9fcb3929c3a1e11cbbc Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 16:59:43 +0800 Subject: [PATCH 03/37] fix: edit pr fork project info --- app/controllers/pull_requests_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index fe04dd5e5..1a31704b2 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -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 From 119883042281d10bef72309e8596e2e3602ab2ae Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Oct 2021 16:41:01 +0800 Subject: [PATCH 04/37] add: project permit change identifier --- app/controllers/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index bea2b429c..e4ad2f136 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -229,7 +229,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 From 018745c062e1067ed1b9dd5938bc632f28fa838e Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Oct 2021 17:08:25 +0800 Subject: [PATCH 05/37] add: project permit change identifier --- app/controllers/projects_controller.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index e4ad2f136..95d9bc1ac 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -139,11 +139,12 @@ 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) + Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params) + @project.repository.update_attributes({hidden: private, identifier: @project.identifier}) end end SendTemplateMessageJob.perform_later('ProjectSettingChanged', current_user.id, @project&.id, @project.previous_changes.slice(:name, :description, :project_category_id, :project_language_id, :is_public)) From 00100e59c451471b17cff059b2a4147f028e329e Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Oct 2021 17:15:50 +0800 Subject: [PATCH 06/37] add: project permit change identifier --- app/controllers/projects_controller.rb | 6 ++---- app/services/gitea/repository/update_service.rb | 3 ++- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 95d9bc1ac..25d8b8d76 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -142,10 +142,8 @@ class ProjectsController < ApplicationController website: @project.website, name: @project.identifier } - if [true, false].include? private - Gitea::Repository::UpdateService.call(@owner, @project&.repository&.identifier, gitea_params) - @project.repository.update_attributes({hidden: private, identifier: @project.identifier}) - 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)) 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 From 98a45eb05cc30b6cb0e02817606324ef9fc732f8 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 14:25:00 +0800 Subject: [PATCH 07/37] fix: update repository identifier valid --- app/controllers/projects_controller.rb | 4 ++-- app/forms/projects/update_form.rb | 3 ++- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 25d8b8d76..54ae85ca0 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)).validate! private = @project.forked_from_project.present? ? !@project.forked_from_project.is_public : params[:private] || false diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index 0cd2c9459..9ccc611cf 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -1,11 +1,12 @@ 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 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) + check_repository_name(user_id, identifier) unless identifier.blank? end end From 79b394d29162cb777ebaa7427961d3883bd38d0b Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 15:30:00 +0800 Subject: [PATCH 08/37] fix: projecttrend show rule --- app/controllers/project_trends_controller.rb | 9 ++++----- app/models/pull_request.rb | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/controllers/project_trends_controller.rb b/app/controllers/project_trends_controller.rb index dc1ffbdb4..621a30d51 100644 --- a/app/controllers/project_trends_controller.rb +++ b/app/controllers/project_trends_controller.rb @@ -14,14 +14,13 @@ 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_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").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_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 diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index ce0cb04ad..14b893556 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -54,7 +54,7 @@ class PullRequest < ApplicationRecord Project.find_by(id: self.fork_project_id) end - def bind_gitea_pull_request!(gitea_pull_number, gitea_pull_id) + def bind_gitea_pull_request!(gitea_pull_number, gitea_pull_id=gitea_pull_number) update_columns( gitea_number: gitea_pull_number, gitea_id: gitea_pull_id) From ffa0715374475ee24659cd969e2262f9c648fdd7 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 18:31:27 +0800 Subject: [PATCH 09/37] fix --- app/controllers/pull_requests_controller.rb | 2 +- app/models/pull_request.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 1a31704b2..8f3df5546 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -58,7 +58,7 @@ class PullRequestsController < ApplicationController ActiveRecord::Base.transaction do @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"]) + @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) else diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index 14b893556..ce0cb04ad 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -54,7 +54,7 @@ class PullRequest < ApplicationRecord Project.find_by(id: self.fork_project_id) end - def bind_gitea_pull_request!(gitea_pull_number, gitea_pull_id=gitea_pull_number) + def bind_gitea_pull_request!(gitea_pull_number, gitea_pull_id) update_columns( gitea_number: gitea_pull_number, gitea_id: gitea_pull_id) From 2a09fadf712e05d473154bd36f99d7743d17e82b Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Oct 2021 14:36:50 +0800 Subject: [PATCH 10/37] fix: change projec trend rule and fix data --- app/controllers/issues_controller.rb | 12 ++++++++ app/controllers/project_trends_controller.rb | 12 ++++++-- app/controllers/pull_requests_controller.rb | 4 ++- app/models/project_trend.rb | 3 +- lib/tasks/refactor_project_trend.rake | 30 ++++++++++++++++++++ 5 files changed, 56 insertions(+), 5 deletions(-) create mode 100644 lib/tasks/refactor_project_trend.rake diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index bfa15aa50..f16edbb38 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -216,6 +216,12 @@ 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 + 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) SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present? end @@ -338,6 +344,12 @@ 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 + 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) SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? end diff --git a/app/controllers/project_trends_controller.rb b/app/controllers/project_trends_controller.rb index 621a30d51..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 @@ -18,7 +18,7 @@ class ProjectTrendsController < ApplicationController @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").size + @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? @@ -26,7 +26,13 @@ class ProjectTrendsController < ApplicationController 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/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index 8f3df5546..ac3968aad 100644 --- a/app/controllers/pull_requests_controller.rb +++ b/app/controllers/pull_requests_controller.rb @@ -130,6 +130,7 @@ class PullRequestsController < ApplicationController begin colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user) if colsed === true + @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE) SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) normal_status(1, "已拒绝") else @@ -171,7 +172,8 @@ 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) normal_status(1, "合并成功") 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/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 From a4ee5292166e45c40d5f826f74989dfa49c3afc0 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Oct 2021 16:47:01 +0800 Subject: [PATCH 11/37] fix: allow update repository identifier origin --- app/controllers/projects_controller.rb | 2 +- app/forms/projects/update_form.rb | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 54ae85ca0..0dbb666bf 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -129,7 +129,7 @@ class ProjectsController < ApplicationController validate_params = project_params.slice(:name, :description, :project_category_id, :project_language_id, :private, :identifier) - Projects::UpdateForm.new(validate_params.merge(user_id: @project.user_id)).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 diff --git a/app/forms/projects/update_form.rb b/app/forms/projects/update_form.rb index 9ccc611cf..ae93abf30 100644 --- a/app/forms/projects/update_form.rb +++ b/app/forms/projects/update_form.rb @@ -1,12 +1,14 @@ class Projects::UpdateForm < BaseForm - attr_accessor :name, :description, :project_category_id, :project_language_id, :private, :identifier, :user_id + 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) - check_repository_name(user_id, identifier) unless identifier.blank? + Rails.logger.info project_identifier + Rails.logger.info identifier + check_repository_name(user_id, identifier) unless identifier.blank? || identifier == project_identifier end end From 73f558d7c34f311b35a76d7e3c38e44988fd7c4b Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Oct 2021 13:42:41 +0800 Subject: [PATCH 12/37] fix: issue subject validate --- app/forms/issues/create_form.rb | 2 +- app/forms/issues/update_form.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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 From d176508010884d034cff7c9f055894c46a9bc03d Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Oct 2021 16:14:45 +0800 Subject: [PATCH 13/37] add: system notification management --- .../admins/system_notifications/index.js | 76 +++++++++++++++++++ .../admins/system_notifications_controller.rb | 76 +++++++++++++++++++ app/models/system_notification.rb | 17 +++++ app/models/system_notification_history.rb | 21 +++++ app/models/user.rb | 4 +- app/views/admins/shared/_sidebar.html.erb | 4 +- .../system_notifications/_form.html.erb | 57 ++++++++++++++ .../system_notifications/_form_modal.html.erb | 40 ++++++++++ .../system_notifications/_list.html.erb | 35 +++++++++ .../admins/system_notifications/edit.js.erb | 2 + .../system_notifications/index.html.erb | 21 +++++ .../admins/system_notifications/index.js.erb | 1 + .../admins/system_notifications/new.js.erb | 2 + config/routes.rb | 5 ++ ...11012060724_create_system_notifications.rb | 13 ++++ ...37_create_system_notification_histories.rb | 10 +++ 16 files changed, 381 insertions(+), 3 deletions(-) create mode 100644 app/assets/javascripts/admins/system_notifications/index.js create mode 100644 app/controllers/admins/system_notifications_controller.rb create mode 100644 app/models/system_notification.rb create mode 100644 app/models/system_notification_history.rb create mode 100644 app/views/admins/system_notifications/_form.html.erb create mode 100644 app/views/admins/system_notifications/_form_modal.html.erb create mode 100644 app/views/admins/system_notifications/_list.html.erb create mode 100644 app/views/admins/system_notifications/edit.js.erb create mode 100644 app/views/admins/system_notifications/index.html.erb create mode 100644 app/views/admins/system_notifications/index.js.erb create mode 100644 app/views/admins/system_notifications/new.js.erb create mode 100644 db/migrate/20211012060724_create_system_notifications.rb create mode 100644 db/migrate/20211012060837_create_system_notification_histories.rb 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..1a71173c6 --- /dev/null +++ b/app/controllers/admins/system_notifications_controller.rb @@ -0,0 +1,76 @@ +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).order("#{sort_by} #{sort_direction},created_at desc") + @notifications = paginate(notifications) + end + + def history + @users = @notification.users + 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/models/system_notification.rb b/app/models/system_notification.rb new file mode 100644 index 000000000..76c514cd3 --- /dev/null +++ b/app/models/system_notification.rb @@ -0,0 +1,17 @@ +# == Schema Information +# +# Table name: system_notifications +# +# id :integer not null, primary key +# subject :string(255) +# sub_subject :string(255) +# content :string(255) +# created_at :datetime not null +# updated_at :datetime not null +# + +class SystemNotification < ApplicationRecord + + has_many :system_notification_histories + has_many :users, through: :system_notification_histories +end diff --git a/app/models/system_notification_history.rb b/app/models/system_notification_history.rb new file mode 100644 index 000000000..8723ca917 --- /dev/null +++ b/app/models/system_notification_history.rb @@ -0,0 +1,21 @@ +# == Schema Information +# +# Table name: system_notification_histories +# +# id :integer not null, primary key +# system_message_id :integer +# user_id :integer +# created_at :datetime not null +# updated_at :datetime not null +# +# Indexes +# +# index_system_notification_histories_on_system_message_id (system_message_id) +# index_system_notification_histories_on_user_id (user_id) +# + +class SystemNotificationHistory < ApplicationRecord + + belongs_to :system_notification + belongs_to :user +end diff --git a/app/models/user.rb b/app/models/user.rb index 3c4a900a0..22c5e3cd7 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -170,7 +170,9 @@ class User < Owner has_many :issues, dependent: :destroy, foreign_key: :author_id 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_many :system_notification_histories + has_many :system_notifications, through: :system_notification_histories + # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } scope :like, lambda { |keywords| 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..8e7619101 --- /dev/null +++ b/app/views/admins/system_notifications/_form.html.erb @@ -0,0 +1,57 @@ +
    +
    <%= type == "create" ? "新建" : "编辑" %>忽略文件
    + <%= link_to "返回", admins_project_ignores_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..63fad5838 --- /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: 'create'}) %>") +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/config/routes.rb b/config/routes.rb index 005bd926a..b940ed700 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -670,6 +670,11 @@ Rails.application.routes.draw do resources :project_licenses resources :project_ignores resources :reversed_keywords + resources :system_notifications do + member do + get :history + end + end 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/20211012060837_create_system_notification_histories.rb b/db/migrate/20211012060837_create_system_notification_histories.rb new file mode 100644 index 000000000..9110f3ce9 --- /dev/null +++ b/db/migrate/20211012060837_create_system_notification_histories.rb @@ -0,0 +1,10 @@ +class CreateSystemNotificationHistories < ActiveRecord::Migration[5.2] + def change + create_table :system_notification_histories do |t| + t.references :system_notification + t.references :user + + t.timestamps + end + end +end From 490ce7a2344d6cd4e27aec9b95257409e0823274 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 12 Oct 2021 16:34:00 +0800 Subject: [PATCH 14/37] add: setting of system notification --- .../admins/system_notifications_controller.rb | 12 ++++++------ app/controllers/settings_controller.rb | 6 +++++- app/models/system_notification.rb | 9 +++++++++ app/views/settings/show.json.jbuilder | 9 +++++++++ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb index 1a71173c6..29109fd80 100644 --- a/app/controllers/admins/system_notifications_controller.rb +++ b/app/controllers/admins/system_notifications_controller.rb @@ -6,7 +6,7 @@ class Admins::SystemNotificationsController < Admins::BaseController 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).order("#{sort_by} #{sort_direction},created_at desc") + notifications = q.result(distinct: true).reorder("#{sort_by} #{sort_direction},created_at desc") @notifications = paginate(notifications) end @@ -25,7 +25,7 @@ class Admins::SystemNotificationsController < Admins::BaseController @notification = SystemNotification.new(notification_params) if @notification.save redirect_to admins_system_notifications_path - flash[:success] = '系统保留关键词创建成功' + flash[:success] = '系统消息创建成功' else redirect_to admins_system_notifications_path flash[:danger] = @notification.errors.full_messages.join(",") @@ -38,7 +38,7 @@ class Admins::SystemNotificationsController < Admins::BaseController if @notification.update_attributes(notification_params) format.html do redirect_to admins_system_notifications_path - flash[:success] = '系统保留关键词更新成功' + flash[:success] = '系统消息更新成功' end format.js {render_ok} else @@ -54,10 +54,10 @@ class Admins::SystemNotificationsController < Admins::BaseController def destroy if @notification.destroy redirect_to admins_system_notifications_path - flash[:success] = "系统保留关键词删除成功" + flash[:success] = "系统消息删除成功" else redirect_to admins_system_notifications_path - flash[:danger] = "系统保留关键词删除失败" + flash[:danger] = "系统消息删除失败" end end @@ -70,7 +70,7 @@ class Admins::SystemNotificationsController < Admins::BaseController @notification = SystemNotification.find_by(id: params[:id]) unless @notification.present? redirect_to admins_system_notifications_path - flash[:danger] = "系统保留关键词不存在" + flash[:danger] = "系统消息不存在" end end end \ No newline at end of file diff --git a/app/controllers/settings_controller.rb b/app/controllers/settings_controller.rb index b6662f661..b2dc2e900 100644 --- a/app/controllers/settings_controller.rb +++ b/app/controllers/settings_controller.rb @@ -4,7 +4,7 @@ class SettingsController < ApplicationController get_add_menu get_common_menu get_personal_menu - + get_top_system_notification end private @@ -40,6 +40,10 @@ class SettingsController < ApplicationController end 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) end diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index 76c514cd3..11220dfc1 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -12,6 +12,15 @@ class SystemNotification < ApplicationRecord + default_scope { order(created_at: :desc)} + has_many :system_notification_histories has_many :users, through: :system_notification_histories + + scope :is_top, lambda { where(is_top: true) } + + + def read_member?(user_id) + self.system_notification_histories.where(user_id: user_id).present? ? true : false + end end diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 330966aa1..c8d4c89eb 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -56,4 +56,13 @@ json.setting do end json.common @common + + if @top_system_notification.present? + json.system_notification do + json.(@top_system_notification, :subject, :sub_subject, :content) + json.is_read @top_system_notification.read_member?(current_user.id) + end + else + json.system_notification nil + end end From 21af31f23c33c77e2a690a57d8bcf962eb17bc5d Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Oct 2021 10:58:41 +0800 Subject: [PATCH 15/37] add: system notification history api --- ...ystem_notification_histories_controller.rb | 15 +++ app/docs/slate/source/includes/_users.md | 30 +++++ app/models/system_notification_history.rb | 2 + app/views/settings/show.json.jbuilder | 2 +- .../system_notification_histories/zh-CN.yml | 6 + config/routes.rb | 1 + public/docs/api.html | 113 ++++++++++++------ 7 files changed, 129 insertions(+), 40 deletions(-) create mode 100644 app/controllers/users/system_notification_histories_controller.rb create mode 100644 config/locales/system_notification_histories/zh-CN.yml diff --git a/app/controllers/users/system_notification_histories_controller.rb b/app/controllers/users/system_notification_histories_controller.rb new file mode 100644 index 000000000..70e91fbb9 --- /dev/null +++ b/app/controllers/users/system_notification_histories_controller.rb @@ -0,0 +1,15 @@ +class Users::SystemNotificationHistoriesController < Users::BaseController + before_action :private_user_resources!, only: [:create] + def create + @history = observed_user.system_notification_histories.new(system_notification_id: params[:system_notification_id]) + if @history.save + render_ok + else + Rails.logger.info @history.errors.as_json + render_error(@history.errors.full_messages.join(",")) + end + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + 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..594ce725a 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -199,6 +199,36 @@ await octokit.request('GET /api/users/:login/messages.json') Success Data. +## 用户阅读系统通知 +用户阅读系统通知 + +> 示例: + +```shell +curl -X POST http://localhost:3000/api/users/yystopf/system_notification_histories.json +``` + +```javascript +await octokit.request('GET /api/users/:login/system_notification_histories.json') +``` + +### HTTP 请求 +`POST /api/users/:login/system_notification_histories.json` + +### 请求字段说明: +参数 | 类型 | 字段说明 +--------- | ----------- | ----------- +|system_notification_id |integer |阅读的系统通知id | + +> 返回的JSON示例: + +```json +{ + "status": 0, + "message": "success" +} +``` + ## 发送消息 发送消息, 目前只支持atme diff --git a/app/models/system_notification_history.rb b/app/models/system_notification_history.rb index 8723ca917..b629babdf 100644 --- a/app/models/system_notification_history.rb +++ b/app/models/system_notification_history.rb @@ -18,4 +18,6 @@ class SystemNotificationHistory < ApplicationRecord belongs_to :system_notification belongs_to :user + + validates :system_notification_id, uniqueness: { scope: :user_id, message: '只能阅读一次'} end diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index c8d4c89eb..3b0935e07 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -59,7 +59,7 @@ json.setting do if @top_system_notification.present? json.system_notification do - json.(@top_system_notification, :subject, :sub_subject, :content) + json.(@top_system_notification, :id, :subject, :sub_subject, :content) json.is_read @top_system_notification.read_member?(current_user.id) end else diff --git a/config/locales/system_notification_histories/zh-CN.yml b/config/locales/system_notification_histories/zh-CN.yml new file mode 100644 index 000000000..8dd7b49db --- /dev/null +++ b/config/locales/system_notification_histories/zh-CN.yml @@ -0,0 +1,6 @@ +zh-CN: + activerecord: + attributes: + system_notification_history: + system_notification: "系统通知" + system_notification_id: "系统通知" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index b940ed700..92061df93 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -263,6 +263,7 @@ Rails.application.routes.draw do end scope module: :users do + resources :system_notification_histories, only: [:create] resources :applied_messages, only: [:index] resources :applied_transfer_projects, only: [:index] do member do diff --git a/public/docs/api.html b/public/docs/api.html index 8368e8fae..0f1121781 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -348,6 +348,9 @@
  • 用户消息列表
  • +
  • + 用户阅读系统通知 +
  • 发送消息
  • @@ -1328,7 +1331,39 @@ Success — a happy kitten is an authenticated kitten! -

    发送消息

    +

    用户阅读系统通知

    +

    用户阅读系统通知

    + +
    +

    示例:

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

    HTTP 请求

    +

    POST /api/users/:login/system_notification_histories.json

    +

    请求字段说明:

    + + + + + + + + + + + + +
    参数类型字段说明
    system_notification_idinteger阅读的系统通知id
    + +
    +

    返回的JSON示例:

    +
    +
    {
    +    "status": 0,
    +    "message": "success"
    +}
    +

    发送消息

    发送消息, 目前只支持atme

    @@ -1336,9 +1371,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/:login/messages.json
     
    await octokit.request('POST /api/users/:login/messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST api/users/yystopf/messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    @@ -1397,9 +1432,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/:login/messages/read.json
     
    await octokit.request('POST /api/users/:login/messages/read.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST api/users/yystopf/messages/read.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1438,9 +1473,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X DELETE http://localhost:3000/api/users/:login/messages.json
     
    await octokit.request('DELETE /api/users/:login/messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE api/users/yystopf/messages.json

    -

    请求字段说明:

    +

    请求字段说明:

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

    HTTP 请求

    +

    HTTP 请求

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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1577,7 +1612,7 @@ 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 +1799,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 +1845,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,7 +1886,7 @@ 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 +1975,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

    -

    请求字段说明:

    +

    请求字段说明:

    @@ -2085,9 +2120,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2402,9 +2437,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2545,9 +2580,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2627,9 +2662,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2688,9 +2723,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2967,9 +3002,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3159,9 +3194,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3350,9 +3385,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3541,9 +3576,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3701,9 +3736,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3860,9 +3895,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    From 1b87a7a733e0fb27d00b3b561097467ae596f45b Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Oct 2021 15:50:51 +0800 Subject: [PATCH 16/37] fix: send message job need open notice menu --- app/controllers/issues_controller.rb | 26 +++++++++++++------ app/controllers/members_controller.rb | 10 +++---- .../organizations/team_users_controller.rb | 2 +- .../projects/project_units_controller.rb | 2 +- app/controllers/projects_controller.rb | 2 +- app/controllers/pull_requests_controller.rb | 12 ++++----- app/controllers/users/messages_controller.rb | 8 +++--- app/jobs/delay_expired_issue_job.rb | 4 +-- app/models/organization_user.rb | 4 +-- app/models/site.rb | 4 +++ app/models/watcher.rb | 2 +- app/services/projects/accept_join_service.rb | 4 +-- 12 files changed, 47 insertions(+), 33 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index f16edbb38..adbe93e3e 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,6 +216,7 @@ 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 +<<<<<<< HEAD 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 @@ -224,6 +225,10 @@ class IssuesController < ApplicationController 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? +======= + 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? +>>>>>>> 356cafdd (fix: send message job need open notice menu) end if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时 @issue.issue_times.update_all(end_time: Time.now) @@ -276,7 +281,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) @@ -299,7 +304,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, "删除成功") @@ -344,6 +349,7 @@ 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 +<<<<<<< HEAD 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 @@ -352,6 +358,10 @@ class IssuesController < ApplicationController 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? +======= + 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? +>>>>>>> 356cafdd (fix: send message job need open notice menu) end normal_status(0, "批量更新成功") else @@ -366,8 +376,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/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 0dbb666bf..3c5cb1f32 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -145,7 +145,7 @@ class ProjectsController < ApplicationController 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)) if Site.has_notice_menu? end rescue Exception => e uid_logger_error(e.message) diff --git a/app/controllers/pull_requests_controller.rb b/app/controllers/pull_requests_controller.rb index ac3968aad..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 @@ -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 @@ -131,7 +131,7 @@ class PullRequestsController < ApplicationController colsed = PullRequests::CloseService.call(@owner, @repository, @pull_request, current_user) if colsed === true @pull_request.project_trends.create!(user: current_user, project: @project,action_type: ProjectTrend::CLOSE) - SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) + SendTemplateMessageJob.perform_later('PullRequestClosed', current_user.id, @pull_request.id) if Site.has_notice_menu? normal_status(1, "已拒绝") else normal_status(-1, '合并失败') @@ -175,7 +175,7 @@ class PullRequestsController < ApplicationController # @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/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/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/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/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/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/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 From 0d60e58304d66636a063210442480998a0141c1d Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Oct 2021 17:13:57 +0800 Subject: [PATCH 17/37] fix: system notification edit error --- app/controllers/admins/system_notifications_controller.rb | 1 - app/models/system_notification.rb | 3 ++- app/views/admins/system_notifications/_form.html.erb | 4 ++-- app/views/admins/system_notifications/edit.js.erb | 2 +- ...211013090556_change_system_notification_content_column.rb | 5 +++++ 5 files changed, 10 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20211013090556_change_system_notification_content_column.rb diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb index 29109fd80..e2081f1a2 100644 --- a/app/controllers/admins/system_notifications_controller.rb +++ b/app/controllers/admins/system_notifications_controller.rb @@ -33,7 +33,6 @@ class Admins::SystemNotificationsController < Admins::BaseController end def update - respond_to do |format| if @notification.update_attributes(notification_params) format.html do diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index 11220dfc1..8eacd437c 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -5,7 +5,8 @@ # id :integer not null, primary key # subject :string(255) # sub_subject :string(255) -# content :string(255) +# content :text(65535) +# is_top :boolean # created_at :datetime not null # updated_at :datetime not null # diff --git a/app/views/admins/system_notifications/_form.html.erb b/app/views/admins/system_notifications/_form.html.erb index 8e7619101..33c35747a 100644 --- a/app/views/admins/system_notifications/_form.html.erb +++ b/app/views/admins/system_notifications/_form.html.erb @@ -1,6 +1,6 @@
    -
    <%= type == "create" ? "新建" : "编辑" %>忽略文件
    - <%= link_to "返回", admins_project_ignores_path, class: "btn btn-default pull-right" %> +
    <%= type == "create" ? "新建" : "编辑" %>系统通知
    + <%= link_to "返回", admins_system_notifications_path, class: "btn btn-default pull-right" %>
    diff --git a/app/views/admins/system_notifications/edit.js.erb b/app/views/admins/system_notifications/edit.js.erb index 63fad5838..e5929f876 100644 --- a/app/views/admins/system_notifications/edit.js.erb +++ b/app/views/admins/system_notifications/edit.js.erb @@ -1,2 +1,2 @@ -$("#admins-system-notification-content").html("<%= j render(partial: 'admins/system_notifications/form', locals: {type: 'create'}) %>") +$("#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/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 From 1dcc38f6177b7f9553c3b676fe441c36975908b5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Oct 2021 14:54:51 +0800 Subject: [PATCH 18/37] fix: remove system_notification_history --- .../admins/system_notifications_controller.rb | 4 - ...ystem_notification_histories_controller.rb | 15 --- app/docs/slate/source/includes/_users.md | 30 ----- app/models/system_notification.rb | 3 - app/models/system_notification_history.rb | 23 ---- app/models/user.rb | 2 - .../system_notification_histories/zh-CN.yml | 6 - config/routes.rb | 7 +- ...37_create_system_notification_histories.rb | 10 -- public/docs/api.html | 113 ++++++------------ 10 files changed, 40 insertions(+), 173 deletions(-) delete mode 100644 app/controllers/users/system_notification_histories_controller.rb delete mode 100644 app/models/system_notification_history.rb delete mode 100644 config/locales/system_notification_histories/zh-CN.yml delete mode 100644 db/migrate/20211012060837_create_system_notification_histories.rb diff --git a/app/controllers/admins/system_notifications_controller.rb b/app/controllers/admins/system_notifications_controller.rb index e2081f1a2..0dc7dd2a2 100644 --- a/app/controllers/admins/system_notifications_controller.rb +++ b/app/controllers/admins/system_notifications_controller.rb @@ -10,10 +10,6 @@ class Admins::SystemNotificationsController < Admins::BaseController @notifications = paginate(notifications) end - def history - @users = @notification.users - end - def new @notification = SystemNotification.new end diff --git a/app/controllers/users/system_notification_histories_controller.rb b/app/controllers/users/system_notification_histories_controller.rb deleted file mode 100644 index 70e91fbb9..000000000 --- a/app/controllers/users/system_notification_histories_controller.rb +++ /dev/null @@ -1,15 +0,0 @@ -class Users::SystemNotificationHistoriesController < Users::BaseController - before_action :private_user_resources!, only: [:create] - def create - @history = observed_user.system_notification_histories.new(system_notification_id: params[:system_notification_id]) - if @history.save - render_ok - else - Rails.logger.info @history.errors.as_json - render_error(@history.errors.full_messages.join(",")) - end - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - 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 594ce725a..9d6b80927 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -199,36 +199,6 @@ await octokit.request('GET /api/users/:login/messages.json') Success Data. -## 用户阅读系统通知 -用户阅读系统通知 - -> 示例: - -```shell -curl -X POST http://localhost:3000/api/users/yystopf/system_notification_histories.json -``` - -```javascript -await octokit.request('GET /api/users/:login/system_notification_histories.json') -``` - -### HTTP 请求 -`POST /api/users/:login/system_notification_histories.json` - -### 请求字段说明: -参数 | 类型 | 字段说明 ---------- | ----------- | ----------- -|system_notification_id |integer |阅读的系统通知id | - -> 返回的JSON示例: - -```json -{ - "status": 0, - "message": "success" -} -``` - ## 发送消息 发送消息, 目前只支持atme diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index 8eacd437c..848d592d5 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -15,9 +15,6 @@ class SystemNotification < ApplicationRecord default_scope { order(created_at: :desc)} - has_many :system_notification_histories - has_many :users, through: :system_notification_histories - scope :is_top, lambda { where(is_top: true) } diff --git a/app/models/system_notification_history.rb b/app/models/system_notification_history.rb deleted file mode 100644 index b629babdf..000000000 --- a/app/models/system_notification_history.rb +++ /dev/null @@ -1,23 +0,0 @@ -# == Schema Information -# -# Table name: system_notification_histories -# -# id :integer not null, primary key -# system_message_id :integer -# user_id :integer -# created_at :datetime not null -# updated_at :datetime not null -# -# Indexes -# -# index_system_notification_histories_on_system_message_id (system_message_id) -# index_system_notification_histories_on_user_id (user_id) -# - -class SystemNotificationHistory < ApplicationRecord - - belongs_to :system_notification - belongs_to :user - - validates :system_notification_id, uniqueness: { scope: :user_id, message: '只能阅读一次'} -end diff --git a/app/models/user.rb b/app/models/user.rb index 22c5e3cd7..623694b33 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -170,8 +170,6 @@ class User < Owner has_many :issues, dependent: :destroy, foreign_key: :author_id 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_many :system_notification_histories - has_many :system_notifications, through: :system_notification_histories # Groups and active users scope :active, lambda { where(status: STATUS_ACTIVE) } diff --git a/config/locales/system_notification_histories/zh-CN.yml b/config/locales/system_notification_histories/zh-CN.yml deleted file mode 100644 index 8dd7b49db..000000000 --- a/config/locales/system_notification_histories/zh-CN.yml +++ /dev/null @@ -1,6 +0,0 @@ -zh-CN: - activerecord: - attributes: - system_notification_history: - system_notification: "系统通知" - system_notification_id: "系统通知" \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index 92061df93..9e5ffa2fb 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -263,7 +263,6 @@ Rails.application.routes.draw do end scope module: :users do - resources :system_notification_histories, only: [:create] resources :applied_messages, only: [:index] resources :applied_transfer_projects, only: [:index] do member do @@ -671,11 +670,7 @@ Rails.application.routes.draw do resources :project_licenses resources :project_ignores resources :reversed_keywords - resources :system_notifications do - member do - get :history - end - end + resources :system_notifications resources :message_templates, only: [:index, :edit, :update] do collection do get :init_data diff --git a/db/migrate/20211012060837_create_system_notification_histories.rb b/db/migrate/20211012060837_create_system_notification_histories.rb deleted file mode 100644 index 9110f3ce9..000000000 --- a/db/migrate/20211012060837_create_system_notification_histories.rb +++ /dev/null @@ -1,10 +0,0 @@ -class CreateSystemNotificationHistories < ActiveRecord::Migration[5.2] - def change - create_table :system_notification_histories do |t| - t.references :system_notification - t.references :user - - t.timestamps - end - end -end diff --git a/public/docs/api.html b/public/docs/api.html index 0f1121781..8368e8fae 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -348,9 +348,6 @@
  • 用户消息列表
  • -
  • - 用户阅读系统通知 -
  • 发送消息
  • @@ -1331,39 +1328,7 @@ Success — a happy kitten is an authenticated kitten! -

    用户阅读系统通知

    -

    用户阅读系统通知

    - -
    -

    示例:

    -
    -
    curl -X POST http://localhost:3000/api/users/yystopf/system_notification_histories.json
    -
    await octokit.request('GET /api/users/:login/system_notification_histories.json')
    -

    HTTP 请求

    -

    POST /api/users/:login/system_notification_histories.json

    -

    请求字段说明:

    -
    参数
    - - - - - - - - - - - -
    参数类型字段说明
    system_notification_idinteger阅读的系统通知id
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "status": 0,
    -    "message": "success"
    -}
    -

    发送消息

    +

    发送消息

    发送消息, 目前只支持atme

    @@ -1371,9 +1336,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/:login/messages.json
     
    await octokit.request('POST /api/users/:login/messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST api/users/yystopf/messages.json

    -

    请求字段说明:

    +

    请求字段说明:

    @@ -1432,9 +1397,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X POST http://localhost:3000/api/users/:login/messages/read.json
     
    await octokit.request('POST /api/users/:login/messages/read.json')
    -

    HTTP 请求

    +

    HTTP 请求

    POST api/users/yystopf/messages/read.json

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1473,9 +1438,9 @@ Success — a happy kitten is an authenticated kitten!
    curl -X DELETE http://localhost:3000/api/users/:login/messages.json
     
    await octokit.request('DELETE /api/users/:login/messages.json')
    -

    HTTP 请求

    +

    HTTP 请求

    DELETE api/users/yystopf/messages.json

    -

    请求字段说明:

    +

    请求字段说明:

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

    HTTP 请求

    +

    HTTP 请求

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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1612,7 +1577,7 @@ 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

    返回字段说明:

    参数
    @@ -1799,9 +1764,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

    -

    请求字段说明:

    同时设定多个星标项目

    +

    请求字段说明:

    同时设定多个星标项目

    @@ -1845,9 +1810,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -1886,7 +1851,7 @@ 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

    返回字段说明:

    参数
    @@ -1975,9 +1940,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

    -

    请求字段说明:

    +

    请求字段说明:

    @@ -2120,9 +2085,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2437,9 +2402,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2580,9 +2545,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2662,9 +2627,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2723,9 +2688,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3002,9 +2967,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3194,9 +3159,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3385,9 +3350,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3576,9 +3541,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3736,9 +3701,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -3895,9 +3860,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    From 0885b7d75d4e6c3c4378fe1ee8c08a612d03df66 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Oct 2021 15:02:56 +0800 Subject: [PATCH 19/37] fix --- app/models/system_notification.rb | 4 ---- 1 file changed, 4 deletions(-) diff --git a/app/models/system_notification.rb b/app/models/system_notification.rb index 848d592d5..6f901b3fd 100644 --- a/app/models/system_notification.rb +++ b/app/models/system_notification.rb @@ -17,8 +17,4 @@ class SystemNotification < ApplicationRecord scope :is_top, lambda { where(is_top: true) } - - def read_member?(user_id) - self.system_notification_histories.where(user_id: user_id).present? ? true : false - end end From 2d4f08316433a73f500ade1a6e745f94ecf64120 Mon Sep 17 00:00:00 2001 From: yystopf Date: Fri, 15 Oct 2021 15:04:16 +0800 Subject: [PATCH 20/37] fix --- app/views/settings/show.json.jbuilder | 1 - 1 file changed, 1 deletion(-) diff --git a/app/views/settings/show.json.jbuilder b/app/views/settings/show.json.jbuilder index 3b0935e07..1147ffde2 100644 --- a/app/views/settings/show.json.jbuilder +++ b/app/views/settings/show.json.jbuilder @@ -60,7 +60,6 @@ json.setting do if @top_system_notification.present? json.system_notification do json.(@top_system_notification, :id, :subject, :sub_subject, :content) - json.is_read @top_system_notification.read_member?(current_user.id) end else json.system_notification nil From ff97daac545e55f1eec46d4349961b9de7097dfe Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Oct 2021 13:52:52 +0800 Subject: [PATCH 21/37] fix --- app/controllers/issues_controller.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/app/controllers/issues_controller.rb b/app/controllers/issues_controller.rb index adbe93e3e..446c699e2 100644 --- a/app/controllers/issues_controller.rb +++ b/app/controllers/issues_controller.rb @@ -216,19 +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 -<<<<<<< HEAD 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) - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id) if @issue.previous_changes[:assigned_to_id].present? -======= 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? ->>>>>>> 356cafdd (fix: send message job need open notice menu) end if params[:status_id].to_i == 5 #任务由非关闭状态到关闭状态时 @issue.issue_times.update_all(end_time: Time.now) @@ -349,19 +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 -<<<<<<< HEAD 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) - SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, i&.id) if i.previous_changes[:assigned_to_id].present? -======= 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? ->>>>>>> 356cafdd (fix: send message job need open notice menu) end normal_status(0, "批量更新成功") else From 8252cb7e71fb30fc4686d94de5912bcc2fe85dde Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Oct 2021 17:04:28 +0800 Subject: [PATCH 22/37] add: template setting model --- app/models/template_message_setting.rb | 21 ++++++++++++++++ .../create_or_assign.rb | 25 +++++++++++++++++++ app/models/template_message_setting/manage.rb | 25 +++++++++++++++++++ app/models/template_message_setting/normal.rb | 23 +++++++++++++++++ app/models/template_message_setting/watch.rb | 21 ++++++++++++++++ app/models/user_template_message_setting.rb | 18 +++++++++++++ ...081221_create_template_message_settings.rb | 15 +++++++++++ ...3_create_user_template_message_settings.rb | 12 +++++++++ 8 files changed, 160 insertions(+) create mode 100644 app/models/template_message_setting.rb create mode 100644 app/models/template_message_setting/create_or_assign.rb create mode 100644 app/models/template_message_setting/manage.rb create mode 100644 app/models/template_message_setting/normal.rb create mode 100644 app/models/template_message_setting/watch.rb create mode 100644 app/models/user_template_message_setting.rb create mode 100644 db/migrate/20211013081221_create_template_message_settings.rb create mode 100644 db/migrate/20211013081713_create_user_template_message_settings.rb diff --git a/app/models/template_message_setting.rb b/app/models/template_message_setting.rb new file mode 100644 index 000000000..349805bd3 --- /dev/null +++ b/app/models/template_message_setting.rb @@ -0,0 +1,21 @@ +# == 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 + + def self.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..385a3af8a --- /dev/null +++ b/app/models/template_message_setting/create_or_assign.rb @@ -0,0 +1,25 @@ +# == 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.build_init_data + self.find_or_create_by(name: "易修状态变更", key: "IssueChanged") + self.find_or_create_by(name: "易修被指派", key: "IssueAssigned") + self.find_or_create_by(name: "合并请求被指派", key: "PullRequestAssigned") + self.find_or_create_by(name: "合并请求状态变更", key: "PullRequestAssigned") + end +end diff --git a/app/models/template_message_setting/manage.rb b/app/models/template_message_setting/manage.rb new file mode 100644 index 000000000..925d503f3 --- /dev/null +++ b/app/models/template_message_setting/manage.rb @@ -0,0 +1,25 @@ +# == 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::Manage < TemplateMessageSetting + + def self.build_init_data + self.find_or_create_by(name: "有新的易修", key: "ProjectIssue") + self.find_or_create_by(name: "有新的合并请求", key: "ProjectPullRequest") + self.find_or_create_by(name: "有成员变动", key: "ProjectMember") + self.find_or_create_by(name: "设置更改", key: "ProjectSettingChanged") + 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..9801891a3 --- /dev/null +++ b/app/models/template_message_setting/normal.rb @@ -0,0 +1,23 @@ +# == 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.build_init_data + self.find_or_create_by(name: "被拉入或移出组织", key: "Organization") + self.find_or_create_by(name: "被拉入或移出项目", key: "Project") + self.find_or_create_by(name: "有权限变更", key: "Permission") + end +end diff --git a/app/models/template_message_setting/watch.rb b/app/models/template_message_setting/watch.rb new file mode 100644 index 000000000..d6d5820a3 --- /dev/null +++ b/app/models/template_message_setting/watch.rb @@ -0,0 +1,21 @@ +# == 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::Watch < TemplateMessageSetting + + def self.build_init_data + end +end diff --git a/app/models/user_template_message_setting.rb b/app/models/user_template_message_setting.rb new file mode 100644 index 000000000..5c6f3a2f3 --- /dev/null +++ b/app/models/user_template_message_setting.rb @@ -0,0 +1,18 @@ +# == 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 +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..618d43b60 --- /dev/null +++ b/db/migrate/20211013081221_create_template_message_settings.rb @@ -0,0 +1,15 @@ +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 + 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 From d54dcb6b676439457943fdf289196e87814b763a Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 14 Oct 2021 14:12:50 +0800 Subject: [PATCH 23/37] add: template message settings api --- .../template_message_settings_controller.rb | 8 + app/docs/slate/source/includes/_users.md | 140 ++++ app/models/template_message_setting.rb | 11 +- .../create_or_assign.rb | 4 + .../{manage.rb => manage_project.rb} | 6 +- app/models/template_message_setting/normal.rb | 4 + .../{watch.rb => watch_project.rb} | 6 +- .../_detail.json.jbuilder | 8 + .../index.json.jbuilder | 11 + config/routes.rb | 2 + ...081221_create_template_message_settings.rb | 2 + public/docs/api.html | 607 +++++++++++------- 12 files changed, 587 insertions(+), 222 deletions(-) create mode 100644 app/controllers/template_message_settings_controller.rb rename app/models/template_message_setting/{manage.rb => manage_project.rb} (86%) rename app/models/template_message_setting/{watch.rb => watch_project.rb} (80%) create mode 100644 app/views/template_message_settings/_detail.json.jbuilder create mode 100644 app/views/template_message_settings/index.json.jbuilder 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/docs/slate/source/includes/_users.md b/app/docs/slate/source/includes/_users.md index 9d6b80927..d02516024 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -372,6 +372,146 @@ 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::CreateOrAssign", + "type_name": "我创建的或负责的", + "total_settings_count": 4, + "settings": [ + { + "name": "易修状态变更", + "key": "IssueChanged", + "openning": true, + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "易修被指派", + "key": "IssueAssigned", + "openning": true, + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "合并请求被指派", + "key": "PullRequestAssigned", + "openning": true, + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "合并请求状态变更", + "key": "PullRequestAssigned", + "openning": true, + "notification_disabled": true, + "email_disabled": false + } + ] + }, + { + "type": "TemplateMessageSetting::ManageProject", + "type_name": "我管理的仓库", + "total_settings_count": 4, + "settings": [ + { + "name": "有新的易修", + "key": "ProjectIssue", + "openning": true, + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "有新的合并请求", + "key": "ProjectPullRequest", + "openning": true, + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "有成员变动", + "key": "ProjectMember", + "openning": true, + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "设置更改", + "key": "ProjectSettingChanged", + "openning": true, + "notification_disabled": true, + "email_disabled": false + } + ] + }, + { + "type": "TemplateMessageSetting::Normal", + "type_name": "", + "total_settings_count": 3, + "settings": [ + { + "name": "被拉入或移出组织", + "key": "Organization", + "openning": true, + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "被拉入或移出项目", + "key": "Project", + "openning": true, + "notification_disabled": true, + "email_disabled": false + }, + { + "name": "有权限变更", + "key": "Permission", + "openning": true, + "notification_disabled": true, + "email_disabled": false + } + ] + } + ] +} +``` + ## 获取用户星标项目 获取用户星标项目 diff --git a/app/models/template_message_setting.rb b/app/models/template_message_setting.rb index 349805bd3..a9c81500b 100644 --- a/app/models/template_message_setting.rb +++ b/app/models/template_message_setting.rb @@ -15,7 +15,16 @@ 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 index 385a3af8a..df98a5ca9 100644 --- a/app/models/template_message_setting/create_or_assign.rb +++ b/app/models/template_message_setting/create_or_assign.rb @@ -16,6 +16,10 @@ #我创建的或负责的 class TemplateMessageSetting::CreateOrAssign < TemplateMessageSetting + def self.type_name + "我创建的或负责的" + end + def self.build_init_data self.find_or_create_by(name: "易修状态变更", key: "IssueChanged") self.find_or_create_by(name: "易修被指派", key: "IssueAssigned") diff --git a/app/models/template_message_setting/manage.rb b/app/models/template_message_setting/manage_project.rb similarity index 86% rename from app/models/template_message_setting/manage.rb rename to app/models/template_message_setting/manage_project.rb index 925d503f3..b0f535ea2 100644 --- a/app/models/template_message_setting/manage.rb +++ b/app/models/template_message_setting/manage_project.rb @@ -14,7 +14,11 @@ # #我管理的 -class TemplateMessageSetting::Manage < TemplateMessageSetting +class TemplateMessageSetting::ManageProject < TemplateMessageSetting + + def self.type_name + "我管理的仓库" + end def self.build_init_data self.find_or_create_by(name: "有新的易修", key: "ProjectIssue") diff --git a/app/models/template_message_setting/normal.rb b/app/models/template_message_setting/normal.rb index 9801891a3..789e35b63 100644 --- a/app/models/template_message_setting/normal.rb +++ b/app/models/template_message_setting/normal.rb @@ -15,6 +15,10 @@ class TemplateMessageSetting::Normal < TemplateMessageSetting + def self.type_name + "" + end + def self.build_init_data self.find_or_create_by(name: "被拉入或移出组织", key: "Organization") self.find_or_create_by(name: "被拉入或移出项目", key: "Project") diff --git a/app/models/template_message_setting/watch.rb b/app/models/template_message_setting/watch_project.rb similarity index 80% rename from app/models/template_message_setting/watch.rb rename to app/models/template_message_setting/watch_project.rb index d6d5820a3..169e68e80 100644 --- a/app/models/template_message_setting/watch.rb +++ b/app/models/template_message_setting/watch_project.rb @@ -14,7 +14,11 @@ # #我关注的 -class TemplateMessageSetting::Watch < TemplateMessageSetting +class TemplateMessageSetting::WatchProject < TemplateMessageSetting + + def self.type_name + "我关注的仓库" + end def self.build_init_data 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..3ca136797 --- /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.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/config/routes.rb b/config/routes.rb index 9e5ffa2fb..34fa0ed6b 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 diff --git a/db/migrate/20211013081221_create_template_message_settings.rb b/db/migrate/20211013081221_create_template_message_settings.rb index 618d43b60..a3140493e 100644 --- a/db/migrate/20211013081221_create_template_message_settings.rb +++ b/db/migrate/20211013081221_create_template_message_settings.rb @@ -11,5 +11,7 @@ class CreateTemplateMessageSettings < ActiveRecord::Migration[5.2] t.timestamps end + + TemplateMessageSetting.build_init_data end end diff --git a/public/docs/api.html b/public/docs/api.html index 8368e8fae..ecfdb055d 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -360,6 +360,9 @@
  • 更改用户信息
  • +
  • + 获取平台消息设置配置信息 +
  • 获取用户星标项目
  • @@ -1569,7 +1572,173 @@ 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::CreateOrAssign",
    +            "type_name": "我创建的或负责的",
    +            "total_settings_count": 4,
    +            "settings": [
    +                {
    +                    "name": "易修状态变更",
    +                    "key": "IssueChanged",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "易修被指派",
    +                    "key": "IssueAssigned",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "合并请求被指派",
    +                    "key": "PullRequestAssigned",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "合并请求状态变更",
    +                    "key": "PullRequestAssigned",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                }
    +            ]
    +        },
    +        {
    +            "type": "TemplateMessageSetting::ManageProject",
    +            "type_name": "我管理的仓库",
    +            "total_settings_count": 4,
    +            "settings": [
    +                {
    +                    "name": "有新的易修",
    +                    "key": "ProjectIssue",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "有新的合并请求",
    +                    "key": "ProjectPullRequest",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "有成员变动",
    +                    "key": "ProjectMember",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "设置更改",
    +                    "key": "ProjectSettingChanged",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                }
    +            ]
    +        },
    +        {
    +            "type": "TemplateMessageSetting::Normal",
    +            "type_name": "",
    +            "total_settings_count": 3,
    +            "settings": [
    +                {
    +                    "name": "被拉入或移出组织",
    +                    "key": "Organization",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "被拉入或移出项目",
    +                    "key": "Project",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                },
    +                {
    +                    "name": "有权限变更",
    +                    "key": "Permission",
    +                    "openning": true,
    +                    "notification_disabled": true,
    +                    "email_disabled": false
    +                }
    +            ]
    +        }
    +    ]
    +}
    +
    + +

    获取用户星标项目

    获取用户星标项目

    @@ -1577,9 +1746,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,7 +1933,7 @@ 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,7 +1979,7 @@ 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 +2020,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,7 +2109,7 @@ 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 +2125,7 @@ Success — a happy kitten is an authenticated kitten!
    年份
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2085,7 +2254,7 @@ 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 +2270,7 @@ Success — a happy kitten is an authenticated kitten!
    日期,格式: 2021-05-28
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2402,7 +2571,7 @@ 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 +2592,7 @@ Success — a happy kitten is an authenticated kitten!
    时间戳,结束时间,格式:1622131200
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2545,7 +2714,7 @@ 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 +2735,7 @@ Success — a happy kitten is an authenticated kitten!
    时间戳,结束时间,格式:1622131200
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2627,7 +2796,7 @@ 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 +2817,7 @@ Success — a happy kitten is an authenticated kitten!
    时间戳,结束时间,格式:1622131200
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2688,7 +2857,7 @@ 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 +2873,7 @@ Success — a happy kitten is an authenticated kitten!
    用户标识
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -2967,7 +3136,7 @@ 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 +3152,7 @@ Success — a happy kitten is an authenticated kitten!
    用户标识
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -3159,7 +3328,7 @@ 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,197 +3349,6 @@ Success — a happy kitten is an authenticated kitten!
    迁移id
    -

    返回字段说明:

    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    idint迁移id
    statusstring迁移状态,canceled:取消,common:正在迁移, accept:已接受,refuse:已拒绝
    time_agostring迁移创建的时间
    project.idint迁移项目的id
    project.identifierstring迁移项目的标识
    project.namestring迁移项目的名称
    project.descriptionstring迁移项目的描述
    project.is_publicbool迁移项目是否公开
    project.owner.idbool迁移项目拥有者id
    project.owner.typestring迁移项目拥有者类型
    project.owner.namestring迁移项目拥有者昵称
    project.owner.loginstring迁移项目拥有者标识
    project.owner.image_urlstring迁移项目拥有者头像
    user.idint迁移创建者的id
    user.typestring迁移创建者的类型
    user.namestring迁移创建者的名称
    user.loginstring迁移创建者的标识
    user.image_urlstring迁移创建者头像
    owner.idint迁移接受者的id
    owner.typestring迁移接受者的类型
    owner.namestring迁移接受者的名称
    owner.loginstring迁移接受者的标识
    owner.image_urlstring迁移接受者头像
    - -
    -

    返回的JSON示例:

    -
    -
    {
    -    "project": {
    -        "id": 86,
    -        "identifier": "ceshi_repo1",
    -        "name": "测试项目啊1",
    -        "description": "二十多",
    -        "is_public": true,
    -        "owner": {
    -            "id": 52,
    -            "type": "Organization",
    -            "name": "身份卡手动阀",
    -            "login": "ceshi1",
    -            "image_url": "images/avatars/Organization/52?t=1618805056"
    -        }
    -    },
    -    "user": {
    -        "id": 6,
    -        "type": "User",
    -        "name": "yystopf",
    -        "login": "yystopf",
    -        "image_url": "system/lets/letter_avatars/2/Y/241_125_89/120.png"
    -    },
    -    "owner": {
    -        "id": 52,
    -        "type": "Organization",
    -        "name": "身份卡手动阀",
    -        "login": "ceshi1",
    -        "image_url": "images/avatars/Organization/52?t=1618805056"
    -    },
    -    "id": 1,
    -    "status": "canceled",
    -    "created_at": "2021-04-25 18:06",
    -    "time_ago": "16小时前"
    -}
    -

    用户拒绝迁移

    -

    用户拒绝迁移

    - -
    -

    示例:

    -
    -
    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 请求

    -

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

    -

    请求字段说明:

    - - - - - - - - - - - - - - - - - -
    参数类型字段说明
    loginstring用户标识
    idint迁移id

    返回字段说明:

    @@ -3496,6 +3474,197 @@ Success — a happy kitten is an authenticated kitten!
    +
    +

    返回的JSON示例:

    +
    +
    {
    +    "project": {
    +        "id": 86,
    +        "identifier": "ceshi_repo1",
    +        "name": "测试项目啊1",
    +        "description": "二十多",
    +        "is_public": true,
    +        "owner": {
    +            "id": 52,
    +            "type": "Organization",
    +            "name": "身份卡手动阀",
    +            "login": "ceshi1",
    +            "image_url": "images/avatars/Organization/52?t=1618805056"
    +        }
    +    },
    +    "user": {
    +        "id": 6,
    +        "type": "User",
    +        "name": "yystopf",
    +        "login": "yystopf",
    +        "image_url": "system/lets/letter_avatars/2/Y/241_125_89/120.png"
    +    },
    +    "owner": {
    +        "id": 52,
    +        "type": "Organization",
    +        "name": "身份卡手动阀",
    +        "login": "ceshi1",
    +        "image_url": "images/avatars/Organization/52?t=1618805056"
    +    },
    +    "id": 1,
    +    "status": "canceled",
    +    "created_at": "2021-04-25 18:06",
    +    "time_ago": "16小时前"
    +}
    +

    用户拒绝迁移

    +

    用户拒绝迁移

    + +
    +

    示例:

    +
    +
    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 请求

    +

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

    +

    请求字段说明:

    + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    loginstring用户标识
    idint迁移id
    +

    返回字段说明:

    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    参数类型字段说明
    idint迁移id
    statusstring迁移状态,canceled:取消,common:正在迁移, accept:已接受,refuse:已拒绝
    time_agostring迁移创建的时间
    project.idint迁移项目的id
    project.identifierstring迁移项目的标识
    project.namestring迁移项目的名称
    project.descriptionstring迁移项目的描述
    project.is_publicbool迁移项目是否公开
    project.owner.idbool迁移项目拥有者id
    project.owner.typestring迁移项目拥有者类型
    project.owner.namestring迁移项目拥有者昵称
    project.owner.loginstring迁移项目拥有者标识
    project.owner.image_urlstring迁移项目拥有者头像
    user.idint迁移创建者的id
    user.typestring迁移创建者的类型
    user.namestring迁移创建者的名称
    user.loginstring迁移创建者的标识
    user.image_urlstring迁移创建者头像
    owner.idint迁移接受者的id
    owner.typestring迁移接受者的类型
    owner.namestring迁移接受者的名称
    owner.loginstring迁移接受者的标识
    owner.image_urlstring迁移接受者头像
    +

    返回的JSON示例:

    @@ -3541,7 +3710,7 @@ 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 +3726,7 @@ Success — a happy kitten is an authenticated kitten!
    用户标识
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -3701,7 +3870,7 @@ 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 +3891,7 @@ Success — a happy kitten is an authenticated kitten!
    申请id
    -

    返回字段说明:

    +

    返回字段说明:

    @@ -3860,7 +4029,7 @@ 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 +4050,7 @@ Success — a happy kitten is an authenticated kitten!
    申请id
    -

    返回字段说明:

    +

    返回字段说明:

    From dbdd2e2dd3b7ac3f0c7681f92dcd289c11810d4b Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Oct 2021 11:54:42 +0800 Subject: [PATCH 24/37] add: user template message setting --- .../template_message_settings_controller.rb | 36 ++ app/docs/slate/source/includes/_users.md | 248 ++++++++++-- .../create_or_assign.rb | 4 +- .../manage_project.rb | 8 +- app/models/user.rb | 4 +- app/models/user_template_message_setting.rb | 54 +++ .../index.json.jbuilder | 2 +- .../_detail.json.jbuilder | 5 + .../current_setting.json.jbuilder | 2 + .../update_setting.json.jbuilder | 2 + config/routes.rb | 2 + public/docs/api.html | 364 ++++++++++++++---- 12 files changed, 599 insertions(+), 132 deletions(-) create mode 100644 app/controllers/users/template_message_settings_controller.rb create mode 100644 app/views/users/template_message_settings/_detail.json.jbuilder create mode 100644 app/views/users/template_message_settings/current_setting.json.jbuilder create mode 100644 app/views/users/template_message_settings/update_setting.json.jbuilder 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 d02516024..4df28755b 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -408,6 +408,31 @@ await octokit.request('GET /api/template_message_settings.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": "我创建的或负责的", @@ -416,28 +441,24 @@ await octokit.request('GET /api/template_message_settings.json') { "name": "易修状态变更", "key": "IssueChanged", - "openning": true, "notification_disabled": true, "email_disabled": false }, { "name": "易修被指派", "key": "IssueAssigned", - "openning": true, "notification_disabled": true, "email_disabled": false }, { "name": "合并请求被指派", "key": "PullRequestAssigned", - "openning": true, "notification_disabled": true, "email_disabled": false }, { "name": "合并请求状态变更", "key": "PullRequestAssigned", - "openning": true, "notification_disabled": true, "email_disabled": false } @@ -450,57 +471,25 @@ await octokit.request('GET /api/template_message_settings.json') "settings": [ { "name": "有新的易修", - "key": "ProjectIssue", - "openning": true, + "key": "Issue", "notification_disabled": true, "email_disabled": false }, { "name": "有新的合并请求", - "key": "ProjectPullRequest", - "openning": true, + "key": "PullRequest", "notification_disabled": true, "email_disabled": false }, { "name": "有成员变动", - "key": "ProjectMember", - "openning": true, + "key": "Member", "notification_disabled": true, "email_disabled": false }, { "name": "设置更改", - "key": "ProjectSettingChanged", - "openning": true, - "notification_disabled": true, - "email_disabled": false - } - ] - }, - { - "type": "TemplateMessageSetting::Normal", - "type_name": "", - "total_settings_count": 3, - "settings": [ - { - "name": "被拉入或移出组织", - "key": "Organization", - "openning": true, - "notification_disabled": true, - "email_disabled": false - }, - { - "name": "被拉入或移出项目", - "key": "Project", - "openning": true, - "notification_disabled": true, - "email_disabled": false - }, - { - "name": "有权限变更", - "key": "Permission", - "openning": true, + "key": "SettingChanged", "notification_disabled": true, "email_disabled": false } @@ -512,6 +501,185 @@ await octokit.request('GET /api/template_message_settings.json') + +## 获取用户消息设置配置信息 +获取用户消息设置配置信息 + +> 示例: + +```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::IssueChanged": true, + "CreateOrAssign::IssueAssigned": true, + "CreateOrAssign::PullRequestAssigned": true, + "CreateOrAssign::PullRequestChanged": 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::IssueChanged": false, + "CreateOrAssign::IssueAssigned": false, + "CreateOrAssign::PullRequestAssigned": false, + "CreateOrAssign::PullRequestChanged": 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::IssueChanged": true, + "CreateOrAssign::IssueAssigned": true, + "CreateOrAssign::PullRequestAssigned": true, + "CreateOrAssign::PullRequestChanged": 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::IssueChanged": false, + "CreateOrAssign::IssueAssigned": false, + "CreateOrAssign::PullRequestAssigned": false, + "CreateOrAssign::PullRequestChanged": 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::IssueChanged": true, + "CreateOrAssign::IssueAssigned": true, + "CreateOrAssign::PullRequestAssigned": true, + "CreateOrAssign::PullRequestChanged": 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::IssueChanged": false, + "CreateOrAssign::IssueAssigned": false, + "CreateOrAssign::PullRequestAssigned": false, + "CreateOrAssign::PullRequestChanged": 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/models/template_message_setting/create_or_assign.rb b/app/models/template_message_setting/create_or_assign.rb index df98a5ca9..65bf26423 100644 --- a/app/models/template_message_setting/create_or_assign.rb +++ b/app/models/template_message_setting/create_or_assign.rb @@ -21,9 +21,9 @@ class TemplateMessageSetting::CreateOrAssign < TemplateMessageSetting end def self.build_init_data - self.find_or_create_by(name: "易修状态变更", key: "IssueChanged") self.find_or_create_by(name: "易修被指派", key: "IssueAssigned") + self.find_or_create_by(name: "易修状态变更", key: "IssueChanged") self.find_or_create_by(name: "合并请求被指派", key: "PullRequestAssigned") - self.find_or_create_by(name: "合并请求状态变更", key: "PullRequestAssigned") + 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 index b0f535ea2..b1e69a5a9 100644 --- a/app/models/template_message_setting/manage_project.rb +++ b/app/models/template_message_setting/manage_project.rb @@ -21,9 +21,9 @@ class TemplateMessageSetting::ManageProject < TemplateMessageSetting end def self.build_init_data - self.find_or_create_by(name: "有新的易修", key: "ProjectIssue") - self.find_or_create_by(name: "有新的合并请求", key: "ProjectPullRequest") - self.find_or_create_by(name: "有成员变动", key: "ProjectMember") - self.find_or_create_by(name: "设置更改", key: "ProjectSettingChanged") + 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/user.rb b/app/models/user.rb index 623694b33..fc4c33618 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -170,7 +170,9 @@ class User < Owner has_many :issues, dependent: :destroy, foreign_key: :author_id 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) } scope :like, lambda { |keywords| diff --git a/app/models/user_template_message_setting.rb b/app/models/user_template_message_setting.rb index 5c6f3a2f3..5992adbb4 100644 --- a/app/models/user_template_message_setting.rb +++ b/app/models/user_template_message_setting.rb @@ -15,4 +15,58 @@ # 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 + { + "CreateOrAssign::IssueChanged": true, + "CreateOrAssign::IssueAssigned": true, + "CreateOrAssign::PullRequestAssigned": true, + "CreateOrAssign::PullRequestChanged": true, + "ManageProject::Issue": true, + "ManageProject::PullRequest": true, + "ManageProject::Member": true, + "ManageProject::SettingChanged": true, + "Normal::Organization": true, + "Normal::Project": true, + "Normal::Permission": true, + }.stringify_keys! + end + + def self.init_email_body + { + "CreateOrAssign::IssueChanged": false, + "CreateOrAssign::IssueAssigned": false, + "CreateOrAssign::PullRequestAssigned": false, + "CreateOrAssign::PullRequestChanged": false, + "ManageProject::Issue": false, + "ManageProject::PullRequest": false, + "ManageProject::Member": false, + "ManageProject::SettingChanged": false, + "Normal::Organization": false, + "Normal::Project": false, + "Normal::Permission": false, + }.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/views/template_message_settings/index.json.jbuilder b/app/views/template_message_settings/index.json.jbuilder index 3ca136797..eae5bb018 100644 --- a/app/views/template_message_settings/index.json.jbuilder +++ b/app/views/template_message_settings/index.json.jbuilder @@ -1,7 +1,7 @@ json.partial! "commons/success" json.setting_types do - json.array! @group_settings.keys.each do |k| + json.array! @group_settings.keys.sort_by{|i| i.constantize.type_name}.each do |k| json.partial! "detail", type: k, count: @group_settings[k] end 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 34fa0ed6b..35fea39c7 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -265,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 diff --git a/public/docs/api.html b/public/docs/api.html index ecfdb055d..e2a642023 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -363,6 +363,12 @@
  • 获取平台消息设置配置信息
  • +
  • + 获取用户消息设置配置信息 +
  • +
  • + 重新设置用户消息设置配置信息 +
  • 获取用户星标项目
  • @@ -1634,6 +1640,31 @@ Success — a happy kitten is an authenticated kitten! "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": "我创建的或负责的", @@ -1642,28 +1673,24 @@ Success — a happy kitten is an authenticated kitten! { "name": "易修状态变更", "key": "IssueChanged", - "openning": true, "notification_disabled": true, "email_disabled": false }, { "name": "易修被指派", "key": "IssueAssigned", - "openning": true, "notification_disabled": true, "email_disabled": false }, { "name": "合并请求被指派", "key": "PullRequestAssigned", - "openning": true, "notification_disabled": true, "email_disabled": false }, { "name": "合并请求状态变更", "key": "PullRequestAssigned", - "openning": true, "notification_disabled": true, "email_disabled": false } @@ -1676,57 +1703,25 @@ Success — a happy kitten is an authenticated kitten! "settings": [ { "name": "有新的易修", - "key": "ProjectIssue", - "openning": true, + "key": "Issue", "notification_disabled": true, "email_disabled": false }, { "name": "有新的合并请求", - "key": "ProjectPullRequest", - "openning": true, + "key": "PullRequest", "notification_disabled": true, "email_disabled": false }, { "name": "有成员变动", - "key": "ProjectMember", - "openning": true, + "key": "Member", "notification_disabled": true, "email_disabled": false }, { "name": "设置更改", - "key": "ProjectSettingChanged", - "openning": true, - "notification_disabled": true, - "email_disabled": false - } - ] - }, - { - "type": "TemplateMessageSetting::Normal", - "type_name": "", - "total_settings_count": 3, - "settings": [ - { - "name": "被拉入或移出组织", - "key": "Organization", - "openning": true, - "notification_disabled": true, - "email_disabled": false - }, - { - "name": "被拉入或移出项目", - "key": "Project", - "openning": true, - "notification_disabled": true, - "email_disabled": false - }, - { - "name": "有权限变更", - "key": "Permission", - "openning": true, + "key": "SettingChanged", "notification_disabled": true, "email_disabled": false } @@ -1738,6 +1733,207 @@ Success — a happy kitten is an authenticated kitten! +

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

    +

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

    + +
    +

    示例:

    +
    +
    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::IssueChanged": true,
    +        "CreateOrAssign::IssueAssigned": true,
    +        "CreateOrAssign::PullRequestAssigned": true,
    +        "CreateOrAssign::PullRequestChanged": 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::IssueChanged": false,
    +        "CreateOrAssign::IssueAssigned": false,
    +        "CreateOrAssign::PullRequestAssigned": false,
    +        "CreateOrAssign::PullRequestChanged": 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::IssueChanged": true,
    +            "CreateOrAssign::IssueAssigned": true,
    +            "CreateOrAssign::PullRequestAssigned": true,
    +            "CreateOrAssign::PullRequestChanged": 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::IssueChanged": false,
    +            "CreateOrAssign::IssueAssigned": false,
    +            "CreateOrAssign::PullRequestAssigned": false,
    +            "CreateOrAssign::PullRequestChanged": 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::IssueChanged": true,
    +        "CreateOrAssign::IssueAssigned": true,
    +        "CreateOrAssign::PullRequestAssigned": true,
    +        "CreateOrAssign::PullRequestChanged": 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::IssueChanged": false,
    +        "CreateOrAssign::IssueAssigned": false,
    +        "CreateOrAssign::PullRequestAssigned": false,
    +        "CreateOrAssign::PullRequestChanged": false,
    +        "ManageProject::Issue": false,
    +        "ManageProject::PullRequest": false,
    +        "ManageProject::Member": false,
    +        "ManageProject::SettingChanged": true,
    +        "Normal::Organization": false,
    +        "Normal::Project": true,
    +        "Normal::Permission": false
    +    }
    +}
    +
    +

    获取用户星标项目

    获取用户星标项目

    @@ -1746,9 +1942,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

    -

    返回字段说明:

    +

    返回字段说明:

    @@ -1933,9 +2129,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

    -

    请求字段说明:

    同时设定多个星标项目

    +

    请求字段说明:

    同时设定多个星标项目

    参数
    @@ -1979,9 +2175,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

    -

    请求字段说明:

    +

    请求字段说明:

    参数
    @@ -2020,9 +2216,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

    -

    返回字段说明:

    +

    返回字段说明:

    参数
    @@ -2109,9 +2305,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -2254,9 +2450,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -2571,9 +2767,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -2714,9 +2910,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -2796,9 +2992,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -2857,9 +3053,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -3136,9 +3332,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -3328,9 +3524,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -3519,9 +3715,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -3710,9 +3906,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -3870,9 +4066,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    @@ -4029,9 +4225,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

    -

    请求字段说明:

    +

    请求字段说明:

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

    返回字段说明:

    +

    返回字段说明:

    From 88a7456300dd24c08741deb10c31d30c5576db5e Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Oct 2021 15:49:06 +0800 Subject: [PATCH 25/37] add: template message control by setting --- app/models/message_template/issue_assigned.rb | 9 +++++++++ app/models/message_template/organization_joined.rb | 9 +++++++++ app/models/message_template/organization_left.rb | 9 +++++++++ app/models/message_template/organization_role.rb | 9 +++++++++ app/models/message_template/project_issue.rb | 9 +++++++++ app/models/message_template/project_joined.rb | 9 +++++++++ app/models/message_template/project_left.rb | 8 ++++++++ app/models/message_template/project_member_joined.rb | 9 +++++++++ app/models/message_template/project_member_left.rb | 9 +++++++++ app/models/message_template/project_pull_request.rb | 9 +++++++++ app/models/message_template/project_role.rb | 9 +++++++++ app/models/message_template/project_setting_changed.rb | 9 +++++++++ app/models/message_template/pull_request_assigned.rb | 9 +++++++++ app/models/template_message_setting/create_or_assign.rb | 2 -- 14 files changed, 116 insertions(+), 2 deletions(-) diff --git a/app/models/message_template/issue_assigned.rb b/app/models/message_template/issue_assigned.rb index 91daa8dcc..4ed581059 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["CreateOrAssign::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["CreateOrAssign::IssueAssigned"] + end project = issue&.project owner = project&.owner title = email_title 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..15548b216 100644 --- a/app/models/message_template/project_issue.rb +++ b/app/models/message_template/project_issue.rb @@ -17,6 +17,12 @@ 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 + return '', '', '' if receivers.blank? project = issue&.project owner = project&.owner receivers = managers + followers @@ -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..340db2c98 100644 --- a/app/models/message_template/project_role.rb +++ b/app/models/message_template/project_role.rb @@ -17,6 +17,12 @@ class MessageTemplate::ProjectRole < MessageTemplate # MessageTemplate::ProjectRole.get_message_content(User.where(login: 'yystopf'), Project.last, '管理员') def self.get_message_content(receivers, project, 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('{repository}', project&.name).gsub('{role}', role) url = notification_url.gsub('{owner}', project&.owner&.login).gsub('{identifier}', project&.identifier) return receivers_string(receivers), content, url @@ -26,6 +32,9 @@ class MessageTemplate::ProjectRole < MessageTemplate end def self.get_email_message_content(receivers, 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) diff --git a/app/models/message_template/project_setting_changed.rb b/app/models/message_template/project_setting_changed.rb index 3a8df5ffc..31ac5f05d 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) @@ -141,6 +147,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 diff --git a/app/models/message_template/pull_request_assigned.rb b/app/models/message_template/pull_request_assigned.rb index 54d51f3f3..39939b6cc 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["CreateOrAssign::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["CreateOrAssign::PullRequestAssigned"] + end project = pull_request&.project owner = project&.owner title = email_title diff --git a/app/models/template_message_setting/create_or_assign.rb b/app/models/template_message_setting/create_or_assign.rb index 65bf26423..2bdcffc82 100644 --- a/app/models/template_message_setting/create_or_assign.rb +++ b/app/models/template_message_setting/create_or_assign.rb @@ -22,8 +22,6 @@ class TemplateMessageSetting::CreateOrAssign < TemplateMessageSetting def self.build_init_data self.find_or_create_by(name: "易修被指派", key: "IssueAssigned") - self.find_or_create_by(name: "易修状态变更", key: "IssueChanged") self.find_or_create_by(name: "合并请求被指派", key: "PullRequestAssigned") - self.find_or_create_by(name: "合并请求状态变更", key: "PullRequestChanged") end end From 9157bc3eb9f4d11affe6840bc90e78c7ea2677c5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Mon, 18 Oct 2021 15:58:27 +0800 Subject: [PATCH 26/37] fix: api doc --- app/docs/slate/source/includes/_users.md | 24 ------------------------ public/docs/api.html | 24 ------------------------ 2 files changed, 48 deletions(-) diff --git a/app/docs/slate/source/includes/_users.md b/app/docs/slate/source/includes/_users.md index 4df28755b..be2728d0b 100644 --- a/app/docs/slate/source/includes/_users.md +++ b/app/docs/slate/source/includes/_users.md @@ -438,12 +438,6 @@ await octokit.request('GET /api/template_message_settings.json') "type_name": "我创建的或负责的", "total_settings_count": 4, "settings": [ - { - "name": "易修状态变更", - "key": "IssueChanged", - "notification_disabled": true, - "email_disabled": false - }, { "name": "易修被指派", "key": "IssueAssigned", @@ -455,12 +449,6 @@ await octokit.request('GET /api/template_message_settings.json') "key": "PullRequestAssigned", "notification_disabled": true, "email_disabled": false - }, - { - "name": "合并请求状态变更", - "key": "PullRequestAssigned", - "notification_disabled": true, - "email_disabled": false } ] }, @@ -539,10 +527,8 @@ await octokit.request('GET /api/uses/yystopf/template_message_settings.json') "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" }, "notification_body": { - "CreateOrAssign::IssueChanged": true, "CreateOrAssign::IssueAssigned": true, "CreateOrAssign::PullRequestAssigned": true, - "CreateOrAssign::PullRequestChanged": true, "ManageProject::Issue": true, "ManageProject::PullRequest": true, "ManageProject::Member": true, @@ -552,10 +538,8 @@ await octokit.request('GET /api/uses/yystopf/template_message_settings.json') "Normal::Permission": true }, "email_body": { - "CreateOrAssign::IssueChanged": false, "CreateOrAssign::IssueAssigned": false, "CreateOrAssign::PullRequestAssigned": false, - "CreateOrAssign::PullRequestChanged": false, "ManageProject::Issue": false, "ManageProject::PullRequest": false, "ManageProject::Member": false, @@ -599,10 +583,8 @@ await octokit.request('POST /api/uses/yystopf/template_message_settings/update_s { "setting": { "notification_body": { - "CreateOrAssign::IssueChanged": true, "CreateOrAssign::IssueAssigned": true, "CreateOrAssign::PullRequestAssigned": true, - "CreateOrAssign::PullRequestChanged": true, "ManageProject::Issue": true, "ManageProject::PullRequest": true, "ManageProject::Member": true, @@ -612,10 +594,8 @@ await octokit.request('POST /api/uses/yystopf/template_message_settings/update_s "Normal::Permission": true }, "email_body": { - "CreateOrAssign::IssueChanged": false, "CreateOrAssign::IssueAssigned": false, "CreateOrAssign::PullRequestAssigned": false, - "CreateOrAssign::PullRequestChanged": false, "ManageProject::Issue": false, "ManageProject::PullRequest": false, "ManageProject::Member": false, @@ -649,10 +629,8 @@ await octokit.request('POST /api/uses/yystopf/template_message_settings/update_s "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" }, "notification_body": { - "CreateOrAssign::IssueChanged": true, "CreateOrAssign::IssueAssigned": true, "CreateOrAssign::PullRequestAssigned": true, - "CreateOrAssign::PullRequestChanged": true, "ManageProject::Issue": true, "ManageProject::PullRequest": true, "ManageProject::Member": true, @@ -662,10 +640,8 @@ await octokit.request('POST /api/uses/yystopf/template_message_settings/update_s "Normal::Permission": true }, "email_body": { - "CreateOrAssign::IssueChanged": false, "CreateOrAssign::IssueAssigned": false, "CreateOrAssign::PullRequestAssigned": false, - "CreateOrAssign::PullRequestChanged": false, "ManageProject::Issue": false, "ManageProject::PullRequest": false, "ManageProject::Member": false, diff --git a/public/docs/api.html b/public/docs/api.html index e2a642023..5df230a28 100644 --- a/public/docs/api.html +++ b/public/docs/api.html @@ -1670,12 +1670,6 @@ Success — a happy kitten is an authenticated kitten! "type_name": "我创建的或负责的", "total_settings_count": 4, "settings": [ - { - "name": "易修状态变更", - "key": "IssueChanged", - "notification_disabled": true, - "email_disabled": false - }, { "name": "易修被指派", "key": "IssueAssigned", @@ -1687,12 +1681,6 @@ Success — a happy kitten is an authenticated kitten! "key": "PullRequestAssigned", "notification_disabled": true, "email_disabled": false - }, - { - "name": "合并请求状态变更", - "key": "PullRequestAssigned", - "notification_disabled": true, - "email_disabled": false } ] }, @@ -1777,10 +1765,8 @@ Success — a happy kitten is an authenticated kitten! "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png" }, "notification_body": { - "CreateOrAssign::IssueChanged": true, "CreateOrAssign::IssueAssigned": true, "CreateOrAssign::PullRequestAssigned": true, - "CreateOrAssign::PullRequestChanged": true, "ManageProject::Issue": true, "ManageProject::PullRequest": true, "ManageProject::Member": true, @@ -1790,10 +1776,8 @@ Success — a happy kitten is an authenticated kitten! "Normal::Permission": true }, "email_body": { - "CreateOrAssign::IssueChanged": false, "CreateOrAssign::IssueAssigned": false, "CreateOrAssign::PullRequestAssigned": false, - "CreateOrAssign::PullRequestChanged": false, "ManageProject::Issue": false, "ManageProject::PullRequest": false, "ManageProject::Member": false, @@ -1843,10 +1827,8 @@ Success — a happy kitten is an authenticated kitten!
    {
         "setting": {
             "notification_body": {
    -            "CreateOrAssign::IssueChanged": true,
                 "CreateOrAssign::IssueAssigned": true,
                 "CreateOrAssign::PullRequestAssigned": true,
    -            "CreateOrAssign::PullRequestChanged": true,
                 "ManageProject::Issue": true,
                 "ManageProject::PullRequest": true,
                 "ManageProject::Member": true,
    @@ -1856,10 +1838,8 @@ Success — a happy kitten is an authenticated kitten!
                 "Normal::Permission": true
             },
             "email_body": {
    -            "CreateOrAssign::IssueChanged": false,
                 "CreateOrAssign::IssueAssigned": false,
                 "CreateOrAssign::PullRequestAssigned": false,
    -            "CreateOrAssign::PullRequestChanged": false,
                 "ManageProject::Issue": false,
                 "ManageProject::PullRequest": false,
                 "ManageProject::Member": false,
    @@ -1904,10 +1884,8 @@ Success — a happy kitten is an authenticated kitten!
             "image_url": "system/lets/letter_avatars/2/H/188_239_142/120.png"
         },
         "notification_body": {
    -        "CreateOrAssign::IssueChanged": true,
             "CreateOrAssign::IssueAssigned": true,
             "CreateOrAssign::PullRequestAssigned": true,
    -        "CreateOrAssign::PullRequestChanged": true,
             "ManageProject::Issue": true,
             "ManageProject::PullRequest": true,
             "ManageProject::Member": true,
    @@ -1917,10 +1895,8 @@ Success — a happy kitten is an authenticated kitten!
             "Normal::Permission": true
         },
         "email_body": {
    -        "CreateOrAssign::IssueChanged": false,
             "CreateOrAssign::IssueAssigned": false,
             "CreateOrAssign::PullRequestAssigned": false,
    -        "CreateOrAssign::PullRequestChanged": false,
             "ManageProject::Issue": false,
             "ManageProject::PullRequest": false,
             "ManageProject::Member": false,
    
    From 7d98bd0bbe3dbb49094be68ccc9a3317c00b08e9 Mon Sep 17 00:00:00 2001
    From: yystopf 
    Date: Mon, 18 Oct 2021 16:02:31 +0800
    Subject: [PATCH 27/37] fix: template message settinng type order by order
     index
    
    ---
     app/models/template_message_setting/create_or_assign.rb | 4 ++++
     app/models/template_message_setting/manage_project.rb   | 4 ++++
     app/models/template_message_setting/normal.rb           | 4 ++++
     app/models/template_message_setting/watch_project.rb    | 4 ++++
     app/views/template_message_settings/index.json.jbuilder | 2 +-
     5 files changed, 17 insertions(+), 1 deletion(-)
    
    diff --git a/app/models/template_message_setting/create_or_assign.rb b/app/models/template_message_setting/create_or_assign.rb
    index 2bdcffc82..4de899068 100644
    --- a/app/models/template_message_setting/create_or_assign.rb
    +++ b/app/models/template_message_setting/create_or_assign.rb
    @@ -20,6 +20,10 @@ class TemplateMessageSetting::CreateOrAssign < TemplateMessageSetting
         "我创建的或负责的"
       end
     
    +  def self.order_index
    +    20
    +  end
    +
       def self.build_init_data
         self.find_or_create_by(name: "易修被指派", key: "IssueAssigned")
         self.find_or_create_by(name: "合并请求被指派", key: "PullRequestAssigned")
    diff --git a/app/models/template_message_setting/manage_project.rb b/app/models/template_message_setting/manage_project.rb
    index b1e69a5a9..18defc6c5 100644
    --- a/app/models/template_message_setting/manage_project.rb
    +++ b/app/models/template_message_setting/manage_project.rb
    @@ -20,6 +20,10 @@ class TemplateMessageSetting::ManageProject < TemplateMessageSetting
         "我管理的仓库"
       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")
    diff --git a/app/models/template_message_setting/normal.rb b/app/models/template_message_setting/normal.rb
    index 789e35b63..b0495b8c2 100644
    --- a/app/models/template_message_setting/normal.rb
    +++ b/app/models/template_message_setting/normal.rb
    @@ -19,6 +19,10 @@ class TemplateMessageSetting::Normal < TemplateMessageSetting
         ""
       end
     
    +  def self.order_index 
    +    10
    +  end
    +
       def self.build_init_data
         self.find_or_create_by(name: "被拉入或移出组织", key: "Organization")
         self.find_or_create_by(name: "被拉入或移出项目", key: "Project")
    diff --git a/app/models/template_message_setting/watch_project.rb b/app/models/template_message_setting/watch_project.rb
    index 169e68e80..35dfef6db 100644
    --- a/app/models/template_message_setting/watch_project.rb
    +++ b/app/models/template_message_setting/watch_project.rb
    @@ -20,6 +20,10 @@ class TemplateMessageSetting::WatchProject < TemplateMessageSetting
         "我关注的仓库"
       end
     
    +  def self.order_index
    +    40
    +  end
    +
       def self.build_init_data
       end
     end
    diff --git a/app/views/template_message_settings/index.json.jbuilder b/app/views/template_message_settings/index.json.jbuilder
    index eae5bb018..4f863ce0f 100644
    --- a/app/views/template_message_settings/index.json.jbuilder
    +++ b/app/views/template_message_settings/index.json.jbuilder
    @@ -1,7 +1,7 @@
     json.partial! "commons/success"
     json.setting_types do 
     
    -  json.array! @group_settings.keys.sort_by{|i| i.constantize.type_name}.each do |k|
    +  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
     
    
    From bd9759a3ed0a8184dad71d95ca757a1b1af341bd Mon Sep 17 00:00:00 2001
    From: yystopf 
    Date: Mon, 18 Oct 2021 17:32:36 +0800
    Subject: [PATCH 28/37] fix: user template message setting init data
    
    ---
     app/models/user_template_message_setting.rb | 4 ----
     1 file changed, 4 deletions(-)
    
    diff --git a/app/models/user_template_message_setting.rb b/app/models/user_template_message_setting.rb
    index 5992adbb4..1039b39df 100644
    --- a/app/models/user_template_message_setting.rb
    +++ b/app/models/user_template_message_setting.rb
    @@ -28,10 +28,8 @@ class UserTemplateMessageSetting < ApplicationRecord
     
       def self.init_notification_body 
         {
    -      "CreateOrAssign::IssueChanged": true,
           "CreateOrAssign::IssueAssigned": true,
           "CreateOrAssign::PullRequestAssigned": true,
    -      "CreateOrAssign::PullRequestChanged": true,
           "ManageProject::Issue": true,
           "ManageProject::PullRequest": true,
           "ManageProject::Member": true,
    @@ -44,10 +42,8 @@ class UserTemplateMessageSetting < ApplicationRecord
     
       def self.init_email_body 
         {
    -      "CreateOrAssign::IssueChanged": false,
           "CreateOrAssign::IssueAssigned": false,
           "CreateOrAssign::PullRequestAssigned": false,
    -      "CreateOrAssign::PullRequestChanged": false,
           "ManageProject::Issue": false,
           "ManageProject::PullRequest": false,
           "ManageProject::Member": false,
    
    From dbe47dbddfd19953a9b933634defc2135caf9a4a Mon Sep 17 00:00:00 2001
    From: yystopf 
    Date: Tue, 19 Oct 2021 14:39:15 +0800
    Subject: [PATCH 29/37] fix: change template message setting default value
    
    ---
     .../create_or_assign.rb                       |  3 +-
     app/models/template_message_setting/normal.rb |  6 ++--
     app/models/user_template_message_setting.rb   | 28 +++++++++----------
     3 files changed, 19 insertions(+), 18 deletions(-)
    
    diff --git a/app/models/template_message_setting/create_or_assign.rb b/app/models/template_message_setting/create_or_assign.rb
    index 4de899068..54f842409 100644
    --- a/app/models/template_message_setting/create_or_assign.rb
    +++ b/app/models/template_message_setting/create_or_assign.rb
    @@ -25,7 +25,6 @@ class TemplateMessageSetting::CreateOrAssign < TemplateMessageSetting
       end
     
       def self.build_init_data
    -    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/normal.rb b/app/models/template_message_setting/normal.rb
    index b0495b8c2..2a1f50078 100644
    --- a/app/models/template_message_setting/normal.rb
    +++ b/app/models/template_message_setting/normal.rb
    @@ -16,7 +16,7 @@
     class TemplateMessageSetting::Normal < TemplateMessageSetting 
     
       def self.type_name 
    -    ""
    +    "我的状态"
       end
     
       def self.order_index 
    @@ -24,8 +24,10 @@ class TemplateMessageSetting::Normal < TemplateMessageSetting
       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: "Permission")
    +    self.find_or_create_by(name: "易修被指派", key: "IssueAssigned")
    +    self.find_or_create_by(name: "合并请求被指派", key: "PullRequestAssigned")
       end
     end
    diff --git a/app/models/user_template_message_setting.rb b/app/models/user_template_message_setting.rb
    index 1039b39df..685eb1bf3 100644
    --- a/app/models/user_template_message_setting.rb
    +++ b/app/models/user_template_message_setting.rb
    @@ -28,29 +28,29 @@ class UserTemplateMessageSetting < ApplicationRecord
     
       def self.init_notification_body 
         {
    -      "CreateOrAssign::IssueAssigned": true,
    -      "CreateOrAssign::PullRequestAssigned": true,
    +      "Normal::Permission": true,
    +      "Normal::Project": true,
    +      "Normal::Organization": true,
    +      "Normal::IssueAssigned": true,
    +      "Normal::PullRequestAssigned": true,
           "ManageProject::Issue": true,
           "ManageProject::PullRequest": true,
           "ManageProject::Member": true,
           "ManageProject::SettingChanged": true,
    -      "Normal::Organization": true,
    -      "Normal::Project": true,
    -      "Normal::Permission": true,
         }.stringify_keys!
       end
     
       def self.init_email_body 
         {
    -      "CreateOrAssign::IssueAssigned": false,
    -      "CreateOrAssign::PullRequestAssigned": false,
    -      "ManageProject::Issue": false,
    -      "ManageProject::PullRequest": false,
    -      "ManageProject::Member": false,
    -      "ManageProject::SettingChanged": false,
    -      "Normal::Organization": false,
    -      "Normal::Project": false,
    -      "Normal::Permission": false,
    +      "Normal::Permission": true,
    +      "Normal::Project": true,
    +      "Normal::Organization": true,
    +      "Normal::IssueAssigned": true,
    +      "Normal::PullRequestAssigned": true,
    +      "ManageProject::Issue": true,
    +      "ManageProject::PullRequest": true,
    +      "ManageProject::Member": true,
    +      "ManageProject::SettingChanged": true,
         }.stringify_keys!
       end
     
    
    From 3ce8723de2de4733e3cf7ec0f0480efc475ef97b Mon Sep 17 00:00:00 2001
    From: yystopf 
    Date: Tue, 19 Oct 2021 14:49:35 +0800
    Subject: [PATCH 30/37] fix
    
    ---
     app/models/template_message_setting/manage_project.rb | 2 +-
     app/models/template_message_setting/normal.rb         | 4 ++--
     2 files changed, 3 insertions(+), 3 deletions(-)
    
    diff --git a/app/models/template_message_setting/manage_project.rb b/app/models/template_message_setting/manage_project.rb
    index 18defc6c5..2aa9e4883 100644
    --- a/app/models/template_message_setting/manage_project.rb
    +++ b/app/models/template_message_setting/manage_project.rb
    @@ -28,6 +28,6 @@ class TemplateMessageSetting::ManageProject < TemplateMessageSetting
         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")
    +    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
    index 2a1f50078..9090196d5 100644
    --- a/app/models/template_message_setting/normal.rb
    +++ b/app/models/template_message_setting/normal.rb
    @@ -27,7 +27,7 @@ class TemplateMessageSetting::Normal < TemplateMessageSetting
         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")
    +    self.find_or_create_by(name: "有新的易修指派给我", key: "IssueAssigned")
    +    self.find_or_create_by(name: "有新的合并请求指派给我", key: "PullRequestAssigned")
       end
     end
    
    From c52f40adbd03f2bb57e7cc5281adcf7e37ea49ce Mon Sep 17 00:00:00 2001
    From: yystopf 
    Date: Tue, 19 Oct 2021 16:21:34 +0800
    Subject: [PATCH 31/37] fix
    
    ---
     app/jobs/send_template_message_job.rb                | 2 +-
     app/models/message_template/issue_assigned.rb        | 4 ++--
     app/models/message_template/project_issue.rb         | 2 +-
     app/models/message_template/project_role.rb          | 2 +-
     app/models/message_template/pull_request_assigned.rb | 4 ++--
     app/models/template_message_setting/normal.rb        | 2 +-
     app/models/user_template_message_setting.rb          | 4 ++--
     7 files changed, 10 insertions(+), 10 deletions(-)
    
    diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb
    index 2c463d705..a5b1434c7 100644
    --- a/app/jobs/send_template_message_job.rb
    +++ b/app/jobs/send_template_message_job.rb
    @@ -193,7 +193,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'
    diff --git a/app/models/message_template/issue_assigned.rb b/app/models/message_template/issue_assigned.rb
    index 4ed581059..23632c3ef 100644
    --- a/app/models/message_template/issue_assigned.rb
    +++ b/app/models/message_template/issue_assigned.rb
    @@ -19,7 +19,7 @@ class MessageTemplate::IssueAssigned < MessageTemplate
       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["CreateOrAssign::IssueAssigned"]
    +        receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["Normal::IssueAssigned"]
           end
         end
         return '', '', '' if receivers.blank?
    @@ -35,7 +35,7 @@ class MessageTemplate::IssueAssigned < MessageTemplate
     
       def self.get_email_message_content(receiver, operator, issue)
         if receiver.user_template_message_setting.present? 
    -      return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::IssueAssigned"]
    +      return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::IssueAssigned"]
         end
         project = issue&.project
         owner = project&.owner 
    diff --git a/app/models/message_template/project_issue.rb b/app/models/message_template/project_issue.rb
    index 15548b216..9106bcc8f 100644
    --- a/app/models/message_template/project_issue.rb
    +++ b/app/models/message_template/project_issue.rb
    @@ -22,10 +22,10 @@ class MessageTemplate::ProjectIssue < MessageTemplate
             managers = managers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["ManageProject::Issue"]
           end
         end
    -    return '', '', '' if receivers.blank?
         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)
         
    diff --git a/app/models/message_template/project_role.rb b/app/models/message_template/project_role.rb
    index 340db2c98..6cb88ab89 100644
    --- a/app/models/message_template/project_role.rb
    +++ b/app/models/message_template/project_role.rb
    @@ -31,7 +31,7 @@ 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
    diff --git a/app/models/message_template/pull_request_assigned.rb b/app/models/message_template/pull_request_assigned.rb
    index 39939b6cc..1101ca46b 100644
    --- a/app/models/message_template/pull_request_assigned.rb
    +++ b/app/models/message_template/pull_request_assigned.rb
    @@ -19,7 +19,7 @@ class MessageTemplate::PullRequestAssigned < MessageTemplate
       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::PullRequestAssigned"]
    +        receivers = receivers.where.not(id: receiver.id) unless receiver.user_template_message_setting.notification_body["Normal::PullRequestAssigned"]
           end
         end
         return '', '', '' if receivers.blank?
    @@ -35,7 +35,7 @@ class MessageTemplate::PullRequestAssigned < MessageTemplate
     
       def self.get_email_message_content(receiver, operator, pull_request)
         if receiver.user_template_message_setting.present? 
    -      return '', '', '' unless receiver.user_template_message_setting.email_body["CreateOrAssign::PullRequestAssigned"]
    +      return '', '', '' unless receiver.user_template_message_setting.email_body["Normal::PullRequestAssigned"]
         end
         project = pull_request&.project
         owner = project&.owner 
    diff --git a/app/models/template_message_setting/normal.rb b/app/models/template_message_setting/normal.rb
    index 9090196d5..44ed35617 100644
    --- a/app/models/template_message_setting/normal.rb
    +++ b/app/models/template_message_setting/normal.rb
    @@ -24,7 +24,7 @@ class TemplateMessageSetting::Normal < TemplateMessageSetting
       end
     
       def self.build_init_data
    -    self.find_or_create_by(name: "账号有权限变更", key: "Permission")
    +    # 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")
    diff --git a/app/models/user_template_message_setting.rb b/app/models/user_template_message_setting.rb
    index 685eb1bf3..7b7f8cb8c 100644
    --- a/app/models/user_template_message_setting.rb
    +++ b/app/models/user_template_message_setting.rb
    @@ -28,7 +28,7 @@ class UserTemplateMessageSetting < ApplicationRecord
     
       def self.init_notification_body 
         {
    -      "Normal::Permission": true,
    +      # "Normal::Permission": true,
           "Normal::Project": true,
           "Normal::Organization": true,
           "Normal::IssueAssigned": true,
    @@ -42,7 +42,7 @@ class UserTemplateMessageSetting < ApplicationRecord
     
       def self.init_email_body 
         {
    -      "Normal::Permission": true,
    +      # "Normal::Permission": true,
           "Normal::Project": true,
           "Normal::Organization": true,
           "Normal::IssueAssigned": true,
    
    From 748e8cc92ab6057106b74883c7dff87e1cfbcb68 Mon Sep 17 00:00:00 2001
    From: yystopf 
    Date: Wed, 20 Oct 2021 14:34:15 +0800
    Subject: [PATCH 32/37] add: send template message email supplement
    
    ---
     app/jobs/send_template_message_job.rb         |  24 ++-
     app/models/message_template.rb                |  29 +--
     app/models/message_template/issue_changed.rb  | 185 ++++++++++++++++++
     app/models/message_template/issue_deleted.rb  |  27 ++-
     app/models/message_template/project_role.rb   |   2 +
     .../message_template/pull_request_changed.rb  |  97 +++++++++
     .../message_template/pull_request_closed.rb   |  32 +++
     .../message_template/pull_request_merged.rb   |  32 +++
     .../create_or_assign.rb                       |   3 +-
     app/models/template_message_setting/normal.rb |   2 +-
     app/models/user_template_message_setting.rb   |   8 +-
     public/message_template/issue_changed.html    |  62 ++++++
     public/message_template/issue_deleted.html    |  52 +++++
     .../message_template/organization_role.html   |  52 +++++
     .../project_pull_request.html                 |   2 +-
     public/message_template/project_role.html     |  52 +++++
     .../pull_request_assigned.html                |   2 +-
     .../pull_request_changed.html                 |  56 ++++++
     .../message_template/pull_request_closed.html |  52 +++++
     .../message_template/pull_request_merged.html |  52 +++++
     20 files changed, 803 insertions(+), 20 deletions(-)
     create mode 100755 public/message_template/issue_changed.html
     create mode 100755 public/message_template/issue_deleted.html
     create mode 100755 public/message_template/organization_role.html
     create mode 100755 public/message_template/project_role.html
     create mode 100755 public/message_template/pull_request_changed.html
     create mode 100755 public/message_template/pull_request_closed.html
     create mode 100755 public/message_template/pull_request_merged.html
    
    diff --git a/app/jobs/send_template_message_job.rb b/app/jobs/send_template_message_job.rb
    index a5b1434c7..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)
    @@ -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..8d3f622b6 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::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_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/project_role.rb b/app/models/message_template/project_role.rb index 6cb88ab89..e1ced084a 100644 --- a/app/models/message_template/project_role.rb +++ b/app/models/message_template/project_role.rb @@ -38,10 +38,12 @@ class MessageTemplate::ProjectRole < MessageTemplate 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/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/template_message_setting/create_or_assign.rb b/app/models/template_message_setting/create_or_assign.rb index 54f842409..2c9fa2076 100644 --- a/app/models/template_message_setting/create_or_assign.rb +++ b/app/models/template_message_setting/create_or_assign.rb @@ -25,6 +25,7 @@ class TemplateMessageSetting::CreateOrAssign < TemplateMessageSetting 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/normal.rb b/app/models/template_message_setting/normal.rb index 44ed35617..9090196d5 100644 --- a/app/models/template_message_setting/normal.rb +++ b/app/models/template_message_setting/normal.rb @@ -24,7 +24,7 @@ class TemplateMessageSetting::Normal < TemplateMessageSetting end def self.build_init_data - # self.find_or_create_by(name: "账号有权限变更", key: "Permission") + 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") diff --git a/app/models/user_template_message_setting.rb b/app/models/user_template_message_setting.rb index 7b7f8cb8c..c581e626e 100644 --- a/app/models/user_template_message_setting.rb +++ b/app/models/user_template_message_setting.rb @@ -28,11 +28,13 @@ class UserTemplateMessageSetting < ApplicationRecord def self.init_notification_body { - # "Normal::Permission": true, + "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, @@ -42,11 +44,13 @@ class UserTemplateMessageSetting < ApplicationRecord def self.init_email_body { - # "Normal::Permission": true, + "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, diff --git a/public/message_template/issue_changed.html b/public/message_template/issue_changed.html new file mode 100755 index 000000000..ed3bbbe54 --- /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/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..4e6e4eac7 --- /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 From 9ffe10bd5baa36e3d2801ce2aaf92fd5fe457cc3 Mon Sep 17 00:00:00 2001 From: jasder Date: Thu, 21 Oct 2021 10:48:14 +0800 Subject: [PATCH 33/37] =?UTF-8?q?FIX=20=E8=B0=83=E6=95=B4detail=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=95=B0=E6=8D=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/repositories/detail_service.rb | 25 +++++---------------- app/views/repositories/detail.json.jbuilder | 24 ++------------------ 2 files changed, 8 insertions(+), 41 deletions(-) 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/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| From 94d5565f5698e131c1220977e644f4caa80b91eb Mon Sep 17 00:00:00 2001 From: jasder Date: Thu, 21 Oct 2021 10:52:58 +0800 Subject: [PATCH 34/37] =?UTF-8?q?FIX=20=E8=B0=83=E6=95=B4detail=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=95=B0=E6=8D=AE[bug]?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../get_branch_and_tag_total_num_service.rb | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 app/services/gitea/repository/get_branch_and_tag_total_num_service.rb 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 From fdcf450eab82052da1e864a75a3baedd6f782c1b Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 21 Oct 2021 11:17:11 +0800 Subject: [PATCH 35/37] fix --- app/models/message_template.rb | 2 +- app/models/message_template/project_role.rb | 2 +- .../message_template/project_setting_changed.rb | 12 ++++++++++++ public/message_template/issue_changed.html | 2 +- public/message_template/pull_request_changed.html | 2 +- 5 files changed, 16 insertions(+), 4 deletions(-) diff --git a/app/models/message_template.rb b/app/models/message_template.rb index 8d3f622b6..6cef999ae 100644 --- a/app/models/message_template.rb +++ b/app/models/message_template.rb @@ -53,7 +53,7 @@ class MessageTemplate < ApplicationRecord 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") diff --git a/app/models/message_template/project_role.rb b/app/models/message_template/project_role.rb index e1ced084a..e306f5c02 100644 --- a/app/models/message_template/project_role.rb +++ b/app/models/message_template/project_role.rb @@ -23,7 +23,7 @@ class MessageTemplate::ProjectRole < MessageTemplate end end return '', '', '' if receivers.blank? - content = sys_notice.gsub('{repository}', project&.name).gsub('{role}', role) + 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 diff --git a/app/models/message_template/project_setting_changed.rb b/app/models/message_template/project_setting_changed.rb index 31ac5f05d..260c284db 100644 --- a/app/models/message_template/project_setting_changed.rb +++ b/app/models/message_template/project_setting_changed.rb @@ -178,6 +178,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/public/message_template/issue_changed.html b/public/message_template/issue_changed.html index ed3bbbe54..5f8d796b4 100755 --- a/public/message_template/issue_changed.html +++ b/public/message_template/issue_changed.html @@ -31,7 +31,7 @@

    {receiver},您好!
    - 在项目 {nickname2}/{repository} 的易修 {title} 中: + 在项目 {nickname2}/{repository} 的易修 {title} 中: {ifassigner}{nickname1}将负责人从 {assigner1} 修改为 {assigner2}{endassigner} {ifstatus}{nickname1}将状态从 {status1} 修改为 {status2}{endstatus} {iftracker}{nickname1}将类型从 {tracker1} 修改为 {tracker2}{endtracker} diff --git a/public/message_template/pull_request_changed.html b/public/message_template/pull_request_changed.html index 4e6e4eac7..5cafdc47e 100755 --- a/public/message_template/pull_request_changed.html +++ b/public/message_template/pull_request_changed.html @@ -31,7 +31,7 @@

    {receiver},您好!
    - 在项目 {nickname2}/{repository} 的合并请求 {title} 中: + 在项目 {nickname2}/{repository} 的合并请求 {title} 中: {ifassigner}{nickname1}将负责人从 {assigner1} 修改为 {assigner2}{endassigner} {ifmilestone}{nickname1}将里程碑从 {milestone1} 修改为 {milestone2}{endmilestone} {iftag}{nickname1}将标记从 {tag1} 修改为 {tag2}{endtag} From 43d125100dd4033366062d8215f13936f2dd5088 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 21 Oct 2021 11:19:12 +0800 Subject: [PATCH 36/37] fix --- app/models/message_template.rb | 2 +- public/message_template/project_setting_changed.html | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/app/models/message_template.rb b/app/models/message_template.rb index 6cef999ae..bd2c68bdd 100644 --- a/app/models/message_template.rb +++ b/app/models/message_template.rb @@ -53,7 +53,7 @@ class MessageTemplate < ApplicationRecord 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}{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::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") 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} From 24ec0398954833ecf903cf12639e20991a7073a2 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 21 Oct 2021 11:23:12 +0800 Subject: [PATCH 37/37] fix --- app/controllers/projects_controller.rb | 2 +- .../message_template/project_setting_changed.rb | 12 ++++++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 3c5cb1f32..1c6e9868c 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -145,7 +145,7 @@ class ProjectsController < ApplicationController 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)) if Site.has_notice_menu? + 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) diff --git a/app/models/message_template/project_setting_changed.rb b/app/models/message_template/project_setting_changed.rb index 260c284db..457ab9207 100644 --- a/app/models/message_template/project_setting_changed.rb +++ b/app/models/message_template/project_setting_changed.rb @@ -40,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?

    参数