diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index e8ef18a3ca27..844f5a64f5ce 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -239,40 +239,6 @@ function isCurrentUserSubmitter(reportID) { return report && report.ownerEmail === currentUserEmail; } -/** - * Can only delete if the author is this user and the action is an ADDCOMMENT action or an IOU action in an unsettled report, or if the user is a - * policy admin - * - * @param {Object} reportAction - * @param {String} reportID - * @returns {Boolean} - */ -function canDeleteReportAction(reportAction, reportID) { - // For now, users cannot delete split actions - if (ReportActionsUtils.isMoneyRequestAction(reportAction) && lodashGet(reportAction, 'originalMessage.type') === CONST.IOU.REPORT_ACTION_TYPE.SPLIT) { - return false; - } - const isActionOwner = reportAction.actorAccountID === currentUserAccountID; - if (isActionOwner && ReportActionsUtils.isMoneyRequestAction(reportAction) && !isSettled(reportAction.originalMessage.IOUReportID)) { - return true; - } - if ( - reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT || - reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || - ReportActionsUtils.isCreatedTaskReportAction(reportAction) || - (ReportActionsUtils.isMoneyRequestAction(reportAction) && isSettled(reportAction.originalMessage.IOUReportID)) || - reportAction.actorAccountID === CONST.ACCOUNT_ID.CONCIERGE - ) { - return false; - } - if (isActionOwner) { - return true; - } - const report = lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}); - const policy = lodashGet(allPolicies, `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`) || {}; - return policy.role === CONST.POLICY.ROLE.ADMIN; -} - /** * Whether the provided report is an Admin room * @param {Object} report @@ -751,6 +717,40 @@ function isMoneyRequestReport(reportOrID) { return isIOUReport(report) || isExpenseReport(report); } +/** + * Can only delete if the author is this user and the action is an ADDCOMMENT action or an IOU action in an unsettled report, or if the user is a + * policy admin + * + * @param {Object} reportAction + * @param {String} reportID + * @returns {Boolean} + */ +function canDeleteReportAction(reportAction, reportID) { + // For now, users cannot delete split actions + if (ReportActionsUtils.isMoneyRequestAction(reportAction) && lodashGet(reportAction, 'originalMessage.type') === CONST.IOU.REPORT_ACTION_TYPE.SPLIT) { + return false; + } + const isActionOwner = reportAction.actorAccountID === currentUserAccountID; + if (isActionOwner && ReportActionsUtils.isMoneyRequestAction(reportAction) && !isSettled(reportAction.originalMessage.IOUReportID)) { + return true; + } + if ( + reportAction.actionName !== CONST.REPORT.ACTIONS.TYPE.ADDCOMMENT || + reportAction.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || + ReportActionsUtils.isCreatedTaskReportAction(reportAction) || + (ReportActionsUtils.isMoneyRequestAction(reportAction) && isSettled(reportAction.originalMessage.IOUReportID)) || + reportAction.actorAccountID === CONST.ACCOUNT_ID.CONCIERGE + ) { + return false; + } + if (isActionOwner) { + return true; + } + const report = lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}); + const policy = lodashGet(allPolicies, `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`) || {}; + return policy.role === CONST.POLICY.ROLE.ADMIN && !isDM(report); +} + /** * Get welcome message based on room type * @param {Object} report