-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Requires core changes: mysociety/alaveteli#7063 Fixes: #1179
- Loading branch information
Showing
8 changed files
with
259 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Please arrange overridden classes alphabetically. | ||
Rails.configuration.to_prepare do | ||
ContactMailer.class_eval do | ||
prepend VolunteerContactForm::MailerMethods | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
Name: <%= @contact.name %> | ||
Email: <%= @contact.email %> | ||
Age: <%= @contact.age %> | ||
|
||
Why: | ||
<%= @contact.why.strip.gsub(/^/, '> ') %> | ||
|
||
Tasks: | ||
<%= @contact.tasks.map { |t| '- ' + t }.join("\n") %> | ||
|
||
Experience: | ||
<%= @contact.experience.strip.gsub(/^/, '> ') %> | ||
|
||
Anything else: | ||
<%= @contact.anything_else.strip.gsub(/^/, '> ') %> | ||
|
||
--------------------------------------------------------------------- | ||
<%= _('Message sent using {{site_name}} volunteer contact form, ', | ||
:site_name => site_name.html_safe) %> | ||
<%= @logged_in_user ? | ||
_("logged in as user {{user_name}}", | ||
:user_name => user_url(@logged_in_user)) : | ||
_("not logged in") %> | ||
--------------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
<%= form_for :contact, | ||
url: help_contact_path + '#' + form_id, | ||
html: { class: 'contact-form' } do |f| %> | ||
<% if not @user %> | ||
<p> | ||
<label class="form_label" for="contact_name">My name:</label> | ||
<%= f.text_field :name, size: 20, required: true %> | ||
(or <%= link_to "sign in", signin_url(r: request.fullpath + '#' + form_id) %>) | ||
</p> | ||
|
||
<p> | ||
<label class="form_label" for="contact_email">My email:</label> | ||
<%= f.text_field :email, size: 20, required: true %> | ||
</p> | ||
<% end %> | ||
|
||
<p> | ||
<label class="form_label" for="contact_why">Why would you like to volunteer for us?</label> | ||
<span class="form_item_note"> | ||
Please introduce yourself and tell us what interests you about FOI. If you are new to FOI and are interested in learning more through volunteering at WhatDoTheyKnow, that’s fine too!<br><br> | ||
</span> | ||
<%= f.text_area :why, rows: 10 %> | ||
</p> | ||
|
||
<p> | ||
<label class="form_label" for="contact_tasks">What kind of tasks are you interested in?</label> | ||
<%= f.fields_for :tasks do |t| %> | ||
<% VolunteerContactForm::TASKS.each do |k, v| %> | ||
<%= t.label k, class: 'form_inline' do %> | ||
<%= t.check_box k, {}, v %> | ||
<%= v %> | ||
<% end %> | ||
<% end %> | ||
<% end %> | ||
</p> | ||
|
||
<p> | ||
<label class="form_label" for="contact_experience">Do you have any previous relevant experience that you could tell us about?</label> | ||
|
||
<span class="form_item_note"> | ||
There's a wide range of different jobs, hobbies or experiences that could be helpful in volunteering at WhatDoTheyKnow.<br><br> | ||
Let us know of anything you think might be relevant: maybe a link to a website you've contributed to, your social media, or campaigning that you've been involved in.<br><br> | ||
Perhaps you're studying for a course that has a link to transparency or FOI, such as law or media; or you've had a job that involved working with the public. Even if you've never done anything directly linked to FOI, it'd be great to hear about anything that shows you have skills that can be applied to the sort of task you're interested in.<br><br> | ||
Finally, if you've got a CV online, please do include the link.<br><br> | ||
</span> | ||
|
||
<%= f.text_area :experience, rows: 10 %> | ||
</p> | ||
|
||
<p> | ||
<label class="form_label" for="contact_anything_else">Anything else?</label> | ||
|
||
<span class="form_item_note"> | ||
Is there anything else that you’d like to tell us?<br><br> | ||
</span> | ||
|
||
<%= f.text_area :anything_else, rows: 10 %> | ||
</p> | ||
|
||
<p> | ||
<label class="form_label" for="contact_age">How old are you?<label> | ||
|
||
<span class="form_item_note"> | ||
We restrict some of our work to those aged 18 or over due to the fact it sometimes involves dealing with sensitive material, but we are still happy for people under 18 to help with some tasks.<br><br> | ||
</span> | ||
|
||
<%= f.label :age_under_18, class: 'form_inline' do %> | ||
<%= f.radio_button :age, label = 'Under 18' %> | ||
<%= label %> | ||
<% end %> | ||
<%= f.label :age_18_or_over, class: 'form_inline' do %> | ||
<%= f.radio_button :age, label = '18 or over' %> | ||
<%= label %> | ||
<% end %> | ||
</p> | ||
|
||
<p style="display:none;"> | ||
<%= f.label :comment, 'Do not fill in this field' %> | ||
<%= f.text_field :comment %> | ||
</p> | ||
|
||
<% if @recaptcha_required %> | ||
<%= recaptcha_tags %><br> | ||
<% end %> | ||
|
||
<div class="form_button"> | ||
<%= hidden_field_tag(:current_form, form_id) %> | ||
<%= hidden_field_tag(:submitted_contact_form, 1) %> | ||
<%= submit_tag "Send message to WhatDoTheyKnow team", data: { disable_with: "Sending..." } %> | ||
</div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
module VolunteerContactForm | ||
TASKS = { | ||
admin: _('Administration tasks such as updating our database of public authorities'), | ||
comms: _('Communications tasks such as blog writing or updating public notes on the site'), | ||
legal: _('Legal tasks such as being involved in reviewing GDPR requests'), | ||
user_support: _('User assistance tasks, such as responding to requests for help and advice in using WhatDoTheyKnow or making requests'), | ||
campaign: _('Campaign-focused tasks such as helping to shape and put into effect our activism around FOI'), | ||
other: _('Other - please let us know what type of task you would like to take on'), | ||
not_sure: _('I’m not sure yet') | ||
}.freeze | ||
|
||
module ControllerMethods | ||
private | ||
|
||
def contact_validator | ||
return super unless contact_volunteer_form? | ||
|
||
ContactVolunteerValidator.new(contact_params) | ||
end | ||
|
||
def contact_mailer | ||
return super unless contact_volunteer_form? | ||
|
||
ContactMailer.volunteer_message(contact_validator, @user) | ||
end | ||
|
||
def contact_params | ||
return super unless contact_volunteer_form? | ||
|
||
params.require(:contact).except(:comment).permit( | ||
:name, :email, :why, :experience, :anything_else, :age, | ||
tasks: TASKS.keys | ||
).tap do |p| | ||
p[:tasks] = p[:tasks].to_h.inject([]) do |m, (_, v)| | ||
m << v if v != '0' | ||
m | ||
end | ||
end | ||
end | ||
|
||
def contact_volunteer_form? | ||
params[:current_form] == 'wdtk_volunteer' | ||
end | ||
end | ||
|
||
module MailerMethods | ||
def volunteer_message(contact, logged_in_user) | ||
@contact = contact | ||
@logged_in_user = logged_in_user | ||
|
||
# From is an address we control so that strict DMARC senders don't get | ||
# refused | ||
from = MailHandler.address_from_name_and_email( | ||
contact.name, blackhole_email | ||
) | ||
reply_to_address = MailHandler.address_from_name_and_email( | ||
contact.name, contact.email | ||
) | ||
set_reply_to_headers(nil, 'Reply-To' => reply_to_address) | ||
|
||
mail( | ||
from: from, | ||
to: contact_from_name_and_email, | ||
subject: _('Message from WDTK volunteer contact form') | ||
) | ||
end | ||
end | ||
|
||
class ContactVolunteerValidator | ||
include ActiveModel::Validations | ||
|
||
attr_accessor :name, :email, :why, :tasks, :experience, :anything_else, | ||
:age, :comment | ||
|
||
validates_presence_of :name, :message => N_("Please enter your name") | ||
validates_presence_of :email, :message => N_("Please enter your email address") | ||
validates_presence_of :why, :message => N_("Please tell us why you're interested in becoming a volunteer") | ||
validates_presence_of :experience, :message => N_("Please list any relevant experience") | ||
validates_presence_of :age, :message => N_("Please confim your age") | ||
validate :email_format | ||
|
||
def initialize(attributes = {}) | ||
attributes.each do |name, value| | ||
send("#{name}=", value) | ||
end | ||
end | ||
|
||
private | ||
|
||
def email_format | ||
unless MySociety::Validate.is_valid_email(email) | ||
errors.add(:email, _("Email doesn't look like a valid address")) | ||
end | ||
end | ||
end | ||
end |