From b8a3fdca028b6edca88f504f3c7296e9e7938aac Mon Sep 17 00:00:00 2001 From: Huzaifa Rasheed Date: Fri, 11 Aug 2023 04:12:49 +0500 Subject: [PATCH 1/3] Hide delete option for report actions in DMs for initiator --- src/libs/ReportUtils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index e8ef18a3ca27..3394bab61a24 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -270,7 +270,7 @@ function canDeleteReportAction(reportAction, reportID) { } const report = lodashGet(allReports, `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, {}); const policy = lodashGet(allPolicies, `${ONYXKEYS.COLLECTION.POLICY}${report.policyID}`) || {}; - return policy.role === CONST.POLICY.ROLE.ADMIN; + return policy.role === CONST.POLICY.ROLE.ADMIN && !isDM(report); } /** From 79da746db2e8442fb491617e49e0680f4cb6dbe2 Mon Sep 17 00:00:00 2001 From: Huzaifa Rasheed Date: Fri, 11 Aug 2023 04:32:51 +0500 Subject: [PATCH 2/3] Fix lint --- src/libs/ReportUtils.js | 68 ++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 3394bab61a24..20a96cb91e2e 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 && !isDM(report); -} - /** * Whether the provided report is an Admin room * @param {Object} report @@ -449,6 +415,40 @@ function isConciergeChatReport(report) { return lodashGet(report, 'participantAccountIDs', []).length === 1 && Number(report.participantAccountIDs[0]) === CONST.ACCOUNT_ID.CONCIERGE && !isChatThread(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); +} + /** * Check if the report is a single chat report that isn't a thread * and personal detail of participant is optimistic data From 015342b0b879850abb4f4143aff522ef7efa7769 Mon Sep 17 00:00:00 2001 From: Huzaifa Rasheed Date: Fri, 11 Aug 2023 04:38:07 +0500 Subject: [PATCH 3/3] Fix lint --- src/libs/ReportUtils.js | 68 ++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index 20a96cb91e2e..844f5a64f5ce 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -415,40 +415,6 @@ function isConciergeChatReport(report) { return lodashGet(report, 'participantAccountIDs', []).length === 1 && Number(report.participantAccountIDs[0]) === CONST.ACCOUNT_ID.CONCIERGE && !isChatThread(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); -} - /** * Check if the report is a single chat report that isn't a thread * and personal detail of participant is optimistic data @@ -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