Implement unsubscribe route to delete subscriptions
This commit is contained in:
@ -18,6 +18,34 @@ class SubscriptionsController < ApplicationController
|
|||||||
authorize!
|
authorize!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# DELETE /subscriptions/1
|
||||||
|
# DELETE /subscriptions/1.json
|
||||||
|
def destroy
|
||||||
|
begin
|
||||||
|
@subscription = Subscription.find(params[:id])
|
||||||
|
rescue
|
||||||
|
skip_authorization
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to request_for_comments_url, alert: t('subscriptions.subscription_not_existent') }
|
||||||
|
format.json { head :internal_server_error }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
authorize!
|
||||||
|
rfc = @subscription.try(:request_for_comment)
|
||||||
|
if @subscription.destroy
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to request_for_comment_url(rfc), notice: t('subscriptions.successfully_unsubscribed') }
|
||||||
|
format.json { head :destroyed }
|
||||||
|
end
|
||||||
|
else
|
||||||
|
respond_to do |format|
|
||||||
|
format.html { redirect_to request_for_comment_url(rfc), :flash => { :danger => t('shared.message_failure') } }
|
||||||
|
format.json { head :internal_server_error }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def set_subscription
|
def set_subscription
|
||||||
@subscription = Subscription.find(params[:id])
|
@subscription = Subscription.find(params[:id])
|
||||||
authorize!
|
authorize!
|
||||||
|
@ -2,4 +2,17 @@ class SubscriptionPolicy < ApplicationPolicy
|
|||||||
def create?
|
def create?
|
||||||
everyone
|
everyone
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def destroy?
|
||||||
|
author? || admin?
|
||||||
|
end
|
||||||
|
|
||||||
|
def show_error?
|
||||||
|
everyone
|
||||||
|
end
|
||||||
|
|
||||||
|
def author?
|
||||||
|
@user == @record.user
|
||||||
|
end
|
||||||
|
private :author?
|
||||||
end
|
end
|
||||||
|
@ -630,4 +630,7 @@ de:
|
|||||||
comments:
|
comments:
|
||||||
deleted: "Gelöscht"
|
deleted: "Gelöscht"
|
||||||
save_update: "Speichern"
|
save_update: "Speichern"
|
||||||
|
subscriptions:
|
||||||
|
successfully_unsubscribed: "Ihr Abonnement für weitere Kommentare auf dieser Kommentaranfrage wurde erfolgreich beendet."
|
||||||
|
subscription_not_existent: "Das Abonnement, von dem Sie sich abmelden wollen, existiert nicht."
|
||||||
|
|
||||||
|
@ -651,3 +651,6 @@ en:
|
|||||||
comments:
|
comments:
|
||||||
deleted: "Deleted"
|
deleted: "Deleted"
|
||||||
save_update: "Save"
|
save_update: "Save"
|
||||||
|
subscriptions:
|
||||||
|
successfully_unsubscribed: "You successfully unsubscribed from this Request for Comment"
|
||||||
|
subscription_not_existent: "The subscription you want to unsubscribe from does not exist."
|
||||||
|
@ -21,7 +21,11 @@ Rails.application.routes.draw do
|
|||||||
delete '/comment_by_id', to: 'comments#destroy_by_id'
|
delete '/comment_by_id', to: 'comments#destroy_by_id'
|
||||||
put '/comments', to: 'comments#update'
|
put '/comments', to: 'comments#update'
|
||||||
|
|
||||||
resources :subscriptions
|
resources :subscriptions do
|
||||||
|
member do
|
||||||
|
get :unsubscribe, to: 'subscriptions#destroy'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
root to: 'application#welcome'
|
root to: 'application#welcome'
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user