Skip to content

Commit

Permalink
Merge pull request #50870 from dominictb/fix/50771
Browse files Browse the repository at this point in the history
fix: workspace member is removable when he is the report owner
  • Loading branch information
marcaaron authored Oct 16, 2024
2 parents 6e0dd34 + 93c573b commit d03e796
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/libs/PolicyUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ function isExpensifyTeam(email: string | undefined): boolean {
return emailDomain === CONST.EXPENSIFY_PARTNER_NAME || emailDomain === CONST.EMAIL.GUIDES_DOMAIN;
}

/**
* Checks if the user with login is an admin of the policy.
*/
const isUserPolicyAdmin = (policy: OnyxInputOrEntry<Policy>, login?: string) => !!(policy && policy.employeeList && login && policy.employeeList[login]?.role === CONST.POLICY.ROLE.ADMIN);

/**
* Checks if the current user is an admin of the policy.
*/
Expand Down Expand Up @@ -1088,6 +1093,7 @@ export {
getCorrectedAutoReportingFrequency,
isPaidGroupPolicy,
isPendingDeletePolicy,
isUserPolicyAdmin,
isPolicyAdmin,
isPolicyUser,
isPolicyAuditor,
Expand Down
8 changes: 7 additions & 1 deletion src/pages/RoomMemberDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,13 @@ import ScreenWrapper from '@components/ScreenWrapper';
import Text from '@components/Text';
import useCurrentUserPersonalDetails from '@hooks/useCurrentUserPersonalDetails';
import useLocalize from '@hooks/useLocalize';
import usePolicy from '@hooks/usePolicy';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import * as Report from '@libs/actions/Report';
import type {RoomMembersNavigatorParamList} from '@libs/Navigation/types';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import Navigation from '@navigation/Navigation';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
Expand All @@ -34,6 +37,7 @@ function RoomMemberDetailsPage({report, route}: RoomMemberDetailsPagePageProps)
const StyleUtils = useStyleUtils();
const currentUserPersonalDetails = useCurrentUserPersonalDetails();
const [personalDetails] = useOnyx(ONYXKEYS.PERSONAL_DETAILS_LIST);
const policy = usePolicy(report?.policyID);

const [isRemoveMemberConfirmModalVisible, setIsRemoveMemberConfirmModalVisible] = React.useState(false);

Expand All @@ -45,6 +49,8 @@ function RoomMemberDetailsPage({report, route}: RoomMemberDetailsPagePageProps)
const fallbackIcon = details.fallbackIcon ?? '';
const displayName = details.displayName ?? '';
const isSelectedMemberCurrentUser = accountID === currentUserPersonalDetails?.accountID;
const isSelectedMemberOwner = accountID === report.ownerAccountID;
const shouldDisableRemoveUser = (ReportUtils.isPolicyExpenseChat(report) && PolicyUtils.isUserPolicyAdmin(policy, details.login)) || isSelectedMemberCurrentUser || isSelectedMemberOwner;
const removeUser = useCallback(() => {
setIsRemoveMemberConfirmModalVisible(false);
Report.removeFromRoom(report?.reportID, [accountID]);
Expand Down Expand Up @@ -88,7 +94,7 @@ function RoomMemberDetailsPage({report, route}: RoomMemberDetailsPagePageProps)
<Button
text={translate('workspace.people.removeRoomMemberButtonTitle')}
onPress={() => setIsRemoveMemberConfirmModalVisible(true)}
isDisabled={isSelectedMemberCurrentUser}
isDisabled={shouldDisableRemoveUser}
icon={Expensicons.RemoveMembers}
iconStyles={StyleUtils.getTransformScaleStyle(0.8)}
style={styles.mv5}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/RoomMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ function RoomMembersPage({report, policies}: RoomMembersPageProps) {
return;
}
const pendingChatMember = report?.pendingChatMembers?.findLast((member) => member.accountID === accountID.toString());
const isAdmin = !!(policy && policy.employeeList && details.login && policy.employeeList[details.login]?.role === CONST.POLICY.ROLE.ADMIN);
const isAdmin = PolicyUtils.isUserPolicyAdmin(policy, details.login);
const isDisabled = pendingChatMember?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || details.isOptimisticPersonalDetail;
const isDisabledCheckbox =
(isPolicyExpenseChat && isAdmin) ||
Expand Down

0 comments on commit d03e796

Please sign in to comment.