Skip to content
Draft
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
230 commits
Select commit Hold shift + click to select a range
393c392
Add notify emails functionality to Push model and forms
LukasMalyszko Feb 2, 2026
6adc148
Refactor error messages in MultipleEmailsValidator for clarity
LukasMalyszko Feb 3, 2026
97e974e
Add SMTP configuration check and conditionally render notify emails f…
LukasMalyszko Feb 3, 2026
db67ff6
Refactor email parsing and validation for notify emails functionality
LukasMalyszko Feb 3, 2026
a6c003f
Add throttling setting for push creation requests
LukasMalyszko Feb 3, 2026
5cdfa6e
Enhance push creation and notification email handling
LukasMalyszko Feb 4, 2026
aeec33c
Add tests to enforce immutability of notify_emails_to fields on update
LukasMalyszko Feb 4, 2026
f35a328
Refactor email error handling and update PushCreatedMailer subject line
LukasMalyszko Feb 4, 2026
fca92e2
Update subject line in PushCreatedMailer for improved clarity
LukasMalyszko Feb 4, 2026
a8cb1e4
Add tests for notify_emails_to validation and email notification content
LukasMalyszko Feb 4, 2026
5869d0c
Enhance test for email subject presence in PushCreatedMailer
LukasMalyszko Feb 5, 2026
7c36c7f
Add time formatting methods and update email notifications
LukasMalyszko Feb 5, 2026
2690ad9
Add tests for notify_emails_to handling and email notification content
LukasMalyszko Feb 5, 2026
407c779
Refactor Rack::Attack throttling for push creation and enhance tests …
LukasMalyszko Feb 5, 2026
f5c91e9
Add tests for HTML and text parts of PushCreatedMailer notifications
LukasMalyszko Feb 5, 2026
173bf36
Add tests for HTML structure and link validation in PushCreatedMailer…
LukasMalyszko Feb 5, 2026
399f849
Add test to validate secret link text in PushCreatedMailer notifications
LukasMalyszko Feb 5, 2026
5ef9324
Update parameter documentation for format_minutes_duration method in …
LukasMalyszko Feb 5, 2026
83ee73b
Refactor secret URL generation in ApplicationHelper and update PushCr…
LukasMalyszko Feb 5, 2026
e1bb879
Update PushCreatedMailer notifications to handle missing user email a…
LukasMalyszko Feb 5, 2026
0e77f8a
Add inline job execution for email notifications in development envir…
LukasMalyszko Feb 6, 2026
603ac11
Enhance email notification handling and formatting
LukasMalyszko Feb 6, 2026
3e3e7ff
Add audit log creation for email notifications in SendPushCreatedEmai…
LukasMalyszko Feb 6, 2026
09d02ad
Refactor MultipleEmailsValidator for improved email validation
LukasMalyszko Feb 9, 2026
d707311
Merge remote-tracking branch 'origin/master' into auto-dispatch
LukasMalyszko Feb 9, 2026
6543105
Merge branch 'master' into auto-dispatch
pglombardo Feb 19, 2026
25107c9
Merge branch 'master' into auto-dispatch
pglombardo Mar 3, 2026
f18159b
Add language dropdown for email notifications and update related forms
LukasMalyszko Mar 6, 2026
7f47d87
Update email notification logic to respect login settings
LukasMalyszko Mar 9, 2026
6eb6ce2
Update email notification wording for clarity
LukasMalyszko Mar 9, 2026
bf2a54a
Refine email notification message for improved clarity
LukasMalyszko Mar 9, 2026
2a425a0
Enhance SSL handling in email notifications and refine duration forma…
LukasMalyszko Mar 11, 2026
58e3141
Remove pushes per day throttle configuration and related tests
LukasMalyszko Mar 12, 2026
e55c7d0
Update email notification logic to use user account email settings
LukasMalyszko Mar 12, 2026
212f97a
Enhance email notification settings and SSL handling
LukasMalyszko Mar 12, 2026
be7ff8f
Enhance Rack::Attack configuration for improved throttling
LukasMalyszko Mar 12, 2026
7399282
Merge origin/master into auto-dispatch
LukasMalyszko Mar 12, 2026
2d5095a
Refactor test setup and teardown for email notification settings
LukasMalyszko Mar 12, 2026
5c9380d
Refactor language selection in email notifications
LukasMalyszko Mar 13, 2026
24d2e1b
Implement notify emails field visibility logic and update push expira…
LukasMalyszko Mar 17, 2026
007b0ca
Refactor email notification job and audit log
LukasMalyszko Mar 17, 2026
2639a0b
Implement notify emails feature in Pushes
LukasMalyszko Mar 17, 2026
f6c2463
Refactor notify emails field rendering in forms
LukasMalyszko Mar 17, 2026
73b6fac
Add notify_emails_to_locale_ciphertext column to pushes table
LukasMalyszko Mar 18, 2026
d87b99e
Refactor PushCreatedMailer and enhance send_creation_emails documenta…
LukasMalyszko Mar 18, 2026
07932dd
Refactor PushesController and email job for improved functionality
LukasMalyszko Mar 18, 2026
587fa42
Update PushesController and views for parameter handling and email fi…
LukasMalyszko Mar 18, 2026
06ad4e6
Enhance accessibility for email language selection in notifications
LukasMalyszko Mar 18, 2026
a091abb
Enhance JSON serialization in Push model to exclude sensitive fields
LukasMalyszko Mar 18, 2026
2329383
Update show_notify_emails_field? method to include login setting check
LukasMalyszko Mar 18, 2026
e3590b0
Merge remote-tracking branch 'origin/master' into auto-dispatch
LukasMalyszko Mar 19, 2026
de46b88
Update application helper to check for disabled logins and adjust tes…
LukasMalyszko Mar 19, 2026
1413ebf
Merge branch 'master' into auto-dispatch
LukasMalyszko Mar 23, 2026
69b34c8
Refactor dropdown item styles in notification email locale view
LukasMalyszko Mar 23, 2026
89d9941
Enhance dropdown styling for notification email locale menu
LukasMalyszko Mar 23, 2026
60119bd
Refactor notification email locale menu styles
LukasMalyszko Mar 23, 2026
b06d971
Update dropdown item class for improved text wrapping in notification…
LukasMalyszko Mar 24, 2026
51c937b
Refactor HTTPS link support in application helper
LukasMalyszko Mar 24, 2026
51f2597
Refactor controller registrations in index.js
LukasMalyszko Mar 24, 2026
2f95af5
Remove obsolete test for FORCE_SSL in PushCreatedMailerTest
LukasMalyszko Mar 24, 2026
6eca4aa
Refactor secret URL and notification email locale dropdowns
LukasMalyszko Mar 24, 2026
5ec786e
Update button style in secret URL bar for improved layout and alignment
LukasMalyszko Mar 25, 2026
fa269f6
Refactor locale dropdown component for improved readability and maint…
LukasMalyszko Mar 25, 2026
0c0eb0b
Remove unnecessary setup and teardown for Settings in PushNotifyEmail…
LukasMalyszko Mar 25, 2026
e58245f
Merge remote-tracking branch 'origin/master' into auto-dispatch
LukasMalyszko Mar 26, 2026
1102cbb
Refactor code for consistency and readability
LukasMalyszko Mar 26, 2026
610e817
Update button style in notify emails locale dropdown for improved layout
LukasMalyszko Mar 27, 2026
9c55cfd
Adjust padding in locale dropdown items for improved layout consistency
LukasMalyszko Mar 27, 2026
b1df096
Enhance locale dropdown functionality and styling
LukasMalyszko Mar 30, 2026
e36ed96
Refactor notify emails partials to integrate locale dropdown
LukasMalyszko Mar 31, 2026
7067c83
Refactor email delivery logic in SendPushCreatedEmailJob
LukasMalyszko Mar 31, 2026
cf701a2
Refactor locale dropdown integration and remove unused controller
LukasMalyszko Apr 1, 2026
f298e0c
Fix CSS comment formatting and ensure newline at end of file in custo…
LukasMalyszko Apr 1, 2026
756abf8
Refactor push email notification logic and remove unused concern
LukasMalyszko Apr 1, 2026
1aa621a
Remove commented-out code and improve test clarity in NotifyEmailsFie…
LukasMalyszko Apr 1, 2026
6b2ab9f
Refactor email notification handling in Push model and mailer
LukasMalyszko Apr 1, 2026
0317710
Update email subject assertions in tests for consistency and clarity
LukasMalyszko Apr 7, 2026
4a5b968
copying mailer from PRO
LukasMalyszko Apr 7, 2026
b04b4db
Refactor comment in notify_emails_to concern for clarity
LukasMalyszko Apr 7, 2026
4392053
Fix indentation in email subject assertion for clarity in SendPushCre…
LukasMalyszko Apr 7, 2026
386807d
Update test name for clarity in ApplicationHelperTest
LukasMalyszko Apr 7, 2026
781e880
Merge remote-tracking branch 'origin/master' into auto-dispatch
LukasMalyszko Apr 9, 2026
1249431
Fix closing tag for notify emails field in multiple forms
LukasMalyszko Apr 9, 2026
f9c0ee4
Add push_locale_dropdown_url helper and update forms to include notif…
LukasMalyszko Apr 9, 2026
b460a1d
Refactor forms to improve layout consistency
LukasMalyszko Apr 9, 2026
79efb56
Update version of a migration file
ozovalihasan Apr 10, 2026
69541a1
Add a view for the `notify_email_to_locale` attribute of pushes
ozovalihasan Apr 12, 2026
7894451
Merge remote-tracking branch 'origin/master' into auto-dispatch
ozovalihasan Apr 12, 2026
750a525
Update validations for `notify_emails_to` attribute of pushes
ozovalihasan Apr 12, 2026
cf813d5
Update tests of SendPushCreatedEmailJob
ozovalihasan Apr 12, 2026
c1c9e43
Remove an unnecessary test of SendPushCreatedEmailJob
ozovalihasan Apr 12, 2026
8e26760
Revert unnecessary changes
ozovalihasan Apr 12, 2026
3ffbdc2
Remove unnecessary log used to debug
ozovalihasan Apr 12, 2026
7c9f17d
Update a few small points
ozovalihasan Apr 12, 2026
331e371
Fix a module name
ozovalihasan Apr 12, 2026
2c4464d
Update push to require owner if notify_emails_to or notify_emails_to_…
ozovalihasan Apr 13, 2026
3e58510
Remove an unnecessary method from Pwpush::NotifyEmailsTo
ozovalihasan Apr 13, 2026
172c675
Update conditions used to show `notify_emails_to` fields
ozovalihasan Apr 13, 2026
76ebff4
Update tests of MultipleEmailsValidator
ozovalihasan Apr 13, 2026
3ec3dea
Remove tests for a view
ozovalihasan Apr 13, 2026
bc08be5
Fix tests related to auto-dispatch
ozovalihasan Apr 14, 2026
e53f6c1
Merge remote-tracking branch 'origin/master' into auto-dispatch
ozovalihasan Apr 14, 2026
f9490ff
Update description of some tests
ozovalihasan Apr 14, 2026
f8815c4
Merge remote-tracking branch 'origin/master' into auto-dispatch
ozovalihasan Apr 15, 2026
3ee69e5
Update tests of pushes related to `notify_emails_to` attribute
ozovalihasan Apr 15, 2026
dd682da
Remove unnecessary lines of a test
ozovalihasan Apr 15, 2026
60643ad
Add a system test for auto-dispatch feature
ozovalihasan Apr 15, 2026
06178d9
Refactor tests related to `notify_emails_to`
ozovalihasan Apr 16, 2026
9df7cd5
Merge remote-tracking branch 'origin/master' into auto-dispatch
ozovalihasan Apr 16, 2026
527ba42
Refactor params of PushesController
ozovalihasan Apr 16, 2026
e22d75e
Add notify_emails_to_recipients for pushes
ozovalihasan Apr 19, 2026
2aca8a3
Add ShareByEmail model
ozovalihasan Apr 19, 2026
81a7d90
Update Pushes controller to render preview for failed shares
ozovalihasan Apr 19, 2026
be68594
Add encryption for columns of ShareByEmail
ozovalihasan Apr 19, 2026
18e612f
Update tests of PushCreatedMailer
ozovalihasan Apr 19, 2026
9e403aa
Add tests for share_by_email model
ozovalihasan Apr 21, 2026
890422f
Update an integration test of the share by email feature
ozovalihasan Apr 21, 2026
9013d91
Add a preview for PushCreatedMailer
ozovalihasan Apr 24, 2026
3513d76
Update all names related notify by email feature
ozovalihasan Apr 24, 2026
d371eb2
Fix unselected option issue of notify_by_email locale
ozovalihasan Apr 26, 2026
2a675ca
Add an endpoint for notify_by_email feature
ozovalihasan Apr 26, 2026
de6fab9
Add system tests for the notify by email feature
ozovalihasan Apr 26, 2026
182d4f7
Add tests for APIv2 PushesController
ozovalihasan Apr 26, 2026
29c57da
Fix indentation issue on the preview view
ozovalihasan Apr 26, 2026
bc9b00b
Refactor a check of notify_by_email
ozovalihasan Apr 27, 2026
9463305
Fix tests of the notify_by_email feature
ozovalihasan Apr 27, 2026
90f925e
Revert the last migration
ozovalihasan Apr 27, 2026
86f4d71
Merge remote-tracking branch 'origin/master' into auto-dispatch
ozovalihasan Apr 27, 2026
7b38c23
Update the timestamp of a migration
ozovalihasan Apr 27, 2026
e9ffc2a
Fix conditions used to show auto-dispatch input
ozovalihasan Apr 27, 2026
2f01930
Fix typos of preview view
ozovalihasan Apr 27, 2026
60fec69
Revert "Fix conditions used to show auto-dispatch input"
ozovalihasan Apr 27, 2026
a94a492
Remove an unnecessary validation from NotifyByEmail model
ozovalihasan Apr 27, 2026
a80d492
Update method used to validate a push
ozovalihasan Apr 27, 2026
d586a54
Refactor notify by email logic and tests
ozovalihasan Apr 29, 2026
d9afd89
Refactor notify by email availability logic and tests
ozovalihasan Apr 29, 2026
eee0c5b
Add a field to track recipients count
ozovalihasan Apr 29, 2026
cbb6e5b
Add `proceed_at` attribute to NotifyByEmail
ozovalihasan Apr 29, 2026
0ef01b7
Remove a transaction
ozovalihasan Apr 29, 2026
ed098c2
Remove an unnecessary guard clause
ozovalihasan Apr 29, 2026
d31980c
Update multiple emails validator and tests
ozovalihasan Apr 29, 2026
0678bd2
Remove `dependent: :destroy` from NotifyByEmail
ozovalihasan Apr 29, 2026
f17032d
Update secret_url's used by PushCreatedMailer
ozovalihasan Apr 30, 2026
5cd83f7
Merge remote-tracking branch 'origin/master' into auto-dispatch
ozovalihasan Apr 30, 2026
3b26d8f
Update response for Api::V2::PushesController#audit
ozovalihasan Apr 30, 2026
5bb9e3a
Merge remote-tracking branch 'origin/master' into auto-dispatch
ozovalihasan May 1, 2026
8c49dbb
Fix LogEvents changed mistakenly
ozovalihasan May 1, 2026
ed4e9a9
Update a parameter of PushCreatedMailer
ozovalihasan May 1, 2026
9ce18bc
Update errors of notify by email feature
ozovalihasan May 1, 2026
f5b71f0
Add notify_by_email for madmin resources
ozovalihasan May 1, 2026
fde3d3f
Update text of a button
ozovalihasan May 1, 2026
c8d25b0
Update conditions of SendPushCreatedEmailJob
ozovalihasan May 1, 2026
e7c87fb
Update version info for email_auto_dispatch
ozovalihasan May 1, 2026
f13d1df
Add attributes for API responses
ozovalihasan May 1, 2026
19d7af7
Update API response for the audit action of pushes
ozovalihasan May 1, 2026
e47b4a5
Add a field to track errors of notify_by_email
ozovalihasan May 2, 2026
419b095
Update an event used to create notify_by_email
ozovalihasan May 2, 2026
05fa4d2
Update parameters used for API requests
ozovalihasan May 2, 2026
fd4eb52
Update tests to reload Settings
ozovalihasan May 3, 2026
d1327ed
Update notify_by_email callback
ozovalihasan May 3, 2026
859352a
Refactor tests
ozovalihasan May 3, 2026
ea26d71
Merge remote-tracking branch 'origin/master' into refactor-tests
ozovalihasan May 3, 2026
92b6bcb
Refactor tests added lastly
ozovalihasan May 3, 2026
e5b203c
Remove unnecessary lines from a test suite
ozovalihasan May 3, 2026
f7ba47e
Add a mailer config for tests
ozovalihasan May 3, 2026
ad0a8cc
Update a test of ExpirePushesJobTest
ozovalihasan May 3, 2026
e0f7ab0
Update tests changing Settings
ozovalihasan May 3, 2026
f016290
Update tests using `reload_routes!`
ozovalihasan May 3, 2026
7b22ab5
Remove redundant comparison
ozovalihasan May 3, 2026
34a75e9
Merge remote-tracking branch 'origin/refactor-tests' into auto-dispatch
ozovalihasan May 5, 2026
75d5126
Merge remote-tracking branch 'origin/master' into refactor-tests
ozovalihasan May 5, 2026
e0fafd5
Merge remote-tracking branch 'origin/refactor-tests' into auto-dispatch
ozovalihasan May 5, 2026
2eb93fe
Update multiple tests
ozovalihasan May 5, 2026
bcb0a68
Add more model unit tests
ozovalihasan May 5, 2026
97ab987
Remove model_name from error messages
ozovalihasan May 6, 2026
1cfc108
Update SendPushCreatedEmailJob as SendNotifyByEmailJob
ozovalihasan May 6, 2026
589dc83
Fix failing tests because of changing error message
ozovalihasan May 6, 2026
06d5f0b
Update api documentation for locales
ozovalihasan May 6, 2026
80cc733
Update attributes of NotifyByEmail
ozovalihasan May 6, 2026
1b19bf7
Merge branch 'master' into auto-dispatch
pglombardo May 7, 2026
895c51b
String updates
pglombardo May 7, 2026
0348d1c
Add safety
pglombardo May 7, 2026
45712f2
Use validated locale var
pglombardo May 7, 2026
3b1f85b
fix: require auth and ownership check on API v2 notify_by_email
pglombardo May 7, 2026
5168257
fix: add explicit auth and ownership check to web notify_by_email
pglombardo May 7, 2026
47d026f
fix: don't append default locale to notify email URL
pglombardo May 7, 2026
93c026f
Fix an encrypted column name
ozovalihasan May 7, 2026
c323323
Update regex used to replace `http` part of URLs
ozovalihasan May 7, 2026
a36aac4
Update a column name of a migration
ozovalihasan May 7, 2026
93595ab
Update a rescue block
ozovalihasan May 7, 2026
de3e567
Add custom validations for notify_by_email feature
ozovalihasan May 7, 2026
f78539e
Refactor notify_by_email params
ozovalihasan May 7, 2026
1e4604a
Refactor params assigned for notify_by_email model
ozovalihasan May 7, 2026
00d9b3e
Remove an unnecessary test
ozovalihasan May 7, 2026
672dc3d
Update name of a method
ozovalihasan May 8, 2026
9c06011
Add a daily limit for emails sent to notify
ozovalihasan May 8, 2026
7ae87e6
Update the mechanism used to track emails sent by users
ozovalihasan May 8, 2026
a1efced
Update style of a warning
ozovalihasan May 8, 2026
ecbd92f
Update tests of PushCreatedMailer
ozovalihasan May 9, 2026
5a6917e
Update hardcoded error message with I18n translation in PushesController
ozovalihasan May 9, 2026
6161835
Update validations coming with NotifiableByEmail concern
ozovalihasan May 9, 2026
ce87b7a
Update MultipleEmailsValidator
ozovalihasan May 9, 2026
d8fed62
Update SendNotifyByEmailJob to update successful sends better
ozovalihasan May 9, 2026
2a4723f
Revert an unrelated change
ozovalihasan May 9, 2026
3945a5d
Update name of a column of User
ozovalihasan May 9, 2026
a43a2ea
Add tests for NotifyByEmail
ozovalihasan May 9, 2026
6cafe4b
Add a system test for notify by email feature
ozovalihasan May 9, 2026
024eac9
Update a class method of Settings
ozovalihasan May 9, 2026
4574946
Update a test of SendNotifyByEmailJob
ozovalihasan May 9, 2026
9458919
Add a migration to remove a few columns from pushes table
ozovalihasan May 10, 2026
480e23d
Merge remote-tracking branch 'origin/master' into auto-dispatch
ozovalihasan May 10, 2026
896f804
Update a few JavaScript functions with replaceChildren
ozovalihasan May 10, 2026
66e195e
Fix a test of NotifiableByEmail concern
ozovalihasan May 10, 2026
689dd4e
Add aria-label for a button
ozovalihasan May 10, 2026
b1d760a
Fix an hardcoded text to be translated
ozovalihasan May 10, 2026
fab5059
Update error part to use a partial
ozovalihasan May 10, 2026
6076c22
Refactor LogEvents
ozovalihasan May 10, 2026
011f41b
Add `notify_by_email_available?` method for the NotifiableByEmail con…
ozovalihasan May 10, 2026
3c469b6
Fix tests failing because of lack of user of some audit logs
ozovalihasan May 10, 2026
b2b87b7
Refactor notify_by_email validations
ozovalihasan May 10, 2026
1eb31bc
Update an API response for Api::V2::PushesController
ozovalihasan May 10, 2026
8f9371b
Update Api::V1::PushesController to handle notify_by_email parameters
ozovalihasan May 10, 2026
395d3ce
Refactor LogEvents#log_creation_email_send
ozovalihasan May 10, 2026
f7133b7
Refactor AuditLog
ozovalihasan May 10, 2026
bbfe21a
Remove an unnecessary validation of SendNotifyByEmailJob
ozovalihasan May 10, 2026
6ca5046
Remove an unnecessary if clause
ozovalihasan May 10, 2026
9c0c70d
Update the preview page of pushes shown when an error with notify_by_…
ozovalihasan May 11, 2026
edbd0ea
Add a field of NotifyByEmail to show in madmin views
ozovalihasan May 11, 2026
6fda534
Update tests related to notify_by_email action
ozovalihasan May 11, 2026
cdc277f
Update name of some hashes used in API controllers
ozovalihasan May 14, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions app/controllers/pushes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def create

