From e668fc92c1a85e5adc9da5dad3e97a12c8e36bd9 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Tue, 9 Jul 2024 10:08:59 +0530 Subject: [PATCH 1/6] conditionally show #admins in LHN when there is value --- src/libs/ReportUtils.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ee8e221e5aba..940de8e166f0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5302,6 +5302,16 @@ function canAccessReport(report: OnyxEntry, policies: OnyxCollection Number(accountID)); + const adminAccounts = PersonalDetailsUtils.getLoginsByAccountIDs(accountIDs).filter((login) => !PolicyUtils.isExpensifyTeam(login)); + const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(report?.reportID ?? ''); + if (ReportActionsUtils.isCreatedAction(lastVisibleAction) && adminAccounts.length <= 1) { + return false; + } + } + return true; } From 3aad92f26d9ff113a7aa8d13a0cfaea7079002c0 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Tue, 9 Jul 2024 14:20:06 +0530 Subject: [PATCH 2/6] updated logic --- src/libs/ReportUtils.ts | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 940de8e166f0..a8a813ec96f6 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5302,16 +5302,6 @@ function canAccessReport(report: OnyxEntry, policies: OnyxCollection Number(accountID)); - const adminAccounts = PersonalDetailsUtils.getLoginsByAccountIDs(accountIDs).filter((login) => !PolicyUtils.isExpensifyTeam(login)); - const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(report?.reportID ?? ''); - if (ReportActionsUtils.isCreatedAction(lastVisibleAction) && adminAccounts.length <= 1) { - return false; - } - } - return true; } @@ -5384,6 +5374,20 @@ function hasWarningTypeViolations(reportID: string, transactionViolations: OnyxC return transactions.some((transaction) => TransactionUtils.hasWarningTypeViolation(transaction.transactionID, transactionViolations)); } +/** + * Checks if #admins room chan be shown + * We show #admin rooms when a) More than one admin exists or b) There exists policy audit log for review. + */ +function shouldAdminsRoomBeVisible(report: OnyxEntry): boolean { + const accountIDs = Object.entries(report?.participants ?? {}).map(([accountID]) => Number(accountID)); + const adminAccounts = PersonalDetailsUtils.getLoginsByAccountIDs(accountIDs).filter((login) => !PolicyUtils.isExpensifyTeam(login)); + const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(report?.reportID ?? ''); + if (ReportActionsUtils.isCreatedAction(lastVisibleAction) && adminAccounts.length <= 1) { + return false; + } + return true; +} + /** * Takes several pieces of data from Onyx and evaluates if a report should be shown in the option list (either when searching * for reports or the reports shown in the LHN). @@ -5490,6 +5494,11 @@ function shouldReportBeInOptionList({ return false; } + // Show #admins room only when it has some value to the user. + if(isAdminRoom(report) && !shouldAdminsRoomBeVisible(report)) { + return false; + } + // Include reports that have errors from trying to add a workspace // If we excluded it, then the red-brock-road pattern wouldn't work for the user to resolve the error if (report.errorFields?.addWorkspaceRoom) { From 01d676ca05d881ed1fb348628e51ffa8a45d93ae Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Tue, 9 Jul 2024 14:21:43 +0530 Subject: [PATCH 3/6] prettier fix --- src/libs/ReportUtils.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index a8a813ec96f6..4c158715ef54 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5385,7 +5385,7 @@ function shouldAdminsRoomBeVisible(report: OnyxEntry): boolean { if (ReportActionsUtils.isCreatedAction(lastVisibleAction) && adminAccounts.length <= 1) { return false; } - return true; + return true; } /** @@ -5495,7 +5495,7 @@ function shouldReportBeInOptionList({ } // Show #admins room only when it has some value to the user. - if(isAdminRoom(report) && !shouldAdminsRoomBeVisible(report)) { + if (isAdminRoom(report) && !shouldAdminsRoomBeVisible(report)) { return false; } From a1aeb5f6891cd31fb16724a4eb8e86673cb6ee9b Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Fri, 12 Jul 2024 16:07:55 +0530 Subject: [PATCH 4/6] prevent default pinned #admin rooms on workspace creation --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 3fdf7539cc97..ce6d138ea9b6 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -4640,7 +4640,7 @@ function buildOptimisticChatReport( type: CONST.REPORT.TYPE.CHAT, chatType, isOwnPolicyExpenseChat, - isPinned: reportName === CONST.REPORT.WORKSPACE_CHAT_ROOMS.ADMINS || isNewlyCreatedWorkspaceChat, + isPinned: isNewlyCreatedWorkspaceChat, lastActorAccountID: 0, lastMessageTranslationKey: '', lastMessageHtml: '', From 1732f77a7e99a29832645e074aa449f8932df745 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Mon, 15 Jul 2024 20:28:51 +0530 Subject: [PATCH 5/6] fallback to report lastActionType --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index ce6d138ea9b6..b5776f18fae0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5415,7 +5415,7 @@ function shouldAdminsRoomBeVisible(report: OnyxEntry): boolean { const accountIDs = Object.entries(report?.participants ?? {}).map(([accountID]) => Number(accountID)); const adminAccounts = PersonalDetailsUtils.getLoginsByAccountIDs(accountIDs).filter((login) => !PolicyUtils.isExpensifyTeam(login)); const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(report?.reportID ?? ''); - if (ReportActionsUtils.isCreatedAction(lastVisibleAction) && adminAccounts.length <= 1) { + if ((ReportActionsUtils.isCreatedAction(lastVisibleAction) || report?.lastActionType === CONST.REPORT.ACTIONS.TYPE.CREATED) && adminAccounts.length <= 1) { return false; } return true; From 3008ee0910e3d312faf71a164fdf9afa2526c0b6 Mon Sep 17 00:00:00 2001 From: Roji Philip Date: Tue, 23 Jul 2024 10:08:22 +0530 Subject: [PATCH 6/6] check lastActionType only when lastVisibleAction is undefined --- src/libs/ReportUtils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index d08de5230953..655cb6600fd0 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -5433,7 +5433,7 @@ function shouldAdminsRoomBeVisible(report: OnyxEntry): boolean { const accountIDs = Object.entries(report?.participants ?? {}).map(([accountID]) => Number(accountID)); const adminAccounts = PersonalDetailsUtils.getLoginsByAccountIDs(accountIDs).filter((login) => !PolicyUtils.isExpensifyTeam(login)); const lastVisibleAction = ReportActionsUtils.getLastVisibleAction(report?.reportID ?? ''); - if ((ReportActionsUtils.isCreatedAction(lastVisibleAction) || report?.lastActionType === CONST.REPORT.ACTIONS.TYPE.CREATED) && adminAccounts.length <= 1) { + if ((lastVisibleAction ? ReportActionsUtils.isCreatedAction(lastVisibleAction) : report?.lastActionType === CONST.REPORT.ACTIONS.TYPE.CREATED) && adminAccounts.length <= 1) { return false; } return true;