From af8c1e2ca1914e6b6dbbb84d34a8bf5e9596f5a9 Mon Sep 17 00:00:00 2001 From: Nutthapat Pongtanyavichai Date: Sat, 13 Jul 2024 03:41:09 +0700 Subject: [PATCH] Deploy Production 13/7/67 (#699) * Enter pre-release mode * fix: disable referrer check * Version Packages (beta) (#696) Co-authored-by: github-actions[bot] * feat: schedule import * Version Packages (beta) (#697) Co-authored-by: github-actions[bot] * fix: build error * Version Packages (beta) (#698) Co-authored-by: github-actions[bot] * Configure pre-release mode --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: github-actions[bot] Co-authored-by: leomotors --- .changeset/pre.json | 21 ++++ .changeset/real-mails-beg.md | 5 + .changeset/rich-grapes-kiss.md | 5 + .changeset/shikanoko-nokonoko-koshitantan.md | 5 + apps/web/CHANGELOG.md | 18 +++ apps/web/package.json | 2 +- .../[studyProgram]/schedule/import/index.tsx | 119 +++++++++++------- 7 files changed, 126 insertions(+), 49 deletions(-) create mode 100644 .changeset/pre.json create mode 100644 .changeset/real-mails-beg.md create mode 100644 .changeset/rich-grapes-kiss.md create mode 100644 .changeset/shikanoko-nokonoko-koshitantan.md diff --git a/.changeset/pre.json b/.changeset/pre.json new file mode 100644 index 000000000..1b2ba6233 --- /dev/null +++ b/.changeset/pre.json @@ -0,0 +1,21 @@ +{ + "mode": "exit", + "tag": "beta", + "initialVersions": { + "admin-api": "1.3.1", + "admin-web": "1.3.0", + "api": "1.9.1", + "reg-scraper": "1.5.1", + "web": "1.10.1", + "web-e2e": "0.3.0", + "@cgr/codegen": "1.5.0", + "@cgr/course-utils": "1.3.0", + "@cgr/project-config": "1.3.0", + "@cgr/schema": "1.5.0" + }, + "changesets": [ + "real-mails-beg", + "rich-grapes-kiss", + "shikanoko-nokonoko-koshitantan" + ] +} diff --git a/.changeset/real-mails-beg.md b/.changeset/real-mails-beg.md new file mode 100644 index 000000000..cb4f085a2 --- /dev/null +++ b/.changeset/real-mails-beg.md @@ -0,0 +1,5 @@ +--- +"web": minor +--- + +fix: disable referrer check diff --git a/.changeset/rich-grapes-kiss.md b/.changeset/rich-grapes-kiss.md new file mode 100644 index 000000000..de7c54ebb --- /dev/null +++ b/.changeset/rich-grapes-kiss.md @@ -0,0 +1,5 @@ +--- +"web": minor +--- + +feat: schedule import diff --git a/.changeset/shikanoko-nokonoko-koshitantan.md b/.changeset/shikanoko-nokonoko-koshitantan.md new file mode 100644 index 000000000..cbec7a73d --- /dev/null +++ b/.changeset/shikanoko-nokonoko-koshitantan.md @@ -0,0 +1,5 @@ +--- +"web": minor +--- + +feat: schedule import part 2 diff --git a/apps/web/CHANGELOG.md b/apps/web/CHANGELOG.md index 7c125a42a..701851726 100644 --- a/apps/web/CHANGELOG.md +++ b/apps/web/CHANGELOG.md @@ -1,5 +1,23 @@ # web +## 1.11.0-beta.2 + +### Minor Changes + +- b80e54d: feat: schedule import part 2 + +## 1.11.0-beta.1 + +### Minor Changes + +- cd80cac: feat: schedule import + +## 1.11.0-beta.0 + +### Minor Changes + +- ef01a7c: fix: disable referrer check + ## 1.10.1 ### Patch Changes diff --git a/apps/web/package.json b/apps/web/package.json index e15ba3e4d..11da5db4c 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -1,6 +1,6 @@ { "name": "web", - "version": "1.10.1", + "version": "1.11.0-beta.2", "private": true, "scripts": { "dev": "next dev -p 4200", diff --git a/apps/web/src/pages/[studyProgram]/schedule/import/index.tsx b/apps/web/src/pages/[studyProgram]/schedule/import/index.tsx index d4060d625..1bbcb5d35 100644 --- a/apps/web/src/pages/[studyProgram]/schedule/import/index.tsx +++ b/apps/web/src/pages/[studyProgram]/schedule/import/index.tsx @@ -1,6 +1,6 @@ import { useEffect } from 'react' -import { ApolloClient, NormalizedCacheObject, isApolloError } from '@apollo/client' +import { ApolloClient, NormalizedCacheObject } from '@apollo/client' import { observer } from 'mobx-react' import { GetServerSidePropsContext, GetServerSidePropsResult } from 'next' import { useRouter } from 'next/router' @@ -32,9 +32,10 @@ interface ScheduleItem { interface ImportPageProps { items: ScheduleItem[] + errorMessage: string[] } -function ImportSchedulePage({ items }: ImportPageProps) { +function ImportSchedulePage({ items, errorMessage }: ImportPageProps) { const router = useRouter() const { buildLink } = useLinkBuilder() @@ -46,64 +47,86 @@ function ImportSchedulePage({ items }: ImportPageProps) { items.forEach(({ course, sectionNo }) => { courseCartStore.addItem(course, sectionNo) }) - router.replace(buildLink(`/schedule`)) + + if (!errorMessage) router.replace(buildLink(`/schedule`)) } fn() - }, [items, router, buildLink]) + }, [items, router, buildLink, errorMessage]) + + return ( + <> + + + {errorMessage && ( +
+

ERROR

- return +
    + {errorMessage.map((msg, i) => ( +
  • {msg}
  • + ))} +
+
+ )} + + ) } // TODO: research security issues for importing from other 3rd party data sources -const whitelistedOrigins = ['https://esc.eng.chula.ac.th', 'http://localhost:8000'] +// const whitelistedOrigins = ['https://esc.eng.chula.ac.th', 'http://localhost:8000'] export async function getServerSideProps( context: GetServerSidePropsContext ): Promise> { - const referer = context.req.headers.referer as string - const isFromWhitelistedOrigins = whitelistedOrigins.some((origin) => { - return typeof referer === 'string' && referer.startsWith(origin) - }) - if (!isFromWhitelistedOrigins) { - return { - notFound: true, - } - } - try { - const client = createApolloServerClient() - const q = context.query - const courseGroup = parseCourseGroup(q) - const itemsQuery = (q.items as string) ?? '' - const rawItems = itemsQuery - .split(',') - .map((it) => { - if (it.length === 0) { - return null - } - const parts = it.split(':') - if (parts.length !== 2) { - throw new Error('expected 2 parts for each item') - } - return { - courseNo: parts[0], - sectionNo: parts[1], - } - }) - .filter((it) => it !== null) as RawScheduleItem[] - const items = await Promise.all(rawItems.map((it) => fetchItem(client, courseGroup, it))) - return { - props: { - items, - }, - } - } catch (e: unknown) { - if (isApolloError(e as Error)) { + // const referer = context.req.headers.referer as string + // const isFromWhitelistedOrigins = whitelistedOrigins.some((origin) => { + // return typeof referer === 'string' && referer.startsWith(origin) + // }) + // if (!isFromWhitelistedOrigins) { + // return { + // notFound: true, + // } + // } + const client = createApolloServerClient() + const q = context.query + const courseGroup = parseCourseGroup(q) + const itemsQuery = (q.items as string) ?? '' + + const errorMessage: string[] = [] + + const rawItems = itemsQuery + .split(',') + .map((it) => { + if (it.length === 0) { + return null + } + const parts = it.split(':') + if (parts.length !== 2) { + errorMessage.push(`expected 2 parts for each item: ${it}`) + } return { - notFound: true, + courseNo: parts[0], + sectionNo: parts[1], } - } else { - throw e - } + }) + .filter((it) => it !== null) as RawScheduleItem[] + + const items = ( + await Promise.all( + rawItems.map((it) => { + return fetchItem(client, courseGroup, it).catch(() => { + errorMessage.push(`error fetching item: ${it.courseNo} ${it.sectionNo}`) + return null + }) + }) + ) + ).filter((x) => x !== null) as ScheduleItem[] + + return { + props: { + items, + errorMessage, + }, } }