diff --git a/src/components/ReportActionItem/TaskView.js b/src/components/ReportActionItem/TaskView.js index 31e984e868e9..215bceb71c69 100644 --- a/src/components/ReportActionItem/TaskView.js +++ b/src/components/ReportActionItem/TaskView.js @@ -17,6 +17,7 @@ import * as PersonalDetailsUtils from '../../libs/PersonalDetailsUtils'; import * as UserUtils from '../../libs/UserUtils'; import * as StyleUtils from '../../styles/StyleUtils'; import * as Task from '../../libs/actions/Task'; +import * as PolicyUtils from '../../libs/PolicyUtils'; import CONST from '../../CONST'; import Checkbox from '../Checkbox'; import convertToLTR from '../../libs/convertToLTR'; @@ -49,7 +50,9 @@ function TaskView(props) { const isOpen = ReportUtils.isOpenTaskReport(props.report); const isCanceled = ReportUtils.isCanceledTaskReport(props.report); const avatarURL = lodashGet(PersonalDetailsUtils.getPersonalDetailsByIDs([props.report.managerID], props.currentUserPersonalDetails.accountID), [0, 'avatar'], ''); - + const policy = ReportUtils.getPolicy(props.report.policyID); + const canEdit = PolicyUtils.isPolicyAdmin(policy) || Task.isTaskAssigneeOrTaskOwner(props.report, props.currentUserPersonalDetails.accountID); + const disableState = !canEdit || !isOpen; return ( [styles.ph5, styles.pv2, StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed, false, !isOpen), true)]} + style={({hovered, pressed}) => [styles.ph5, styles.pv2, StyleUtils.getButtonBackgroundColorStyle(getButtonState(hovered, pressed, false, disableState), true)]} ref={props.forwardedRef} - disabled={!isOpen} + disabled={disableState} accessibilityLabel={taskTitle || props.translate('task.task')} > {({hovered, pressed}) => ( @@ -77,7 +80,7 @@ function TaskView(props) { containerBorderRadius={8} caretSize={16} accessibilityLabel={taskTitle || props.translate('task.task')} - disabled={isCanceled} + disabled={isCanceled || !canEdit} /> )} @@ -105,7 +108,7 @@ function TaskView(props) { title={props.report.description || ''} onPress={() => Navigation.navigate(ROUTES.getTaskReportDescriptionRoute(props.report.reportID))} shouldShowRightIcon={isOpen} - disabled={!isOpen} + disabled={disableState} wrapperStyle={[styles.pv2]} numberOfLinesTitle={3} shouldGreyOutWhenDisabled={false} @@ -120,7 +123,7 @@ function TaskView(props) { titleStyle={styles.assigneeTextStyle} onPress={() => Navigation.navigate(ROUTES.getTaskReportAssigneeRoute(props.report.reportID))} shouldShowRightIcon={isOpen} - disabled={!isOpen} + disabled={disableState} wrapperStyle={[styles.pv2]} isSmallAvatarSubscriptMenu shouldGreyOutWhenDisabled={false} @@ -130,7 +133,7 @@ function TaskView(props) { description={props.translate('task.assignee')} onPress={() => Navigation.navigate(ROUTES.getTaskReportAssigneeRoute(props.report.reportID))} shouldShowRightIcon={isOpen} - disabled={!isOpen} + disabled={disableState} wrapperStyle={[styles.pv2]} shouldGreyOutWhenDisabled={false} /> diff --git a/src/libs/ReportUtils.js b/src/libs/ReportUtils.js index ccb7e79874f0..764699947a97 100644 --- a/src/libs/ReportUtils.js +++ b/src/libs/ReportUtils.js @@ -2576,6 +2576,15 @@ function getReportOfflinePendingActionAndErrors(report) { } /** + * @param {String} policyID + * @returns {Object} + */ +function getPolicy(policyID) { + const policy = lodashGet(allPolicies, `${ONYXKEYS.COLLECTION.POLICY}${policyID}`) || {}; + return policy; +} + +/* * @param {Object|null} report * @param {Object|null} policy - the workspace the report is on, null if the user isn't a member of the workspace * @returns {Boolean} @@ -2702,5 +2711,6 @@ export { getOriginalReportID, canAccessReport, getReportOfflinePendingActionAndErrors, + getPolicy, shouldDisableRename, };