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: Restrict Pin Icon Visibility Based on User Permissions #674

Merged
merged 2 commits into from
Dec 15, 2024

Conversation

SinghaAnirban005
Copy link
Contributor

@SinghaAnirban005 SinghaAnirban005 commented Dec 1, 2024

Brief Title

Restrict Pin Icon Visibility Based on User Permissions

Acceptance Criteria fulfillment

  • Ensure users without permissions do not see the pin icon
  • Verify pin icon visibility for users with admin-granted permissions.

Fixes #672

Video/Screenshots

Case 1: When non-priviledged users are granted permission to pin/unpin messages

Permissions.-.Singha.-.Brave.2024-11-30.23-37-09.mp4

Case 2: When non-priviledged users are not granted permission to pin/unpin messages

Permissions.-.Singha.-.Brave.2024-12-01.00-19-14.mp4

PR Test Details

Note: The PR will be ready for live testing at https://rocketchat.github.io/EmbeddedChat/pulls/pr-674 after approval. Contributors are requested to replace <pr_number> with the actual PR number.

Copy link
Collaborator

@Spiral-Memory Spiral-Memory left a comment

Choose a reason for hiding this comment

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

LGTM

@Spiral-Memory Spiral-Memory merged commit 8284ffa into RocketChat:develop Dec 15, 2024
6 checks passed
github-actions bot added a commit that referenced this pull request Dec 15, 2024
@devanshkansagra
Copy link
Contributor

devanshkansagra commented Dec 16, 2024

Hey @SinghaAnirban005 your code is not working properly for admin user, check this
image

@Spiral-Memory
Copy link
Collaborator

Check if it's due to alphabet case?

@devanshkansagra
Copy link
Contributor

meaning?

@Spiral-Memory
Copy link
Collaborator

lower/upper case difference while comparing

@@ -56,6 +60,7 @@ export const useRCAuth = () => {
setIsTotpModalOpen(false);
setEmailorUser(null);
setPassword(null);
setUserPinPermissions(permissions.update[150]);
Copy link
Contributor

@devanshkansagra devanshkansagra Dec 16, 2024

Choose a reason for hiding this comment

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

Hey @SinghaAnirban005, I think it should be permissions.update[146] according to the pr - #520

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The 150th index returns the pin permissions correctly

Copy link
Contributor

Choose a reason for hiding this comment

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

okay then what is on 146th??

Copy link
Contributor

Choose a reason for hiding this comment

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

check and try pr 520

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i am getting this log on 146
Screenshot 2024-12-17 004227

Copy link
Contributor

Choose a reason for hiding this comment

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

Ohh so might this permissions array got changed later

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes exactly

@devanshkansagra
Copy link
Contributor

devanshkansagra commented Dec 16, 2024

lower/upper case difference while comparing

we are setting the permissions for pin messages according to the user roles, so how this lower/upper case difference comparison came, could you please explain? I still don't get it.

@@ -67,6 +69,7 @@ export const MessageToolbox = ({
setShowDeleteModal(false);
};

const isAllowedToPin = userRoles.some((role) => pinRoles.has(role));
Copy link
Collaborator

@Spiral-Memory Spiral-Memory Dec 16, 2024

Choose a reason for hiding this comment

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

@devanshkansagra

At this point, we are comparing two different roles. There is a possibility that one of the rules is in a different case. (Maybe returned from api in different case)

It's just a possibility, but I wanted to check.
I'm not sure if that's the issue.

The problem might lie in fetching the wrong PIN permission list,
or it could be that the fetch operation somehow fails.

Copy link
Contributor

@devanshkansagra devanshkansagra Dec 16, 2024

Choose a reason for hiding this comment

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

Okay so you mean, the roles in the entire roles array?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Suppose in userRole, my role is Admin
In roles array, in pin permission, the role is admin

Now Admin != admin
Hence check fails

Copy link
Contributor

Choose a reason for hiding this comment

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

Hey @Spiral-Memory when I was researching for the solution of this issue, I somehow fetched the entire roles array from the permissions response and in that I have seen all the roles were having same case all small

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ohh ok then,
Try figuring out the issue and let me know

Copy link
Contributor

Choose a reason for hiding this comment

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

Okay

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@devanshkansagra @Spiral-Memory
In my POV , the code seems to work well for all user groups including admin , the reason why it might not have worked is that when pin roles are changed by admin in the panel, changes are instantaneously not updated in the user's permission store . Thus a user needs to logout and re-login in order to see changes in permissions

Copy link
Contributor

Choose a reason for hiding this comment

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

rather than doing logout and login again is it possible to view changes on refreshing the page?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i can try fixing it !!

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.

Non-admin users can see the pin/unpin icon in group chats despite lacking permissions
3 participants