about summary refs log tree commit diff
path: root/app/controllers/settings/flavours_controller.rb
blob: 865d5a47924b2e244d629455be371b3ebf05c24b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# frozen_string_literal: true

class Settings::FlavoursController < Settings::BaseController

  def index
    redirect_to action: 'show', flavour: current_flavour
  end

  def show
    unless Themes.instance.flavours.include?(params[:flavour]) or params[:flavour] == current_flavour
      redirect_to action: 'show', flavour: current_flavour
    end

    @listing = Themes.instance.flavours
    @selected = params[:flavour]
  end

  def update
    user_settings.update(user_settings_params(params[:flavour]).to_h)
    redirect_to action: 'show', flavour: params[:flavour]
  end

  private

  def user_settings
    UserSettingsDecorator.new(current_user)
  end

  def user_settings_params(flavour)
    params.require(:user).merge({ setting_flavour: flavour }).permit(
      :setting_flavour,
      :setting_skin
    )
  end
end