Skip to content

Commit

Permalink
Merge branch '1179-volunteer-contact-form'
Browse files Browse the repository at this point in the history
  • Loading branch information
gbp committed Jul 6, 2022
2 parents d67114d + b448f75 commit 46d75fd
Show file tree
Hide file tree
Showing 8 changed files with 259 additions and 1 deletion.
8 changes: 8 additions & 0 deletions app/assets/stylesheets/responsive/custom.scss
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,14 @@ dd {

label {
margin-bottom: 0.3em;

input[type="radio"], input[type="checkbox"] {
margin: 0 3px 0 -20px
}

&.form_inline {
padding-left: 20px;
}
}

input[type="text"],
Expand Down
4 changes: 3 additions & 1 deletion lib/alavetelitheme.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ def prepend_theme_assets
'controller_patches.rb',
'model_patches.rb',
'helper_patches.rb',
'mailer_patches.rb',
'analytics_event.rb',
'public_body_questions.rb']
'public_body_questions.rb',
'volunteer_contact_form.rb']
require File.expand_path "../#{patch}", __FILE__
end

Expand Down
2 changes: 2 additions & 0 deletions lib/controller_patches.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Please arrange overridden classes alphabetically.
Rails.configuration.to_prepare do
HelpController.class_eval do
prepend VolunteerContactForm::ControllerMethods

before_action :set_history, except: :index

def principles; end
Expand Down
6 changes: 6 additions & 0 deletions lib/mailer_patches.rb
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
24 changes: 24 additions & 0 deletions lib/views/contact_mailer/volunteer_message.text.erb
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") %>
---------------------------------------------------------------------
91 changes: 91 additions & 0 deletions lib/views/help/_contact_volunteer_form.html.erb
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 %>
29 changes: 29 additions & 0 deletions lib/views/help/contact.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,35 @@
</div>


<h2 class="contact-page__goal" id="wdtk">
<label class="houdini-label" for="goal3">
I’d like to get involved and become a <strong>volunteer</strong>
</label>
</h2>

<input class="houdini-input" type="radio" name="goals" id="goal3"
<% if params["contact"] && params[:current_form] == 'wdtk' %>checked<% end %>>
<div class="houdini-target contact-page__options">
<ul>
<li>
Please use this form if you are interested in volunteering for
WhatDoTheyKnow
</li>
<li>
If you would like more information on what volunteering
involves, see
<%= link_to _("our get involved page"), help_volunteers_path %>.
</li>
<li>
<%= foi_error_messages_for :contact %>

<%= render :partial => "help/contact_volunteer_form",
:locals => { :form_id => 'wdtk_volunteer' } %>
</li>
</ul>
</div>


<h2 class="contact-page__goal" id="wdtk">
<label class="houdini-label" for="goal3">
I have another issue, or feedback relating to the
Expand Down
96 changes: 96 additions & 0 deletions lib/volunteer_contact_form.rb
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

0 comments on commit 46d75fd

Please sign in to comment.