if @push.save
log_creation(@push)
@push.send_creation_emails

redirect_to preview_push_path(@push)
else
Expand Down Expand Up @@ -365,16 +366,14 @@ def set_push
end

def push_params
base = %i[kind name expire_after_days expire_after_views retrieval_step payload note passphrase notify_emails_to notify_emails_to_locale]
case params.dig(:push, :kind)
when "url"
params.require(:push).permit(:kind, :name, :expire_after_days, :expire_after_views,
:retrieval_step, :payload, :note, :passphrase)
params.require(:push).permit(*base - [:deletable_by_viewer])
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was redundant so removed

when "file"
params.require(:push).permit(:kind, :name, :expire_after_days, :expire_after_views, :deletable_by_viewer,
:retrieval_step, :payload, :note, :passphrase, files: [])
params.require(:push).permit(*(base + [:deletable_by_viewer, {files: []}]))
else
params.require(:push).permit(:kind, :name, :expire_after_days, :expire_after_views, :deletable_by_viewer,
:retrieval_step, :payload, :note, :passphrase)
params.require(:push).permit(*(base + [:deletable_by_viewer]))
end
rescue => e
Rails.logger.error("Error in push_params: #{e.message}")
Expand Down
15 changes: 15 additions & 0 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@ def secret_url(push, with_retrieval_step: true, locale: nil)
raw_url
end

