Skip to content

Commit

Permalink
Merge pull request #645 from alphagov/add-easter-message
Browse files Browse the repository at this point in the history
Add a moderation delay message for Easter
  • Loading branch information
pixeltrix authored Mar 29, 2018
2 parents 1d1c4fa + dbfc33b commit 7de060c
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 34 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ GEM
logstash-event (1.2.02)
logstash-logger (0.25.1)
logstash-event (~> 1.2)
loofah (2.2.1)
loofah (2.2.2)
crass (~> 1.0.2)
nokogiri (>= 1.5.9)
mail (2.7.0)
Expand Down Expand Up @@ -220,8 +220,8 @@ GEM
activesupport (>= 4.2.0.beta, < 5.0)
nokogiri (~> 1.6)
rails-deprecated_sanitizer (>= 1.0.1)
rails-html-sanitizer (1.0.3)
loofah (~> 2.0)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
railties (4.2.10)
actionpack (= 4.2.10)
activesupport (= 4.2.10)
Expand Down
4 changes: 4 additions & 0 deletions app/assets/stylesheets/petitions/_forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ select.form-control:hover {
width: 25%;
}

.form-control-auto {
width: auto;
}

.form-group {
margin-bottom: $gutter;
clear: both;
Expand Down
34 changes: 34 additions & 0 deletions app/controllers/admin/holidays_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
class Admin::HolidaysController < Admin::AdminController
before_action :require_sysadmin
before_action :fetch_holiday

def edit
respond_to do |format|
format.html
end
end

def update
if @holiday.update(holiday_params)
redirect_to edit_admin_site_url, notice: :site_updated
else
respond_to do |format|
format.html { render :edit }
end
end
end

private

def fetch_holiday
@holiday = Holiday.instance
end

def holiday_params
params.require(:holiday).permit(*holiday_attributes)
end

def holiday_attributes
%i[christmas_start christmas_end easter_start easter_end]
end
end
12 changes: 5 additions & 7 deletions app/helpers/date_time_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,10 @@ def scheduled_for_debate_in_words(date, today = Date.current)
end

def christmas_period?(today = Date.current)
if today.mon == 12
today.day > 21 ? true : false
elsif today.mon == 1
today.day < 5 ? true : false
else
false
end
Holiday.christmas?(today)
end

def easter_period?(today = Date.current)
Holiday.easter?(today)
end
end
48 changes: 48 additions & 0 deletions app/models/holiday.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
class Holiday < ActiveRecord::Base
class << self
def before_remove_const
Thread.current[:__holiday__] = nil
end

def instance
Thread.current[:__holiday__] ||= first_or_create(defaults)
end

def christmas?(today = Date.current)
instance.christmas?(today)
end

def easter?(today = Date.current)
instance.easter?(today)
end

private

def defaults
{
christmas_start: '2017-12-22',
christmas_end: '2018-01-04',
easter_start: '2018-03-30',
easter_end: '2018-04-09'
}
end
end

def christmas?(today = Date.current)
christmas.cover?(today)
end

def easter?(today = Date.current)
easter.cover?(today)
end

private

def christmas
christmas_start..christmas_end
end

def easter
easter_start..easter_end
end
end
2 changes: 2 additions & 0 deletions app/models/invalidation.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'textacular/searchable'

class Invalidation < ActiveRecord::Base
extend Searchable(:id, :summary, :details, :petition_id)
include Browseable
Expand Down
28 changes: 28 additions & 0 deletions app/views/admin/holidays/edit.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<h1>Edit Site</h1>

<div class="grid-row">
<div class="grid-column">
<%= render "admin/shared/site_tabs" %>
</div>

<div class="column-two-thirds extra-gutter">
<%= form_for @holiday, url: admin_holidays_url do |form| %>
<div class="form-group">
<label class="form-label" for="holiday_christmas_start">Christmas period</label>
<%= form.date_select :christmas_start, {}, tabindex: increment, class: 'form-control form-control-auto' %>
<%= form.date_select :christmas_end, {}, tabindex: increment, class: 'form-control form-control-auto' %>
</div>

<div class="form-group">
<label class="form-label" for="holiday_easter_start">Easter period</label>
<%= form.date_select :easter_start, {}, tabindex: increment, class: 'form-control form-control-auto' %>
<%= form.date_select :easter_end, {}, tabindex: increment, class: 'form-control form-control-auto' %>
</div>

<%= form.submit 'Save', class: 'button' %>
<%= link_to 'Cancel', admin_root_path, class: 'button-secondary' %>
<% end %>
</div>
</div>
33 changes: 33 additions & 0 deletions app/views/admin/shared/_site_tabs.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<p class="tabs">
<% if params[:tab] == "petitions" %>
<%= link_to "Description", edit_admin_site_path %> |
Petitions |
<%= link_to "Moderation", edit_admin_site_path(tab: 'moderation') %> |
<%= link_to "Access", edit_admin_site_path(tab: 'access') %> |
<%= link_to "Holidays", edit_admin_holidays_path %>
<% elsif params[:tab] == "moderation" %>
<%= link_to "Description", edit_admin_site_path %> |
<%= link_to "Petitions", edit_admin_site_path(tab: 'petitions') %> |
Moderation |
<%= link_to "Access", edit_admin_site_path(tab: 'access') %> |
<%= link_to "Holidays", edit_admin_holidays_path %>
<% elsif params[:tab] == "access" %>
<%= link_to "Description", edit_admin_site_path %> |
<%= link_to "Petitions", edit_admin_site_path(tab: 'petitions') %> |
<%= link_to "Moderation", edit_admin_site_path(tab: 'moderation') %> |
Access |
<%= link_to "Holidays", edit_admin_holidays_path %>
<% elsif controller_name == "holidays" %>
<%= link_to "Description", edit_admin_site_path %> |
<%= link_to "Petitions", edit_admin_site_path(tab: 'petitions') %> |
<%= link_to "Moderation", edit_admin_site_path(tab: 'moderation') %> |
<%= link_to "Access", edit_admin_site_path(tab: 'access') %> |
Holidays
<% else %>
Description |
<%= link_to "Petitions", edit_admin_site_path(tab: 'petitions') %> |
<%= link_to "Moderation", edit_admin_site_path(tab: 'moderation') %> |
<%= link_to "Access", edit_admin_site_path(tab: 'access') %> |
<%= link_to "Holidays", edit_admin_holidays_path %>
<% end %>
</p>
24 changes: 1 addition & 23 deletions app/views/admin/sites/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,7 @@

<div class="grid-row">
<div class="grid-column">
<p class="tabs">
<% if params[:tab] == "petitions" %>
<%= link_to "Description", edit_admin_site_path %> |
Petitions |
<%= link_to "Moderation", edit_admin_site_path(tab: 'moderation') %> |
<%= link_to "Access", edit_admin_site_path(tab: 'access') %>
<% elsif params[:tab] == "moderation" %>
<%= link_to "Description", edit_admin_site_path %> |
<%= link_to "Petitions", edit_admin_site_path(tab: 'petitions') %> |
Moderation |
<%= link_to "Access", edit_admin_site_path(tab: 'access') %>
<% elsif params[:tab] == "access" %>
<%= link_to "Description", edit_admin_site_path %> |
<%= link_to "Petitions", edit_admin_site_path(tab: 'petitions') %> |
<%= link_to "Moderation", edit_admin_site_path(tab: 'moderation') %> |
Access
<% else %>
Description |
<%= link_to "Petitions", edit_admin_site_path(tab: 'petitions') %> |
<%= link_to "Moderation", edit_admin_site_path(tab: 'moderation') %> |
<%= link_to "Access", edit_admin_site_path(tab: 'access') %>
<% end %>
</p>
<%= render "admin/shared/site_tabs" %>
</div>

<div class="column-two-thirds extra-gutter">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

<% if christmas_period? %>
<p><%= @sponsor_count %> people have supported your petition so far. We’re checking your petition to make sure it meets the petition standards. If it does, we’ll publish it. This usually takes a week or less but over the Christmas period it may take us a little longer than usual. We’ll check your petition as quickly as we can.</p>
<% elsif easter_period? %>
<p><%= @sponsor_count %> people have supported your petition so far. We’re checking your petition to make sure it meets the petition standards. If it does, we’ll publish it. This usually takes a week or less but over the Easter period it may take us a little longer than usual. We’ll check your petition as quickly as we can.</p>
<% else %>
<p><%= @sponsor_count %> people have supported your petition so far. We’re checking your petition to make sure it meets the petition standards. If it does, we’ll publish it. This usually takes a week or less.</p>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ Your petition is nearly ready to go.

<% if christmas_period? %>
<%= @sponsor_count %> people have supported your petition so far. We’re checking your petition to make sure it meets the petition standards. If it does, we’ll publish it. This usually takes a week or less but over the Christmas period it may take us a little longer than usual. We’ll check your petition as quickly as we can.
<% elsif christmas_period? %>
<%= @sponsor_count %> people have supported your petition so far. We’re checking your petition to make sure it meets the petition standards. If it does, we’ll publish it. This usually takes a week or less but over the Easter period it may take us a little longer than usual. We’ll check your petition as quickly as we can.
<% else %>
<%= @sponsor_count %> people have supported your petition so far. We’re checking your petition to make sure it meets the petition standards. If it does, we’ll publish it. This usually takes a week or less.
<% end %>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@

resource :rate_limits, path: 'rate-limits', only: %i[edit update]
resource :site, only: %i[edit update]
resource :holidays, only: %i[edit update]

resources :signatures, only: %i[index destroy] do
post :validate, :invalidate, on: :member
Expand Down
11 changes: 11 additions & 0 deletions db/migrate/20180329062433_create_holidays.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class CreateHolidays < ActiveRecord::Migration
def change
create_table :holidays do |t|
t.date :christmas_start
t.date :christmas_end
t.date :easter_start
t.date :easter_end
t.timestamps null: false
end
end
end
51 changes: 51 additions & 0 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,40 @@ CREATE SEQUENCE government_responses_id_seq
ALTER SEQUENCE government_responses_id_seq OWNED BY government_responses.id;


--
-- Name: holidays; Type: TABLE; Schema: public; Owner: -; Tablespace:
--

CREATE TABLE holidays (
id integer NOT NULL,
christmas_start date,
christmas_end date,
easter_start date,
easter_end date,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);


--
-- Name: holidays_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE holidays_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;


--
-- Name: holidays_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE holidays_id_seq OWNED BY holidays.id;


--
-- Name: invalidations; Type: TABLE; Schema: public; Owner: -; Tablespace:
--
Expand Down Expand Up @@ -1266,6 +1300,13 @@ ALTER TABLE ONLY feedback ALTER COLUMN id SET DEFAULT nextval('feedback_id_seq':
ALTER TABLE ONLY government_responses ALTER COLUMN id SET DEFAULT nextval('government_responses_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY holidays ALTER COLUMN id SET DEFAULT nextval('holidays_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--
Expand Down Expand Up @@ -1478,6 +1519,14 @@ ALTER TABLE ONLY government_responses
ADD CONSTRAINT government_responses_pkey PRIMARY KEY (id);


--
-- Name: holidays_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--

ALTER TABLE ONLY holidays
ADD CONSTRAINT holidays_pkey PRIMARY KEY (id);


--
-- Name: invalidations_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace:
--
Expand Down Expand Up @@ -2607,3 +2656,5 @@ INSERT INTO schema_migrations (version) VALUES ('20171204113835');

INSERT INTO schema_migrations (version) VALUES ('20171204122339');

INSERT INTO schema_migrations (version) VALUES ('20180329062433');

2 changes: 1 addition & 1 deletion features/step_definitions/common_steps.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
end

Then(/^I wait for (\d+) ((?:day|week|month|year|)s?)$/) do |duration, period|
travel(duration.to_i.send(period) + 1.second)
travel_to(Time.current + (duration.to_i.send(period) + 1.second))
end

Then /^the response status should be (\d+)$/ do |code|
Expand Down
Loading

0 comments on commit 7de060c

Please sign in to comment.