Sha256: 504733ee64dd5510b0ed761da9c5b7c13576b5ac5a0cb69ccbd2f5480f4ab88b

Contents?: true

Size: 1.25 KB

Versions: 4

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module Thredded
  class PreferencesController < Thredded::ApplicationController
    before_action :thredded_require_login!,
                  :init_preferences

    def edit; end

    def update
      if @preferences.save
        flash[:notice] = t('thredded.preferences.updated_notice')
        redirect_back fallback_location: edit_preferences_url(@preferences.messageboard)
      else
        render :edit
      end
    end

    private

    def init_preferences
      @preferences = UserPreferencesForm.new(
        user:         thredded_current_user,
        messageboard: messageboard_or_nil,
        messageboards: policy_scope(Messageboard.all),
        params: preferences_params
      )
    end

    def preferences_params
      params.fetch(:user_preferences_form, {}).permit(
        :auto_follow_topics,
        :messageboard_auto_follow_topics,
        :follow_topics_on_mention,
        :messageboard_follow_topics_on_mention,
        messageboard_notifications_for_followed_topics_attributes: %i[notifier_key id messageboard_id enabled],
        notifications_for_followed_topics_attributes: %i[notifier_key id enabled],
        notifications_for_private_topics_attributes: %i[notifier_key id enabled]
      )
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
thredded-0.13.0 app/controllers/thredded/preferences_controller.rb
thredded-0.12.4 app/controllers/thredded/preferences_controller.rb
thredded-0.12.3 app/controllers/thredded/preferences_controller.rb
thredded-0.12.2 app/controllers/thredded/preferences_controller.rb