# True when the application can send email (SMTP or equivalent), so the
# "notify emails" push option should be shown. In production this requires
# Settings.mail with smtp_address; in development mailbin counts as configured.
#
# @return [Boolean]
def smtp_configured?
Comment thread
pglombardo marked this conversation as resolved.
Outdated
if Rails.env.test?
false
elsif Rails.env.development?
true
else
Settings.mail.present? && Settings.mail.smtp_address.to_s.present?
end
end

# qr_code
#
# Generates a QR code for the given URL
Expand Down
11 changes: 11 additions & 0 deletions app/jobs/send_push_created_email_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# frozen_string_literal: true

class SendPushCreatedEmailJob < ApplicationJob
queue_as :default

def perform(push)
return if push.notify_emails_to.blank?

PushCreatedMailer.with(record: push).notify.deliver_now
end
end
36 changes: 36 additions & 0 deletions app/mailers/push_created_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

class PushCreatedMailer < ApplicationMailer
def notify
@push = params[:record]
locale = @push.notify_emails_to_locale.presence
I18n.with_locale(locale || I18n.default_locale) do
@secret_url = secret_url_for_push(@push, locale: locale)
@subject = "#{Settings.brand&.title || "Password Pusher"} #{_("has sent you a push")}"
mail(
to: parse_emails(@push.notify_emails_to),
subject: @subject
)
end
Comment thread
LukasMalyszko marked this conversation as resolved.
end

