Skip to content

Commit

Permalink
Merge pull request #56398 from bernhardoj/fix/55012-filter-out-read-o…
Browse files Browse the repository at this point in the history
…nly-report-from-share-log-options

Filter out read only report from share log options
  • Loading branch information
luacmartins authored Feb 10, 2025
2 parents bf22ce9 + 09d06bd commit 153e884
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ type GetValidReportsConfig = {
includeMoneyRequests?: boolean;
includeInvoiceRooms?: boolean;
includeDomainEmail?: boolean;
includeReadOnly?: boolean;
loginsToExclude?: Record<string, boolean>;
shouldSeparateWorkspaceChat?: boolean;
shouldSeparateSelfDMChat?: boolean;
Expand Down Expand Up @@ -1273,6 +1274,7 @@ function getValidReports(reports: OptionList['reports'], config: GetValidReports
includeThreads = false,
includeTasks = false,
includeMoneyRequests = false,
includeReadOnly = true,
transactionViolations = {},
includeSelfDM = false,
includeInvoiceRooms = false,
Expand Down Expand Up @@ -1348,6 +1350,10 @@ function getValidReports(reports: OptionList['reports'], config: GetValidReports
continue;
}

if (!canUserPerformWriteAction(report) && !includeReadOnly) {
continue;
}

// In case user needs to add credit bank account, don't allow them to submit an expense from the workspace.
if (includeOwnedWorkspaceChats && hasIOUWaitingOnCurrentUserBankAccount(report)) {
continue;
Expand Down Expand Up @@ -1597,6 +1603,7 @@ function getShareLogOptions(options: OptionList, betas: Beta[] = []): Options {
includeOwnedWorkspaceChats: true,
includeSelfDM: true,
includeThreads: true,
includeReadOnly: false,
});
}

Expand Down
14 changes: 14 additions & 0 deletions tests/unit/OptionsListUtilsTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -735,6 +735,20 @@ describe('OptionsListUtils', () => {
expect(results.recentReports.length).toBe(Object.values(OPTIONS_WITH_WORKSPACE_ROOM.reports).length - 1);
});

describe('getShareLogOptions', () => {
it('should not include read-only report', () => {
// Given a list of 11 report options with reportID of 10 is archived
// OPTIONS, defined above

// When getting the share log options
const results = OptionsListUtils.getShareLogOptions(OPTIONS, []);

// Then the report with reportID of 10 should not be included on the list
expect(results.recentReports.length).toBe(10);
expect(results.recentReports.find((report) => report.reportID === '10')).toBeUndefined();
});
});

it('getMemberInviteOptions()', () => {
// When we only pass personal details
const results = OptionsListUtils.getMemberInviteOptions(OPTIONS.personalDetails, []);
Expand Down

0 comments on commit 153e884

Please sign in to comment.