@@ -15,12 +15,11 @@ def self.create_registration_allowed!(registration_request, current_user)
15
15
validate_comment! ( registration_request . dig ( 'competing' , 'comment' ) , competition )
16
16
end
17
17
18
- def self . update_registration_allowed! ( update_request , current_user )
19
- registration = Registration . find_by ( competition_id : update_request [ 'competition_id' ] , user_id : update_request [ 'user_id' ] )
18
+ def self . update_registration_allowed! ( update_request , competition , current_user )
19
+ registration = Registration . find_by ( competition_id : competition . id , user_id : update_request [ 'user_id' ] )
20
20
raise WcaExceptions ::RegistrationError . new ( :not_found , Registrations ::ErrorCodes ::REGISTRATION_NOT_FOUND ) unless registration . present?
21
21
22
22
target_user = User . find ( update_request [ 'user_id' ] )
23
- competition = Competition . find ( update_request [ 'competition_id' ] )
24
23
waiting_list_position = update_request . dig ( 'competing' , 'waiting_list_position' )
25
24
comment = update_request . dig ( 'competing' , 'comment' )
26
25
guests = update_request [ 'guests' ]
@@ -49,7 +48,7 @@ def self.bulk_update_allowed!(bulk_update_request, current_user)
49
48
50
49
errors = { }
51
50
bulk_update_request [ 'requests' ] . each do |update_request |
52
- update_registration_allowed! ( update_request , current_user )
51
+ update_registration_allowed! ( update_request , competition , current_user )
53
52
rescue WcaExceptions ::RegistrationError => e
54
53
errors [ update_request [ 'user_id' ] ] = e . error
55
54
end
@@ -98,7 +97,8 @@ def can_administer_or_current_user?(competition, current_user, target_user)
98
97
def validate_create_events! ( request , competition )
99
98
event_ids = request [ 'competing' ] [ 'event_ids' ]
100
99
# Event submitted must be held at the competition
101
- raise WcaExceptions ::RegistrationError . new ( :unprocessable_entity , Registrations ::ErrorCodes ::INVALID_EVENT_SELECTION ) unless competition . events_held? ( event_ids )
100
+ raise WcaExceptions ::RegistrationError . new ( :unprocessable_entity , Registrations ::ErrorCodes ::INVALID_EVENT_SELECTION ) unless
101
+ event_ids . present? && competition . events_held? ( event_ids )
102
102
103
103
event_limit = competition . events_per_registration_limit
104
104
raise WcaExceptions ::RegistrationError . new ( :forbidden , Registrations ::ErrorCodes ::INVALID_EVENT_SELECTION ) if event_limit . present? && event_ids . count > event_limit
@@ -197,7 +197,8 @@ def validate_update_status!(new_status, competition, current_user, target_user,
197
197
end
198
198
199
199
def validate_update_events! ( event_ids , competition )
200
- raise WcaExceptions ::RegistrationError . new ( :unprocessable_entity , Registrations ::ErrorCodes ::INVALID_EVENT_SELECTION ) unless competition . events_held? ( event_ids )
200
+ raise WcaExceptions ::RegistrationError . new ( :unprocessable_entity , Registrations ::ErrorCodes ::INVALID_EVENT_SELECTION ) unless
201
+ event_ids . present? && competition . events_held? ( event_ids )
201
202
202
203
event_limit = competition . events_per_registration_limit
203
204
raise WcaExceptions ::RegistrationError . new ( :forbidden , Registrations ::ErrorCodes ::INVALID_EVENT_SELECTION ) if event_limit . present? && event_ids . count > event_limit
0 commit comments