private

def parse_emails(raw)
raw.to_s.split(",").map(&:strip).reject(&:blank?)
Comment thread
LukasMalyszko marked this conversation as resolved.
Outdated
end

def secret_url_for_push(push, locale: nil)
raw_url = if push.retrieval_step
preliminary_push_url(push)
else
push_url(push)
end
base = raw_url.split("?").first
if locale.present? && Array(Settings.enabled_language_codes).include?(locale.to_s)
Comment thread
LukasMalyszko marked this conversation as resolved.
Outdated
base += "?locale=#{locale}"
end
Comment thread
LukasMalyszko marked this conversation as resolved.
base = base.gsub(/http/i, "https") if ENV.key?("FORCE_SSL")
Comment thread
LukasMalyszko marked this conversation as resolved.
Outdated
base
end
end
22 changes: 22 additions & 0 deletions app/models/concerns/pwpush/notify_emails_to.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# frozen_string_literal: true

module Pwpush
module NotifyEmailsTo
extend ActiveSupport::Concern

included do
validates :notify_emails_to, multiple_emails: true, allow_blank: true
Comment thread
LukasMalyszko marked this conversation as resolved.
Outdated
end

# Enqueue job to send creation email if notify_emails_to is present.
def send_creation_emails
return if notify_emails_to.blank?

