Skip to content

Commit

Permalink
Merge pull request #31024 from DylanDylann/fix/29829-scan-workspace-a…
Browse files Browse the repository at this point in the history
…dmin-is-unable-to-replace-receipt

Fix/29829: Admin cannot replace receipt
  • Loading branch information
pecanoro authored Nov 16, 2023
2 parents 863f78b + c5086d1 commit 06ddd6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 1 addition & 6 deletions src/components/AttachmentModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import * as StyleUtils from '@styles/StyleUtils';
import useTheme from '@styles/themes/useTheme';
import useThemeStyles from '@styles/useThemeStyles';
import * as IOU from '@userActions/IOU';
import * as Policy from '@userActions/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
Expand Down Expand Up @@ -361,12 +360,8 @@ function AttachmentModal(props) {
}
const menuItems = [];
const parentReportAction = props.parentReportActions[props.report.parentReportActionID];
const isDeleted = ReportActionsUtils.isDeletedAction(parentReportAction);
const isSettled = ReportUtils.isSettled(props.parentReport.reportID);

const isAdmin = Policy.isAdminOfFreePolicy([props.policy]) && ReportUtils.isExpenseReport(props.parentReport);
const isRequestor = ReportUtils.isMoneyRequestReport(props.parentReport) && lodashGet(props.session, 'accountID', null) === parentReportAction.actorAccountID;
const canEdit = !isSettled && !isDeleted && (isAdmin || isRequestor);
const canEdit = ReportUtils.canEditFieldOfMoneyRequest(parentReportAction, props.parentReport.reportID, CONST.EDIT_REQUEST_FIELD.RECEIPT);
if (canEdit) {
menuItems.push({
icon: Expensicons.Camera,
Expand Down
9 changes: 6 additions & 3 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1652,9 +1652,10 @@ function getTransactionDetails(transaction, createdDateFormat = CONST.DATE.FNS_F
* - or the user is an admin on the policy the expense report is tied to
*
* @param {Object} reportAction
* @param {String} fieldToEdit
* @returns {Boolean}
*/
function canEditMoneyRequest(reportAction) {
function canEditMoneyRequest(reportAction, fieldToEdit = '') {
const isDeleted = ReportActionsUtils.isDeletedAction(reportAction);

if (isDeleted) {
Expand All @@ -1676,7 +1677,9 @@ function canEditMoneyRequest(reportAction) {
const isReportSettled = isSettled(moneyRequestReport.reportID);
const isAdmin = isExpenseReport(moneyRequestReport) && lodashGet(getPolicy(moneyRequestReport.policyID), 'role', '') === CONST.POLICY.ROLE.ADMIN;
const isRequestor = currentUserAccountID === reportAction.actorAccountID;

if (isAdmin && !isRequestor && fieldToEdit === CONST.EDIT_REQUEST_FIELD.RECEIPT) {
return false;
}
if (isAdmin) {
return true;
}
Expand All @@ -1703,7 +1706,7 @@ function canEditFieldOfMoneyRequest(reportAction, reportID, fieldToEdit) {
];

// Checks if this user has permissions to edit this money request
if (!canEditMoneyRequest(reportAction)) {
if (!canEditMoneyRequest(reportAction, fieldToEdit)) {
return false; // User doesn't have permission to edit
}

Expand Down

0 comments on commit 06ddd6e

Please sign in to comment.