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(be): check if admin when get submissions #2086

Closed
wants to merge 2 commits into from
Closed
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
10 changes: 8 additions & 2 deletions apps/backend/apps/client/src/submission/submission.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ import {
Headers
} from '@nestjs/common'
import { Prisma } from '@prisma/client'
import { AuthNotNeededIfOpenSpace, AuthenticatedRequest } from '@libs/auth'
import {
AuthenticatedRequest,
UserNullWhenAuthFailedIfOpenSpace
} from '@libs/auth'
import {
ConflictFoundException,
EntityNotExistException,
Expand Down Expand Up @@ -94,8 +97,9 @@ export class SubmissionController {
}

@Get()
@AuthNotNeededIfOpenSpace()
@UserNullWhenAuthFailedIfOpenSpace()
async getSubmissions(
@Req() req: AuthenticatedRequest,
@Query('cursor', CursorValidationPipe) cursor: number | null,
@Query('take', new DefaultValuePipe(10), new RequiredIntPipe('take'))
take: number,
Expand All @@ -104,6 +108,7 @@ export class SubmissionController {
) {
try {
return await this.submissionService.getSubmissions({
userRole: req.user?.role,
cursor,
take,
problemId,
Expand Down Expand Up @@ -173,6 +178,7 @@ export class ContestSubmissionController {
) {
try {
return await this.submissionService.getContestSubmissions({
userRole: req.user.role,
cursor,
take,
problemId,
Expand Down
29 changes: 15 additions & 14 deletions apps/backend/apps/client/src/submission/submission.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -320,27 +320,31 @@ export class SubmissionService {
// FIXME: Workbook 구분
@Span()
async getSubmissions({
userRole,
problemId,
groupId = OPEN_SPACE_ID,
cursor = null,
take = 10
}: {
userRole?: Role
problemId: number
groupId?: number
cursor?: number | null
take?: number
}) {
const paginator = this.prisma.getPaginator(cursor)

await this.prisma.problem.findFirstOrThrow({
where: {
id: problemId,
groupId,
visibleLockTime: {
equals: MIN_DATE
if (!(userRole === 'Admin' || userRole === 'SuperAdmin')) {
await this.prisma.problem.findFirstOrThrow({
where: {
id: problemId,
groupId,
visibleLockTime: {
equals: MIN_DATE
}
}
}
})
})
}

const submissions = await this.prisma.submission.findMany({
...paginator,
Expand Down Expand Up @@ -515,13 +519,15 @@ export class SubmissionService {

@Span()
async getContestSubmissions({
userRole,
problemId,
contestId,
userId,
groupId = OPEN_SPACE_ID,
cursor = null,
take = 10
}: {
userRole: Role
problemId: number
contestId: number
userId: number
Expand All @@ -531,12 +537,7 @@ export class SubmissionService {
}) {
const paginator = this.prisma.getPaginator(cursor)

const isAdmin = await this.prisma.user.findFirst({
where: {
id: userId,
role: 'Admin'
}
})
const isAdmin = userRole === 'Admin' || userRole === 'SuperAdmin'

if (!isAdmin) {
await this.prisma.contestRecord.findUniqueOrThrow({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -530,6 +530,7 @@ describe('SubmissionService', () => {

expect(
await service.getContestSubmissions({
userRole: 'Admin',
problemId: problems[0].id,
contestId: 1,
userId: submissions[0].userId
Expand All @@ -545,6 +546,7 @@ describe('SubmissionService', () => {

await expect(
service.getContestSubmissions({
userRole: 'User',
problemId: problems[0].id,
contestId: 1,
userId: submissions[0].userId
Expand All @@ -560,6 +562,7 @@ describe('SubmissionService', () => {

await expect(
service.getContestSubmissions({
userRole: 'Admin',
problemId: problems[0].id,
contestId: 1,
userId: submissions[0].userId
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
meta {
name: Succeed
name: Succeed(Admin)
type: http
seq: 1
}
Expand Down
27 changes: 27 additions & 0 deletions collection/client/Auth/Log In/Succeed(User).bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
meta {
name: Succeed(User)
type: http
seq: 5
}

post {
url: {{baseUrl}}/auth/login
body: json
auth: none
}

body:json {
{
"username": "user01",
"password": "Useruser"
}
}

vars:post-response {
jwtToken: res.headers.authorization
}

assert {
res.status: eq 201
res.headers.authorization: contains Bearer
}
Loading