Skip to content

Commit

Permalink
Merge pull request #30019 from Expensify/puneet-expensify-owner
Browse files Browse the repository at this point in the history
Allow requesting money when expensify account owns workspace
  • Loading branch information
grgia authored Nov 1, 2023
2 parents 26c2752 + 70a10f7 commit b57460d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 19 deletions.
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));
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 @@ -3638,15 +3655,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
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 @@ -4135,6 +4153,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

0 comments on commit b57460d

Please sign in to comment.