if Rails.env.development?
SendPushCreatedEmailJob.perform_now(self)
else
SendPushCreatedEmailJob.perform_later(self)
end
Comment thread
LukasMalyszko marked this conversation as resolved.
Outdated
end
Comment thread
LukasMalyszko marked this conversation as resolved.
Outdated
end
end
2 changes: 2 additions & 0 deletions app/models/push.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
require "addressable/uri"

class Push < ApplicationRecord
include Pwpush::NotifyEmailsTo

enum :kind, [:text, :file, :url, :qr], validate: true

validate :check_enabled_push_kinds, on: :create
Expand Down
26 changes: 26 additions & 0 deletions app/validators/multiple_emails_validator.rb
Comment thread
LukasMalyszko marked this conversation as resolved.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

# Validates comma-separated email addresses: format, max 5, no duplicates.
class MultipleEmailsValidator < ActiveModel::EachValidator
EMAIL_REGEX = /\A[^@\s]+@[^@\s]+\.[^@\s]+\z/
MAX_EMAILS = 5

def validate_each(record, attribute, value)
return if value.blank?

emails = value.to_s.split(",").map(&:strip).reject(&:blank?)

if emails.size > MAX_EMAILS
record.errors.add(attribute, "You can enter at most %{count} email addresses", count: MAX_EMAILS)
end

