Don't allow employee to delete submitted request#35744
Conversation
| if (ReportUtils.isPaidGroupPolicyExpenseReport(moneyRequestReport)) { | ||
| // If it's a paid policy expense report, only allow modifying the request if it's not submitted or the user is the policy admin | ||
| canModifyRequest = canModifyRequest && (ReportUtils.isDraftExpenseReport(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy)); | ||
| } |
There was a problem hiding this comment.
I tested and found out that we can't add a receipt on a submitted expense too, so I decided to move the condition here.
But if the submitted expense has a receipt, we can replace/delete it.
There was a problem hiding this comment.
I tested and it seems that I can add a receipt on a submitted expense. Can you please double check?
There was a problem hiding this comment.
Let me check once again.
There was a problem hiding this comment.
Yeah, I can add a receipt on a submitted request. Updated
|
Here is the video showing that the admin can still successfully add a receipt and delete a submitted report. Screen.Recording.2024-02-03.at.16.29.07.mov |
| * Checks if the current user is an admin of the policy. | ||
| */ | ||
| const isPolicyAdmin = (policy: OnyxEntry<Policy>): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN; | ||
| const isPolicyAdmin = (policy?: OnyxEntry<Policy>): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN; |
There was a problem hiding this comment.
Revert. Pass null if policy is not available. (same for other util changes)
There was a problem hiding this comment.
Oh, I don't know that. Updated.
| * Whether the provided report belongs to a Control or Collect policy | ||
| */ | ||
| function isPaidGroupPolicy(report: OnyxEntry<Report>): boolean { | ||
| function isPaidGroupPolicy(report: OnyxEntry<Report> | EmptyObject): boolean { |
There was a problem hiding this comment.
Oh, I see that we use EmptyObject in many places. Updated
| * Whether the provided report belongs to a Control or Collect policy and is an expense report | ||
| */ | ||
| function isPaidGroupPolicyExpenseReport(report: OnyxEntry<Report>): boolean { | ||
| function isPaidGroupPolicyExpenseReport(report: OnyxEntry<Report> | EmptyObject): boolean { |
| if (ReportUtils.isPaidGroupPolicyExpenseReport(moneyRequestReport)) { | ||
| // If it's a paid policy expense report, only allow modifying the request if it's not submitted or the user is the policy admin | ||
| canModifyRequest = canModifyRequest && (ReportUtils.isDraftExpenseReport(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy)); | ||
| } |
There was a problem hiding this comment.
I tested and it seems that I can add a receipt on a submitted expense. Can you please double check?
| * @param policies must have Onyxkey prefix (i.e 'policy_') for keys | ||
| */ | ||
| function getPolicyType(report: OnyxEntry<Report>, policies: OnyxCollection<Policy>): string { | ||
| function getPolicyType(report: OnyxEntry<Report> | EmptyObject, policies: OnyxCollection<Policy>): string { |
Reviewer Checklist
Screenshots/Videos |
| } | ||
|
|
||
| if (isActionOwner) { | ||
| if (isPaidGroupPolicyExpenseReport(!isEmptyObject(report) ? report : null)) { |
There was a problem hiding this comment.
| if (isPaidGroupPolicyExpenseReport(!isEmptyObject(report) ? report : null)) { | |
| if (!isEmptyObject(report) && isPaidGroupPolicyExpenseReport(report)) { |
NAB
There was a problem hiding this comment.
Oh, I like this one better, updated
There was a problem hiding this comment.
Oh, that's weird. I though it's pushed. Done
| let canDeleteRequest = canModifyRequest; | ||
|
|
||
| if (ReportUtils.isPaidGroupPolicyExpenseReport(moneyRequestReport)) { | ||
| // If it's a paid policy expense report, only allow deleting the request if it's not submitted or the user is the policy admin | ||
| canDeleteRequest = canDeleteRequest && (ReportUtils.isDraftExpenseReport(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy)); | ||
| } |
There was a problem hiding this comment.
| let canDeleteRequest = canModifyRequest; | |
| if (ReportUtils.isPaidGroupPolicyExpenseReport(moneyRequestReport)) { | |
| // If it's a paid policy expense report, only allow deleting the request if it's not submitted or the user is the policy admin | |
| canDeleteRequest = canDeleteRequest && (ReportUtils.isDraftExpenseReport(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy)); | |
| } | |
| // If it's a paid policy expense report, only allow deleting the request if it's not submitted or the user is the policy admin | |
| const canDeleteRequest = | |
| canModifyRequest && | |
| (ReportUtils.isPaidGroupPolicyExpenseReport(moneyRequestReport) ? ReportUtils.isDraftExpenseReport(moneyRequestReport) || PolicyUtils.isPolicyAdmin(policy) : true); |
NAB. But I think using const is better for this case. It's easier to know where canDeleteRequest value is coming from
There was a problem hiding this comment.
Hmm, I feel the current code is easier to read
|
@bernhardoj Can you please merge main see it fixes the failing tests |
|
Perf test still failing, can you please check it? |
|
Hmm, it shouldn't be related to this PR as it fails on SearchPage. It has happened there many times on my previous PRs. I guess it's just flaky |
|
✋ 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 staging by https://github.com/Gonals in version: 1.4.39-0 🚀
|
|
🚀 Deployed to production by https://github.com/Beamanator in version: 1.4.39-8 🚀
|






Details
Currently, an employee can delete a submitted expense request, but the BE will gives an error.
Fixed Issues
$ #34538
PROPOSAL: #34538 (comment)
Tests
Same as QA Steps
Offline tests
Same as QA Steps
QA Steps
PR Author Checklist
### Fixed Issuessection aboveTestssectionOffline stepssectionQA stepssectiontoggleReportand notonIconClick)myBool && <MyComponent />.src/languages/*files and using the translation methodWaiting for Copylabel for a copy review on the original GH to get the correct copy.STYLE.md) were followedAvatar, I verified the components usingAvatarare working as expected)StyleUtils.getBackgroundAndBorderStyle(theme.componentBG))Avataris modified, I verified thatAvataris working as expected in all cases)Designlabel so the design team can review the changes.ScrollViewcomponent to make it scrollable when more elements are added to the page.mainbranch was merged into this PR after a review, I tested again and verified the outcome was still expected according to theTeststeps.Screenshots/Videos
Android: Native
Screen.Recording.2024-02-03.at.16.30.04.mov
Android: mWeb Chrome
Screen.Recording.2024-02-03.at.16.07.41.mov
iOS: Native
Screen.Recording.2024-02-03.at.15.59.15.mov
iOS: mWeb Safari
Screen.Recording.2024-02-03.at.16.03.12.mov
MacOS: Chrome / Safari
Screen.Recording.2024-02-03.at.15.54.22.mov
MacOS: Desktop
Screen.Recording.2024-02-03.at.15.56.07.mov