Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Permissions out of DB Watcher #32360

Merged
merged 11 commits into from May 14, 2024

Conversation

ricardogarim
Copy link
Contributor

@ricardogarim ricardogarim commented May 1, 2024

As per the updates mentioned in PROJ-7 SCA-4 and ADR #74, this pull request focuses on relocating Permissions entity out of DB Watcher service.

Quick context to public readers

In essence, this modification empowers RocketChat's app to directly call listeners through the api.broadcast global function, eliminating the reliance on MongoDB Change Stream data propagation

Why is this beneficial? It provides better control over notifying users by enabling more precise use-case management. Unlike Change Streams, which notify every action on Mongo's documents and sometimes might result in unnecessary duplicate notifications. Moreover, it contributes to the future removal of the DB Watcher deployment, thereby optimizing resource utilization.

Proposed changes

Key changes include:

  • Conditionally incorporating Permissions entity import within DB watchers on application startup based on the dbWatchersDisabled flag.
  • Enabling support for the following use cases to directly trigger permission.changed listener event, subject to the dbWatchersDisabled flag.
Updated use cases.
Use Case Route/Trigger Notes
removeRole Method authorization:removeRoleFromPermission
setRoles Route POST permissions.update
addRole Method authorization:addPermissionToRole

Steps to test or reproduce

  1. Start RocketChat's application with the DISABLE_DB_WATCHERS flag set to true.
  2. Perform a POST request to above given endpoints available on updated use cases.
  3. Observe websocket received events. Related events should be of eventName: permissions-changed, containing all changed fields as well as the updated permission identification data.

Further comments

To maintain consistency and avoid potential regressions, event names and signatures have been kept unchanged on both the client and app sides. This decision streamlines efforts and mitigates the risk of unintended consequences.

Startup and feature activation events were not refactored to call listener event.
Permissions model WBS. Used to guide changes discovery.
🔄 Work in progress
✅ Done
➖ Not applicable

Function Status
createOrUpdate
create
addRole
setRoles
removeRole
findByLevel

Copy link

changeset-bot bot commented May 1, 2024

⚠️ No Changeset found

Latest commit: 50dd03f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

dionisio-bot bot commented May 1, 2024

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@ricardogarim ricardogarim changed the title refactor: Permission out of DB Watcher refactor: Permissions out of DB Watcher May 2, 2024
Copy link

codecov bot commented May 2, 2024

Codecov Report

Attention: Patch coverage is 3.03030% with 32 lines in your changes are missing coverage. Please review.

Project coverage is 55.60%. Comparing base (18cae03) to head (50dd03f).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #32360      +/-   ##
===========================================
- Coverage    55.62%   55.60%   -0.02%     
===========================================
  Files         2408     2408              
  Lines        52965    52997      +32     
  Branches     10884    10894      +10     
===========================================
+ Hits         29462    29470       +8     
- Misses       20888    20918      +30     
+ Partials      2615     2609       -6     
Flag Coverage Δ
e2e 55.08% <ø> (+0.03%) ⬆️
unit 73.03% <3.03%> (-0.24%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

@ricardogarim ricardogarim force-pushed the refactor/permissions-out-of-db-watcher branch 2 times, most recently from 617a2dc to f814553 Compare May 12, 2024 22:33
@ricardogarim ricardogarim marked this pull request as ready for review May 13, 2024 12:26
@ricardogarim ricardogarim requested review from a team as code owners May 13, 2024 12:26
Copy link
Member

@sampaiodiego sampaiodiego left a comment

Choose a reason for hiding this comment

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

it needs to get conflicts solved as well

apps/meteor/server/models/raw/Permissions.ts Outdated Show resolved Hide resolved
@ricardogarim ricardogarim force-pushed the refactor/permissions-out-of-db-watcher branch from e8e2e18 to 6c38385 Compare May 14, 2024 01:43
@ricardogarim
Copy link
Contributor Author

Additionally, I've used this PR to relocate Role related functions to the same notifyListener.ts file as its peers entities. No rules were changed; only function naming and file names were adjusted.

cc @sampaiodiego

@ricardogarim ricardogarim force-pushed the refactor/permissions-out-of-db-watcher branch from 2881d6f to 7adfa6c Compare May 14, 2024 03:22
@ricardogarim ricardogarim force-pushed the refactor/permissions-out-of-db-watcher branch from 7adfa6c to 94da5a2 Compare May 14, 2024 03:34
@sampaiodiego sampaiodiego added this to the 6.9 milestone May 14, 2024
@sampaiodiego sampaiodiego added the stat: QA assured Means it has been tested and approved by a company insider label May 14, 2024
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label May 14, 2024
@kodiakhq kodiakhq bot merged commit 190d1de into develop May 14, 2024
48 of 50 checks passed
@kodiakhq kodiakhq bot deleted the refactor/permissions-out-of-db-watcher branch May 14, 2024 16:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants