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

Commit

Permalink
Enforce missing Registration Requirements in the Frontend (#297)
Browse files Browse the repository at this point in the history
* Ensure that competitor comments if enforce comment is on

* Allow organizers to register before competition is open

* don't show guest dropdown when no guests are allowed

* Update Frontend/src/pages/register/components/CompetingStep.jsx

Co-authored-by: Kevin Matthews <49137025+kr-matthews@users.noreply.github.com>

* Only allow delegates and organizers to sign up early, not WRT or WST

* fix tests

---------

Co-authored-by: Kevin Matthews <49137025+kr-matthews@users.noreply.github.com>
  • Loading branch information
FinnIckler and kr-matthews authored Oct 31, 2023
1 parent 75560b4 commit 431d57f
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 25 deletions.
58 changes: 38 additions & 20 deletions Frontend/src/pages/register/components/CompetingStep.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,14 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
import { EventSelector, UiIcon } from '@thewca/wca-components'
import { dinero, toDecimal } from 'dinero.js'
import React, { useContext, useEffect, useState } from 'react'
import { Button, Divider, Dropdown, Popup, TextArea } from 'semantic-ui-react'
import {
Button,
Divider,
Dropdown,
Message,
Popup,
TextArea,
} from 'semantic-ui-react'
import { CompetitionContext } from '../../../api/helper/context/competition_context'
import { UserContext } from '../../../api/helper/context/user_context'
import { getSingleRegistration } from '../../../api/registration/get/get_registrations'
Expand Down Expand Up @@ -128,6 +135,12 @@ export default function CompetingStep({ nextStep }) {
</>
) : (
<>
{!competitionInfo['registration_opened?'] && (
<Message warning>
Registration is not open yet, but you can still register as a
competition organizer or delegate.
</Message>
)}
<div className={styles.registrationGreeting}>
You can register for {competitionInfo.name}
</div>
Expand Down Expand Up @@ -183,24 +196,26 @@ export default function CompetingStep({ nextStep }) {
<div className={styles.eventSelectionText}>
<div className={styles.eventSelectionHeading}>Guests</div>
</div>
<div className={styles.commentWrapper}>
<Dropdown
value={guests}
onChange={(e, data) => setGuests(data.value)}
selection
options={[
...new Array(
(competitionInfo.guests_per_registration_limit ?? 99) + 1 // Arrays start at 0
),
].map((_, index) => {
return {
key: `registration-guest-dropdown-${index}`,
text: index,
value: index,
}
})}
/>
</div>
{competitionInfo.guest_entry_status !== 'restricted' && (
<div className={styles.commentWrapper}>
<Dropdown
value={guests}
onChange={(e, data) => setGuests(data.value)}
selection
options={[
...new Array(
(competitionInfo.guests_per_registration_limit ?? 99) + 1 // Arrays start at 0
),
].map((_, index) => {
return {
key: `registration-guest-dropdown-${index}`,
text: index,
value: index,
}
})}
/>
</div>
)}
</div>
<div className={styles.registrationRow}>
{registration?.competing?.registration_status ? (
Expand All @@ -216,7 +231,10 @@ export default function CompetingStep({ nextStep }) {
</div>
<Button
disabled={
isUpdating || !competitionInfo.allow_registration_edits
isUpdating ||
!competitionInfo.allow_registration_edits ||
(competitionInfo.force_comment_in_registration &&
comment === '')
}
color="blue"
onClick={() => {
Expand Down
5 changes: 4 additions & 1 deletion Frontend/src/pages/register/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ export default function Register() {
You need to log in to Register for a competition
</PermissionMessage>
) : // eslint-disable-next-line unicorn/no-nested-ternary
competitionInfo['registration_opened?'] ? (
competitionInfo['registration_opened?'] ||
competitionInfo.organizers
.concat(competitionInfo.delegates)
.find((u) => u.id === user.id) ? (
<div>
{canAttendCompetition ? (
<StepPanel />
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/registration_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -329,11 +329,11 @@ def user_can_create_registration!
raise RegistrationError.new(:unauthorized, ErrorCodes::USER_INSUFFICIENT_PERMISSIONS) unless is_admin_or_current_user?

# Only admins can register when registration is closed, and they can only register for themselves - not for other users
raise RegistrationError.new(:forbidden, ErrorCodes::REGISTRATION_CLOSED) unless @competition.registration_open? || admin_modifying_own_registration?
raise RegistrationError.new(:forbidden, ErrorCodes::REGISTRATION_CLOSED) unless @competition.registration_open? || organizer_signing_up_themselves?
end

def admin_modifying_own_registration?
UserApi.can_administer?(@current_user, @competition_id) && (@current_user == @user_id.to_s)
def organizer_signing_up_themselves?
@competition.is_organizer_or_delegate?(@current_user) && (@current_user == @user_id.to_s)
end

def is_admin_or_current_user?
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/competition_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ def payment_info
[@competition_json['base_entry_fee_lowest_denomination'], @competition_json['currency_code']]
end

def is_organizer_or_delegate?(user_id)
(@competition_json['delegates'] + @competition_json['organizers']).any? { |p| p['id'].to_s == user_id }
end

def name
@competition_json['name']
end
Expand Down
Loading

0 comments on commit 431d57f

Please sign in to comment.