mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 09:42:46 +08:00
Merge pull request #6785 from artoscinote/ma_SCI_9856
Implement delivery notifications, fix specs [SCI-9856]
This commit is contained in:
commit
58acbcaecf
11 changed files with 75 additions and 76 deletions
|
@ -24,11 +24,14 @@ module FailedDeliveryNotifiableJob
|
||||||
@user = User.find_by(id: arguments.last[:user_id])
|
@user = User.find_by(id: arguments.last[:user_id])
|
||||||
return if @user.blank?
|
return if @user.blank?
|
||||||
|
|
||||||
DeliveryNotification.with(
|
DeliveryNotification.send_notifications(
|
||||||
title: failed_notification_title,
|
{
|
||||||
message: failed_notification_message,
|
title: failed_notification_title,
|
||||||
error: true
|
message: failed_notification_message,
|
||||||
).deliver(@user)
|
error: true,
|
||||||
|
user: @user
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def failed_notification_title
|
def failed_notification_title
|
||||||
|
|
|
@ -136,13 +136,17 @@ module Protocols
|
||||||
"href='#{Rails.application.routes.url_helpers.rails_blob_path(@tmp_files.take.file)}'>" \
|
"href='#{Rails.application.routes.url_helpers.rails_blob_path(@tmp_files.take.file)}'>" \
|
||||||
"#{@tmp_files.take.file.filename}</a>"
|
"#{@tmp_files.take.file.filename}</a>"
|
||||||
|
|
||||||
DeliveryNotification.with(
|
DeliveryNotification.send_notifications(
|
||||||
title: I18n.t('protocols.import_export.import_protocol_notification.title', link: original_file_download_link),
|
{
|
||||||
message: "#{I18n.t('protocols.import_export.import_protocol_notification.message')} " \
|
title:
|
||||||
"<a data-id='#{@protocol.id}' data-turbolinks='false' " \
|
I18n.t('protocols.import_export.import_protocol_notification.title', link: original_file_download_link),
|
||||||
"href='#{Rails.application.routes.url_helpers.protocol_path(@protocol)}'>" \
|
message: "#{I18n.t('protocols.import_export.import_protocol_notification.message')} " \
|
||||||
"#{@protocol.name}</a>"
|
"<a data-id='#{@protocol.id}' data-turbolinks='false' " \
|
||||||
).deliver(@user)
|
"href='#{Rails.application.routes.url_helpers.protocol_path(@protocol)}'>" \
|
||||||
|
"#{@protocol.name}</a>",
|
||||||
|
user: @user
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overrides method from FailedDeliveryNotifiableJob concern
|
# Overrides method from FailedDeliveryNotifiableJob concern
|
||||||
|
|
|
@ -22,12 +22,15 @@ module Reports
|
||||||
report_path = Rails.application.routes.url_helpers
|
report_path = Rails.application.routes.url_helpers
|
||||||
.reports_path(team: report.team.id, preview_report_id: report.id, preview_type: :docx)
|
.reports_path(team: report.team.id, preview_report_id: report.id, preview_type: :docx)
|
||||||
|
|
||||||
DeliveryNotification.with(
|
DeliveryNotification.send_notifications(
|
||||||
title: I18n.t('projects.reports.index.generation.completed_docx_notification_title'),
|
{
|
||||||
message: I18n.t('projects.reports.index.generation.completed_notification_message',
|
title: I18n.t('projects.reports.index.generation.completed_docx_notification_title'),
|
||||||
report_link: "<a href='#{report_path}'>#{escape_input(report.name)}</a>",
|
message: I18n.t('projects.reports.index.generation.completed_notification_message',
|
||||||
team_name: escape_input(report.team.name))
|
report_link: "<a href='#{report_path}'>#{escape_input(report.name)}</a>",
|
||||||
).deliver(user)
|
team_name: escape_input(report.team.name)),
|
||||||
|
user: @user
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
Reports::DocxPreviewJob.perform_now(report.id)
|
Reports::DocxPreviewJob.perform_now(report.id)
|
||||||
ensure
|
ensure
|
||||||
|
|
|
@ -162,12 +162,15 @@ module Reports
|
||||||
def create_notification_for_user
|
def create_notification_for_user
|
||||||
report_path = Rails.application.routes.url_helpers
|
report_path = Rails.application.routes.url_helpers
|
||||||
.reports_path(team: @report.team.id, preview_report_id: @report.id, preview_type: :pdf)
|
.reports_path(team: @report.team.id, preview_report_id: @report.id, preview_type: :pdf)
|
||||||
DeliveryNotification.with(
|
DeliveryNotification.send_notifications(
|
||||||
title: I18n.t('projects.reports.index.generation.completed_pdf_notification_title'),
|
{
|
||||||
message: I18n.t('projects.reports.index.generation.completed_notification_message',
|
title: I18n.t('projects.reports.index.generation.completed_pdf_notification_title'),
|
||||||
report_link: "<a href='#{report_path}'>#{escape_input(@report.name)}</a>",
|
message: I18n.t('projects.reports.index.generation.completed_notification_message',
|
||||||
team_name: escape_input(@report.team.name))
|
report_link: "<a href='#{report_path}'>#{escape_input(@report.name)}</a>",
|
||||||
).deliver(@user)
|
team_name: escape_input(@report.team.name)),
|
||||||
|
user: @user
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
def append_result_asset_previews
|
def append_result_asset_previews
|
||||||
|
|
|
@ -83,16 +83,19 @@ class RepositoriesExportJob < ApplicationJob
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_notification
|
def generate_notification
|
||||||
DeliveryNotification.with(
|
DeliveryNotification.send_notifications(
|
||||||
title: I18n.t('zip_export.notification_title'),
|
{
|
||||||
message: "<a data-id='#{@zip_export.id}' " \
|
title: I18n.t('zip_export.notification_title'),
|
||||||
"data-turbolinks='false' " \
|
message: "<a data-id='#{@zip_export.id}' " \
|
||||||
"href='#{Rails.application
|
"data-turbolinks='false' " \
|
||||||
.routes
|
"href='#{Rails.application
|
||||||
.url_helpers
|
.routes
|
||||||
.zip_exports_download_export_all_path(@zip_export)}'>" \
|
.url_helpers
|
||||||
"#{@zip_export.zip_file_name}</a>"
|
.zip_exports_download_export_all_path(@zip_export)}'>" \
|
||||||
).deliver(@user)
|
"#{@zip_export.zip_file_name}</a>",
|
||||||
|
user: @user
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# Overrides method from FailedDeliveryNotifiableJob concern
|
# Overrides method from FailedDeliveryNotifiableJob concern
|
||||||
|
|
|
@ -34,15 +34,18 @@ class ZipExportJob < ApplicationJob
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_notification!
|
def generate_notification!
|
||||||
DeliveryNotification.with(
|
DeliveryNotification.send_notifications(
|
||||||
title: I18n.t('zip_export.notification_title'),
|
{
|
||||||
message: "<a data-id='#{@zip_export.id}' " \
|
title: I18n.t('zip_export.notification_title'),
|
||||||
"data-turbolinks='false' " \
|
message: "<a data-id='#{@zip_export.id}' " \
|
||||||
"href='#{Rails.application
|
"data-turbolinks='false' " \
|
||||||
.routes
|
"href='#{Rails.application
|
||||||
.url_helpers
|
.routes
|
||||||
.zip_exports_download_path(@zip_export)}'>" \
|
.url_helpers
|
||||||
"#{@zip_export.zip_file_name}</a>"
|
.zip_exports_download_path(@zip_export)}'>" \
|
||||||
).deliver(@user)
|
"#{@zip_export.zip_file_name}</a>",
|
||||||
|
user: @user
|
||||||
|
}
|
||||||
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,36 +1,15 @@
|
||||||
# frozen_string_literal: true
|
# frozen_string_literal: true
|
||||||
|
|
||||||
# To deliver this notification:
|
|
||||||
#
|
|
||||||
# DeliveryNotification.with(post: @post).deliver_later(current_user)
|
|
||||||
# DeliveryNotification.with(post: @post).deliver(current_user)
|
|
||||||
|
|
||||||
class DeliveryNotification < BaseNotification
|
class DeliveryNotification < BaseNotification
|
||||||
# Add your delivery methods
|
def self.subtype
|
||||||
#
|
:delivery
|
||||||
# deliver_by :email, mailer: "UserMailer"
|
end
|
||||||
# deliver_by :slack
|
|
||||||
# deliver_by :custom, class: "MyDeliveryMethod"
|
|
||||||
|
|
||||||
# Add required params
|
|
||||||
#
|
|
||||||
# param :post
|
|
||||||
|
|
||||||
# Define helper methods to make rendering easier.
|
|
||||||
#
|
|
||||||
def message
|
def message
|
||||||
# if params[:legacy]
|
|
||||||
params[:message]
|
params[:message]
|
||||||
# else
|
|
||||||
# new logic
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def title
|
def title
|
||||||
# if params[:legacy]
|
|
||||||
params[:title]
|
params[:title]
|
||||||
# else
|
|
||||||
# new logic
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -97,6 +97,9 @@ class NotificationExtends
|
||||||
change_users_role_on_team_activity: {
|
change_users_role_on_team_activity: {
|
||||||
code: 94,
|
code: 94,
|
||||||
recipients_module: :UserChangedRecipient
|
recipients_module: :UserChangedRecipient
|
||||||
|
},
|
||||||
|
delivery: {
|
||||||
|
recipients_module: :DirectRecipient
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -151,7 +154,9 @@ class NotificationExtends
|
||||||
remove_user_from_team
|
remove_user_from_team
|
||||||
change_users_role_on_team_activity
|
change_users_role_on_team_activity
|
||||||
],
|
],
|
||||||
always_on: []
|
always_on: %I[
|
||||||
|
delivery
|
||||||
|
]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,11 +6,12 @@ describe UserMyModulesController, type: :controller do
|
||||||
login_user
|
login_user
|
||||||
|
|
||||||
include_context 'reference_project_structure'
|
include_context 'reference_project_structure'
|
||||||
|
let(:other_user) { create :user }
|
||||||
|
|
||||||
describe 'POST create' do
|
describe 'POST create' do
|
||||||
let(:action) { post :create, params: params, format: :json }
|
let(:action) { post :create, params: params, format: :json }
|
||||||
let(:params) do
|
let(:params) do
|
||||||
{ my_module_id: my_module.id, user_my_module: { user_id: user.id } }
|
{ my_module_id: my_module.id, user_my_module: { user_id: other_user.id } }
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'calls create activity for assigning user to task' do
|
it 'calls create activity for assigning user to task' do
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory :notification do
|
factory :notification do
|
||||||
recipient_type { 'User' }
|
recipient_type { 'User' }
|
||||||
recipient_id { 1 }
|
recipient_id { FactoryBot.create(:user).id }
|
||||||
read_at { Time.now }
|
read_at { Time.now }
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -89,7 +89,6 @@ describe User, type: :model do
|
||||||
it { should have_many :archived_protocols }
|
it { should have_many :archived_protocols }
|
||||||
it { should have_many :restored_protocols }
|
it { should have_many :restored_protocols }
|
||||||
it { should have_many :assigned_my_module_repository_rows }
|
it { should have_many :assigned_my_module_repository_rows }
|
||||||
it { should have_many :user_notifications }
|
|
||||||
it { should have_many :notifications }
|
it { should have_many :notifications }
|
||||||
it { should have_many :zip_exports }
|
it { should have_many :zip_exports }
|
||||||
it { should have_many(:shareable_links).dependent(:destroy) }
|
it { should have_many(:shareable_links).dependent(:destroy) }
|
||||||
|
@ -150,10 +149,6 @@ describe User, type: :model do
|
||||||
|
|
||||||
describe 'user settings' do
|
describe 'user settings' do
|
||||||
it { is_expected.to respond_to(:time_zone) }
|
it { is_expected.to respond_to(:time_zone) }
|
||||||
it { is_expected.to respond_to(:assignments_notification) }
|
|
||||||
it { is_expected.to respond_to(:assignments_email_notification) }
|
|
||||||
it { is_expected.to respond_to(:recent_notification) }
|
|
||||||
it { is_expected.to respond_to(:recent_email_notification) }
|
|
||||||
end
|
end
|
||||||
|
|
||||||
describe 'user variables' do
|
describe 'user variables' do
|
||||||
|
|
Loading…
Reference in a new issue