-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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: ws options available from all devices for same user #42008
Conversation
@rlinoz Can you help to add me as reviewer for this PR? Thanks |
src/libs/PolicyUtils.ts
Outdated
const isPolicyAdmin = (policy: OnyxEntry<Policy> | EmptyObject): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN; | ||
|
||
const isPolicyAdmin = (policy: OnyxEntry<Policy> | EmptyObject): boolean => | ||
policy?.role === CONST.POLICY.ROLE.ADMIN || policy?.employeeList?.[policy?.owner]?.role === CONST.POLICY.ROLE.ADMIN; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should check the role of the current user accountID here. Or it'll introduce regression - non-admin members can also see protected items.
Screen.Recording.2024-05-13.at.8.38.33.PM.mov
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the note. Working on it..
@dragnoir Friendly bump! When can we expect an update on the PR? |
Working on it, will be done today.. |
const currentUserPersonalDetails = useCurrentUserPersonalDetails(); | ||
const employee = policyProp?.employeeList?.[currentUserPersonalDetails.login ?? ''] ?? {}; | ||
const shouldShowProtectedItems = PolicyUtils.isPolicyAdmin(policyProp) || (employee && employee.role === CONST.POLICY.ROLE.ADMIN); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to move the fix into method isPolicyAdmin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem I am facing is that policyProp
is not turning the role
. When policyProp
is checking the role from another device, it's undefined.
but policyProp
has the correct logic.
What do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you can try get accountid by policy owner, get employee and then compare employee role.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I will move the fix into the method isPolicyAdmin
. I tried using useCurrentUserPersonalDetails
into isPolicyAdmin
but I got an error, seems I can't use a hook there, I will see.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eh2077 can we do the following?
const isPolicyAdmin = (policy: OnyxEntry<Policy> | EmptyObject, currentUserLogin?: string): boolean =>
Where currentUserLogin
will be props passed from WorkspaceInitialPage
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think it's okay to add an optional parameter to the method
const shouldShowProtectedItems = PolicyUtils.isPolicyAdmin(policy); | ||
const currentUserPersonalDetails = useCurrentUserPersonalDetails(); | ||
const employee = policyProp?.employeeList?.[currentUserPersonalDetails.login ?? ''] ?? {}; | ||
const shouldShowProtectedItems = PolicyUtils.isPolicyAdmin(policyProp, employee.role); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do you pass the role to the method? I think you should pass current user account id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmmm then what should I do with the account id?
I need the role from the employeeList for the current user because policy.role is not available.
Then I can check if employeeList[currentuseremail@gmail.com].tole is equal to admin
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me know what do you think about the suggested changes, thanks!
@eh2077 I like your approach, it's better, thank you |
Reviewer Checklist
Screenshots/VideosAndroid: Native0-all-in-one.mp4Android: mWeb Chrome0-all-in-one.mp4iOS: Native0-all-in-one.mp4iOS: mWeb Safari0-all-in-one.mp4MacOS: Chrome / Safari0-all-in-one.mp4MacOS: Desktop0-all-in-one.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@rlinoz All yours
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good!
One question, in the second device when we click on Categories or More Features we briefly get a Not found page, is this the same root cause?
I think so, since we check if the user is a policy admin here
[CONST.POLICY.ACCESS_VARIANTS.ADMIN]: (policy: OnyxEntry<OnyxTypes.Policy>) => PolicyUtils.isPolicyAdmin(policy), |
@rlinoz do you want me to dig into this and try to fix it? |
Yeah, I mean, if it is the same root cause and we can apply the same solution, it would be great. |
@dragnoir Friendly bump, do you have any update on the above comments? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is working for me, just one question
@@ -73,7 +74,7 @@ function PageNotFoundFallback({policyID, shouldShowFullScreenFallback, fullPageN | |||
|
|||
function AccessOrNotFoundWrapper({accessVariants = [], fullPageNotFoundViewProps, shouldBeBlocked, ...props}: AccessOrNotFoundWrapperProps) { | |||
const {policy, policyID, featureName, isLoadingReportData} = props; | |||
|
|||
const {login = ''} = useCurrentUserPersonalDetails(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need the = ''
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TS error, login can be undefined, and one of the solutions is to set a default value.
There is also a conflict @dragnoir |
@eh2077 if you could also take a last look 😄 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
✋ This PR was not deployed to staging yet because QA is ongoing. It will be automatically deployed to staging after the next production release. |
🚀 Deployed to production by https://github.com/Julesssss in version: 1.4.79-11 🚀
|
Details
This PR fix the issue where a user create a workspace from a device but can't find all the wp options from a second device
Fixed Issues
$ #40686
PROPOSAL: #40686 (comment)
Tests
20240511_132746.mp4
Offline tests
QA Steps
PR Author Checklist
### Fixed Issues
section aboveTests
sectionOffline steps
sectionQA steps
sectiontoggleReport
and notonIconClick
)myBool && <MyComponent />
.src/languages/*
files and using the translation methodSTYLE.md
) were followedAvatar
, I verified the components usingAvatar
are working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG)
)Avatar
is modified, I verified thatAvatar
is working as expected in all cases)Design
label and/or tagged@Expensify/design
so the design team can review the changes.ScrollView
component to make it scrollable when more elements are added to the page.main
branch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTest
steps.Screenshots/Videos
Android: Native
Android: mWeb Chrome
iOS: Native
iOS: mWeb Safari
MacOS: Chrome / Safari
MacOS: Desktop