Commit 231f4642 authored by Mario Manno's avatar Mario Manno

move notifications onto conferences

parent c83e06f8
......@@ -27,29 +27,19 @@ class CallForPapersController < ApplicationController
@call_for_papers = @conference.call_for_papers
end
def edit_notifications
@call_for_papers = @conference.call_for_papers
end
def update
@call_for_papers = @conference.call_for_papers
if @call_for_papers.update_attributes(call_for_papers_params)
redirect_to call_for_papers_path, notice: "Changes saved successfully!"
else
flash[:alert] = "Failed to update notifications"
flash[:alert] = "Failed to update"
render action: "edit"
end
end
def default_notifications
locale = params[:code]
@notification = Notification.new(locale: locale)
@notification.set_default_text(locale)
end
private
def call_for_papers_params
params.require(:call_for_papers).permit(:start_date, :end_date, :hard_deadline, :welcome_text, :info_url, :contact_email, notifications_attributes: %i(id locale accept_subject accept_body reject_subject reject_body _destroy))
params.require(:call_for_papers).permit(:start_date, :end_date, :hard_deadline, :welcome_text, :info_url, :contact_email)
end
end
......@@ -44,6 +44,9 @@ class ConferencesController < ApplicationController
def edit
end
def edit_notifications
end
# POST /conferences
# POST /conferences.xml
def create
......@@ -71,6 +74,12 @@ class ConferencesController < ApplicationController
end
end
def default_notifications
locale = params[:code]
@notification = Notification.new(locale: locale)
@notification.set_default_text(locale)
end
# DELETE /conferences/1
# DELETE /conferences/1.xml
def destroy
......@@ -118,7 +127,8 @@ class ConferencesController < ApplicationController
days_attributes: %i(start_date end_date _destroy id),
tracks_attributes: %i(name color _destroy id),
languages_attributes: %i(language_id code _destroy id),
ticket_server_attributes: %i(url user password queue _destroy id)
ticket_server_attributes: %i(url user password queue _destroy id),
notifications_attributes: %i(id locale accept_subject accept_body reject_subject reject_body _destroy)
)
end
......
......@@ -169,8 +169,8 @@ class EventsController < ApplicationController
if params[:send_mail]
# If integrated mailing is used, take care that a notification text is present.
if @event.conference.call_for_papers.notifications.empty?
return redirect_to edit_call_for_papers_path, alert: 'No notification text present. Please change the default text for your needs, before accepting/ rejecting events.'
if @event.conference.notifications.empty?
return redirect_to edit_conference_path, alert: 'No notification text present. Please change the default text for your needs, before accepting/ rejecting events.'
end
return redirect_to(@event, alert: "Cannot send mails: Please specify an email address for this conference.") unless @conference.email
......
module ConferencesHelper
def conference_tab(current, active)
css_class = 'active' if current == active
haml_tag :li, class: css_class do
yield
end
end
def timeslot_durations(conference)
result = Array.new
durations = [1,5,10,15,20,30,45,60,90,120]
if conference.timeslot_duration and conference.events.count > 0
durations.reject! do |duration|
durations.reject! do |duration|
duration > conference.timeslot_duration or (conference.timeslot_duration % duration) != 0
end
end
......
class SelectionNotification < ActionMailer::Base
default from: Settings['from_email']
def acceptance_notification(event_person)
@person = event_person.person
@event = event_person.event
@conference = @event.conference
@token = event_person.confirmation_token
@locale = @person.locale_for_mailing(@conference)
@notification = @conference.call_for_papers.notifications.with_locale(@locale).first
@notification = @conference.notifications.with_locale(@locale).first
raise "Notification for #{@locale} not found" if @notification.nil?
mail(
......@@ -23,7 +23,7 @@ class SelectionNotification < ActionMailer::Base
@event = event_person.event
@conference = @event.conference
@locale = @person.locale_for_mailing(@conference)
@notification = @conference.call_for_papers.notifications.with_locale(@locale).first
@notification = @conference.notifications.with_locale(@locale).first
raise "Notification for #{@locale} not found" if @notification.nil?
mail(
......
class CallForPapers < ActiveRecord::Base
belongs_to :conference
has_many :notifications, dependent: :destroy
accepts_nested_attributes_for :notifications, allow_destroy: true
validates_presence_of :start_date, :end_date
......
......@@ -7,6 +7,7 @@ class Conference < ActiveRecord::Base
has_many :days, dependent: :destroy
has_many :events, dependent: :destroy
has_many :languages, as: :attachable, dependent: :destroy
has_many :notifications, dependent: :destroy
has_many :rooms, dependent: :destroy
has_many :tracks, dependent: :destroy
has_many :conference_exports, dependent: :destroy
......@@ -15,9 +16,11 @@ class Conference < ActiveRecord::Base
accepts_nested_attributes_for :rooms, reject_if: proc {|r| r["name"].blank?}, allow_destroy: true
accepts_nested_attributes_for :days, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :notifications, allow_destroy: true
accepts_nested_attributes_for :tracks, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :languages, reject_if: :all_blank, allow_destroy: true
accepts_nested_attributes_for :ticket_server
validates_presence_of :title,
:acronym,
:default_timeslots,
......
class Notification < ActiveRecord::Base
belongs_to :call_for_papers
belongs_to :conference
validates :locale, presence: true
validates :reject_subject, presence: true
......@@ -49,8 +49,8 @@ BODY
private
def uniq_locale
return if self.call_for_papers.nil?
self.call_for_papers.notifications.each { |n|
return if self.conference.nil?
self.conference.notifications.each { |n|
if n.id != self.id and n.locale == self.locale
self.errors.add(:locale, "#{n.locale} already added to this cfp")
end
......
%section
.page-header
%h1 Edit Call for Papers
- if @conference.ticket_type == 'integrated'
%ul.tabs
%li.active= link_to "General", edit_call_for_papers_path
%li= link_to "Notification text", edit_notifications_call_for_papers_path
.row
.span16
......
......@@ -3,8 +3,6 @@
.pull-right
- if can? :manage, CallForPapers
= action_button "primary", "Edit", edit_call_for_papers_path, :hint => "Edit this call for paper's data."
- if @conference.ticket_type == 'integrated'
= action_button "primary", "Edit Notifications", edit_notifications_call_for_papers_path, :hint => "Edit email notififaction templates."
%h1 Call for Papers
- if @conference.call_for_papers.welcome_text
.row
......@@ -27,10 +25,10 @@
.row
.span16
#submission_graph-sum_to_submission_time{:style => "width: 800px; height: 300px;"}
:javascript
var data = #{@conference.submission_data.inspect};
$.plot($("#submission_graph"), [data], { xaxis: { mode: "time" } });
$.plot($("#submission_graph-sum_to_submission_time"), [data.reduce(function (a,b) {
......
- call_for_papers = @conference.call_for_papers
= simple_form_for(call_for_papers, url: call_for_papers_path) do |f|
= simple_form_for(@conference, url: conference_path) do |f|
= dynamic_association :notifications, t(:notifications), f
.actions
= f.button :submit, class: 'primary'
.notification
%fieldset.inputs
= link_to "use default text", "#", style: 'float:right', data: { function: 'notification-defaults', args: { url: "#{ call_for_papers_default_notifications_path(conference_acronym: @conference.acronym) }" } }
= link_to "use default text", "#", style: 'float:right', data: { function: 'notification-defaults', args: { url: "#{ conferences_default_notifications_path(conference_acronym: @conference.acronym) }" } }
= f.input :locale, as: :select, collection: available_locales(@conference), hint: "Available locales for this conference and its speakers"
= f.input "accept_subject", label: 'Accept subject'
= f.input "accept_body", label: 'Accept body', as: :text
......
%ul.tabs
- conference_tab(:settings, active) do
= link_to t(:settings), edit_conference_path
- conference_tab(:days, active) do
= link_to t(:days), edit_days_conference_path
- conference_tab(:tracks, active) do
= link_to t(:tracks), edit_tracks_conference_path
- conference_tab(:rooms, active) do
= link_to t(:rooms), edit_rooms_conference_path
- conference_tab(:schedule, active) do
= link_to t(:schedule), edit_schedule_conference_path
- if @conference.is_ticket_server_enabled?
- conference_tab(:ticket_server, active) do
= link_to t(:ticket_server), edit_ticket_server_conference_path
- if @conference.ticket_type == 'integrated'
- conference_tab(:notifications, active) do
= link_to "Notifications", edit_notifications_conference_path
%section
.page-header
%h1= t :edit_conference
%ul.tabs
%li.active= link_to t(:settings), edit_conference_path
%li= link_to t(:days), edit_days_conference_path
%li= link_to t(:tracks), edit_tracks_conference_path
%li= link_to t(:rooms), edit_rooms_conference_path
%li= link_to t(:schedule), edit_schedule_conference_path
- if @conference.is_ticket_server_enabled?
%li= link_to t(:ticket_server), edit_ticket_server_conference_path
= render partial: 'tabs', locals: { active: :settings }
.row
.span16
= render 'form'
%section
.page-header
%h1= t :edit_conference_days
%ul.tabs
%li= link_to t(:settings), edit_conference_path
%li.active= link_to t(:days), edit_days_conference_path
%li= link_to t(:tracks), edit_tracks_conference_path
%li= link_to t(:rooms), edit_rooms_conference_path
%li= link_to t(:schedule), edit_schedule_conference_path
- if @conference.is_ticket_server_enabled?
%li= link_to t(:ticket_server), edit_ticket_server_conference_path
= render partial: 'tabs', locals: { active: :days }
- if @conference.days.empty?
.row
.span16
......
%section
.page-header
%h1 Edit Call for Papers
- if @conference.ticket_type == 'integrated'
%ul.tabs
%li= link_to "General", edit_call_for_papers_path
%li.active= link_to "Notification text", edit_notifications_call_for_papers_path
= render partial: 'tabs', locals: { active: :notifications }
.row
.span6
......
%section
.page-header
%h1= t :edit_conference_rooms
%ul.tabs
%li= link_to t(:settings), edit_conference_path
%li= link_to t(:days), edit_days_conference_path
%li= link_to t(:tracks), edit_tracks_conference_path
%li.active= link_to t(:rooms), edit_rooms_conference_path
%li= link_to t(:schedule), edit_schedule_conference_path
- if @conference.is_ticket_server_enabled?
%li= link_to t(:ticket_server), edit_ticket_server_conference_path
= render partial: 'tabs', locals: { active: :rooms }
- if @conference.rooms.empty?
.row
.span16
......
%section
.page-header
%h1= t :edit_conference_schedule
%ul.tabs
%li= link_to t(:settings), edit_conference_path
%li= link_to t(:days), edit_days_conference_path
%li= link_to t(:tracks), edit_tracks_conference_path
%li= link_to t(:rooms), edit_rooms_conference_path
%li.active= link_to t(:schedule), edit_schedule_conference_path
- if @conference.is_ticket_server_enabled?
%li= link_to t(:ticket_server), edit_ticket_server_conference_path
= render partial: 'tabs', locals: { active: :schedule }
.row
.span16
= render 'form_schedule'
%section
.page-header
%h1= t :edit_ticket_server
%ul.tabs
%li= link_to t(:settings), edit_conference_path
%li= link_to t(:days), edit_days_conference_path
%li= link_to t(:tracks), edit_tracks_conference_path
%li= link_to t(:rooms), edit_rooms_conference_path
%li= link_to t(:schedule), edit_schedule_conference_path
%li.active= link_to t(:ticket_server), edit_ticket_server_conference_path
= render partial: 'tabs', locals: { active: :ticket_server }
.row
.span16
= render 'form_ticket_server'
%section
.page-header
%h1= t :edit_conference_tracks
%ul.tabs
%li= link_to t(:settings), edit_conference_path
%li= link_to t(:days), edit_days_conference_path
%li.active= link_to t(:tracks), edit_tracks_conference_path
%li= link_to t(:rooms), edit_rooms_conference_path
%li= link_to t(:schedule), edit_schedule_conference_path
- if @conference.is_ticket_server_enabled?
%li= link_to t(:ticket_server), edit_ticket_server_conference_path
= render partial: 'tabs', locals: { active: :tracks }
- if @conference.tracks.empty?
.row
.span16
......
......@@ -82,12 +82,11 @@ Frab::Application.routes.draw do
get :edit_schedule
get :edit_rooms
get :edit_ticket_server
end
resource :call_for_papers do
get :edit_notifications
end
get "/call_for_papers/default_notifications" => "call_for_papers#default_notifications", as: "call_for_papers_default_notifications"
get "/conferences/default_notifications" => "conferences#default_notifications", as: "conferences_default_notifications"
resource :call_for_papers
resources :people do
resource :user
......
class MoveNotificationsOntoConference < ActiveRecord::Migration
def change
add_column :notifications, :conference_id, :integer
Notification.find_each { |n|
next unless n.call_for_papers
n.update(conference_id: n.call_for_papers.conference.id)
}
remove_column :notifications, :call_for_papers_id
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20150815143628) do
ActiveRecord::Schema.define(version: 20150815181454) do
create_table "availabilities", force: :cascade do |t|
t.integer "person_id"
......@@ -234,14 +234,14 @@ ActiveRecord::Schema.define(version: 20150815143628) do
add_index "links", ["linkable_id"], name: "index_links_on_linkable_id"
create_table "notifications", force: :cascade do |t|
t.integer "call_for_papers_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "locale", limit: 255
t.string "accept_subject", limit: 255
t.string "reject_subject", limit: 255
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "locale", limit: 255
t.string "accept_subject", limit: 255
t.string "reject_subject", limit: 255
t.text "accept_body"
t.text "reject_body"
t.integer "conference_id"
end
create_table "people", force: :cascade do |t|
......
......@@ -149,7 +149,7 @@ FactoryGirl.define do
accept_body "accept body text"
accept_subject "accepted subject"
locale "en"
call_for_papers
conference
end
factory :availability do
......
......@@ -50,34 +50,4 @@ class CallForPapersControllerTest < ActionController::TestCase
assert_redirected_to call_for_papers_path(conference_acronym: @conference.acronym)
end
test "should get edit notification" do
get :edit_notifications, conference_acronym: @conference.acronym
assert_response :success
end
test "should add cfp notification" do
params = {
conference_acronym: @conference.acronym,
call_for_papers: call_for_papers_params.merge(
welcome_text: "welcome",
notifications_attributes: {
"0" => {
reject_body: 'reject body text',
reject_subject: 'rejected subject',
accept_body: 'accept body text',
accept_subject: 'accepted subject',
locale: 'en'
}
}
)
}
assert_difference('Notification.count') do
put :update, params
end
end
test "get default notification texts as json" do
get :default_notifications, format: :json, code: "en", conference_acronym: @conference.acronym
assert_response :success
end
end
......@@ -57,4 +57,34 @@ class ConferencesControllerTest < ActionController::TestCase
end
end
test "should get edit notification" do
get :edit_notifications, conference_acronym: @conference.acronym
assert_response :success
end
test "should add notification" do
params = {
conference_acronym: @conference.acronym,
conference: conference_params.merge(
welcome_text: "welcome",
notifications_attributes: {
"0" => {
reject_body: 'reject body text',
reject_subject: 'rejected subject',
accept_body: 'accept body text',
accept_subject: 'accepted subject',
locale: 'en'
}
}
)
}
assert_difference('Notification.count') do
put :update, params
end
end
test "get default notification texts as json" do
get :default_notifications, format: :json, code: "en", conference_acronym: @conference.acronym
assert_response :success
end
end
......@@ -5,7 +5,7 @@ class EventTest < ActiveSupport::TestCase
setup do
ActionMailer::Base.deliveries = []
@notification = FactoryGirl.create(:notification)
@event = FactoryGirl.create(:event, conference: @notification.call_for_papers.conference)
@event = FactoryGirl.create(:event, conference: @notification.conference)
@speaker = FactoryGirl.create(:person)
FactoryGirl.create(:event_person, event: @event, person: @speaker, event_role: "speaker")
@coordinator = FactoryGirl.create(:person)
......@@ -21,7 +21,7 @@ class EventTest < ActiveSupport::TestCase
@speaker.languages << Language.new(code: 'de')
@event.conference.languages << Language.new(code: 'de')
notification = FactoryGirl.create(:notification, locale: 'de')
@notification.call_for_papers.notifications << notification
@notification.conference.notifications << notification
@event.process_acceptance(send_mail: true)
assert !ActionMailer::Base.deliveries.empty?
......
......@@ -4,19 +4,19 @@ class NotificationTest < ActiveSupport::TestCase
setup do
@cfp = FactoryGirl.create(:call_for_papers)
FactoryGirl.create(:notification, call_for_papers: @cfp, locale: "en")
FactoryGirl.create(:notification, call_for_papers: @cfp, locale: "de")
FactoryGirl.create(:notification, conference: @cfp.conference, locale: "en")
FactoryGirl.create(:notification, conference: @cfp.conference, locale: "de")
@cfp.reload
end
test "call for papers can have multiple notifications" do
assert_equal @cfp.notifications.count, 2
assert_equal @cfp.conference.notifications.count, 2
end
test "cannot add same language twice" do
notification = Notification.new(call_for_papers: @cfp, locale: "en")
notification.set_default_text "en"
assert !notification.valid?
notification = Notification.new(conference: @cfp.conference, locale: "en")
notification.set_default_text "en"
assert !notification.valid?
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment