From 8252cb7e71fb30fc4686d94de5912bcc2fe85dde Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 13 Oct 2021 17:04:28 +0800 Subject: [PATCH 01/14] 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 02/14] 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 03/14] 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 04/14] 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 05/14] 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 06/14] 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 07/14] 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 08/14] 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 09/14] 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 10/14] 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 11/14] 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 fdcf450eab82052da1e864a75a3baedd6f782c1b Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 21 Oct 2021 11:17:11 +0800 Subject: [PATCH 12/14] 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 13/14] 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 14/14] 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?

    参数