Skip to content

Commit

Permalink
Move Regional Organizations' application form to the website.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlbertoPdRF committed Jun 23, 2019
1 parent 99210a1 commit fb64450
Show file tree
Hide file tree
Showing 13 changed files with 179 additions and 74 deletions.
13 changes: 9 additions & 4 deletions WcaOnRails/app/controllers/regional_organizations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class RegionalOrganizationsController < ApplicationController
before_action :authenticate_user!, except: [:index]
before_action -> { redirect_to_root_unless_user(:can_manage_regional_organizations?) }, except: [:index]
before_action -> { redirect_to_root_unless_user(:can_manage_regional_organizations?) }, except: [:index, :new, :create]

def admin
@regional_organizations = RegionalOrganization.all.order(country: :asc)
Expand All @@ -24,7 +24,7 @@ def update
@regional_organization = regional_organization_from_params

if @regional_organization.update_attributes(regional_organization_params)
flash[:success] = "Updated Regional Organization"
flash[:success] = "Successfully updated Regional Organization!"
redirect_to edit_regional_organization_path(@regional_organization)
else
render :edit
Expand All @@ -38,8 +38,13 @@ def create
@regional_organization.bylaws.attach(params[:regional_organization][:bylaws])
@regional_organization.extra_file.attach(params[:regional_organization][:extra_file])
if @regional_organization.save
flash[:success] = "Created new Regional Organization"
redirect_to edit_regional_organization_path(@regional_organization)
flash[:success] = t('.create_success')
RegionalOrganizationsMailer.notify_board_of_new_regional_organization_application(current_user, @regional_organization).deliver_later
if current_user.can_manage_regional_organizations?
redirect_to edit_regional_organization_path(@regional_organization)
else
redirect_to root_path
end
else
@regional_organization.errors[:name].concat(@regional_organization.errors[:id])
render :new
Expand Down
17 changes: 17 additions & 0 deletions WcaOnRails/app/mailers/regional_organizations_mailer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

class RegionalOrganizationsMailer < ApplicationMailer
def notify_board_of_new_regional_organization_application(user_who_applied, regional_organization)
I18n.with_locale :en do
@user_who_applied = user_who_applied
@regional_organization = regional_organization
to = ["board@worldcubeassociation.org"]
cc = [@user_who_applied.email, @regional_organization.email]
mail(
to: to,
cc: cc,
subject: "Regional Organization application - #{@regional_organization.name}",
)
end
end
end
6 changes: 3 additions & 3 deletions WcaOnRails/app/models/regional_organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ class RegionalOrganization < ApplicationRecord
has_one_attached :bylaws
has_one_attached :extra_file

scope :currently_acknowledged, -> { where("end_date IS NULL OR end_date > ?", Date.today) }
scope :not_currently_acknowledged, -> { where("end_date < ?", Date.today) }
scope :currently_acknowledged, -> { where("start_date IS NOT NULL AND end_date IS NULL OR end_date > ?", Date.today) }
scope :pending_approval, -> { where("start_date IS NULL") }
scope :previously_acknowledged, -> { where("start_date IS NOT NULL AND end_date < ?", Date.today) }

