Skip to content
This repository has been archived by the owner on Jan 7, 2025. It is now read-only.

Commit

Permalink
Refactored permission service implementations
Browse files Browse the repository at this point in the history
  • Loading branch information
M-Rybalko committed Jan 4, 2024
2 parents 1476195 + 4ca1cfe commit 412998d
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 225 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ const EditingColumn: FC<EditingColumnProps> = ({
<ArrowUpCircleIcon />
);

<<<<<<< HEAD
return (
<>
<Popup
Expand All @@ -113,90 +112,6 @@ const EditingColumn: FC<EditingColumnProps> = ({
color={ButtonColor.PRIMARY}
variant={ButtonVariant.OUTLINE}
onClick={() => setChangePopupOpen(false)}
=======
if (
permissions[PERMISSION.GROUPS_$GROUPID_STUDENTS_REMOVE] &&
permissions[PERMISSION.GROUPS_$GROUPID_TRANSFER] &&
student.role !== UserGroupRole.CAPTAIN
) {
return (
<>
<Popup
icon={<CheckCircleIcon />}
open={changePopupOpen}
title={
student.role === UserGroupRole.MODERATOR
? 'Зробити студентом'
: 'Зробити заст. старости'
}
content={`Ти дійсно бажаєш зробити ${student.fullName} ${
student.role === UserGroupRole.MODERATOR
? 'студентом'
: 'заст. старости'
}?`}
onClose={() => setChangePopupOpen(false)}
firstButton={
<Button
size={ButtonSize.SMALL}
text="Скасувати"
color={ButtonColor.PRIMARY}
variant={ButtonVariant.OUTLINE}
onClick={() => setChangePopupOpen(false)}
/>
}
secondButton={
<Button
size={ButtonSize.SMALL}
text="Так"
color={ButtonColor.PRIMARY}
variant={ButtonVariant.FILLED}
onClick={handleChangeStatus}
/>
}
/>
<Popup
icon={<TrashIcon />}
open={deletePopupOpen}
title="Видалити користувача"
content={`Чи дійсно ти бажаєш видалити користувача ${student.fullName}? Якщо ти випадково видалиш користувача, йому треба буде відправити повторний запит до групи.`}
onClose={() => setDeletePopupOpen(false)}
firstButton={
<Button
size={ButtonSize.SMALL}
text="Скасувати"
color={ButtonColor.PRIMARY}
variant={ButtonVariant.TEXT}
onClick={() => setDeletePopupOpen(false)}
/>
}
secondButton={
<AlertButton
text="Видалити"
variant={AlertButtonVariant.ERROR_OUTLINE}
onClick={handleDelete}
/>
}
/>
{(student.role === UserGroupRole.STUDENT ||
student.role === UserGroupRole.MODERATOR) &&
!isMobile && (
<Button
text={buttonText}
sx={{ width: 'fit-content', whiteSpace: 'nowrap' }}
size={ButtonSize.SMALL}
variant={ButtonVariant.OUTLINE}
startIcon={buttonIcon}
onClick={() => setChangePopupOpen(true)}
/>
)}
{isMobile ? (
<MobileDropdown
arrowIcon={buttonIcon}
setDeletePopupOpen={setDeletePopupOpen}
setChangePopupOpen={setChangePopupOpen}
permissions={permissions}
student={student}
>>>>>>> a8b03e1c50771667c0cee7264a4a0dc0018e13cd
/>
}
secondButton={
Expand Down Expand Up @@ -245,7 +160,6 @@ const EditingColumn: FC<EditingColumnProps> = ({
onClick={() => setChangePopupOpen(true)}
/>
)}
<<<<<<< HEAD
{isMobile ? (
<MobileDropdown
arrowIcon={buttonIcon}
Expand Down Expand Up @@ -278,116 +192,6 @@ const EditingColumn: FC<EditingColumnProps> = ({
)}
</>
);
=======
</>
);
}

if (
permissions[PERMISSION.GROUPS_$GROUPID_STUDENTS_REMOVE] &&
!permissions[PERMISSION.GROUPS_$GROUPID_TRANSFER] &&
student.role === UserGroupRole.STUDENT
) {
return (
<>
<Popup
open={deletePopupOpen}
hasCross
title="Видалити користувача"
content={`Чи дійсно ти бажаєш видалити користувача ${student.fullName}? Якщо ти випадково видалиш користувача, йому треба буде відправити повторний запит до групи.`}
onClose={() => setDeletePopupOpen(false)}
firstButton={
<Button
size={ButtonSize.SMALL}
text="Скасувати"
color={ButtonColor.PRIMARY}
variant={ButtonVariant.OUTLINE}
onClick={() => setDeletePopupOpen(false)}
/>
}
secondButton={
<Button
size={ButtonSize.SMALL}
text="Так"
color={ButtonColor.PRIMARY}
variant={ButtonVariant.FILLED}
onClick={handleDelete}
/>
}
/>
{isMobile ? (
<MobileDropdown
arrowIcon={buttonIcon}
setDeletePopupOpen={setDeletePopupOpen}
setChangePopupOpen={setChangePopupOpen}
permissions={permissions}
student={student}
/>
) : (
<IconButton
onClick={() => setDeletePopupOpen(true)}
icon={<TrashIcon />}
shape={IconButtonShape.CIRCLE}
color={IconButtonColor.SECONDARY}
/>
)}
</>
);
}
return <Fragment></Fragment>;
>>>>>>> a8b03e1c50771667c0cee7264a4a0dc0018e13cd
};

// if (
// permissions[PERMISSION.GROUPS_$GROUPID_STUDENTS_REMOVE] &&
// !permissions[PERMISSION.GROUPS_$GROUPID_ADMIN_SWITCH] &&
// student.role === UserGroupRole.STUDENT
// ) {
// return (
// <>
// <Popup
// open={deletePopupOpen}
// hasCross
// title="Видалити користувача"
// content={`Чи дійсно ти бажаєш видалити користувача ${student.fullName}? Якщо ти випадково видалиш користувача, йому треба буде відправити повторний запит до групи.`}
// onClose={() => setDeletePopupOpen(false)}
// firstButton={
// <Button
// size={ButtonSize.SMALL}
// text="Скасувати"
// color={ButtonColor.PRIMARY}
// variant={ButtonVariant.OUTLINE}
// onClick={() => setDeletePopupOpen(false)}
// />
// }
// secondButton={
// <Button
// size={ButtonSize.SMALL}
// text="Так"
// color={ButtonColor.PRIMARY}
// variant={ButtonVariant.FILLED}
// onClick={handleDelete}
// />
// }
// />
// {isMobile ? (
// <MobileDropdown
// arrowIcon={buttonIcon}
// setDeletePopupOpen={setDeletePopupOpen}
// setChangePopupOpen={setChangePopupOpen}
// permissions={permissions}
// student={student}
// />
// ) : (
// <IconButton
// onClick={() => setDeletePopupOpen(true)}
// icon={<TrashIcon />}
// shape={IconButtonShape.CIRCLE}
// color={IconButtonColor.SECONDARY}
// />
// )}
// </>
// );
// }

export default EditingColumn;
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
import IconButton from '@/components/common/ui/icon-button-mui/IconButton';
import { IconButtonColor } from '@/components/common/ui/icon-button-mui/types';
import roleNamesMapper from '@/components/pages/account-page/components/group-tab/components/table/constants';
import useAuthentication from '@/hooks/use-authentication';
import { PERMISSION, PermissionResponse } from '@/lib/services/permisson/types';
import { UserGroupRole } from '@/types/user';

Expand Down Expand Up @@ -63,13 +62,8 @@ const MobileStudentsTableButtons: FC<MobileStudentTableButtonsProps> = ({
anchorEl={EllipsisIconRef.current}
>
<Stack sx={styles.dropdown}>
<<<<<<< HEAD
{permissions[PERMISSION.GROUPS_$GROUPID_ADMIN_SWITCH] &&
student.role !== UserGroupRole.CAPTAIN && (
=======
{permissions[PERMISSION.GROUPS_$GROUPID_TRANSFER] &&
student.role == UserGroupRole.STUDENT && (
>>>>>>> a8b03e1c50771667c0cee7264a4a0dc0018e13cd
<Button
size={ButtonSize.SMALL}
text={buttonName}
Expand All @@ -79,18 +73,11 @@ const MobileStudentsTableButtons: FC<MobileStudentTableButtonsProps> = ({
/>
)}
{((permissions[PERMISSION.GROUPS_$GROUPID_STUDENTS_REMOVE] &&
<<<<<<< HEAD
permissions[PERMISSION.GROUPS_$GROUPID_ADMIN_SWITCH] &&
student.role !== UserGroupRole.CAPTAIN) ||
(permissions[PERMISSION.GROUPS_$GROUPID_STUDENTS_REMOVE] &&
!permissions[PERMISSION.GROUPS_$GROUPID_ADMIN_SWITCH] &&
student.role === UserGroupRole.STUDENT)) && (
=======
student.role !== UserGroupRole.CAPTAIN) ||
(user.group?.role === UserGroupRole.MODERATOR &&
permissions[PERMISSION.GROUPS_$GROUPID_STUDENTS_REMOVE] &&
student.role == UserGroupRole.STUDENT)) && (
>>>>>>> a8b03e1c50771667c0cee7264a4a0dc0018e13cd
<Button
size={ButtonSize.SMALL}
text={'Видалити'}
Expand Down
16 changes: 0 additions & 16 deletions src/lib/services/permisson/utils/createPermissionRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { PERMISSION, PermissionData } from '../types';
const createPermissionRequest = (values: PermissionData) => {
const permissions: PERMISSION[] = [];
for (const permission of Object.values(PERMISSION)) {
<<<<<<< HEAD
if (permission.includes('$userId') && values.userId) {
permissions.push(permission);
}
Expand All @@ -17,21 +16,6 @@ const createPermissionRequest = (values: PermissionData) => {
permissions.push(permission);
}
if (!permission.includes('$')) {
=======
if (permission.split('.')[1] === '$userId' && values.userId) {
permissions.push(permission);
}
if (permission.split('.')[1] === '$groupId' && values.groupId) {
permissions.push(permission);
}
if (permission.split('.')[1] === '$roleId' && values.roleId) {
permissions.push(permission);
}
if (permission.split('.')[1] === '$teacherId' && values.teacherId) {
permissions.push(permission);
}
if (permission.split('.')[1][0] !== '$') {
>>>>>>> a8b03e1c50771667c0cee7264a4a0dc0018e13cd
permissions.push(permission);
}
}
Expand Down

0 comments on commit 412998d

Please sign in to comment.