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

feat: add endpoints groups.membersOrderedByRole channels.membersOrderedByRole #34153

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

abhinavkrin
Copy link
Member

@abhinavkrin abhinavkrin commented Dec 10, 2024

Proposed changes (including videos or screenshots)

Adds groups.membersOrderedByRole and channels.membersOrderedByRole endpoints to retrieve members of groups and channels sorted according to their respective role in the room.
This will help in grouping of users according to their roles in the room like below.
image

The endpoint works similar as groups.members and channels.members, but accepts an optional rolesOrder[] param which can be used for defining roles order while sorting. The index of the role will signify its priority. By default, owner > moderator > rest of members.

A sample request

curl --location --globoff 'http://localhost:3000/api/v1/channels.membersOrderedByRole?roomId=GENERAL&sort={%22username%22%3A%201}&offset=0&rolesOrder[]=leader&rolesOrder[]=owner' \
--header 'X-Auth-Token: Ce_2eOJ19mnW59wVO5IfSv4s650MF1w7mqY6i52uPG5' \
--header 'X-User-Id: u29m4aQNjZujdE4r5' \
--data ''

Issue(s)

Steps to test or reproduce

Further comments

CORE-846

Copy link
Contributor

dionisio-bot bot commented Dec 10, 2024

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is targeting the wrong base branch. It should target 7.3.0, but it targets 7.2.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

Copy link

changeset-bot bot commented Dec 10, 2024

🦋 Changeset detected

Latest commit: e8d16bf

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 35 packages
Name Type
@rocket.chat/meteor Minor
@rocket.chat/rest-typings Minor
@rocket.chat/api-client Patch
@rocket.chat/core-services Patch
@rocket.chat/ddp-client Patch
@rocket.chat/ui-contexts Major
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/network-broker Patch
@rocket.chat/livechat Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/fuselage-ui-kit Major
@rocket.chat/gazzodown Major
@rocket.chat/ui-avatar Major
@rocket.chat/ui-client Major
@rocket.chat/ui-video-conf Major
@rocket.chat/ui-voip Major
@rocket.chat/web-ui-registration Major
@rocket.chat/core-typings Minor
@rocket.chat/apps Patch
@rocket.chat/cron Patch
@rocket.chat/freeswitch Patch
@rocket.chat/model-typings Patch
@rocket.chat/license Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/models Patch
@rocket.chat/instance-status Patch

Not sure what this means? Click here to learn what changesets are.

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

@abhinavkrin abhinavkrin added this to the 7.2.0 milestone Dec 10, 2024
@abhinavkrin abhinavkrin force-pushed the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch from 4a3be37 to aa02c7a Compare December 10, 2024 12:55
Copy link
Contributor

github-actions bot commented Dec 10, 2024

PR Preview Action v1.4.8
🚀 Deployed preview to https://RocketChat.github.io/Rocket.Chat/pr-preview/pr-34153/
on branch gh-pages at 2024-12-20 14:42 UTC

Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 75.27%. Comparing base (7edc3db) to head (6ceb8e3).
Report is 30 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #34153      +/-   ##
===========================================
- Coverage    75.83%   75.27%   -0.57%     
===========================================
  Files          511      516       +5     
  Lines        22171    22532     +361     
  Branches      5397     5485      +88     
===========================================
+ Hits         16813    16960     +147     
- Misses        4710     4911     +201     
- Partials       648      661      +13     
Flag Coverage Δ
unit 75.27% <ø> (-0.57%) ⬇️

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

@abhinavkrin abhinavkrin force-pushed the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch from 7c92475 to df876a0 Compare December 13, 2024 17:58
@abhinavkrin abhinavkrin changed the title [WIP] feat: add endpoints groups.membersOrderedByRole channels.membersOrderedByRole feat: add endpoints groups.membersOrderedByRole channels.membersOrderedByRole Dec 16, 2024
@abhinavkrin abhinavkrin marked this pull request as ready for review December 16, 2024 15:48
@abhinavkrin abhinavkrin requested review from a team as code owners December 16, 2024 15:48
Copy link
Member

@MarcosSpessatto MarcosSpessatto left a comment

Choose a reason for hiding this comment

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

I think we could create a rooms.membersOrderedByRole instead of creating one for each room type.

