Skip to content
This repository was archived by the owner on Feb 6, 2025. It is now read-only.

Commit a4984d7

Browse files
UX: Avoid triggering notifications when decrypting (#350)
System user edits will never trigger notifications (see PostRevisor#alert_users). The acting user is still recorded in the edit_reason for auditing purposes.
1 parent 739267a commit a4984d7

File tree

2 files changed

+26
-11
lines changed

2 files changed

+26
-11
lines changed

app/controllers/encrypt_controller.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,12 +266,12 @@ def complete_decryption
266266
decrypted_posts.each do |post_id, raw|
267267
post = topic.posts.find(post_id)
268268

269-
changes = { raw: raw, edit_reason: "Decrypting topic" }
269+
changes = { raw: raw, edit_reason: "@#{current_user.username} decrypted topic" }
270270

271271
changes[:title] = decrypted_title if post.post_number == 1
272272

273273
post.revise(
274-
current_user,
274+
Discourse.system_user,
275275
changes,
276276
{ skip_validations: true, bypass_rate_limiter: true, bypass_bump: true },
277277
)

spec/system/permanent_decrypt_spec.rb

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,30 +19,42 @@
1919
activate_encrypt(user_preferences_page, current_user)
2020
end
2121

22-
def select_self_as_recipient
22+
def select_recipient(username)
2323
find("#private-message-users").click
24-
find("#private-message-users-filter input[name='filter-input-search']").send_keys(
25-
current_user.username,
26-
)
24+
find("#private-message-users-filter input[name='filter-input-search']").send_keys(username)
2725
find(".email-group-user-chooser-row").click
2826
find("#private-message-users").click
2927
end
3028

3129
it "can permanently decrypt the topic" do
30+
Jobs.run_immediately!
31+
3232
topic_page.open_new_message
3333
expect(page).to have_css(".encrypt-controls .d-icon-lock")
3434

35-
select_self_as_recipient
35+
enable_encrypt_for_user_in_session(other_user, user_preferences_page)
36+
select_recipient(other_user.username)
3637

3738
# Create encrypted PM
3839
topic_page.fill_in_composer_title(topic_title)
3940
topic_page.fill_in_composer("This is an initial post in the encrypted PM")
4041
topic_page.send_reply
4142

42-
# Check it worked, and post a reply
43+
# Check it worked
4344
expect(find(".fancy-title")).to have_content(topic_title)
4445
expect(page).to have_css(".topic-status .d-icon-user-secret")
4546
expect(find("#post_1")).to have_content("This is an initial post in the encrypted PM")
47+
48+
# Reply from other user
49+
using_session("user_#{other_user.username}_enable_encrypt") do
50+
visit "/t/#{Topic.last.id}"
51+
topic_page.click_reply_button
52+
topic_page.fill_in_composer("Reply from other user")
53+
topic_page.send_reply
54+
expect(find("#post_2")).to have_content("Reply from other user")
55+
end
56+
57+
# Final reply from initial user, with uploads
4658
topic_page.click_reply_button
4759
topic_page.fill_in_composer("This is a reply to the encrypted PM")
4860
attach_file(file_from_fixtures("logo.png", "images").path) do
@@ -51,7 +63,7 @@ def select_self_as_recipient
5163
expect(page).to have_no_css("#file-uploading")
5264
topic_page.send_reply
5365

54-
expect(find("#post_2")).to have_content("This is a reply to the encrypted PM")
66+
expect(find("#post_3")).to have_content("This is a reply to the encrypted PM")
5567

5668
try_until_success do
5769
upload = Topic.last.posts.last.uploads.first
@@ -60,6 +72,7 @@ def select_self_as_recipient
6072
end
6173

6274
initial_bump_date = Topic.last.bumped_at
75+
initial_notification_count = Notification.count
6376

6477
# Permanently decrypt the topic
6578
find(".decrypt-topic-button").click
@@ -72,21 +85,23 @@ def select_self_as_recipient
7285
expect(page).not_to have_css("body.encrypted-topic-page")
7386
expect(page).to have_css(".private-message-glyph")
7487
expect(find("#post_1")).to have_content("This is an initial post in the encrypted PM")
75-
expect(find("#post_2")).to have_content("This is a reply to the encrypted PM")
88+
expect(find("#post_2")).to have_content("Reply from other user")
89+
expect(find("#post_3")).to have_content("This is a reply to the encrypted PM")
7690

7791
# Check database state is good
7892
expect(Topic.last.is_encrypted?).to eq(false)
7993
upload = Topic.last.posts.last.uploads.first
8094
expect(upload).to be_present
8195
expect(upload.url).not_to end_with(".encrypted")
8296
expect(Topic.last.bumped_at).to eq(initial_bump_date) # rubocop:disable Discourse/TimeEqMatcher because it should be precisely the same
97+
expect(Notification.count).to eq(initial_notification_count)
8398
end
8499

85100
it "can permanently decrypt multiple topics" do
86101
3.times do |i|
87102
topic_page.open_new_message
88103
expect(page).to have_css(".encrypt-controls .d-icon-lock")
89-
select_self_as_recipient
104+
select_recipient(current_user.username)
90105

91106
# Create encrypted PM
92107
topic_page.fill_in_composer_title(topic_title)

0 commit comments

Comments
 (0)