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

Allow requesting money when expensify account owns workspace #30019

Merged
merged 9 commits into from
Nov 1, 2023
51 changes: 35 additions & 16 deletions src/libs/ReportUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,16 @@ function isChatThread(report) {
return isThread(report) && report.type === CONST.REPORT.TYPE.CHAT;
}

/**
* Returns true if report is a DM/Group DM chat.
*
* @param {Object} report
* @returns {Boolean}
*/
function isDM(report) {
return !getChatType(report);
}

/**
* Only returns true if this is our main 1:1 DM report with Concierge
*
Expand Down Expand Up @@ -514,6 +524,23 @@ function isExpensifyOnlyParticipantInReport(report) {
return reportParticipants.length === 1 && _.some(reportParticipants, (accountID) => _.contains(CONST.EXPENSIFY_ACCOUNT_IDS, accountID));
}

/**
* Returns whether a given report can have tasks created in it.
* We only prevent the task option if it's a DM/group-DM and the other users are all special Expensify accounts
*
* @param {Object} report
* @returns {Boolean}
*/
function canCreateTaskInReport(report) {
const otherReportParticipants = _.without(lodashGet(report, 'participantAccountIDs', []), currentUserAccountID);
const areExpensifyAccountsOnlyOtherParticipants = _.every(otherReportParticipants, (accountID) => _.contains(CONST.EXPENSIFY_ACCOUNT_IDS, accountID));
Copy link
Contributor

@chiragsalian chiragsalian Nov 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heads up, i believe the logic here caused this deploy blocker because it does not account for creating a task within an existing task.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing that out! That's a good catch.

if (areExpensifyAccountsOnlyOtherParticipants && isDM(report)) {
return false;
}

return true;
}

/**
* Returns true if there are any Expensify accounts (i.e. with domain 'expensify.com') in the set of accountIDs
* by cross-referencing the accountIDs with personalDetails.
Expand Down Expand Up @@ -646,16 +673,6 @@ function isPolicyAdmin(policyID, policies) {
return policyRole === CONST.POLICY.ROLE.ADMIN;
}

/**
* Returns true if report is a DM/Group DM chat.
*
* @param {Object} report
* @returns {Boolean}
*/
function isDM(report) {
return !getChatType(report);
}

/**
* Returns true if report has a single participant.
*
Expand Down Expand Up @@ -3650,15 +3667,16 @@ function getMoneyRequestOptions(report, reportParticipants) {

const participants = _.filter(reportParticipants, (accountID) => currentUserPersonalDetails.accountID !== accountID);

// Verify if there is any of the expensify accounts amongst the participants in which case user cannot take IOU actions on such report
const hasExcludedIOUAccountIDs = lodashIntersection(reportParticipants, CONST.EXPENSIFY_ACCOUNT_IDS).length > 0;
const hasSingleParticipantInReport = participants.length === 1;
const hasMultipleParticipants = participants.length > 1;

if (hasExcludedIOUAccountIDs) {
// We don't allow IOU actions if an Expensify account is a participant of the report, unless the policy that the report is on is owned by an Expensify account
puneetlath marked this conversation as resolved.
Show resolved Hide resolved
const doParticipantsIncludeExpensifyAccounts = lodashIntersection(reportParticipants, CONST.EXPENSIFY_ACCOUNT_IDS).length > 0;
const isPolicyOwnedByExpensifyAccounts = report.policyID ? CONST.EXPENSIFY_ACCOUNT_IDS.includes(getPolicy(report.policyID).ownerAccountID || 0) : false;
if (doParticipantsIncludeExpensifyAccounts && !isPolicyOwnedByExpensifyAccounts) {
return [];
}

const hasSingleParticipantInReport = participants.length === 1;
const hasMultipleParticipants = participants.length > 1;

// User created policy rooms and default rooms like #admins or #announce will always have the Split Bill option
// unless there are no participants at all (e.g. #admins room for a policy with only 1 admin)
// DM chats will have the Split Bill option only when there are at least 3 people in the chat.
Expand Down Expand Up @@ -4147,6 +4165,7 @@ export {
getPolicyType,
isArchivedRoom,
isExpensifyOnlyParticipantInReport,
canCreateTaskInReport,
isPolicyExpenseChatAdmin,
isPolicyAdmin,
isPublicRoom,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ function AttachmentPickerWithMenuItems({
* @returns {Boolean}
*/
const taskOption = useMemo(() => {
// We only prevent the task option from showing if it's a DM and the other user is an Expensify default email
if (!Permissions.canUseTasks(betas) || ReportUtils.isExpensifyOnlyParticipantInReport(report)) {
if (!Permissions.canUseTasks(betas) || !ReportUtils.canCreateTaskInReport(report)) {
return [];
}

Expand Down
2 changes: 1 addition & 1 deletion src/pages/tasks/TaskShareDestinationSelectorModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function TaskShareDestinationSelectorModal(props) {
_.keys(props.reports).forEach((reportKey) => {
if (
!ReportUtils.canUserPerformWriteAction(props.reports[reportKey]) ||
ReportUtils.isExpensifyOnlyParticipantInReport(props.reports[reportKey]) ||
!ReportUtils.canCreateTaskInReport(props.reports[reportKey]) ||
ReportUtils.isCanceledTaskReport(props.reports[reportKey])
) {
return;
Expand Down
Loading