diff --git a/app/controllers/admin_controller.rb b/app/controllers/admin_controller.rb index 23afd1d7..660bb583 100644 --- a/app/controllers/admin_controller.rb +++ b/app/controllers/admin_controller.rb @@ -1,6 +1,6 @@ class AdminController < ApplicationController layout 'admin' - layout 'application', only: [:unsubscribe] + layout 'application', only: [:unsubscribe, :perform_unsubscribe] before_action :authenticate_user! before_action :require_admin_access @@ -45,7 +45,9 @@ class AdminController < ApplicationController emails = params[:emails].split(/[\r|\n]+/) @users = User.where(email: emails) @users.update_all(selected_billing_plan_id: 1) - Subscription.where(user_id: @users.pluck(:id)).where('end_date > ?', DateTime.current).update_all(end_date: DateTime.current) + @users.each do |user| + SubscriptionService.cancel_all_existing_subscriptions(user) + end end private diff --git a/app/views/admin/perform_unsubscribe.html.erb b/app/views/admin/perform_unsubscribe.html.erb index 70252f30..048b4537 100644 --- a/app/views/admin/perform_unsubscribe.html.erb +++ b/app/views/admin/perform_unsubscribe.html.erb @@ -27,3 +27,5 @@ + +<%= link_to 'Unsubscribe more users', mass_unsubscribe_path, class: 'btn white black-text' %> diff --git a/config/routes.rb b/config/routes.rb index 41bff41f..c0e409df 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -168,7 +168,7 @@ Rails.application.routes.draw do get '/content_type/:type', to: 'admin#content_type', as: :admin_content_type get '/attributes', to: 'admin#attributes', as: :admin_attributes get '/masquerade/:user_id', to: 'admin#masquerade', as: :masquerade - get '/unsubscribe', to: 'admin#unsubscribe' + get '/unsubscribe', to: 'admin#unsubscribe', as: :mass_unsubscribe post '/perform_unsubscribe', to: 'admin#perform_unsubscribe', as: :perform_unsubscribe end mount RailsAdmin::Engine => '/admin', as: 'rails_admin'