if emails.size != emails.uniq.size
Comment thread
LukasMalyszko marked this conversation as resolved.
Outdated
record.errors.add(attribute, "Duplicate email addresses are not allowed")
end

invalid = emails.reject { |e| e.match?(EMAIL_REGEX) }
unless invalid.empty?
record.errors.add(attribute, "%{list} are invalid email addresses", list: invalid.join(", "))
end
end
end
16 changes: 16 additions & 0 deletions app/views/push_created_mailer/notify.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<h1><%= Settings.brand.title %> <%= _('has sent you a push') %></h1>
Comment thread
LukasMalyszko marked this conversation as resolved.
Outdated

<p>
<%= _('Use the link below to view the shared content. The link will expire after a certain number of views or time.') %>
</p>

<p>
<%= link_to _('View the secret'), @secret_url %>
</p>

<p class="text-muted small">
<%= _('Or copy and paste this URL into your browser') %>
</p>
<pre><%= @secret_url %></pre>

<%= render 'shared/email_footer' %>
11 changes: 11 additions & 0 deletions app/views/push_created_mailer/notify.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<%= Settings.brand.title %> <%= _('has sent you a push') %>
Comment thread
LukasMalyszko marked this conversation as resolved.
Outdated

<%= _('Use the link below to view the shared content. The link will expire after a certain number of views or time.') %>

