Skip to content

Commit f7e31ed

Browse files
authored
Merge pull request #362 from qa-guru/QAGDEV-689
QAGDEV-689 - Дать возможность администратору менять статус ДЗ у студента
2 parents 18e0aa4 + b32da43 commit f7e31ed

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

src/features/kanban/views/homework-details-full/homework-details-full.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import Homework from "shared/features/homework/view";
88
import StatusText from "shared/components/status-text";
99
import HomeworkBaseInfo from "shared/components/homework-base-info";
1010
import { formatId } from "shared/helpers";
11+
import { useRoleAccess } from "shared/hooks";
12+
import { UserRole } from "api/graphql/generated/graphql";
1113

1214
import StatusSelect from "../../views/status-select";
1315
import { IHomeworkDescriptionFull } from "./homework-details-full.types";
@@ -27,10 +29,14 @@ const HomeworkDetailsFull: FC<IHomeworkDescriptionFull> = ({ data }) => {
2729
id,
2830
} = data?.homeWork!;
2931

32+
const hasAdminRoleAcces = useRoleAccess({
33+
allowedRoles: [UserRole.Admin],
34+
});
35+
3036
const currentUserId = useReactiveVar(userIdVar);
3137
const isCurrentMentor = currentUserId === mentor?.id;
3238
const hasNoMentor = mentor?.id === undefined;
33-
const showSelect = isCurrentMentor || hasNoMentor;
39+
const showSelect = hasAdminRoleAcces || isCurrentMentor || hasNoMentor;
3440

3541
return (
3642
<Container>

src/shared/helpers/get-updated-allowed-columns.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ export const getUpdatedAllowedColumns = (
1616
allowedRoles: [UserRole.Mentor, UserRole.Lector, UserRole.Admin],
1717
});
1818

19+
const hasAdminRoleAcces = useRoleAccess({
20+
allowedRoles: [UserRole.Admin],
21+
});
22+
1923
if (!hasDraggAccess) {
2024
return [];
2125
}
@@ -27,17 +31,17 @@ export const getUpdatedAllowedColumns = (
2731
allowedColumns = [STATUS_COLUMN.IN_REVIEW];
2832
break;
2933
case STATUS_COLUMN.IN_REVIEW:
30-
if (currentUserId === mentorId) {
34+
if (hasAdminRoleAcces || currentUserId === mentorId) {
3135
allowedColumns = [STATUS_COLUMN.APPROVED, STATUS_COLUMN.NOT_APPROVED];
3236
}
3337
break;
3438
case STATUS_COLUMN.APPROVED:
35-
if (currentUserId === mentorId) {
39+
if (hasAdminRoleAcces || currentUserId === mentorId) {
3640
allowedColumns = [];
3741
}
3842
break;
3943
case STATUS_COLUMN.NOT_APPROVED:
40-
if (currentUserId === mentorId) {
44+
if (hasAdminRoleAcces || currentUserId === mentorId) {
4145
allowedColumns = [STATUS_COLUMN.APPROVED];
4246
}
4347
break;

src/shared/hooks/use-drag-effect.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export const useDragEffect = ({
3232
allowedRoles: [UserRole.Mentor, UserRole.Lector, UserRole.Admin],
3333
});
3434

35+
const hasAdminRoleAcces = useRoleAccess({
36+
allowedRoles: [UserRole.Admin],
37+
});
38+
3539
const currentUserId = useReactiveVar(userIdVar);
3640
const mentorId = card.mentor?.id;
3741

@@ -54,7 +58,11 @@ export const useDragEffect = ({
5458
return;
5559
}
5660

57-
if (currentUserId !== mentorId && (isFromInReview || isFromNotApproved)) {
61+
if (
62+
!hasAdminRoleAcces &&
63+
currentUserId !== mentorId &&
64+
(isFromInReview || isFromNotApproved)
65+
) {
5866
enqueueSnackbar("Вы не можете поменять статус чужой домашней работы");
5967
return;
6068
}
@@ -76,5 +84,6 @@ export const useDragEffect = ({
7684
mentorId,
7785
enqueueSnackbar,
7886
setDraggingState,
87+
hasAdminRoleAcces,
7988
]);
8089
};

0 commit comments

Comments
 (0)