Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out read only report from share log options #56398

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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