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/29829: Admin cannot replace receipt #31024

Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 styles from '@styles/styles';
import * as StyleUtils from '@styles/StyleUtils';
import themeColors from '@styles/themes/default';
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 @@ -359,12 +358,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 @@ -1617,9 +1617,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) {
pecanoro marked this conversation as resolved.
Show resolved Hide resolved
const isDeleted = ReportActionsUtils.isDeletedAction(reportAction);

if (isDeleted) {
Expand All @@ -1641,7 +1642,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 @@ -1668,7 +1671,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
Loading