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

Fix/31863: Don't allow member to edit task in room #32165

Merged
merged 10 commits into from
Dec 15, 2023
Merged
Changes from 4 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
15 changes: 14 additions & 1 deletion src/libs/actions/Task.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ Onyx.connect({
callback: (val) => (allPersonalDetails = val),
});

let allPolicies;
Onyx.connect({
key: ONYXKEYS.COLLECTION.POLICY,
waitForCollectionCallback: true,
callback: (val) => (allPolicies = val),
});

DylanDylann marked this conversation as resolved.
Show resolved Hide resolved
/**
* Clears out the task info from the store
*/
Expand Down Expand Up @@ -877,10 +884,16 @@ function canModifyTask(taskReport, sessionAccountID) {
return true;
}

const parentReport = ReportUtils.getParentReport(taskReport);
const policy = allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${parentReport.policyID}`];

if ((ReportUtils.isChatRoom(parentReport) || ReportUtils.isPolicyExpenseChat(parentReport)) && lodashGet(policy, 'role', '') !== CONST.POLICY.ROLE.ADMIN) {
return false;
}

// If you don't have access to the task report (maybe haven't opened it yet), check if you can access the parent report
// - If the parent report is an #admins only room
// - If you are a policy admin
const parentReport = ReportUtils.getParentReport(taskReport);
return ReportUtils.isAllowedToComment(parentReport);
}

Expand Down