mirror of
https://github.com/openSUSE/osem.git
synced 2026-01-25 14:29:51 -05:00
Prevent excpetion at user subscription when already is subscribed to a conference and add hanling to the similar unsubscribe event. remove double validation at app/models/subscription.rb update subscription_controller_spec
26 lines
1.0 KiB
Ruby
26 lines
1.0 KiB
Ruby
class SubscriptionsController < ApplicationController
|
|
before_filter :authenticate_user!
|
|
load_resource :conference, find_by: :short_title
|
|
load_and_authorize_resource only: [:create, :destroy], through: :conference
|
|
|
|
def create
|
|
@subscription = current_user.subscriptions.build(conference_id: @conference.id)
|
|
if @subscription.save
|
|
redirect_to root_path, notice: "You have subscribed to receive email notifications for #{@conference.title}."
|
|
else
|
|
redirect_to root_path, error: @subscription.errors.full_messages.to_sentence
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
@subscription = current_user.subscriptions.find_by(conference_id: @conference.id)
|
|
|
|
redirect_to(root_path, error: "You are not subscribed to #{@conference.title}.") && return unless @subscription
|
|
if @subscription.destroy
|
|
redirect_to root_path, notice: "You have unsubscribed and you will not be receiving email notifications for #{@conference.title}."
|
|
else
|
|
redirect_to root_path, error: @subscription.errors.full_messages.to_sentence
|
|
end
|
|
end
|
|
end
|