add: user template message setting

This commit is contained in:
2021-10-18 11:54:42 +08:00
parent d54dcb6b67
commit dbdd2e2dd3
12 changed files with 599 additions and 132 deletions

View File

@@ -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