mirror of
https://github.com/openSUSE/osem.git
synced 2026-08-13 19:54:02 +00:00
Merge pull request #377 from gopesht/add_email_settings_to_user_accounts
Add email settings to user accounts
This commit is contained in:
commit
d4074b798e
17 changed files with 179 additions and 52 deletions
|
|
@ -12,20 +12,13 @@ module Admin
|
|||
def update
|
||||
@cfp = @conference.call_for_papers
|
||||
@cfp.assign_attributes(params[:call_for_papers])
|
||||
notify_on_schedule_public = @cfp.schedule_public_changed? && @cfp.schedule_public\
|
||||
&& @conference.email_settings.send_on_call_for_papers_schedule_public\
|
||||
&& !@conference.email_settings.call_for_papers_schedule_public_subject.blank?\
|
||||
&& !@conference.email_settings.call_for_papers_schedule_public_template.blank?
|
||||
send_mail_on_schedule_public = @cfp.notify_on_schedule_public?
|
||||
|
||||
notify_on_cfp_date_update = !@cfp.end_date.blank? && !@cfp.start_date.blank?\
|
||||
&& (@cfp.start_date_changed? || @cfp.end_date_changed?)\
|
||||
&& @conference.email_settings.send_on_call_for_papers_dates_updates\
|
||||
&& !@conference.email_settings.call_for_papers_dates_updates_subject.blank?\
|
||||
&& !@conference.email_settings.call_for_papers_dates_updates_template.blank?
|
||||
send_mail_on_cfp_dates_updates = @cfp.notify_on_cfp_date_update?
|
||||
|
||||
if @cfp.update_attributes(params[:call_for_papers])
|
||||
Mailbot.delay.send_on_call_for_papers_dates_updates(@conference) if notify_on_cfp_date_update
|
||||
Mailbot.delay.send_on_schedule_public(@conference) if notify_on_schedule_public
|
||||
Mailbot.delay.send_on_call_for_papers_dates_updates(@conference) if send_mail_on_cfp_dates_updates
|
||||
Mailbot.delay.send_on_schedule_public(@conference) if send_mail_on_schedule_public
|
||||
redirect_to(admin_conference_callforpapers_path(
|
||||
id: @conference.short_title),
|
||||
notice: 'Call for Papers was successfully updated.')
|
||||
|
|
|
|||
|
|
@ -72,6 +72,25 @@ module Admin
|
|||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@conference = Conference.find_by(short_title: params[:id])
|
||||
short_title = @conference.short_title
|
||||
@conference.assign_attributes(params[:conference])
|
||||
send_mail_on_conf_update = @conference.notify_on_conf_dates_updates?
|
||||
send_mail_on_reg_update = @conference.notify_on_conf_reg_dates_updates?
|
||||
|
||||
if @conference.update_attributes(params[:conference])
|
||||
Mailbot.delay.conference_date_update_mail(@conference) if send_mail_on_conf_update
|
||||
Mailbot.delay.conference_registration_date_update_mail(@conference) if send_mail_on_reg_update
|
||||
redirect_to(edit_admin_conference_path(id: @conference.short_title),
|
||||
notice: 'Conference was successfully updated.')
|
||||
else
|
||||
redirect_to(edit_admin_conference_path(id: short_title),
|
||||
alert: 'Updating conference failed. ' \
|
||||
"#{@conference.errors.full_messages.join('. ')}.")
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@conference = Conference.find_by(short_title: params[:id])
|
||||
short_title = @conference.short_title
|
||||
|
|
|
|||
|
|
@ -8,14 +8,9 @@ module Admin
|
|||
def update
|
||||
@venue = @conference.venue
|
||||
@venue.assign_attributes(params[:venue])
|
||||
venue_notify = (@venue.name_changed? || @venue.address_changed?) &&
|
||||
(!@venue.name.blank? && !@venue.address.blank?) &&
|
||||
(@conference.email_settings.send_on_venue_update &&
|
||||
!@conference.email_settings.venue_update_subject.blank? &&
|
||||
@conference.email_settings.venue_update_template)
|
||||
|
||||
send_mail = @venue.venue_notify?(@conference)
|
||||
if @venue.update_attributes(params[:venue])
|
||||
Mailbot.delay.send_email_on_venue_update(@conference) if venue_notify
|
||||
Mailbot.delay.send_email_on_venue_update(@conference) if send_mail
|
||||
redirect_to(admin_conference_venue_info_path(conference_id: @conference.short_title),
|
||||
notice: 'Venue was successfully updated.')
|
||||
else
|
||||
|
|
|
|||
|
|
@ -4,6 +4,42 @@ class ConferenceController < ApplicationController
|
|||
redirect_to root_path, notice: "Conference not ready yet!!" unless @conference.make_conference_public?
|
||||
end
|
||||
|
||||
def subscribe
|
||||
conference = Conference.find_by_short_title(params[:id])
|
||||
if current_user.subscriptions.where(conference: conference).blank?
|
||||
subscription = Subscription.new(user_id: current_user.id, conference_id: conference.id)
|
||||
begin
|
||||
subscription.save!
|
||||
flash[:success] = "You have been subscribed to receive Email Notifications from this Conference."
|
||||
redirect_to root_path
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
flash[:error] = subscription.errors.full_messages.to_sentence
|
||||
redirect_to root_path
|
||||
end
|
||||
else
|
||||
flash[:notice] = "Already Subscribed"
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
|
||||
def unsubscribe
|
||||
conference = Conference.find_by_short_title(params[:id])
|
||||
subscription = current_user.subscriptions.where(conference_id: conference.id).first
|
||||
if subscription.blank?
|
||||
flash[:notice] = "Already Unsubscribed"
|
||||
redirect_to root_path
|
||||
else
|
||||
begin
|
||||
subscription.destroy!
|
||||
flash[:notice] = "You have been unsubscribed and now you won't be receiving any Email Notifications."
|
||||
redirect_to root_path
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
flash[:error] = subscription.errors.full_messages.to_sentence
|
||||
redirect_to root_path
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def gallery_photos
|
||||
@photos = Conference.find_by_short_title(params[:id]).photos
|
||||
render "photos", formats: [:js]
|
||||
|
|
|
|||
|
|
@ -65,6 +65,10 @@ class ConferenceRegistrationController < ApplicationController
|
|||
|
||||
registration.conference_id = conference.id
|
||||
registration.save!
|
||||
if user.subscriptions.where(conference: conference).blank?
|
||||
subscription = Subscription.new(conference_id: conference.id, user_id: user.id)
|
||||
redirect_message = subscription.save ? 'You are now Registered and will be receiving Email Notifications.' : 'You are now Registered.'
|
||||
end
|
||||
else
|
||||
registration.update_attributes!(registration_params)
|
||||
end
|
||||
|
|
@ -75,7 +79,6 @@ class ConferenceRegistrationController < ApplicationController
|
|||
return
|
||||
end
|
||||
|
||||
redirect_message = 'You are now registered.'
|
||||
if update_registration
|
||||
redirect_message = 'Registration updated.'
|
||||
else
|
||||
|
|
@ -93,6 +96,10 @@ class ConferenceRegistrationController < ApplicationController
|
|||
conference = Conference.find_by(short_title: params[:id])
|
||||
user = current_user
|
||||
registration = user.registrations.where(conference_id: conference.id).first
|
||||
subscription = user.subscriptions.where(conference: conference)
|
||||
unless subscription.blank?
|
||||
subscription.first.destroy
|
||||
end
|
||||
registration.destroy
|
||||
redirect_to :root
|
||||
end
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ class Mailbot < ActionMailer::Base
|
|||
build_email(conference,
|
||||
person.email,
|
||||
conference.email_settings.accepted_subject,
|
||||
conference.email_settings.generate_accepted_email(event))
|
||||
conference.email_settings.generate_event_email(event, accepted_email_template))
|
||||
end
|
||||
|
||||
def rejection_mail(event)
|
||||
|
|
@ -23,59 +23,58 @@ class Mailbot < ActionMailer::Base
|
|||
build_email(conference,
|
||||
person.email,
|
||||
conference.email_settings.rejected_subject,
|
||||
conference.email_settings.generate_rejected_email(event))
|
||||
conference.email_settings.generate_event_email(event, rejected_email_template))
|
||||
end
|
||||
|
||||
def confirm_reminder_mail(event)
|
||||
conference = event.conference
|
||||
person = event.submitter
|
||||
|
||||
build_email(conference,
|
||||
person.email,
|
||||
conference.email_settings.confirmed_without_registration_subject,
|
||||
conference.email_settings.confirmed_but_not_registered_email(event))
|
||||
conference.email_settings.generate_event_email(event, confirmed_email_template))
|
||||
end
|
||||
|
||||
def conference_date_update_mail(conference)
|
||||
conference.registrations.each do |user|
|
||||
User.joins(:subscriptions).merge(conference.subscriptions) do |user|
|
||||
build_email(conference,
|
||||
user.user.email,
|
||||
user.email,
|
||||
conference.email_settings.updated_conference_dates_subject,
|
||||
conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.updated_conference_dates_template))
|
||||
end
|
||||
end
|
||||
|
||||
def conference_registration_date_update_mail(conference)
|
||||
conference.registrations.each do |user|
|
||||
User.joins(:subscriptions).merge(conference.subscriptions).uniq.joins('INNER JOIN registrations ON registrations.user_id != users.id').merge(conference.registrations) do |user|
|
||||
build_email(conference,
|
||||
user.user.email,
|
||||
user.email,
|
||||
conference.email_settings.updated_conference_registration_dates_subject,
|
||||
conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.updated_conference_registration_dates_template))
|
||||
end
|
||||
end
|
||||
|
||||
def send_email_on_venue_update(conference)
|
||||
conference.registrations.each do |user|
|
||||
User.joins(:subscriptions).merge(conference.subscriptions) do |user|
|
||||
build_email(conference,
|
||||
user.user.email,
|
||||
user.email,
|
||||
conference.email_settings.venue_update_subject,
|
||||
conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.venue_update_template))
|
||||
end
|
||||
end
|
||||
|
||||
def send_on_schedule_public(conference)
|
||||
conference.registrations.each do |user|
|
||||
User.joins(:subscriptions).merge(conference.subscriptions) do |user|
|
||||
build_email(conference,
|
||||
user.user.email,
|
||||
user.email,
|
||||
conference.email_settings.call_for_papers_schedule_public_subject,
|
||||
conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.call_for_papers_schedule_public_template))
|
||||
end
|
||||
end
|
||||
|
||||
def send_on_call_for_papers_dates_updates(conference)
|
||||
conference.registrations.each do |user|
|
||||
User.joins(:subscriptions).merge(conference.subscriptions) do |user|
|
||||
build_email(conference,
|
||||
user.user.email,
|
||||
user.email,
|
||||
conference.email_settings.call_for_papers_dates_updates_subject,
|
||||
conference.email_settings.generate_email_on_conf_updates(conference, user, conference.email_settings.call_for_papers_dates_updates_template))
|
||||
end
|
||||
|
|
|
|||
|
|
@ -33,4 +33,31 @@ class CallForPapers < ActiveRecord::Base
|
|||
def end_week
|
||||
end_date.strftime('%W').to_i
|
||||
end
|
||||
|
||||
##
|
||||
# Checks whether cfp dates is updated
|
||||
#
|
||||
# ====Returns
|
||||
# * +True+ -> If cfp dates is updated and all other parameters are set
|
||||
# * +False+ -> Either cfp date is not updated or one or more parameter is not set
|
||||
def notify_on_cfp_date_update?
|
||||
!self.end_date.blank? && !self.start_date.blank?\
|
||||
&& (self.start_date_changed? || self.end_date_changed?)\
|
||||
&& self.conference.email_settings.send_on_call_for_papers_dates_updates\
|
||||
&& !self.conference.email_settings.call_for_papers_dates_updates_subject.blank?\
|
||||
&& !self.conference.email_settings.call_for_papers_dates_updates_template.blank?
|
||||
end
|
||||
##
|
||||
# Checks whether cfp dates is updated
|
||||
#
|
||||
# ====Returns
|
||||
# * +True+ -> If cfp dates is updated and all other parameters are set
|
||||
# * +False+ -> Either cfp date is not updated or one or more parameter is not set
|
||||
def notify_on_schedule_public?
|
||||
!self.end_date.blank? && !self.start_date.blank?\
|
||||
&& (self.start_date_changed? || self.end_date_changed?)\
|
||||
&& self.conference.email_settings.send_on_call_for_papers_dates_updates\
|
||||
&& !self.conference.email_settings.call_for_papers_dates_updates_subject.blank?\
|
||||
&& !self.conference.email_settings.call_for_papers_dates_updates_template.blank?
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -49,6 +49,7 @@ class Conference < ActiveRecord::Base
|
|||
has_many :targets, dependent: :destroy
|
||||
has_many :campaigns, dependent: :destroy
|
||||
has_many :commercials, as: :commercialable, dependent: :destroy
|
||||
has_many :subscriptions, dependent: :destroy
|
||||
belongs_to :venue
|
||||
|
||||
accepts_nested_attributes_for :rooms, reject_if: proc { |r| r['name'].blank? }, allow_destroy: true
|
||||
|
|
@ -928,4 +929,30 @@ class Conference < ActiveRecord::Base
|
|||
|
||||
result
|
||||
end
|
||||
|
||||
##
|
||||
# Checks if conference is updated for email notifications.
|
||||
#
|
||||
# ====Returns
|
||||
# * +True+ -> If conference is updated and all other parameters are set
|
||||
# * +False+ -> Either conference is not updated or one or more parameter is not set
|
||||
def notify_on_conf_dates_updates?
|
||||
(self.start_date_changed? || self.end_date_changed?)\
|
||||
&& self.email_settings.send_on_updated_conference_dates\
|
||||
&& !self.email_settings.updated_conference_dates_subject.blank?\
|
||||
&& self.email_settings.updated_conference_dates_template
|
||||
end
|
||||
|
||||
##
|
||||
# Checks if registration dates are updated for email notifications.
|
||||
#
|
||||
# ====Returns
|
||||
# * +True+ -> If registration dates is updated and all other parameters are set
|
||||
# * +False+ -> Either registration date is not updated or one or more parameter is not set
|
||||
def notify_on_reg_dates?
|
||||
(self.registration_start_date_changed? || self.registration_end_date_changed?)\
|
||||
&& self.email_settings.send_on_updated_conference_registration_dates\
|
||||
&& !self.email_settings.updated_conference_registration_dates_subject.blank?\
|
||||
&& self.email_settings.updated_conference_registration_dates_template
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -41,28 +41,14 @@ class EmailSettings < ActiveRecord::Base
|
|||
h
|
||||
end
|
||||
|
||||
def generate_accepted_email(event)
|
||||
def generate_event_mail(event, event_template)
|
||||
values = get_values(event.conference, event.submitter, event)
|
||||
template = accepted_email_template
|
||||
parse_template(template, values)
|
||||
end
|
||||
|
||||
def generate_rejected_email(event)
|
||||
values = get_values(event.conference, event.submitter, event)
|
||||
template = rejected_email_template
|
||||
parse_template(template, values)
|
||||
end
|
||||
|
||||
def confirmed_but_not_registered_email(event)
|
||||
values = get_values(event.conference, event.submitter, event)
|
||||
template = confirmed_email_template
|
||||
parse_template(template, values)
|
||||
parse_template(event_template, values)
|
||||
end
|
||||
|
||||
def generate_email_on_conf_updates(conference, user, conf_update_template)
|
||||
values = get_values(conference, user)
|
||||
template = conf_update_template
|
||||
parse_template(template, values)
|
||||
parse_template(conf_update_template, values)
|
||||
end
|
||||
|
||||
def parse_template(text, values)
|
||||
|
|
|
|||
6
app/models/subscription.rb
Normal file
6
app/models/subscription.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
class Subscription < ActiveRecord::Base
|
||||
attr_accessible :user_id, :conference_id
|
||||
validates_uniqueness_of :user_id, scope: [:conference_id]
|
||||
belongs_to :conference
|
||||
belongs_to :user
|
||||
end
|
||||
|
|
@ -20,7 +20,7 @@ class User < ActiveRecord::Base
|
|||
has_many :registrations, dependent: :destroy
|
||||
has_many :votes, dependent: :destroy
|
||||
has_many :voted_events, through: :votes, source: :events
|
||||
|
||||
has_many :subscriptions, dependent: :destroy
|
||||
accepts_nested_attributes_for :roles
|
||||
|
||||
before_create :setup_role
|
||||
|
|
|
|||
|
|
@ -12,6 +12,14 @@ class Venue < ActiveRecord::Base
|
|||
size: { in: 0..500.kilobytes }
|
||||
accepts_nested_attributes_for :lodgings, allow_destroy: true
|
||||
|
||||
def venue_notify?(conference)
|
||||
(self.name_changed? || self.address_changed?) &&
|
||||
(!self.name.blank? && !self.address.blank?) &&
|
||||
(conference.email_settings.send_on_venue_update &&
|
||||
!conference.email_settings.venue_update_subject.blank? &&
|
||||
conference.email_settings.venue_update_template)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# TODO: create a module to be mixed into model to perform same operation
|
||||
|
|
|
|||
|
|
@ -20,6 +20,12 @@
|
|||
= simple_format(conference.venue.description, class: 'lead')
|
||||
.col-md-2
|
||||
.btn-group-vertical
|
||||
- unless current_user.blank?
|
||||
- if Conference.joins(:subscriptions).merge(current_user.subscriptions).include? conference
|
||||
= link_to "Unsubscribe", subscription_conference_path(conference.short_title), method: "DELETE", class: "btn btn-danger btn-group-vertical"
|
||||
-else
|
||||
= link_to "Subscribe", subscription_conference_path(conference.short_title), method: "PATCH", class: "btn btn-info btn-group-vertical"
|
||||
|
||||
- if !@conference || @conference != conference
|
||||
- if conference.make_conference_public?
|
||||
= link_to "View Conference", conference_path(conference.short_title), :class =>"btn btn-default"
|
||||
|
|
|
|||
|
|
@ -97,6 +97,8 @@ Osem::Application.routes.draw do
|
|||
patch "/register" => "conference_registration#update"
|
||||
delete "/register" => "conference_registration#unregister"
|
||||
get "gallery_photos"
|
||||
patch "subscription" => "conference#subscribe"
|
||||
delete "subscription" => "conference#unsubscribe"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
9
db/migrate/20140724153520_create_subscriptions.rb
Normal file
9
db/migrate/20140724153520_create_subscriptions.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
class CreateSubscriptions < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :subscriptions do |t|
|
||||
t.belongs_to :user
|
||||
t.belongs_to :conference
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -408,6 +408,13 @@ ActiveRecord::Schema.define(version: 20140801170430) do
|
|||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "subscriptions", force: true do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "conference_id"
|
||||
t.datetime "created_at"
|
||||
t.datetime "updated_at"
|
||||
end
|
||||
|
||||
create_table "supporter_levels", force: true do |t|
|
||||
t.integer "conference_id"
|
||||
t.string "title", null: false
|
||||
|
|
|
|||
|
|
@ -130,7 +130,7 @@ feature Event do
|
|||
|
||||
# Register for conference
|
||||
find('#register').click
|
||||
expect(flash).to eq('You are now registered.')
|
||||
expect(flash).to eq('You are now Registered and will be receiving Email Notifications.')
|
||||
|
||||
# Withdraw proposal
|
||||
visit conference_proposal_index_path(conference.short_title)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue