mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-26 01:35:34 +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])
|
||||
return if @user.blank?
|
||||
|
||||
DeliveryNotification.with(
|
||||
title: failed_notification_title,
|
||||
message: failed_notification_message,
|
||||
error: true
|
||||
).deliver(@user)
|
||||
DeliveryNotification.send_notifications(
|
||||
{
|
||||
title: failed_notification_title,
|
||||
message: failed_notification_message,
|
||||
error: true,
|
||||
user: @user
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
def failed_notification_title
|
||||
|
|
|
@ -136,13 +136,17 @@ module Protocols
|
|||
"href='#{Rails.application.routes.url_helpers.rails_blob_path(@tmp_files.take.file)}'>" \
|
||||
"#{@tmp_files.take.file.filename}</a>"
|
||||
|
||||
DeliveryNotification.with(
|
||||
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')} " \
|
||||
"<a data-id='#{@protocol.id}' data-turbolinks='false' " \
|
||||
"href='#{Rails.application.routes.url_helpers.protocol_path(@protocol)}'>" \
|
||||
"#{@protocol.name}</a>"
|
||||
).deliver(@user)
|
||||
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')} " \
|
||||
"<a data-id='#{@protocol.id}' data-turbolinks='false' " \
|
||||
"href='#{Rails.application.routes.url_helpers.protocol_path(@protocol)}'>" \
|
||||
"#{@protocol.name}</a>",
|
||||
user: @user
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
# Overrides method from FailedDeliveryNotifiableJob concern
|
||||
|
|
|
@ -22,12 +22,15 @@ module Reports
|
|||
report_path = Rails.application.routes.url_helpers
|
||||
.reports_path(team: report.team.id, preview_report_id: report.id, preview_type: :docx)
|
||||
|
||||
DeliveryNotification.with(
|
||||
title: I18n.t('projects.reports.index.generation.completed_docx_notification_title'),
|
||||
message: I18n.t('projects.reports.index.generation.completed_notification_message',
|
||||
report_link: "<a href='#{report_path}'>#{escape_input(report.name)}</a>",
|
||||
team_name: escape_input(report.team.name))
|
||||
).deliver(user)
|
||||
DeliveryNotification.send_notifications(
|
||||
{
|
||||
title: I18n.t('projects.reports.index.generation.completed_docx_notification_title'),
|
||||
message: I18n.t('projects.reports.index.generation.completed_notification_message',
|
||||
report_link: "<a href='#{report_path}'>#{escape_input(report.name)}</a>",
|
||||
team_name: escape_input(report.team.name)),
|
||||
user: @user
|
||||
}
|
||||
)
|
||||
|
||||
Reports::DocxPreviewJob.perform_now(report.id)
|
||||
ensure
|
||||
|
|
|
@ -162,12 +162,15 @@ module Reports
|
|||
def create_notification_for_user
|
||||
report_path = Rails.application.routes.url_helpers
|
||||
.reports_path(team: @report.team.id, preview_report_id: @report.id, preview_type: :pdf)
|
||||
DeliveryNotification.with(
|
||||
title: I18n.t('projects.reports.index.generation.completed_pdf_notification_title'),
|
||||
message: I18n.t('projects.reports.index.generation.completed_notification_message',
|
||||
report_link: "<a href='#{report_path}'>#{escape_input(@report.name)}</a>",
|
||||
team_name: escape_input(@report.team.name))
|
||||
).deliver(@user)
|
||||
DeliveryNotification.send_notifications(
|
||||
{
|
||||
title: I18n.t('projects.reports.index.generation.completed_pdf_notification_title'),
|
||||
message: I18n.t('projects.reports.index.generation.completed_notification_message',
|
||||
report_link: "<a href='#{report_path}'>#{escape_input(@report.name)}</a>",
|
||||
team_name: escape_input(@report.team.name)),
|
||||
user: @user
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
def append_result_asset_previews
|
||||
|
|
|
@ -83,16 +83,19 @@ class RepositoriesExportJob < ApplicationJob
|
|||
end
|
||||
|
||||
def generate_notification
|
||||
DeliveryNotification.with(
|
||||
title: I18n.t('zip_export.notification_title'),
|
||||
message: "<a data-id='#{@zip_export.id}' " \
|
||||
"data-turbolinks='false' " \
|
||||
"href='#{Rails.application
|
||||
.routes
|
||||
.url_helpers
|
||||
.zip_exports_download_export_all_path(@zip_export)}'>" \
|
||||
"#{@zip_export.zip_file_name}</a>"
|
||||
).deliver(@user)
|
||||
DeliveryNotification.send_notifications(
|
||||
{
|
||||
title: I18n.t('zip_export.notification_title'),
|
||||
message: "<a data-id='#{@zip_export.id}' " \
|
||||
"data-turbolinks='false' " \
|
||||
"href='#{Rails.application
|
||||
.routes
|
||||
.url_helpers
|
||||
.zip_exports_download_export_all_path(@zip_export)}'>" \
|
||||
"#{@zip_export.zip_file_name}</a>",
|
||||
user: @user
|
||||
}
|
||||
)
|
||||
end
|
||||
|
||||
# Overrides method from FailedDeliveryNotifiableJob concern
|
||||
|
|
|
@ -34,15 +34,18 @@ class ZipExportJob < ApplicationJob
|
|||
end
|
||||
|
||||
def generate_notification!
|
||||
DeliveryNotification.with(
|
||||
title: I18n.t('zip_export.notification_title'),
|
||||
message: "<a data-id='#{@zip_export.id}' " \
|
||||
"data-turbolinks='false' " \
|
||||
"href='#{Rails.application
|
||||
.routes
|
||||
.url_helpers
|
||||
.zip_exports_download_path(@zip_export)}'>" \
|
||||
"#{@zip_export.zip_file_name}</a>"
|
||||
).deliver(@user)
|
||||
DeliveryNotification.send_notifications(
|
||||
{
|
||||
title: I18n.t('zip_export.notification_title'),
|
||||
message: "<a data-id='#{@zip_export.id}' " \
|
||||
"data-turbolinks='false' " \
|
||||
"href='#{Rails.application
|
||||
.routes
|
||||
.url_helpers
|
||||
.zip_exports_download_path(@zip_export)}'>" \
|
||||
"#{@zip_export.zip_file_name}</a>",
|
||||
user: @user
|
||||
}
|
||||
)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,36 +1,15 @@
|
|||
# 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
|
||||
# Add your delivery methods
|
||||
#
|
||||
# deliver_by :email, mailer: "UserMailer"
|
||||
# deliver_by :slack
|
||||
# deliver_by :custom, class: "MyDeliveryMethod"
|
||||
def self.subtype
|
||||
:delivery
|
||||
end
|
||||
|
||||
# Add required params
|
||||
#
|
||||
# param :post
|
||||
|
||||
# Define helper methods to make rendering easier.
|
||||
#
|
||||
def message
|
||||
# if params[:legacy]
|
||||
params[:message]
|
||||
# else
|
||||
# new logic
|
||||
# end
|
||||
end
|
||||
|
||||
def title
|
||||
# if params[:legacy]
|
||||
params[:title]
|
||||
# else
|
||||
# new logic
|
||||
# end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -97,6 +97,9 @@ class NotificationExtends
|
|||
change_users_role_on_team_activity: {
|
||||
code: 94,
|
||||
recipients_module: :UserChangedRecipient
|
||||
},
|
||||
delivery: {
|
||||
recipients_module: :DirectRecipient
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,7 +154,9 @@ class NotificationExtends
|
|||
remove_user_from_team
|
||||
change_users_role_on_team_activity
|
||||
],
|
||||
always_on: []
|
||||
always_on: %I[
|
||||
delivery
|
||||
]
|
||||
}
|
||||
}
|
||||
end
|
||||
|
|
|
@ -6,11 +6,12 @@ describe UserMyModulesController, type: :controller do
|
|||
login_user
|
||||
|
||||
include_context 'reference_project_structure'
|
||||
let(:other_user) { create :user }
|
||||
|
||||
describe 'POST create' do
|
||||
let(:action) { post :create, params: params, format: :json }
|
||||
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
|
||||
|
||||
it 'calls create activity for assigning user to task' do
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
FactoryBot.define do
|
||||
factory :notification do
|
||||
recipient_type { 'User' }
|
||||
recipient_id { 1 }
|
||||
recipient_id { FactoryBot.create(:user).id }
|
||||
read_at { Time.now }
|
||||
end
|
||||
end
|
||||
|
|
|
@ -89,7 +89,6 @@ describe User, type: :model do
|
|||
it { should have_many :archived_protocols }
|
||||
it { should have_many :restored_protocols }
|
||||
it { should have_many :assigned_my_module_repository_rows }
|
||||
it { should have_many :user_notifications }
|
||||
it { should have_many :notifications }
|
||||
it { should have_many :zip_exports }
|
||||
it { should have_many(:shareable_links).dependent(:destroy) }
|
||||
|
@ -150,10 +149,6 @@ describe User, type: :model do
|
|||
|
||||
describe 'user settings' do
|
||||
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
|
||||
|
||||
describe 'user variables' do
|
||||
|
|
Loading…
Reference in a new issue