fix: user-specific banners failing with `Banner not found` error when dismissing it

Merged
NA
2mo ago
+128-3

Proposed changes (including videos or screenshots)

When migrating some Meteor methods to REST endpoints in https://github.com/RocketChat/Rocket.Chat/pull/40704 we overlooked that banners.dismiss do not cover user-specific banners (banners within the user record in a banners array).

To fix this:

  • I modified the dismiss method from the BannerService to try to mark user-specific banners as read as fallback if there is none matching the rocketchat_banner collection. I did this following the banner/dismiss Meteor method current logic (the one used before).
  • The setBannerReadById User model method was modified to avoid the user from arbitrarily setting a banner in their record.
  • API tests were added covering this new behavior.

Issue(s)

SUP-1095 "Update your Rocket.Chat" banner cannot be dismissed on 8.6.0 and later

Steps to test or reproduce

  1. Login as an admin user
  2. Run the following MongoDB shell command, replacing with the proper user’s username:
    (the version number must be higher than the current one you’re using to test for the banner to show up)
db.users.updateOne(
  { username: "rocketchat.internal.admin.test" },
  { $set: { "banners.versionUpdate-8_9_0": {
      id: "versionUpdate-8_9_0",
      priority: 10,
      title: "Update_your_RocketChat",
      text: "New_version_available_(s)",
      textArguments: ["8.9.0"],
      link: "https://github.com/RocketChat/Rocket.Chat/releases/tag/8.9.0",
      modifiers: []
  } } }
)
  1. Click on the cross icon to dismiss the banner.

Expected result: Banner should be dismissed without errors and if you refresh the page it shouldn’t come back.

Further comments

Summary by CodeRabbit

  • Bug Fixes
    • Dismissing a banner stored on a user record now marks it as read.
    • Repeated dismissal of an already-read banner succeeds safely.
    • Unknown banners now return an error without creating or modifying banner records.
    • Banner updates are skipped when no matching banner exists.
    • Banner changes are reflected promptly in the user’s session.
    • Banner dismissal behavior is now consistent across stored and standard banners.