Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
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);

/**
Comment on lines +199 to 202

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why are we introducing a new check here ?, we already have a util which checks this:

App/src/libs/PolicyUtils.ts

Lines 197 to 201 in 0b3569a

/**
* Checks if the current user is an admin of the policy.
*/
const isPolicyAdmin = (policy: OnyxInputOrEntry<Policy>, currentUserLogin?: string): boolean => getPolicyRole(policy, currentUserLogin) === CONST.POLICY.ROLE.ADMIN;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This will break the checklist check:

I verified all code is DRY (the PR doesn't include any logic written more than once, with the exception of tests)

Unless i am missing something there

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ohh i get it now, the end user in this case, No worries, sorry for the confusion

* 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