validates_presence_of :name, :country, :email, :address, :directors_and_officers, :area_description, :past_and_current_activities, :future_plans
validates :website, presence: true, format: { with: %r{\Ahttps?://.*\z} }
Expand All @@ -19,7 +20,6 @@ def validate_email
errors.add(:email, I18n.t('common.errors.invalid')) unless ValidateEmail.valid?(email)
end

validates :start_date, presence: true
validate :start_date_must_be_earlier_than_end_date
def start_date_must_be_earlier_than_end_date
if start_date && end_date && start_date >= end_date
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<%= f.input :website %>
<%= f.input :logo %>
<% if @regional_organization.logo.attached? && @regional_organization.logo.previewable? %>
<% if @regional_organization.logo.attached? %>
<%= image_tag @regional_organization.logo.variant(resize: "200x200") %>
<% end %>

Expand All @@ -33,17 +33,21 @@
<%= link_to(image_tag(@regional_organization.extra_file.preview(resize: "200x200")), rails_blob_path(@regional_organization.extra_file, disposition: "attachment")) %>
<% end %>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-9">
<div class="row">
<%= f.input :start_date, as: :date_picker, wrapper: :ranged_datetime %>
<%= f.input :end_date, as: :date_picker, wrapper: :ranged_datetime %>
<% if @current_user.can_manage_regional_organizations? %>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-9">
<div class="row">
<%= f.input :start_date, as: :date_picker, wrapper: :ranged_datetime %>
<%= f.input :end_date, as: :date_picker, wrapper: :ranged_datetime %>
</div>
</div>
</div>
</div>
<% end %>

<div class="form-group form-actions">
<%= link_to icon("undo", "Back to Regional Organizations list"), admin_regional_organizations_path, class: "btn btn-default" %>
<% if @current_user.can_manage_regional_organizations? %>
<%= link_to icon("undo", "Back to Regional Organizations list"), admin_regional_organizations_path, class: "btn btn-default" %>
<% end %>
<%= f.button :submit, class: "btn btn-primary" %>
</div>
<% end %>
9 changes: 7 additions & 2 deletions WcaOnRails/app/views/regional_organizations/admin.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
<%= render "regional_organizations/regional_organizations_table", regional_organizations: @regional_organizations.currently_acknowledged %>
<% end %>
<% unless @regional_organizations.not_currently_acknowledged.empty? %>
<% unless @regional_organizations.pending_approval.empty? %>
<h2>Pending approval:</h2>
<%= render "regional_organizations/regional_organizations_table", regional_organizations: @regional_organizations.pending_approval %>
<% end %>
<% unless @regional_organizations.previously_acknowledged.empty? %>
<h2>Previously acknowledged:</h2>
<%= render "regional_organizations/regional_organizations_table", regional_organizations: @regional_organizations.not_currently_acknowledged %>
<%= render "regional_organizations/regional_organizations_table", regional_organizations: @regional_organizations.previously_acknowledged %>
<% end %>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<h1>
<%= @user_who_applied.name %> has submitted an application for <%= @regional_organization.name %> to be acknowledged as a WCA Regional Organization.
</h1>
<p>
Here's the Regional Organization data:
<ul>
<li><b><%= t 'activerecord.attributes.regional_organization.name' %>:</b> <%= @regional_organization.name %></li>
<li><b><%= t 'activerecord.attributes.regional_organization.country' %>:</b> <%= @regional_organization.country %></li>
<li><b><%= t 'activerecord.attributes.regional_organization.website' %>:</b> <%= link_to "#{@regional_organization.website}", @regional_organization.website %></li>
<% if @regional_organization.logo.attached? %>
<li><b><%= t 'activerecord.attributes.regional_organization.logo' %>:</b></li>
<%= link_to(image_tag(@regional_organization.logo.variant(resize: "200x200")), rails_blob_url(@regional_organization.logo, disposition: "attachment")) %>
<% end %>
<li><b><%= t 'activerecord.attributes.regional_organization.email' %>:</b> <%= mail_to @regional_organization.email, "#{@regional_organization.email}" %></li>
<li><b><%= t 'activerecord.attributes.regional_organization.address' %>:</b> <%= @regional_organization.address %></li>
<% if @regional_organization.bylaws.attached? && @regional_organization.bylaws.previewable? %>
<li><b><%= t 'activerecord.attributes.regional_organization.bylaws' %>:</b></li>
<%= link_to(image_tag(@regional_organization.bylaws.preview(resize: "200x200")), rails_blob_url(@regional_organization.bylaws, disposition: "attachment")) %>
<% end %>
<li><b><%= t 'activerecord.attributes.regional_organization.directors_and_officers' %>:</b> <%= @regional_organization.directors_and_officers %></li>
<li><b><%= t 'activerecord.attributes.regional_organization.area_description' %>:</b> <%= @regional_organization.area_description %></li>
<li><b><%= t 'activerecord.attributes.regional_organization.past_and_current_activities' %>:</b> <%= @regional_organization.past_and_current_activities %></li>
<li><b><%= t 'activerecord.attributes.regional_organization.future_plans' %>:</b> <%= @regional_organization.future_plans %></li>
<% if @regional_organization.extra_information? %>
<li><b>Extra information:</b> <%= @regional_organization.extra_information %></li>
<% end %>
<% if @regional_organization.extra_file.attached? && @regional_organization.extra_file.previewable? %>
<li><b>Extra file:</b></li>
<%= link_to(image_tag(@regional_organization.extra_file.preview(resize: "200x200")), rails_blob_url(@regional_organization.extra_file, disposition: "attachment")) %>
<% end %>
</ul>
</p>
<p>
@Board: You can check all the information and approve or reject the application in the <%= link_to "Edit Regional Organization", edit_regional_organization_url(@regional_organization) %> page.
</p>
22 changes: 9 additions & 13 deletions WcaOnRails/config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1564,33 +1564,29 @@ en:
content: "The WCA acknowledges the following Regional Organizations:"
empty: "No Regional Organizations are currently acknowledged by the WCA."
how_to:
title: How to become a WCA Regional Organization
description: The WCA recognizes various regional organizations worldwide.
The purpose of a WCA regional organization is to organize WCA
Competitions and support the WCA’s activities in the region. Countries
wishing to form a regional organization are encouraged to contribute to
the WCA in their area before submitting their application. For help
organizing a WCA competition in your area, please contact your nearest
Delegate.
title: How to become an acknowledged WCA Regional Organization
description: The WCA recognizes various Regional Organizations worldwide. The purpose of a WCA Regional Organization is to organize WCA Competitions and support the WCA’s activities in the region. Countries wishing to form a Regional Organization are encouraged to contribute to the WCA in their area before submitting their application. For help organizing a WCA competition in your area, please contact your nearest WCA Delegate.
requirements:
title: Requirements for WCA Regional Organizations
list:
'1': To actively organize or support WCA Competitions in the region of the organization
'2': To actively contribute to the Continental WCA Competitions that are held in the continent of the Regional Organization
'3': To respect and operationalize the Objectives set out in the Bylaws and Regulations of the WCA
'2': To contribute to the Continental WCA Competitions that are held in the continent of the Regional Organization, if required by the corresponding Organization Team
'3': To respect and operationalize the Objectives set out in the WCA Bylaws and Motions
'4': To comply with all applicable WCA Regulations
'5': To accept and comply with decisions of WCA Officials
'6': To keep on file with the WCA a copy of its current Bylaws and regulations in an electronic format
'5': To accept and comply with decisions of WCA Staff
'6': To keep on file at the WCA a copy of its current bylaws and, if applicable, regulations in an electronic format
application_instructions:
title: Application Instructions
description_html: Please fill out <a href='https://docs.google.com/forms/d/e/1FAIpQLSfX2HbafvMbWw-9DTgIP0Zf7im1VMZEaRq1J-jXnyW2nVYzsg/viewform'>this form</a>.
description_html: To apply for acknowledgment, please fill out <a href='/regional-organizations/new'>this form</a>.
regional_organization_form:
filling_instructions_html: "Please fill everything <b>in English!</b>"
public_information: "Public information"
private_information: "Private information"
private_information_disclaimer: "All the information below will only be visible to the WCA Board of Directors"
errors:
end_date_after_start_date: "cannot be after Acknowledged until"
create:
create_success: "Application successfully submitted! Please check your email, and wait for the WCA Board of Directors to review it"
#context: Contact page
contact:
title: "Contact Information"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class AllowNullStartDateForRegionalOrganizations < ActiveRecord::Migration[5.2]
def change
change_column_null(:regional_organizations, :start_date, true)
end
end
5 changes: 3 additions & 2 deletions WcaOnRails/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1028,7 +1028,7 @@ CREATE TABLE `regional_organizations` (
`name` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`country` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`website` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
`start_date` date NOT NULL,
`start_date` date DEFAULT NULL,
`end_date` date DEFAULT NULL,
`created_at` datetime NOT NULL,
`updated_at` datetime NOT NULL,
Expand Down Expand Up @@ -1556,4 +1556,5 @@ INSERT INTO `schema_migrations` (version) VALUES
('20190216102110'),
('20190221194112'),
('20190601105825'),
('20190601231550');
('20190601231550'),
('20190622173635');
1 change: 1 addition & 0 deletions WcaOnRails/spec/factories/regional_organizations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
area_description { "World" }
past_and_current_activities { "Activities" }
future_plans { "Plans" }
extra_information { "" }
start_date { Date.today }
end_date { nil }
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

# Preview all emails at http://localhost:3000/rails/mailers/regional_organizations_mailer
class RegionalOrganizationsMailerPreview < ActionMailer::Preview
def notify_board_of_new_regional_organization_application
user = User.first
regional_organization = FactoryBot.create(:regional_organization)
RegionalOrganizationsMailer.notify_board_of_new_regional_organization_application(user, regional_organization)
end
end
24 changes: 24 additions & 0 deletions WcaOnRails/spec/mailers/regional_organizations_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe RegionalOrganizationsMailer, type: :mailer do
describe "notify_board_of_new_regional_organization_application" do
let(:user) { FactoryBot.create :user }
let(:regional_organization) { FactoryBot.create :regional_organization }
let(:mail) do
I18n.locale = :es
RegionalOrganizationsMailer.notify_board_of_new_regional_organization_application(user, regional_organization)
end

it "renders in English" do
expect(mail.to).to eq(["board@worldcubeassociation.org"])
expect(mail.cc).to eq([user.email, regional_organization.email])
expect(mail.from).to eq(["notifications@worldcubeassociation.org"])

expect(mail.subject).to eq("Regional Organization application - #{regional_organization.name}")
expect(mail.body.encoded).to match("#{user.name} has submitted an application for #{regional_organization.name} to be acknowledged as a WCA Regional Organization.")
expect(mail.body.encoded).to match(edit_regional_organization_url(regional_organization))
end
end
end
Loading

0 comments on commit fb64450

Please sign in to comment.