Skip to content
This repository has been archived by the owner on Jan 3, 2025. It is now read-only.

Commit

Permalink
Fix issues found on staging (#283)
Browse files Browse the repository at this point in the history
* fix private methods

* fix payment api

* added /v2 to match the current staging implementation

* move BASE_ROUTE to /competitions/v2

* remove data from payload as the current version of jwt-devise does not wrap it anymore

* fix talking with permissions on the monolith

* ran eslint fix

* correct jwt payload

* remove comma

* don't leak if the user is banned
  • Loading branch information
FinnIckler authored Oct 22, 2023
1 parent d67d293 commit 65e96aa
Show file tree
Hide file tree
Showing 19 changed files with 136 additions and 121 deletions.
2 changes: 1 addition & 1 deletion Frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"scripts": {
"build:types": "TYPES_ONLY=true node src/build.mjs",
"build:dev": "NODE_ENV=\"development\" ASSET_PATH=\"/dist\" API_URL=\"http://localhost:3001/api/v1\" AUTH_URL=\"http://localhost:3001/jwt\" node src/build.mjs",
"build:staging": "POLL_URL=\"https://1rq8d7dif3.execute-api.us-west-2.amazonaws.com/v1/staging\" NODE_ENV=\"staging\" ASSET_PATH=\"https://d1qizdh27al0a7.cloudfront.net/staging/dist\" API_URL=\"https://staging.registration.worldcubeassociation.org/api/v1\" WCA_URL=\"https://staging.worldcubeassociation.org\" node src/build.mjs",
"build:staging": "POLL_URL=\"https://1rq8d7dif3.execute-api.us-west-2.amazonaws.com/v1/staging\" NODE_ENV=\"production\" ASSET_PATH=\"https://d1qizdh27al0a7.cloudfront.net/staging/dist\" API_URL=\"https://staging.registration.worldcubeassociation.org/api/v1\" WCA_URL=\"https://staging.worldcubeassociation.org\" node src/build.mjs",
"build:prod": "POLL_URL=\"https://1rq8d7dif3.execute-api.us-west-2.amazonaws.com/v1/prod\" NODE_ENV=\"production\" ASSET_PATH=\"https://d1qizdh27al0a7.cloudfront.net/dist\" API_URL=\"https://registration.worldcubeassociation.org/api/v1\" WCA_URL=\"https://worldcubeassociation.org\" node src/build.mjs",
"watch": "node src/watch.mjs",
"lint": "eslint src --ext .js,.jsx,.ts,.tsx",
Expand Down
2 changes: 1 addition & 1 deletion Frontend/src/api/mocks/get_jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default async function getJWTMock(): Promise<string> {
const secret = new TextEncoder().encode('jwt-test-secret')
const alg = 'HS256'
const issuedAt = Date.now()
const jwt = await new jose.SignJWT({ data: { user_id: user } })
const jwt = await new jose.SignJWT({ user_id: user })
.setProtectedHeader({ alg })
.setIssuedAt(issuedAt)
.setJti(Base64.stringify(md5(`${secret}:${issuedAt}`)))
Expand Down
19 changes: 10 additions & 9 deletions Frontend/src/index.dev.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import Registrations from './pages/registrations'
import Schedule from './pages/schedule'
import TestLogin from './pages/test/login'
import TestLogout from './pages/test/logout'
import { BASE_ROUTE } from './routes'
import App from './ui/App'
import Competition from './ui/Competition'
import CustomTab from './ui/CustomTab'
Expand Down Expand Up @@ -60,7 +61,7 @@ const router = createBrowserRouter([
),
},
{
path: '/competitions/:competition_id',
path: `${BASE_ROUTE}/:competition_id`,
element: (
<Container>
<Competition>
Expand All @@ -73,35 +74,35 @@ const router = createBrowserRouter([
),
children: [
{
path: '/competitions/:competition_id',
path: `${BASE_ROUTE}/:competition_id`,
element: <HomePage />,
},
{
path: '/competitions/:competition_id/events',
path: `${BASE_ROUTE}/:competition_id/events`,
element: <Events />,
},
{
path: '/competitions/:competition_id/schedule',
path: `${BASE_ROUTE}/:competition_id/schedule`,
element: <Schedule />,
},
{
path: '/competitions/:competition_id/register',
path: `${BASE_ROUTE}/:competition_id/register`,
element: <Register />,
},
{
path: '/competitions/:competition_id/tabs/:tab_id',
path: `${BASE_ROUTE}/:competition_id/tabs/:tab_id`,
element: <CustomTab />,
},
{
path: '/competitions/:competition_id/registrations',
path: `${BASE_ROUTE}/:competition_id/registrations`,
element: <Registrations />,
},
{
path: '/competitions/:competition_id/:user_id/edit',
path: `${BASE_ROUTE}/:competition_id/:user_id/edit`,
element: <RegistrationEdit />,
},
{
path: '/competitions/:competition_id/registrations/edit',
path: `${BASE_ROUTE}/:competition_id/registrations/edit`,
element: <RegistrationAdministration />,
},
],
Expand Down
81 changes: 3 additions & 78 deletions Frontend/src/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,85 +2,10 @@
import '@thewca/wca-components/dist/index.esm.css'
import React from 'react'
import { createRoot } from 'react-dom/client'
import { createBrowserRouter, Outlet, RouterProvider } from 'react-router-dom'
import { Container } from 'semantic-ui-react'
import Events from './pages/events'
import HomePage from './pages/home'
import Register from './pages/register'
import RegistrationAdministration from './pages/registration_administration'
import RegistrationEdit from './pages/registration_edit'
import Registrations from './pages/registrations'
import Schedule from './pages/schedule'
import App from './ui/App'
import Competition from './ui/Competition'
import CustomTab from './ui/CustomTab'
import FlashMessage from './ui/messages/flashMessage'
import PermissionsProvider from './ui/providers/PermissionsProvider'
import UserProvider from './ui/providers/UserProvider'
import PageTabs from './ui/Tabs'
import { createBrowserRouter, RouterProvider } from 'react-router-dom'
import routes from './routes'

const router = createBrowserRouter([
{
path: '/competitions',
element: (
<App>
<FlashMessage />
<UserProvider>
<Outlet />
</UserProvider>
</App>
),
children: [
{
path: '/competitions/:competition_id',
element: (
<Container>
<Competition>
<PermissionsProvider>
<PageTabs />
<Outlet />
</PermissionsProvider>
</Competition>
</Container>
),
children: [
{
path: '/competitions/:competition_id',
element: <HomePage />,
},
{
path: '/competitions/:competition_id/events',
element: <Events />,
},
{
path: '/competitions/:competition_id/schedule',
element: <Schedule />,
},
{
path: '/competitions/:competition_id/register',
element: <Register />,
},
{
path: '/competitions/:competition_id/tabs/:tab_id',
element: <CustomTab />,
},
{
path: '/competitions/:competition_id/registrations',
element: <Registrations />,
},
{
path: '/competitions/:competition_id/:user_id/edit',
element: <RegistrationEdit />,
},
{
path: '/competitions/:competition_id/registrations/edit',
element: <RegistrationAdministration />,
},
],
},
],
},
])
const router = createBrowserRouter(routes)

// Render the React component into the body of the monolith
const root = createRoot(document.querySelector('#registration-app'))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { Link } from 'react-router-dom'
import { Checkbox, Popup, Table } from 'semantic-ui-react'
import { CompetitionContext } from '../../../api/helper/context/competition_context'
import { getAllRegistrations } from '../../../api/registration/get/get_registrations'
import { BASE_ROUTE } from '../../../routes'
import { setMessage } from '../../../ui/events/messages'
import LoadingMessage from '../../../ui/messages/loadingMessage'
import styles from './list.module.scss'
Expand Down Expand Up @@ -276,7 +277,7 @@ function RegistrationAdministrationTable({
</Table.Cell>
<Table.Cell>
<Link
to={`/competitions/${competition_id}/${registration.user.id}/edit`}
to={`${BASE_ROUTE}/${competition_id}/${registration.user.id}/edit`}
>
Edit
</Link>
Expand Down
84 changes: 84 additions & 0 deletions Frontend/src/routes.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import React from 'react'
import { Outlet } from 'react-router-dom'
import { Container } from 'semantic-ui-react'
import Events from './pages/events'
import HomePage from './pages/home'
import Register from './pages/register'
import RegistrationAdministration from './pages/registration_administration'
import RegistrationEdit from './pages/registration_edit'
import Registrations from './pages/registrations'
import Schedule from './pages/schedule'
import App from './ui/App'
import Competition from './ui/Competition'
import CustomTab from './ui/CustomTab'
import FlashMessage from './ui/messages/flashMessage'
import PermissionsProvider from './ui/providers/PermissionsProvider'
import UserProvider from './ui/providers/UserProvider'
import PageTabs from './ui/Tabs'

export const BASE_ROUTE = '/competitions/v2'

const routes = [
{
path: BASE_ROUTE,
element: (
<App>
<FlashMessage />
<UserProvider>
<Outlet />
</UserProvider>
</App>
),
children: [
{
path: `${BASE_ROUTE}/:competition_id`,
element: (
<Container>
<Competition>
<PermissionsProvider>
<PageTabs />
<Outlet />
</PermissionsProvider>
</Competition>
</Container>
),
children: [
{
path: `${BASE_ROUTE}/:competition_id`,
element: <HomePage />,
},
{
path: `${BASE_ROUTE}/:competition_id/events`,
element: <Events />,
},
{
path: `${BASE_ROUTE}/:competition_id/schedule`,
element: <Schedule />,
},
{
path: `${BASE_ROUTE}/:competition_id/register`,
element: <Register />,
},
{
path: `${BASE_ROUTE}/:competition_id/tabs/:tab_id`,
element: <CustomTab />,
},
{
path: `${BASE_ROUTE}/:competition_id/registrations`,
element: <Registrations />,
},
{
path: `${BASE_ROUTE}/:competition_id/:user_id/edit`,
element: <RegistrationEdit />,
},
{
path: `${BASE_ROUTE}/:competition_id/registrations/edit`,
element: <RegistrationAdministration />,
},
],
},
],
},
]

export default routes
3 changes: 2 additions & 1 deletion Frontend/src/ui/Competition.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { useNavigate, useParams } from 'react-router-dom'
import { Button, Image } from 'semantic-ui-react'
import getCompetitionInfo from '../api/competition/get/get_competition_info'
import { CompetitionContext } from '../api/helper/context/competition_context'
import { BASE_ROUTE } from '../routes'
import styles from './competition.module.scss'
import LoadingMessage from './messages/loadingMessage'

Expand Down Expand Up @@ -64,7 +65,7 @@ export default function Competition({ children }) {
onClick={(_, data) => {
if (!data.disabled) {
if (competitionInfo.use_wca_registration) {
navigate(`/competitions/${competitionInfo.id}/register`)
navigate(`${BASE_ROUTE}/${competitionInfo.id}/register`)
} else {
window.location =
competitionInfo.external_registration_page
Expand Down
15 changes: 8 additions & 7 deletions Frontend/src/ui/Tabs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { useLocation, useNavigate } from 'react-router-dom'
import { Menu, Tab } from 'semantic-ui-react'
import { CompetitionContext } from '../api/helper/context/competition_context'
import { PermissionsContext } from '../api/helper/context/permission_context'
import { BASE_ROUTE } from '../routes'
import styles from './tabs.module.scss'

function pathMatch(name, pathname) {
Expand Down Expand Up @@ -50,7 +51,7 @@ export default function PageTabs() {
name="register"
className={styles.tabItem}
onClick={() =>
navigate(`/competitions/${competitionInfo.id}/register`)
navigate(`${BASE_ROUTE}/${competitionInfo.id}/register`)
}
>
<UiIcon name="sign in alt" />
Expand All @@ -68,7 +69,7 @@ export default function PageTabs() {
name="registrations"
className={styles.tabItem}
onClick={() =>
navigate(`/competitions/${competitionInfo.id}/registrations/edit`)
navigate(`${BASE_ROUTE}/${competitionInfo.id}/registrations/edit`)
}
>
<UiIcon name="list ul" />
Expand All @@ -86,7 +87,7 @@ export default function PageTabs() {
name="competitors"
className={styles.tabItem}
onClick={() =>
navigate(`/competitions/${competitionInfo.id}/registrations`)
navigate(`${BASE_ROUTE}/${competitionInfo.id}/registrations`)
}
>
<UiIcon name="users" />
Expand All @@ -103,7 +104,7 @@ export default function PageTabs() {
key="tab-info"
name="info"
className={styles.tabItem}
onClick={() => navigate(`/competitions/${competitionInfo.id}`)}
onClick={() => navigate(`${BASE_ROUTE}/${competitionInfo.id}`)}
>
<UiIcon name="info" />
General Info
Expand All @@ -119,7 +120,7 @@ export default function PageTabs() {
name="events"
className={styles.tabItem}
onClick={() =>
navigate(`/competitions/${competitionInfo.id}/events`)
navigate(`${BASE_ROUTE}/${competitionInfo.id}/events`)
}
>
<CubingIcon event={competitionInfo.main_event_id} selected />
Expand All @@ -135,7 +136,7 @@ export default function PageTabs() {
name="schedule"
className={styles.tabItem}
onClick={() =>
navigate(`/competitions/${competitionInfo.id}/schedule`)
navigate(`${BASE_ROUTE}/${competitionInfo.id}/schedule`)
}
>
<UiIcon name="calendar" />
Expand All @@ -152,7 +153,7 @@ export default function PageTabs() {
name={`tabs-${tab.id}`}
className={styles.tabItem}
onClick={() =>
navigate(`/competitions/${competitionInfo.id}/tabs/${tab.id}`)
navigate(`${BASE_ROUTE}/${competitionInfo.id}/tabs/${tab.id}`)
}
>
{tab.name}
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def validate_token
token = request.headers['Authorization'].split[1]
begin
decoded_token = (JWT.decode token, JwtOptions.secret, true, { algorithm: JwtOptions.algorithm })[0]
@current_user = decoded_token['data']['user_id']
@current_user = decoded_token['user_id']
rescue JWT::VerificationError, JWT::InvalidJtiError
Metrics.jwt_verification_error_counter.increment
render json: { error: ErrorCodes::INVALID_TOKEN }, status: :unauthorized
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/registration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ def validate_create_request

user_can_create_registration!

can_compete, reasons = UserApi.can_compete?(@user_id)
raise RegistrationError.new(:unauthorized, reasons) unless can_compete
can_compete = UserApi.can_compete?(@user_id)
raise RegistrationError.new(:unauthorized, ErrorCodes::USER_PROFILE_INCOMPLETE) unless can_compete

validate_events!
raise RegistrationError.new(:unprocessable_entity, ErrorCodes::GUEST_LIMIT_EXCEEDED) if params.key?(:guests) && @competition.guest_limit_exceeded?(params[:guests])
Expand Down Expand Up @@ -171,12 +171,12 @@ def payment_ticket
refresh = params[:refresh]
if refresh || @registration.payment_ticket.nil?
amount, currency_code = @competition.payment_info
ticket, account_id = PaymentApi.get_ticket(@registration[:attendee_id], amount, currency_code)
ticket = PaymentApi.get_ticket(@registration[:attendee_id], amount, currency_code)
@registration.init_payment_lane(amount, currency_code, ticket)
else
ticket = @registration.payment_ticket
end
render json: { client_secret_id: ticket, connected_account_id: account_id }
render json: { id: ticket }
end

def validate_payment_ticket_request
Expand Down
Loading

0 comments on commit 65e96aa

Please sign in to comment.