|
1class SponsorsController < SignaturesController
|
|
2 skip_before_filter :redirect_to_petition_page_if_rejected
|
|
3 skip_before_filter :redirect_to_petition_page_if_closed
|
|
4 skip_before_filter :redirect_to_petition_page_if_closed_for_signing
|
|
|
|
6 before_action :redirect_to_new_sponsor_page_if_validated, only: [:verify]
|
|
7 before_action :redirect_to_petition_page_if_moderated, except: [:thank_you, :signed]
|
|
8 before_action :redirect_to_moderation_info_page_if_sponsored, except: [:thank_you, :signed]
|
|
9 before_action :validate_creator, only: [:new]
|
|
|
|
|
|
12 unless @signature.validated?
|
|
13 @signature.validate!(request: request)
|
|
|
|
|
|
16 store_signed_token_in_session
|
|
17 send_sponsor_support_notification_email_to_petition_owner
|
|
18 redirect_to signed_sponsor_url(@signature)
|
|
|
|
|
|
|
|
|
|
|
|
24 @petition = Petition.not_hidden.find(petition_id)
|
|
|
|
26 if @petition.flagged? || @petition.stopped?
|
|
27 raise ActiveRecord::RecordNotFound, "Unable to find Petition with id: #{petition_id}"
|
|
|
|
|
|
30 unless @petition.sponsor_token == token_param
|
|
31 raise ActiveRecord::RecordNotFound, "Unable to find Petition with sponsor token: #{token_param.inspect}"
|
|
|
|
|
|
|
|
35 def retrieve_signature
|
|
36 @signature = Signature.sponsors.find(signature_id)
|
|
37 @petition = @signature.petition
|
|
|
|
39 if @petition.flagged? || @petition.hidden? || @petition.stopped?
|
|
40 raise ActiveRecord::RecordNotFound, "Unable to find Signature with id: #{signature_id}"
|
|
|
|
|
|
|
- DuplicateMethodCall - calls '@petition.sponsors' 2 times » reek
- Complexity 2 » saikuro
|
|
|
45 if action_name == "new"
|
|
46 @signature = @petition.sponsors.build(signature_params_for_new)
|
|
|
|
48 @signature = @petition.sponsors.build(signature_params_for_create)
|
|
|
|
|
|
|
|
52 def send_email_to_petition_signer
|
|
53 unless @signature.email_threshold_reached?
|
|
54 if @signature.pending?
|
|
55 PetitionAndEmailConfirmationForSponsorEmailJob.perform_later(@signature)
|
|
|
|
57 EmailDuplicateSignaturesEmailJob.perform_later(@signature)
|
|
|
|
|
|
|
|
|
|
62 def send_sponsor_support_notification_email_to_petition_owner
|
|
63 if @petition.collecting_sponsors?
|
|
64 if @petition.will_reach_threshold_for_moderation?
|
|
65 SponsorSignedEmailOnThresholdEmailJob.perform_later(@signature)
|
|
66 elsif @signature.just_validated?
|
|
67 SponsorSignedEmailBelowThresholdEmailJob.perform_later(@signature)
|
|
|
|
|
|
|
|
|
|
|
|
73 thank_you_petition_sponsors_url(@petition, token: @petition.sponsor_token)
|
|
|
|
|
|
76 def signed_token_failure_url
|
|
77 moderation_info_petition_url(@petition)
|
|
|
|
|
|
80 def redirect_to_new_sponsor_page_if_validated
|
|
81 if @signature.validated_before?(15.minutes.ago)
|
|
82 redirect_to new_petition_sponsor_url(@petition, token: @petition.sponsor_token)
|
|
|
|
|
|
|
|
86 def redirect_to_petition_page_if_moderated
|
|
87 if @petition.moderated?
|
|
88 redirect_to petition_url(@petition)
|
|
|
|
|
|
|
|
92 def redirect_to_moderation_info_page_if_sponsored
|
|
93 if @petition.has_maximum_sponsors?
|
|
94 redirect_to moderation_info_petition_url(@petition)
|
|
|
|
|
|
|
|
|
|
99 @petition.validate_creator!
|
|
|
|
|