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

fix: show only relevant userInfoActions for mentioned non-members #31525

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

Conversation

abhinavkrin
Copy link
Member

@abhinavkrin abhinavkrin commented Jan 24, 2024

Proposed changes (including videos or screenshots)

This pull request addresses an issue in the user mention functionality within Rocket.Chat channels. Previously, when a user mentioned another user who was not a member of the channel, the User Info card still displayed options like 'Remove User', 'Set as Leader', 'Set as Moderator', etc., which were not applicable for non-members. This fix introduces a check to determine if the mentioned user is a member of the channel/group. If the user is not a member, it now shows an option to 'Add User' to the channel and omits inappropriate options for non-members.

  1. Implemented an API to verify if the mentioned user is a member of the channel/group/dm.
  2. Display 'Add User' option if the mentioned user is not a member of the channel.
  3. Hide options like 'Remove User', 'Set as Leader', 'Set as Moderator', etc., for non-members.
add-user-2024-01-24_17.28.08.mp4

Issue(s)

When a user mentions another user who was not a member of the channel, the User Info card still displays options like 'Remove User', 'Set as Leader', 'Set as Moderator', etc., which are not applicable for non-members
Also
Fixes #31712

Steps to test or reproduce

  1. Mention a user who is not a member of the channel.
  2. Observe the options available in the User Info card.
  3. 'Add User' option should be visible while options like 'Remove User', 'Set as Leader', 'Set as Moderator' should not be available for non-members.

Further comments

TC-1079

Justification for New Endpoint room.isMember

We considered using channels.members/groups.members with filters for membership checks but faced issues:

  1. User Matching: Regex filters might return similar, not exact, usernames, causing inaccuracies.
  2. Pagination: If results exceed LIMIT_PER_PAGE, the target user might not appear on the first page, requiring extra API calls.
  3. Performance: Regex searches are slower than direct comparisons.
    To ensure precise and efficient user membership verification, we introduced the room.isMember endpoint, circumventing the limitations of existing endpoints and ensuring a more reliable and performant solution.

Copy link

changeset-bot bot commented Jan 24, 2024

🦋 Changeset detected

Latest commit: fdad230

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

This PR includes changesets to release 34 packages
Name Type
@rocket.chat/rest-typings Patch
@rocket.chat/meteor Patch
@rocket.chat/i18n Patch
@rocket.chat/core-services Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/api-client Patch
@rocket.chat/ddp-client Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/mock-providers Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/gazzodown Patch
@rocket.chat/livechat Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-client Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/core-typings Patch
@rocket.chat/apps Patch
@rocket.chat/cron 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

Copy link

codecov bot commented Jan 24, 2024

Codecov Report

Attention: Patch coverage is 68.42105% with 18 lines in your changes missing coverage. Please review.

Project coverage is 56.76%. Comparing base (209a062) to head (fdad230).
Report is 5 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff            @@
##           develop   #31525   +/-   ##
========================================
  Coverage    56.76%   56.76%           
========================================
  Files         2496     2495    -1     
  Lines        55358    55364    +6     
  Branches     11455    11457    +2     
========================================
+ Hits         31423    31428    +5     
+ Misses       21241    21237    -4     
- Partials      2694     2699    +5     
Flag Coverage Δ
e2e 56.56% <68.42%> (+0.04%) ⬆️
unit 71.88% <ø> (-0.05%) ⬇️

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

@abhinavkrin abhinavkrin marked this pull request as ready for review January 24, 2024 15:42
@abhinavkrin abhinavkrin requested review from a team as code owners January 24, 2024 15:42
Copy link
Member

@debdutdeb debdutdeb left a comment

Choose a reason for hiding this comment

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

could we not use subscription.getOne endpoint instead?

apps/meteor/app/api/server/v1/channels.ts Outdated Show resolved Hide resolved
apps/meteor/app/api/server/v1/groups.ts Outdated Show resolved Hide resolved
apps/meteor/app/api/server/v1/im.ts Outdated Show resolved Hide resolved
@abhinavkrin
Copy link
Member Author

could we not use subscription.getOne endpoint instead?

Hey @debdutdeb, sorry for delayed reply.
The use-case is different here, I have created endpoints to check if another user is member of a channel/group/member or not.

@debdutdeb
Copy link
Member

Right. But I don't think you need all these endpoints. Membership is a subscription. So one endpoint should be sufficient, like subscription.exists?uid=..&rid=.... Furthermore, nobody can leave a dm, so a case where you need to check for user exists in a dm or not shouldn't come up in this context.

@debdutdeb
Copy link
Member

async function _validateIfAlreadyJoined(room, user): Promise<boolean> {
if (!room?._id || !user?._id) {
return false;
}
if (!(await Subscriptions.countByRoomIdAndUserId(room._id, user._id))) {
return false;
}

@debdutdeb
Copy link
Member

also idk if client caches the memberlist, might be a good idea to utilize if it does.

Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
@abhinavkrin
Copy link
Member Author

Right. But I don't think you need all these endpoints. Membership is a subscription. So one endpoint should be sufficient, like subscription.exists?uid=..&rid=.... Furthermore, nobody can leave a dm, so a case where you need to check for user exists in a dm or not shouldn't come up in this context.

Thanks for the input @debdutdeb. I did not know about subscriptions earlier.
Indeed, I created an endpoint subscriptions.exists?roomId=...&username=.... to check a user's membership for which I am checking whether a subscription exists for them or not. I have applied appropriate validation so that unauthorized users cannot access this endpoint.

@abhinavkrin
Copy link
Member Author

also idk if client caches the memberlist, might be a good idea to utilize if it does.

This was my initial approach, but the member list functionality does a search and receives a paginated result. So there is no guarantee that the required username would be present in the result or not.

packages/rest-typings/src/v1/dm/im.ts Outdated Show resolved Hide resolved
apps/meteor/app/api/server/v1/subscriptions.ts Outdated Show resolved Hide resolved
apps/meteor/app/api/server/v1/subscriptions.ts Outdated Show resolved Hide resolved
apps/meteor/app/api/server/v1/subscriptions.ts Outdated Show resolved Hide resolved
apps/meteor/app/api/server/v1/subscriptions.ts Outdated Show resolved Hide resolved
apps/meteor/app/api/server/v1/subscriptions.ts Outdated Show resolved Hide resolved
apps/meteor/app/api/server/v1/subscriptions.ts Outdated Show resolved Hide resolved
Copy link
Contributor

dionisio-bot bot commented Apr 12, 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 missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
@abhinavkrin abhinavkrin force-pushed the fix/mention-user-membership-check branch from dc0eb25 to 5c383ec Compare June 18, 2024 20:07
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
@abhinavkrin abhinavkrin force-pushed the fix/mention-user-membership-check branch from 29facd0 to b68f6ab Compare June 21, 2024 21:20
Copy link
Contributor

@matheusbsilva137 matheusbsilva137 left a comment

Choose a reason for hiding this comment

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

Could you please fix the conflicts too?

apps/meteor/app/api/server/v1/rooms.ts Outdated Show resolved Hide resolved
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
apps/meteor/tests/end-to-end/api/09-rooms.ts Dismissed Show dismissed Hide dismissed
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
apps/meteor/tests/end-to-end/api/09-rooms.ts Outdated Show resolved Hide resolved
apps/meteor/tests/end-to-end/api/09-rooms.ts Outdated Show resolved Hide resolved
apps/meteor/tests/end-to-end/api/09-rooms.ts Outdated Show resolved Hide resolved
Signed-off-by: Abhinav Kumar <abhinav@avitechlab.com>
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.

Admin can remove user even if user is already removed from the room
10 participants