<%= _('View the secret') %>: <%= @secret_url %>

<%= _('Or copy and paste this URL into your browser') %>: <%= @secret_url %>

--
<%= Settings.brand.title %>
<%= Settings.brand.tagline %>
Comment thread
LukasMalyszko marked this conversation as resolved.
Outdated
4 changes: 4 additions & 0 deletions app/views/pushes/_files_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@
</div>
</div>
</div>
<% if smtp_configured? %>
<%= render partial: "shared/notify_emails_to", locals: { f: f } %>
<%= render partial: "shared/notify_emails_to_locale", locals: { f: f } %>
<% end %>
<% unless action_name == 'edit' %>
<div class='row'>
<div class='col'>
Expand Down
4 changes: 4 additions & 0 deletions app/views/pushes/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,10 @@
</div>
</div>
</div>
<% if smtp_configured? %>
<%= render partial: "shared/notify_emails_to", locals: { f: f } %>
<%= render partial: "shared/notify_emails_to_locale", locals: { f: f } %>
<% end %>
<% unless action_name == 'edit' %>
<div class='row'>
<div class='col'>
Expand Down
4 changes: 4 additions & 0 deletions app/views/pushes/_qr_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@
</div>
</div>
</div>
<% if smtp_configured? %>
<%= render partial: "shared/notify_emails_to", locals: { f: f } %>
<%= render partial: "shared/notify_emails_to_locale", locals: { f: f } %>
<% end %>
<% unless action_name == 'edit' %>
<div class='row'>
<div class='col'>
Expand Down
4 changes: 4 additions & 0 deletions app/views/pushes/_url_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@
</div>
</div>
</div>
<% if smtp_configured? %>
<%= render partial: "shared/notify_emails_to", locals: { f: f } %>
<%= render partial: "shared/notify_emails_to_locale", locals: { f: f } %>
<% end %>
<% unless action_name == 'edit' %>
<div class='row'>
<div class='col'>
Expand Down
13 changes: 13 additions & 0 deletions app/views/shared/_notify_emails_to.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<% unless action_name == 'edit' %>
<div class='row mb-3'>
<div class='col'>
<div class="input-group">
<span class="input-group-text"><%= _('Email notification recipients') %></span>
<%= f.text_field(:notify_emails_to, { class: "form-control",
placeholder: _('Enter email addresses separated by commas'),
autocomplete: "off" }) %>
</div>
<div class="form-text"><%= _('Enter email addresses separated by commas') %></div>
</div>
</div>
<% end %>
14 changes: 14 additions & 0 deletions app/views/shared/_notify_emails_to_locale.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<% unless action_name == 'edit' %>
<div class='row mb-3'>
<div class='col'>
<div class="input-group">
<span class="input-group-text"><%= _('Email notification language') %></span>
<%= f.select(:notify_emails_to_locale,
options_for_select([["", ""]] + language_options_for_select, f.object.notify_emails_to_locale),
{},
{ class: "form-select" }) %>
</div>
<div class="form-text"><%= _('Select the language of the email notification') %></div>
</div>
</div>
<% end %>
8 changes: 8 additions & 0 deletions db/migrate/20260202120000_add_notify_emails_to_pushes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class AddNotifyEmailsToPushes < ActiveRecord::Migration[8.1]
def change
add_column :pushes, :notify_emails_to, :text
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These fields should be encrypted like in Pro:

