-
Notifications
You must be signed in to change notification settings - Fork 16
feat(be): fix unauthorized access to course management pages #3576
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
Open
Choi-Jung-Hyeon
wants to merge
6
commits into
main
Choose a base branch
from
t2716-management-url-access
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
12fbf8b
feat(fe): implement server side course authorization
Choi-Jung-Hyeon 74d5aaa
refactor(be): throw ForbiddenException instead of returning false in …
Choi-Jung-Hyeon 919121e
refactor(be): migrate course detail layout
Choi-Jung-Hyeon 3bfd582
refactor(fe): qna components and implement new features
Choi-Jung-Hyeon d936f3b
Merge branch 'main' into t2716-management-url-access
Choi-Jung-Hyeon cd9891c
fix(fe): resolve broken merge conflict in course layout
Choi-Jung-Hyeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "features": { | ||
| "ghcr.io/devcontainers-extra/features/pnpm:2": { | ||
| "version": "2.0.5", | ||
| "resolved": "ghcr.io/devcontainers-extra/features/pnpm@sha256:694c2b6182435c9e9c06f6071728b087c1181b38c18cecf0defe2ab8c11cddd6", | ||
| "integrity": "sha256:694c2b6182435c9e9c06f6071728b087c1181b38c18cecf0defe2ab8c11cddd6" | ||
| }, | ||
| "ghcr.io/devcontainers/features/go:1": { | ||
| "version": "1.3.4", | ||
| "resolved": "ghcr.io/devcontainers/features/go@sha256:d85e921f91b41340055bb12b325d9d551170ed04b3b832e33530bf42f167c032", | ||
| "integrity": "sha256:d85e921f91b41340055bb12b325d9d551170ed04b3b832e33530bf42f167c032" | ||
| }, | ||
| "ghcr.io/devcontainers/features/java:1": { | ||
| "version": "1.8.0", | ||
| "resolved": "ghcr.io/devcontainers/features/java@sha256:9663ce0219ff85786e87901ce5f0a59f488edd5f99b46015192cda48468b233a", | ||
| "integrity": "sha256:9663ce0219ff85786e87901ce5f0a59f488edd5f99b46015192cda48468b233a" | ||
| }, | ||
| "ghcr.io/devcontainers/features/terraform:1": { | ||
| "version": "1.4.3", | ||
| "resolved": "ghcr.io/devcontainers/features/terraform@sha256:503d0888b3a43a32335e08cd4477f8c4629404ad83f6a36f0e0fee7f567c06c7", | ||
| "integrity": "sha256:503d0888b3a43a32335e08cd4477f8c4629404ad83f6a36f0e0fee7f567c06c7" | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
apps/frontend/app/admin/course/[courseId]/_components/CourseDetailTabs.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| 'use client' | ||
|
|
||
| import { cn } from '@/libs/utils' | ||
| import Link from 'next/link' | ||
| import { usePathname } from 'next/navigation' | ||
|
|
||
| interface CourseDetailTabsProps { | ||
| courseId: string | ||
| courseCode: string | ||
| courseTitle: string | ||
| } | ||
|
|
||
| export function CourseDetailTabs({ | ||
| courseId, | ||
| courseCode, | ||
| courseTitle | ||
| }: CourseDetailTabsProps) { | ||
| const pathname = usePathname() | ||
|
|
||
| const tabs = [ | ||
| { name: 'Home', title: 'HOME', href: `/admin/course/${courseId}` }, | ||
| { | ||
| name: 'Member', | ||
| title: 'MEMBER', | ||
| description: | ||
| "Here's a list of the instructors and students of the course", | ||
| href: `/admin/course/${courseId}/user` | ||
| }, | ||
| { | ||
| name: 'Assignment', | ||
| title: 'ASSIGNMENT', | ||
| description: "Here's a assignment list you made", | ||
| href: `/admin/course/${courseId}/assignment` | ||
| }, | ||
| { | ||
| name: 'Exercise', | ||
| title: 'EXERCISE', | ||
| description: "Here's a exercise list you made", | ||
| href: `/admin/course/${courseId}/exercise` | ||
| }, | ||
| { | ||
| name: 'Q&A', | ||
| title: 'Question & Answer', | ||
| description: | ||
| 'Assignment와 Exercise 문제와 관련된 질문과 답변을 제공합니다.', | ||
| href: `/admin/course/${courseId}/qna` | ||
| } | ||
| ] | ||
|
|
||
| const activeTabName = | ||
| tabs.find((tab) => pathname === tab.href)?.title || 'HOME' | ||
|
|
||
| return ( | ||
| <> | ||
| <h1 className="text-head3_sb_28">{activeTabName}</h1> | ||
| <p className="text-body1_m_16 text-color-neutral-50"> | ||
| {activeTabName === 'HOME' | ||
| ? `[${courseCode}] ${courseTitle}` | ||
| : tabs.find((tab) => tab.title === activeTabName)?.description} | ||
| </p> | ||
|
|
||
| <div className="mx-auto my-10 w-full"> | ||
| <nav className="flex w-full justify-start border-b border-gray-200"> | ||
| {tabs.map((tab) => { | ||
| const isActive = pathname === tab.href | ||
| return ( | ||
| <Link | ||
| key={`tab-${tab.name}`} | ||
| href={tab.href} | ||
| className={cn( | ||
| 'text-sub3_sb_16 relative flex h-[40px] w-[285.5px] items-center justify-center pb-4 transition-colors', | ||
| isActive | ||
| ? 'text-primary after:bg-primary after:absolute after:bottom-[-1px] after:left-0 after:h-[2px] after:w-full' | ||
| : 'text-color-neutral-40 hover:text-color-neutral-70' | ||
| )} | ||
| > | ||
| {tab.name} | ||
| </Link> | ||
| ) | ||
| })} | ||
| </nav> | ||
| </div> | ||
| </> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,102 +1,73 @@ | ||
| 'use client' | ||
| import { auth } from '@/libs/auth' | ||
| import { adminBaseUrl } from '@/libs/constants' | ||
| import { redirect } from 'next/navigation' | ||
| import { CourseDetailTabs } from './_components/CourseDetailTabs' | ||
|
|
||
| import { GET_COURSE } from '@/graphql/course/queries' | ||
| import { cn } from '@/libs/utils' | ||
| import { useQuery } from '@apollo/client' | ||
| import Link from 'next/link' | ||
| import { useParams, usePathname } from 'next/navigation' | ||
| import { title } from 'process' | ||
| import { description } from 'valibot' | ||
| const GET_COURSE_QUERY = ` | ||
| query GetCourse($groupId: Int!) { | ||
| getCourse(groupId: $groupId) { | ||
| id | ||
| groupName | ||
| courseInfo { | ||
| courseNum | ||
| classNum | ||
| } | ||
| } | ||
| } | ||
| ` | ||
|
|
||
| export default function CourseDetailLayout({ | ||
| children | ||
| export default async function CourseDetailLayout({ | ||
| children, | ||
| params | ||
| }: { | ||
| children: React.ReactNode | ||
| params: Promise<{ courseId: string }> | ||
| }) { | ||
| const pathname = usePathname() | ||
| const params = useParams() | ||
| const courseId = params?.courseId as string | ||
| const { courseId } = await params | ||
| const session = await auth() | ||
|
|
||
| const { data, loading } = useQuery(GET_COURSE, { | ||
| variables: { groupId: Number(courseId) }, | ||
| skip: !courseId | ||
| }) | ||
| if (!session) { | ||
| redirect('/') | ||
| } | ||
|
|
||
| const currentCourse = data?.getCourse | ||
| let json | ||
| try { | ||
| const res = await fetch(adminBaseUrl as string, { | ||
| method: 'POST', | ||
| headers: { | ||
| 'Content-Type': 'application/json', | ||
| Authorization: session.token.accessToken | ||
| }, | ||
| body: JSON.stringify({ | ||
| query: GET_COURSE_QUERY, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여기 그냥 GET_COURSE로 수정 부탁드립니다..! |
||
| variables: { groupId: Number(courseId) } | ||
| }) | ||
| }) | ||
| json = await res.json() | ||
| } catch { | ||
| redirect('/') | ||
| } | ||
|
|
||
| const courseNum = currentCourse?.courseInfo?.courseNum | ||
| const classNum = currentCourse?.courseInfo?.classNum | ||
| // If the user doesn't have permission, the backend's GroupLeaderGuard | ||
| // will throw a ForbiddenException and return errors here. | ||
| if (json.errors || !json.data?.getCourse) { | ||
| redirect('/') | ||
| } | ||
|
|
||
| const course = json.data.getCourse | ||
| const courseNum = course.courseInfo?.courseNum | ||
| const classNum = course.courseInfo?.classNum | ||
| const courseCode = courseNum ? `${courseNum}-${classNum}` : courseId | ||
| const courseTitle = | ||
| currentCourse?.groupName || (loading ? '로딩 중...' : '과목 정보 없음') | ||
|
|
||
| const tabs = [ | ||
| { name: 'Home', title: 'HOME', href: `/admin/course/${courseId}` }, | ||
| { | ||
| name: 'Member', | ||
| title: 'MEMBER', | ||
| description: | ||
| "Here's a list of the instructors and students of the course", | ||
| href: `/admin/course/${courseId}/user` | ||
| }, | ||
| { | ||
| name: 'Assignment', | ||
| title: 'ASSIGNMENT', | ||
| description: "Here's a assignment list you made", | ||
| href: `/admin/course/${courseId}/assignment` | ||
| }, | ||
| { | ||
| name: 'Exercise', | ||
| title: 'EXERCISE', | ||
| description: "Here's a exercise list you made", | ||
| href: `/admin/course/${courseId}/exercise` | ||
| }, | ||
| { | ||
| name: 'Q&A', | ||
| title: 'Question & Answer', | ||
| description: | ||
| 'Assignment와 Exercise 문제와 관련된 질문과 답변을 제공합니다.', | ||
| href: `/admin/course/${courseId}/qna` | ||
| } | ||
| ] | ||
|
|
||
| const activeTabName = | ||
| tabs.find((tab) => pathname === tab.href)?.title || 'HOME' | ||
| const courseTitle = course.groupName || '' | ||
|
|
||
| return ( | ||
| <div className="flex w-full flex-col"> | ||
| <div className="pb-[71px] pl-[86px] pr-[106px] pt-[80px]"> | ||
| <h1 className="text-head3_sb_28">{activeTabName}</h1> | ||
| <p className="text-body1_m_16 text-color-neutral-50"> | ||
| {activeTabName === 'HOME' | ||
| ? `[${courseCode}] ${courseTitle}` | ||
| : tabs.find((tab) => tab.title === activeTabName)?.description} | ||
| </p> | ||
|
|
||
| <div className="mx-auto my-10 w-full"> | ||
| <div className="w-full"> | ||
| <nav className="flex w-full justify-start border-b border-gray-200"> | ||
| {tabs.map((tab) => { | ||
| const isActive = pathname === tab.href | ||
| return ( | ||
| <Link | ||
| key={`tab-${tab.name}`} | ||
| href={tab.href} | ||
| className={cn( | ||
| 'text-sub3_sb_16 relative flex h-[40px] w-[285.5px] items-center justify-center pb-4 transition-colors', | ||
| isActive | ||
| ? 'text-primary after:bg-primary after:absolute after:bottom-[-1px] after:left-0 after:h-[2px] after:w-full' | ||
| : 'text-color-neutral-40 hover:text-color-neutral-70' | ||
| )} | ||
| > | ||
| {tab.name} | ||
| </Link> | ||
| ) | ||
| })} | ||
| </nav> | ||
| </div> | ||
| </div> | ||
| <CourseDetailTabs | ||
| courseId={courseId} | ||
| courseCode={courseCode} | ||
| courseTitle={courseTitle} | ||
| /> | ||
|
|
||
| <main className="w-full flex-1">{children}</main> | ||
| </div> | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이거 get_course_query 는 지워주세요!