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

fix: update assign checker permission #2521

Merged
merged 1 commit into from
Aug 5, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type Props = {
handleReviewerAssigned: () => void;
loading?: boolean;
tasks: CourseTaskDto[];
isManager: boolean;
};

export default function MentorReviewsTable({
Expand All @@ -20,6 +21,7 @@ export default function MentorReviewsTable({
handleReviewerAssigned,
loading,
tasks,
isManager,
}: Props) {
const [modalData, setModalData] = useState<MentorReviewDto | null>(null);

Expand All @@ -32,7 +34,7 @@ export default function MentorReviewsTable({
showHeader
dataSource={content}
size="small"
columns={getColumns(tasks, handleClick)}
columns={getColumns(tasks, handleClick, isManager)}
onChange={handleChange}
rowKey="id"
pagination={pagination}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,79 +34,84 @@ enum ColumnName {
export const getColumns = (
tasks: CourseTaskDto[],
handleClick: (review: MentorReviewDto) => void,
): ColumnsType<MentorReviewDto> => [
{
key: ColumnKey.TaskName,
title: ColumnName.TaskName,
dataIndex: ColumnKey.TaskName,
width: '15%',
render: (taskName, review) => renderTask(taskName, review.taskDescriptionUrl),
filters: tasks.map(task => ({ text: task.name, value: task.id })),
},
{
key: ColumnKey.Student,
title: ColumnName.Student,
dataIndex: ColumnKey.Student,
width: '12.5%',
render: (_v, review) => <GithubUserLink value={review.student} />,
...getSearchProps(ColumnKey.Student),
},
{
key: ColumnKey.SubmittedDate,
title: ColumnName.SubmittedDate,
dataIndex: ColumnKey.SubmittedDate,
width: '12.5%',
sorter: true,
render: (_v, review) => dateTimeRenderer(review.submittedAt),
},
{
key: ColumnKey.SubmittedLink,
title: ColumnName.SubmittedLink,
dataIndex: ColumnKey.SubmittedLink,
width: '12.5%',
render: solutionUrl => (
<a target="_blank" href={solutionUrl}>
{stringTrimRenderer(solutionUrl)}
</a>
),
},
{
key: ColumnKey.Checker,
title: ColumnName.Checker,
dataIndex: ColumnKey.Checker,
width: '12.5%',
render: checker => (checker ? <GithubUserLink value={checker} /> : null),
},
{
key: ColumnKey.ReviewedDate,
title: ColumnName.ReviewedDate,
dataIndex: ColumnKey.ReviewedDate,
width: '12.5%',
sorter: true,
render: (_v, review) => dateTimeRenderer(review.reviewedAt),
},
{
align: 'right',
key: ColumnKey.Score,
title: ColumnName.Score,
dataIndex: ColumnKey.Score,
width: '10%',
render: (_v, review) => (
<>
{review.score ?? 0} / {review.maxScore}
</>
),
},
{
align: 'center',
key: ColumnKey.Actions,
title: ColumnName.Actions,
dataIndex: ColumnKey.Actions,
width: '12.5%',
render: (_v, review) => (
<Button type="link" onClick={() => handleClick(review)} disabled={!!review.score}>
Assign Reviewer
</Button>
),
},
];
isManager: boolean,
): ColumnsType<MentorReviewDto> => {
const columns: ColumnsType<MentorReviewDto> = [
{
key: ColumnKey.TaskName,
title: ColumnName.TaskName,
dataIndex: ColumnKey.TaskName,
width: '15%',
render: (taskName, review) => renderTask(taskName, review.taskDescriptionUrl),
filters: tasks.map(task => ({ text: task.name, value: task.id })),
},
{
key: ColumnKey.Student,
title: ColumnName.Student,
dataIndex: ColumnKey.Student,
width: '12.5%',
render: (_v, review) => <GithubUserLink value={review.student} />,
...getSearchProps(ColumnKey.Student),
},
{
key: ColumnKey.SubmittedDate,
title: ColumnName.SubmittedDate,
dataIndex: ColumnKey.SubmittedDate,
width: '12.5%',
sorter: true,
render: (_v, review) => dateTimeRenderer(review.submittedAt),
},
{
key: ColumnKey.SubmittedLink,
title: ColumnName.SubmittedLink,
dataIndex: ColumnKey.SubmittedLink,
width: '12.5%',
render: solutionUrl => (
<a target="_blank" href={solutionUrl}>
{stringTrimRenderer(solutionUrl)}
</a>
),
},
{
key: ColumnKey.Checker,
title: ColumnName.Checker,
dataIndex: ColumnKey.Checker,
width: '12.5%',
render: checker => (checker ? <GithubUserLink value={checker} /> : null),
},
{
key: ColumnKey.ReviewedDate,
title: ColumnName.ReviewedDate,
dataIndex: ColumnKey.ReviewedDate,
width: '12.5%',
sorter: true,
render: (_v, review) => dateTimeRenderer(review.reviewedAt),
},
{
align: 'right',
key: ColumnKey.Score,
title: ColumnName.Score,
dataIndex: ColumnKey.Score,
width: '10%',
render: (_v, review) => (
<>
{review.score ?? 0} / {review.maxScore}
</>
),
},
{
align: 'center',
key: ColumnKey.Actions,
title: ColumnName.Actions,
dataIndex: ColumnKey.Actions,
width: '12.5%',
render: (_v, review) => (
<Button type="link" onClick={() => handleClick(review)} disabled={!!review.score}>
Assign Reviewer
</Button>
),
},
];

return isManager ? columns : columns.filter(column => column.key !== ColumnKey.Actions);
};
11 changes: 8 additions & 3 deletions client/src/modules/MentorTasksReview/pages/MentorTasksReview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ import { MentorReviewDto, MentorReviewsApi } from 'api';
import { IPaginationInfo } from 'common/types/pagination';
import { AdminPageLayout } from 'components/PageLayout';
import { useLoading } from 'components/useLoading';
import { useActiveCourseContext } from 'modules/Course/contexts';
import { useState } from 'react';
import { SessionContext, useActiveCourseContext } from 'modules/Course/contexts';
import { useContext, useMemo, useState } from 'react';
import { useAsync } from 'react-use';
import type { PageProps } from './getServerSideProps';
import MentorReviewsTable from '../components/ReviewsTable';
import { FilterValue } from 'antd/es/table/interface';
import { ColumnKey } from '../components/ReviewsTable/renderers';
import { SorterResult } from 'antd/lib/table/interface';
import { sortDirectionMap } from './MentorTasksReview.constants';
import { isCourseManager } from 'domain/user';

const { Text } = Typography;

Expand All @@ -24,6 +25,9 @@ type ReviewsState = {

export const MentorTasksReview = ({ tasks }: PageProps) => {
const { courses, course } = useActiveCourseContext();
const session = useContext(SessionContext);

const isManager = useMemo(() => isCourseManager(session, course.id), [session, course.id]);

const [reviews, setReviews] = useState<ReviewsState>({
content: [],
Expand Down Expand Up @@ -71,14 +75,15 @@ export const MentorTasksReview = ({ tasks }: PageProps) => {
<Text strong>Submitted tasks</Text>
<Text>{course.name}</Text>
</Space>
<Text type="secondary">You can assign a checker for the student’s task</Text>
{isManager && <Text type="secondary">You can assign a checker for the student’s task</Text>}
</Space>
<MentorReviewsTable
content={reviews.content}
pagination={reviews.pagination}
handleChange={getMentorReviews}
handleReviewerAssigned={handleReviewerAssigned}
tasks={tasks}
isManager={isManager}
/>
</AdminPageLayout>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ export class MentorReviewsController {
@Post('/')
@ApiOperation({ operationId: 'assignReviewer' })
@ApiOkResponse({})
@RequiredRoles([CourseRole.Dementor, CourseRole.Manager, Role.Admin], true)
public async assignReviewer(@Param('courseId', ParseIntPipe) courseId: number, @Body() dto: MentorReviewAssignDto) {
@RequiredRoles([CourseRole.Manager, Role.Admin], true)
public async assignReviewer(@Param('courseId', ParseIntPipe) _courseId: number, @Body() dto: MentorReviewAssignDto) {
return await this.mentorReviewsService.assignReviewer(dto);
}
}
Loading