Skip to content

Commit

Permalink
Merge pull request #45048 from rojiphil/36236-show-admins-only-when-r…
Browse files Browse the repository at this point in the history
…equired
  • Loading branch information
francoisl authored Jul 23, 2024
2 parents 4ba10bf + 3008ee0 commit 8cde16f
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4655,7 +4655,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: '',
Expand Down Expand Up @@ -5425,6 +5425,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<Report>): 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 ((lastVisibleAction ? ReportActionsUtils.isCreatedAction(lastVisibleAction) : report?.lastActionType === CONST.REPORT.ACTIONS.TYPE.CREATED) && 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).
Expand Down Expand Up @@ -5537,6 +5551,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) {
Expand Down

0 comments on commit 8cde16f

Please sign in to comment.