Then in the concern, we set encrypts for these fields.

Double check the Pro implementation and the OSS implementation. They should be as similar as possible.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added like in PRO

add_column :pushes, :notify_emails_to_locale, :string
end
end
4 changes: 3 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2025_06_06_094103) do
ActiveRecord::Schema[8.1].define(version: 2026_02_02_120000) do
create_table "active_storage_attachments", force: :cascade do |t|
t.integer "blob_id", null: false
t.datetime "created_at", precision: nil, null: false
Expand Down Expand Up @@ -72,6 +72,8 @@
t.integer "kind", null: false
t.string "name"
t.text "note_ciphertext"
t.text "notify_emails_to"
t.string "notify_emails_to_locale"
t.text "passphrase_ciphertext", limit: 2048
t.text "payload_ciphertext", limit: 16777215
t.boolean "retrieval_step", default: false
Expand Down
55 changes: 55 additions & 0 deletions test/helpers/application_helper_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,4 +181,59 @@ def push_url(push)
assert qr.html_safe?
assert qr.is_a?(ActiveSupport::SafeBuffer)
end

# Test smtp_configured? method
test "smtp_configured? is false in test environment" do
assert_equal "test", Rails.env
assert_not smtp_configured?
end

test "smtp_configured? is true in development environment" do
env = env_inquirer("development")
Rails.stub(:env, env) do
assert smtp_configured?
end
end

test "smtp_configured? in production is true when Settings.mail has smtp_address" do
env = env_inquirer("production")
Rails.stub(:env, env) do
Settings.stub(:mail, OpenStruct.new(smtp_address: "smtp.example.com")) do
assert smtp_configured?
end
end
end

test "smtp_configured? in production is false when Settings.mail has no smtp_address" do
env = env_inquirer("production")
Rails.stub(:env, env) do
Settings.stub(:mail, OpenStruct.new(smtp_address: nil)) do
assert_not smtp_configured?
end
end
end

test "smtp_configured? in production is false when Settings.mail is nil" do
env = env_inquirer("production")
Rails.stub(:env, env) do
Settings.stub(:mail, nil) do
assert_not smtp_configured?
end
end
end

test "smtp_configured? in production is false when smtp_address is empty string" do
env = env_inquirer("production")
Rails.stub(:env, env) do
Settings.stub(:mail, OpenStruct.new(smtp_address: "")) do
assert_not smtp_configured?
end
end
end

private

def env_inquirer(name)
ActiveSupport::StringInquirer.new(name)
end
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-evaluate - even in tests user_signed_in? should be provided by devise.

end
Loading
Loading