Class: ActivityNotification::SubscriptionsController

Inherits:
Object
  • Object
show all
Includes:
CommonController
Defined in:
app/controllers/activity_notification/subscriptions_controller.rb

Overview

Controller to manage subscriptions.

Constant Summary

Constants included from CommonController

CommonController::DEFAULT_VIEW_DIRECTORY

Instance Method Summary collapse

Instance Method Details

#create(params) ⇒ Response

Creates new subscription.

PUT /:target_type/:target_id/subscriptions

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :subscription (String)

    Subscription parameters

  • :subscription[:key] (String)

    Key of the subscription

  • :subscription[:subscribing] (String) — default: nil

    Whether the target will subscribe to the notification

  • :subscription[:subscribing_to_email] (String) — default: nil

    Whether the target will subscribe to the notification email

  • :filter (String) — default: nil

    Filter option to load subscription index (Nothing as all, ‘configured’ or ‘unconfigured’)

  • :limit (String) — default: nil

    Limit to query for subscriptions

  • :reverse (String) — default: 'false'

    Whether subscription index and unconfigured notification keys will be ordered as earliest first

  • :filtered_by_key (String) — default: nil

    Key of the subscription for filter

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



39
40
41
42
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 39

def create
  @subscription = @target.create_subscription(subscription_params)
  return_back_or_ajax
end

#destroy(params) ⇒ Response

Deletes a subscription.

DELETE /:target_type/:target_id/subscriptions/:id

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :filter (String) — default: nil

    Filter option to load subscription index (Nothing as all, ‘configured’ or ‘unconfigured’)

  • :limit (String) — default: nil

    Limit to query for subscriptions

  • :reverse (String) — default: 'false'

    Whether subscription index and unconfigured notification keys will be ordered as earliest first

  • :filtered_by_key (String) — default: nil

    Key of the subscription for filter

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



76
77
78
79
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 76

def destroy
  @subscription.destroy
  return_back_or_ajax
end

#index(params) ⇒ Response

Finds and shows a subscription from specified key.

GET /:target_type/:target_id/subscriptions/find

Returns HTML view as default or JSON of subscription index with json format parameter.

Parameters:

  • params (Hash)

    Request parameter options for subscription index

Options Hash (params):

  • :key (required, String) — default: nil

    Key of the subscription

Returns:

  • (Response)

    HTML view as default or JSON of subscription index with json format parameter



51
52
53
54
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 51

def find
  @subscription = @target.find_subscription(params[:key])
  @subscription ? redirect_to_subscription_path : render_resource_not_found("Couldn't find subscription with this target and 'key'=#{params[:key]}")
end

#index(params) ⇒ Response

Shows subscription index of the target.

GET /:target_type/:target_id/subscriptions

Returns HTML view of subscription index.

Parameters:

  • params (Hash)

    Request parameter options for subscription index

Options Hash (params):

  • :filter (String) — default: nil

    Filter option to load subscription index by their configuration status (Nothing as all, ‘configured’ or ‘unconfigured’)

  • :limit (String) — default: nil

    Limit to query for subscriptions

  • :reverse (String) — default: 'false'

    Whether subscription index and unconfigured notification keys will be ordered as earliest first

  • :filtered_by_key (String) — default: nil

    Key of the subscription for filter

Returns:

  • (Response)

    HTML view of subscription index



20
21
22
23
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 20

def index
  set_index_options
  load_index if params[:reload].to_s.to_boolean(true)
end

#show(params) ⇒ Response

Shows a subscription.

GET /:target_type/:target_id/subscriptions/:id

Returns HTML view as default.

Parameters:

  • params (Hash)

    Request parameters

Returns:

  • (Response)

    HTML view as default



62
63
64
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 62

def show
  set_index_options
end

#open(params) ⇒ Response

Updates a subscription to subscribe to notifications.

PUT /:target_type/:target_id/subscriptions/:id/subscribe

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :with_email_subscription (String) — default: 'true'

    Whether the subscriber also subscribes notification email

  • :with_optional_targets (String) — default: 'true'

    Whether the subscriber also subscribes optional targets

  • :filter (String) — default: nil

    Filter option to load subscription index (Nothing as all, ‘configured’ or ‘unconfigured’)

  • :limit (String) — default: nil

    Limit to query for subscriptions

  • :reverse (String) — default: 'false'

    Whether subscription index and unconfigured notification keys will be ordered as earliest first

  • :filtered_by_key (String) — default: nil

    Key of the subscription for filter

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



