]> git.openstreetmap.org Git - rails.git/blob - app/controllers/preferences_controller.rb
Merge pull request #5388 from AntonKhorev/map-layer-can-embed
[rails.git] / app / controllers / preferences_controller.rb
1 class PreferencesController < ApplicationController
2   layout "site"
3
4   before_action :authorize_web
5   before_action :set_locale
6
7   authorize_resource :class => false
8
9   before_action :check_database_readable
10   before_action :check_database_writable, :only => [:update]
11
12   def show; end
13
14   def edit; end
15
16   def update
17     current_user.languages = params[:user][:languages].split(",")
18
19     current_user.preferred_editor = if params[:user][:preferred_editor] == "default"
20                                       nil
21                                     else
22                                       params[:user][:preferred_editor]
23                                     end
24
25     success = current_user.save
26
27     if params[:site_color_scheme]
28       site_color_scheme_preference = current_user.preferences.find_or_create_by(:k => "site.color_scheme")
29       success &= site_color_scheme_preference.update(:v => params[:site_color_scheme])
30     end
31
32     if params[:map_color_scheme]
33       map_color_scheme_preference = current_user.preferences.find_or_create_by(:k => "map.color_scheme")
34       success &= map_color_scheme_preference.update(:v => params[:map_color_scheme])
35     end
36
37     if success
38       # Use a partial so that it is rendered during the next page load in the correct language.
39       flash[:notice] = { :partial => "preferences/update_success_flash" }
40       redirect_to preferences_path
41     else
42       flash.now[:error] = t ".failure"
43       render :edit
44     end
45   end
46 end