Skip to content

Commit 5c2340e

Browse files
authored
Merge pull request #18573 from opf/fix/restricted-comments-on-polling
Fix polling of restricted comments
2 parents e7e2c0b + 9db8d0f commit 5c2340e

File tree

2 files changed

+100
-39
lines changed

2 files changed

+100
-39
lines changed

Diff for: app/controllers/work_packages/activities_tab_controller.rb

+1
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,7 @@ def update_journal_service_call
329329
def generate_time_based_update_streams(last_update_timestamp)
330330
journals = @work_package
331331
.journals
332+
.restricted_visible
332333
.with_sequence_version
333334

334335
if @filter == :only_comments

Diff for: spec/features/activities/work_package/activities_spec.rb

+99-39
Original file line numberDiff line numberDiff line change
@@ -419,57 +419,117 @@
419419
end
420420

421421
context "when multiple users are commenting on a workpackage" do
422-
current_user { admin }
423-
let(:work_package) { create(:work_package, project:, author: admin) }
422+
context "when the user has permissions to see restricted comments" do
423+
current_user { admin }
424+
let(:work_package) { create(:work_package, project:, author: admin) }
424425

425-
before do
426-
# set WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS to 1000
427-
# to speed up the polling interval for test duration
428-
ENV["WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS"] = "1000"
426+
before do
427+
# set WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS to 1000
428+
# to speed up the polling interval for test duration
429+
ENV["WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS"] = "1000"
429430

430-
# for some reason the journal is set to the "Anonymous"
431-
# although the work_package is created by the admin
432-
# so we need to update the journal to the admin manually to simulate the real world case
433-
work_package.journals.first.update!(user: admin)
431+
# for some reason the journal is set to the "Anonymous"
432+
# although the work_package is created by the admin
433+
# so we need to update the journal to the admin manually to simulate the real world case
434+
work_package.journals.first.update!(user: admin)
434435

435-
wp_page.visit!
436-
wp_page.wait_for_activity_tab
437-
end
436+
wp_page.visit!
437+
wp_page.wait_for_activity_tab
438+
end
438439

439-
after do
440-
ENV.delete("WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS")
440+
after do
441+
ENV.delete("WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS")
442+
end
443+
444+
it "shows the comment of another user without browser reload" do
445+
# simulate member creating a comment
446+
first_journal = create(:work_package_journal,
447+
user: member,
448+
notes: "First comment by member",
449+
journable: work_package,
450+
version: 2)
451+
452+
# the comment is shown without browser reload
453+
activity_tab.expect_journal_notes(text: "First comment by member")
454+
455+
# simulate comments made within the polling interval
456+
create(:work_package_journal, user: member, notes: "Second comment by member", journable: work_package, version: 3)
457+
create(:work_package_journal, user: member, notes: "Third comment by member", journable: work_package, version: 4)
458+
459+
activity_tab.add_comment(text: "First comment by admin")
460+
461+
activity_tab.expect_comments_order(
462+
[
463+
"First comment by member",
464+
"Second comment by member",
465+
"Third comment by member",
466+
"First comment by admin"
467+
]
468+
)
469+
470+
first_journal.update!(notes: "First comment by member updated")
471+
472+
# properly updates the comment when the comment is updated
473+
activity_tab.expect_journal_notes(text: "First comment by member updated")
474+
end
441475
end
442476

443-
it "shows the comment of another user without browser reload" do
444-
# simulate member creating a comment
445-
first_journal = create(:work_package_journal,
446-
user: member,
447-
notes: "First comment by member",
448-
journable: work_package,
449-
version: 2)
477+
context "when the user does not have permissions to see restricted comments" do
478+
current_user { member }
479+
let(:work_package) { create(:work_package, project:, author: admin) }
450480

451-
# the comment is shown without browser reload
452-
activity_tab.expect_journal_notes(text: "First comment by member")
481+
before do
482+
# set WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS to 1000
483+
# to speed up the polling interval for test duration
484+
ENV["WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS"] = "1000"
453485

454-
# simulate comments made within the polling interval
455-
create(:work_package_journal, user: member, notes: "Second comment by member", journable: work_package, version: 3)
456-
create(:work_package_journal, user: member, notes: "Third comment by member", journable: work_package, version: 4)
486+
# for some reason the journal is set to the "Anonymous"
487+
# although the work_package is created by the admin
488+
# so we need to update the journal to the admin manually to simulate the real world case
489+
work_package.journals.first.update!(user: admin)
457490

458-
activity_tab.add_comment(text: "First comment by admin")
491+
wp_page.visit!
492+
wp_page.wait_for_activity_tab
493+
end
459494

460-
activity_tab.expect_comments_order(
461-
[
462-
"First comment by member",
463-
"Second comment by member",
464-
"Third comment by member",
465-
"First comment by admin"
466-
]
467-
)
495+
after do
496+
ENV.delete("WORK_PACKAGES_ACTIVITIES_TAB_POLLING_INTERVAL_IN_MS")
497+
end
468498

469-
first_journal.update!(notes: "First comment by member updated")
499+
it "does not show the comment of another user if they don't have permissions to see it" do
500+
# simulate member creating a comment
501+
create(:work_package_journal,
502+
user: admin,
503+
notes: "First comment by admin",
504+
journable: work_package,
505+
version: 2)
506+
507+
# the comment is shown without browser reload
508+
activity_tab.expect_journal_notes(text: "First comment by admin")
509+
510+
# simulate comments made within the polling interval
511+
create(:work_package_journal,
512+
user: admin,
513+
notes: "Second comment by admin",
514+
restricted: true,
515+
journable: work_package,
516+
version: 3)
517+
create(:work_package_journal,
518+
user: admin,
519+
notes: "Third comment by admin",
520+
restricted: true,
521+
journable: work_package,
522+
version: 4)
523+
524+
activity_tab.add_comment(text: "First comment by member")
470525

471-
# properly updates the comment when the comment is updated
472-
activity_tab.expect_journal_notes(text: "First comment by member updated")
526+
activity_tab.expect_comments_order(
527+
[
528+
"First comment by admin",
529+
"First comment by member"
530+
]
531+
)
532+
end
473533
end
474534
end
475535

0 commit comments

Comments
 (0)