93
94
95
96
97
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 93

def subscribe
  @subscription.subscribe(with_email_subscription: params[:with_email_subscription].to_s.to_boolean(ActivityNotification.config.subscribe_to_email_as_default),
                          with_optional_targets:   params[:with_optional_targets].to_s.to_boolean(ActivityNotification.config.subscribe_to_optional_targets_as_default))
  return_back_or_ajax
end

#open(params) ⇒ Response

Updates a subscription to subscribe to the notification email.

PUT /:target_type/:target_id/subscriptions/:id/subscribe_email

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :filter (String) — default: nil

    Filter option to load subscription index (Nothing as all, ‘configured’ or ‘unconfigured’)

  • :limit (String) — default: nil

    Limit to query for subscriptions

  • :reverse (String) — default: 'false'

    Whether subscription index and unconfigured notification keys will be ordered as earliest first

  • :filtered_by_key (String) — default: nil

    Key of the subscription for filter

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



124
125
126
127
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 124

def subscribe_to_email
  @subscription.subscribe_to_email
  return_back_or_ajax
end

#open(params) ⇒ Response

Updates a subscription to subscribe to the specified optional target.

PUT /:target_type/:target_id/subscriptions/:id/subscribe_to_optional_target

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :optional_target_name (required, String) — default: nil

    Class name of the optional target implementation (e.g. ‘amazon_sns’, ‘slack’)

  • :filter (String) — default: nil

    Filter option to load subscription index (Nothing as all, ‘configured’ or ‘unconfigured’)

  • :limit (String) — default: nil

    Limit to query for subscriptions

  • :reverse (String) — default: 'false'

    Whether subscription index and unconfigured notification keys will be ordered as earliest first

  • :filtered_by_key (String) — default: nil

    Key of the subscription for filter

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



155
156
157
158
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 155

def subscribe_to_optional_target
  @subscription.subscribe_to_optional_target(params[:optional_target_name])
  return_back_or_ajax
end

#open(params) ⇒ Response

Updates a subscription to unsubscribe to the notifications.

PUT /:target_type/:target_id/subscriptions/:id/unsubscribe

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :filter (String) — default: nil

    Filter option to load subscription index (Nothing as all, ‘configured’ or ‘unconfigured’)

  • :limit (String) — default: nil

    Limit to query for subscriptions

  • :reverse (String) — default: 'false'

    Whether subscription index and unconfigured notification keys will be ordered as earliest first

  • :filtered_by_key (String) — default: nil

    Key of the subscription for filter

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



109
110
111
112
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 109

def unsubscribe
  @subscription.unsubscribe
  return_back_or_ajax
end

#open(params) ⇒ Response

Updates a subscription to unsubscribe to the notification email.

PUT /:target_type/:target_id/subscriptions/:id/unsubscribe_email

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :filter (String) — default: nil

    Filter option to load subscription index (Nothing as all, ‘configured’ or ‘unconfigured’)

  • :limit (String) — default: nil

    Limit to query for subscriptions

  • :reverse (String) — default: 'false'

    Whether subscription index and unconfigured notification keys will be ordered as earliest first

  • :filtered_by_key (String) — default: nil

    Key of the subscription for filter

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



139
140
141
142
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 139

def unsubscribe_to_email
  @subscription.unsubscribe_to_email
  return_back_or_ajax
end

#open(params) ⇒ Response

Updates a subscription to unsubscribe to the specified optional target.

PUT /:target_type/:target_id/subscriptions/:id/unsubscribe_to_optional_target

Returns JavaScript view for ajax request or redirects to back as default.

Parameters:

  • params (Hash)

    Request parameters

Options Hash (params):

  • :optional_target_name (required, String) — default: nil

    Class name of the optional target implementation (e.g. ‘amazon_sns’, ‘slack’)

  • :filter (String) — default: nil

    Filter option to load subscription index (Nothing as all, ‘configured’ or ‘unconfigured’)

  • :limit (String) — default: nil

    Limit to query for subscriptions

  • :reverse (String) — default: 'false'

    Whether subscription index and unconfigured notification keys will be ordered as earliest first

  • :filtered_by_key (String) — default: nil

    Key of the subscription for filter

Returns:

  • (Response)

    JavaScript view for ajax request or redirects to back as default



171
172
173
174
# File 'app/controllers/activity_notification/subscriptions_controller.rb', line 171

def unsubscribe_to_optional_target
  @subscription.unsubscribe_to_optional_target(params[:optional_target_name])
  return_back_or_ajax
end