Also, we need to create some mock data to test the aggregation part and its performance.
@ricardogarim can you help us with that.

.changeset/silly-kings-approve.md Outdated Show resolved Hide resolved
apps/meteor/tests/end-to-end/api/channels.ts Outdated Show resolved Hide resolved
apps/meteor/tests/end-to-end/api/channels.ts Outdated Show resolved Hide resolved
@abhinavkrin abhinavkrin force-pushed the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch 2 times, most recently from ae9d2e1 to c5fa198 Compare December 17, 2024 16:54
@@ -3647,4 +3648,179 @@ describe('[Rooms]', () => {
});
});
});

describe('[/rooms.membersOrderedByRole]', () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Add test cases for:

  • Trying to fetch a private room by a user not part of room
  • Trying to fetch a public room by a user not part of room
  • The same 2, but with users that are part of the rooms
  • Trying to fetch a private channel inside a public team for someone not part of the room
  • Trying to fetch a public channel inside a private team for someone not part of the room
  • The same 2, but with users that are part of the rooms

Just to ensure we don't show more data than what we should 🙈

Copy link
Member Author

Choose a reason for hiding this comment

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

I have added the following tests:

[Rooms]

    [/rooms.membersOrderedByRole]

      ✔ should return a list of members ordered by owner, moderator, then members by default

      ✔ should allow custom role order

      ✔ should support pagination

      ✔ should return matched members when using filter param

      ✔ should return empty list if no matches (e.g., filter by status that no one has)

      ✔ should support custom sorting by username descending

      Additional Visibility Tests

        ✔ should not fetch private room members by user not part of room

        ✔ should fetch private room members by user who is part of the room

        ✔ should fetch public room members by user who is part of the room

        ✔ should fetch public room members by user not part of room - because public (135ms)

        ✔ should fetch a private channel members inside a public team by someone part of the room 

        ✔ should not fetch a private channel members inside a public team by someone not part of the room, but part of team

        ✔ should not fetch a private channel members inside a public team by someone not part of the team 

        ✔ should fetch a public channel members inside a public team by someone part of the room 

        ✔ should fetch a public channel members inside a public team by someone not part of the room, but part of team

        ✔ should fetch a public channel members inside a public team by someone not part of the team 

        ✔ should fetch a public channel members inside a private team by someone part of the room

        ✔ should fetch a public channel members inside a private team by someone not part of the room, but part of team

        ✔ should not fetch a public channel members inside a private team by someone not part of team

        ✔ should fetch a private channel members inside a private team by someone part of the room

        ✔ should not fetch a private channel members inside a private team by someone not part of the room, but part of team

        ✔ should not fetch a private channel members inside a private team by someone not part of team

},
];

const [result] = await Subscriptions.col.aggregate(facetPipeline, { allowDiskUse: true }).toArray();
Copy link
Contributor

Choose a reason for hiding this comment

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

@MarcosSpessatto , should we run this on the secondary like the other aggregations?

Copy link
Member

Choose a reason for hiding this comment

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

I think it makes sense

roles: IRole['_id'][];
};

export async function findUsersOfRoomOrderedByRole({
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some explains with some decent amount of data to check on the perf of the aggregation? :please:

apps/meteor/server/lib/findUsersOfRoomOrderedByRole.ts Outdated Show resolved Hide resolved
apps/meteor/app/api/server/v1/rooms.ts Show resolved Hide resolved
Copy link
Member

@MarcosSpessatto MarcosSpessatto left a comment

Choose a reason for hiding this comment

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

It looks good to me, we just need to do some perf tests with some fake data to ensure the query perf

@scuciatto scuciatto modified the milestones: 7.2.0, 7.3.0 Dec 20, 2024
Signed-off-by: Abhinav Kumar <[email protected]>
Signed-off-by: Abhinav Kumar <[email protected]>
Signed-off-by: Abhinav Kumar <[email protected]>
Signed-off-by: Abhinav Kumar <[email protected]>
@abhinavkrin abhinavkrin force-pushed the feat/add-endpoints-groups.membersOrderedByRole-channels.membersOrderedByRole branch from 6ceb8e3 to e8d16bf Compare December 20, 2024 14:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants