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

Prevent removal of admin and default members from workspace chats #43065

Merged
merged 12 commits into from
Jun 14, 2024
5 changes: 3 additions & 2 deletions src/pages/ReportDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
isAnonymousAction: false,
shouldShowRightIcon: true,
action: () => {
if (isUserCreatedPolicyRoom || isChatThread || isPolicyExpenseChat) {
if (isUserCreatedPolicyRoom || isChatThread || (isPolicyExpenseChat && isPolicyAdmin)) {
jasperhuangg marked this conversation as resolved.
Show resolved Hide resolved
Navigation.navigate(ROUTES.ROOM_MEMBERS.getRoute(report?.reportID ?? '-1'));
} else {
Navigation.navigate(ROUTES.REPORT_PARTICIPANTS.getRoute(report?.reportID ?? '-1'));
Expand Down Expand Up @@ -204,7 +204,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
});
}

if (!isThread && (isGroupChat || (isChatRoom && ReportUtils.canLeaveChat(report, policy)))) {
if (!isThread && (isGroupChat || (isChatRoom && ReportUtils.canLeaveChat(report, policy)) || (isPolicyExpenseChat && !isPolicyAdmin))) {
items.push({
key: CONST.REPORT_DETAILS_MENU_ITEM.LEAVE_ROOM,
translationKey: 'common.leave',
Expand Down Expand Up @@ -232,6 +232,7 @@ function ReportDetailsPage({policies, report, session, personalDetails}: ReportD
isChatThread,
isPolicyEmployee,
isPolicyExpenseChat,
isPolicyAdmin,
isUserCreatedPolicyRoom,
participants.length,
report,
Expand Down
6 changes: 5 additions & 1 deletion src/pages/RoomMembersPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ function RoomMembersPage({report, session, policies}: RoomMembersPageProps) {
const [searchValue, setSearchValue] = useState('');
const [didLoadRoomMembers, setDidLoadRoomMembers] = useState(false);
const personalDetails = usePersonalDetails() || CONST.EMPTY_OBJECT;
const policy = useMemo(() => policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID ?? ''}`], [policies, report?.policyID]);
const isPolicyExpenseChat = useMemo(() => ReportUtils.isPolicyExpenseChat(report), [report]);

const isFocusedScreen = useIsFocused();

Expand Down Expand Up @@ -182,12 +184,14 @@ function RoomMembersPage({report, session, 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 isDisabled = (isPolicyExpenseChat && isAdmin) || accountID === session?.accountID || pendingChatMember?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE;
Copy link
Contributor

Choose a reason for hiding this comment

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

Regarding this issue #42928, when determining if the option should be disabled, we should have also checked the workspace chat's ownerAccountID and disable it when account id matches the ownerAccountID.

We fixed this by adding a check details.accountID === report.ownerAccountID;


result.push({
keyForList: String(accountID),
accountID,
isSelected: selectedMembers.includes(accountID),
isDisabled: accountID === session?.accountID || pendingChatMember?.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE,
isDisabled,
text: formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details)),
alternateText: details?.login ? formatPhoneNumber(details.login) : '',
icons: [
Expand Down
Loading