Class: ExamRegistration
Defined Under Namespace
Classes: AuthorizationCriterion
Instance Method Summary
collapse
#friendly, #navigable_name, #navigation_end?, #next_for, #siblings, #structural_parent
#enabled?, #enabled_range
Methods included from WithPgLock
#with_pg_lock
active_between, aggregate_of, all_except, defaults, #delete, #destroy!, enum_prefixed_translations_for, numbered, organic_on, resource_fields, #save, #save_and_notify!, #save_and_notify_changes!, serialize_symbolized_hash_array, teaser_on, #update_and_notify!, update_or_create!, whitelist_attributes, with_pg_retry, with_temporary_token
Instance Method Details
#authorization_criterion ⇒ Object
22
23
24
|
# File 'app/models/exam_registration.rb', line 22
def authorization_criterion
@authorization_criterion ||= ExamRegistration::AuthorizationCriterion.parse(authorization_criterion_type, authorization_criterion_value)
end
|
#authorization_request_for(user) ⇒ Object
63
64
65
66
|
# File 'app/models/exam_registration.rb', line 63
def authorization_request_for(user)
authorization_requests.find_by(user: user) ||
ExamAuthorizationRequest.new(exam_registration: self, organization: organization)
end
|
#ensure_valid_authorization_criterion! ⇒ Object
26
27
28
|
# File 'app/models/exam_registration.rb', line 26
def ensure_valid_authorization_criterion!
authorization_criterion.ensure_valid!
end
|
#notify_unnotified_registrees! ⇒ Object
30
31
32
|
# File 'app/models/exam_registration.rb', line 30
def notify_unnotified_registrees!
unnotified_registrees.each { |registree| notify_registree! registree }
end
|
#process_authorization_requests! ⇒ Object
55
56
57
58
59
60
61
|
# File 'app/models/exam_registration.rb', line 55
def process_authorization_requests!
authorization_requests.each do |it|
process_request! it
it.try_authorize!
end
update! processed: true
end
|
#process_requests! ⇒ Object
Try to process authorization request, by acquiring a database lock for update the appropriate record.
This method is aimed to be sent across multiple servers or processed concurrently and still not send duplicate mails
51
52
53
|
# File 'app/models/exam_registration.rb', line 51
def process_requests!
with_pg_lock proc { process_authorization_requests! }, proc { !processed? }
end
|
#register!(user) ⇒ Object
68
69
70
|
# File 'app/models/exam_registration.rb', line 68
def register!(user)
registrees << user unless registered?(user)
end
|
#register_users!(users) ⇒ Object
38
39
40
|
# File 'app/models/exam_registration.rb', line 38
def register_users!(users)
users.each { |user| register! user }
end
|
#registered?(user) ⇒ Boolean
72
73
74
|
# File 'app/models/exam_registration.rb', line 72
def registered?(user)
registrees.include? user
end
|
#unnotified_registrees ⇒ Object
42
43
44
|
# File 'app/models/exam_registration.rb', line 42
def unnotified_registrees
registrees.where.not(id: Notification.notified_users_ids_for(self, self.organization))
end
|
#unnotified_registrees? ⇒ Boolean
34
35
36
|
# File 'app/models/exam_registration.rb', line 34
def unnotified_registrees?
unnotified_registrees.exists?
end
|