Add admin UI for managing email subscriptions (#38741)
Co-authored-by: Claire <claire.github-309c@sitedethib.com>
This commit is contained in:
1 parent
46ccfa6e8d
commit
ee88da4511
31 files changed
+560
-7
No files matched your search
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Admin::EmailSubscriptions::AdditionalFooterTextsController < Admin::SettingsController
|
||||
private
|
||||
|
||||
def after_update_redirect_path
|
||||
admin_email_subscriptions_path
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Admin::EmailSubscriptions::SetupsController < Admin::BaseController
|
||||
before_action :require_enabled!
|
||||
|
||||
def show
|
||||
authorize :email_subscription, :enable?
|
||||
|
||||
@form = Form::EmailSubscriptionsConfirmation.new
|
||||
end
|
||||
|
||||
def create
|
||||
authorize :email_subscription, :enable?
|
||||
|
||||
@form = Form::EmailSubscriptionsConfirmation.new(resource_params)
|
||||
|
||||
if @form.valid?
|
||||
Setting.email_subscriptions = true
|
||||
redirect_to admin_email_subscriptions_path
|
||||
else
|
||||
render :show
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def require_enabled!
|
||||
raise ActionController::RoutingError, 'Feature disabled' unless Rails.application.config.x.email_subscriptions
|
||||
end
|
||||
|
||||
def resource_params
|
||||
params.expect(form_email_subscriptions_confirmation: [:agreement_email_volume, :agreement_privacy_and_terms])
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,23 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class Admin::EmailSubscriptionsController < Admin::BaseController
|
||||
def index
|
||||
authorize :email_subscription, :index?
|
||||
|
||||
@enabled = Setting.email_subscriptions
|
||||
@roles = UserRole.where('permissions & ? != 0', UserRole::FLAGS[:manage_email_subscriptions] | UserRole::FLAGS[:administrator])
|
||||
@accounts = Account.local.joins(:email_subscriptions).where.associated(:email_subscriptions).includes(:user)
|
||||
end
|
||||
|
||||
def disable
|
||||
authorize :email_subscription, :disable?
|
||||
Setting.email_subscriptions = false
|
||||
redirect_to admin_email_subscriptions_path, notice: I18n.t('admin.email_subscriptions.disabled_msg')
|
||||
end
|
||||
|
||||
def purge
|
||||
authorize :email_subscription, :purge?
|
||||
Admin::EmailSubscriptionsPurgeWorker.perform_async
|
||||
redirect_to admin_email_subscriptions_path, notice: I18n.t('admin.email_subscriptions.purged_msg')
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user