can [:make_friend, :remove_friend], Friendship
can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message
can [:close, :reopen], Note
+ can [:show, :edit, :update], :preference
can [:new, :create], Report
can [:mine, :new, :create, :edit, :update, :destroy], Trace
can [:account, :go_public], User
--- /dev/null
+class PreferencesController < ApplicationController
+ layout "site"
+
+ before_action :authorize_web
+ before_action :set_locale
+
+ authorize_resource :class => false
+
+ before_action :check_database_readable
+ before_action :check_database_writable, :only => [:update]
+
+ def show; end
+
+ def edit; end
+
+ def update
+ current_user.languages = params[:user][:languages].split(",")
+
+ current_user.preferred_editor = if params[:user][:preferred_editor] == "default"
+ nil
+ else
+ params[:user][:preferred_editor]
+ end
+ if current_user.save
+ flash[:notice] = t ".success"
+ redirect_to preferences_path
+ else
+ flash[:error] = t ".failure"
+ render :edit
+ end
+ end
+end
user.description_format = "markdown"
end
- user.languages = params[:user][:languages].split(",")
-
case params[:avatar_action]
when "new"
user.avatar.attach(params[:user][:avatar])
user.home_lat = params[:user][:home_lat]
user.home_lon = params[:user][:home_lon]
- user.preferred_editor = if params[:user][:preferred_editor] == "default"
- nil
- else
- params[:user][:preferred_editor]
- end
-
if params[:user][:auth_provider].nil? || params[:user][:auth_provider].blank?
user.auth_provider = nil
user.auth_uid = nil
if user.save
session[:fingerprint] = user.fingerprint
- set_locale(:reset => true)
-
if user.new_email.blank? || user.new_email == user.email
flash[:notice] = t "users.account.flash update success"
else
<% end %>
<%= link_to t("users.show.my profile"), user_path(current_user), :class => "dropdown-item" %>
<%= link_to t("users.show.my settings"), { :controller => "users", :action => "account", :display_name => current_user.display_name }, { :class => "dropdown-item" } %>
+ <%= link_to t("users.show.my_preferences"), preferences_path, :class => "dropdown-item" %>
<div class="dropdown-divider"></div>
<%= yield :greeting %>
<%= link_to t("layouts.logout"), logout_path(:referer => request.fullpath), :method => "post", :class => "geolink dropdown-item" %>
--- /dev/null
+<% content_for :heading do %>
+ <h1><%= t ".title" %></h1>
+<% end %>
+
+<%= bootstrap_form_for current_user, :url => { :action => :update } do |f| %>
+ <%= f.select :preferred_editor, [[t("editor.default", :name => t("editor.#{Settings.default_editor}.name")), "default"]] + Editors::AVAILABLE_EDITORS.collect { |e| [t("editor.#{e}.description"), e] } %>
+
+ <%= f.text_field :languages %>
+
+ <%= f.primary t(".save") %>
+ <%= link_to t(".cancel"), preferences_path, :class => "btn btn-link" %>
+<% end %>
--- /dev/null
+<% content_for :heading do %>
+ <h1><%= t ".title" %></h1>
+<% end %>
+
+<dl class="row">
+ <dt class="col-sm-4"><%= t ".preferred_editor" %></dt>
+
+ <% if current_user.preferred_editor? %>
+ <dd class="col-sm-8"><%= t("editor.#{current_user.preferred_editor}.description") %></dd>
+ <% else %>
+ <dd class="col-sm-8"><%= t("editor.default", :name => t("editor.#{Settings.default_editor}.name")) %></dd>
+ <% end %>
+
+ <dt class="col-sm-4"><%= t ".preferred_languages" %></dt>
+
+ <dd class="col-sm-8">
+ <ul>
+ <% current_user.preferred_languages.each do |locale| %>
+ <li><%= locale %></li>
+ <% end %>
+ </ul>
+
+ </dd>
+</dl>
+
+<div>
+ <%= link_to t(".edit_preferences"), edit_preferences_path, :class => "btn btn-outline-primary" %>
+</div>
</span>
</div>
- <%= f.select :preferred_editor, [[t("editor.default", :name => t("editor.#{Settings.default_editor}.name")), "default"]] + Editors::AVAILABLE_EDITORS.collect { |e| [t("editor.#{e}.description"), e] } %>
<%= f.richtext_field :description, :cols => 80, :rows => 20 %>
- <%= f.text_field :languages %>
<fieldset class="form-group">
<%= f.label t(".image") %>
reset: "Reset Password"
flash changed: "Your password has been changed."
flash token bad: "Did not find that token, check the URL maybe?"
+ preferences:
+ show:
+ title: My Preferences
+ preferred_editor: Preferred Editor
+ preferred_languages: Preferred Languages
+ edit_preferences: Edit Preferences
+ edit:
+ title: Edit Preferences
+ save: Update Preferences
+ cancel: Cancel
+ update:
+ success: Preferences updated.
+ failure: Couldn't update preferences.
sessions:
new:
title: "Login"
my profile: My Profile
my settings: My Settings
my comments: My Comments
+ my_preferences: My Preferences
blocks on me: Blocks on Me
blocks by me: Blocks by Me
send message: Send Message
match "/user/:display_name/account" => "users#account", :via => [:get, :post], :as => "user_account"
post "/user/:display_name/set_status" => "users#set_status", :as => :set_status_user
+ resource :preferences, :only => [:show, :edit, :update]
+
# friendships
match "/user/:display_name/make_friend" => "friendships#make_friend", :via => [:get, :post], :as => "make_friend"
match "/user/:display_name/remove_friend" => "friendships#remove_friend", :via => [:get, :post], :as => "remove_friend"
--- /dev/null
+require "test_helper"
+
+class PreferencesControllerTest < ActionDispatch::IntegrationTest
+ ##
+ # test all routes which lead to this controller
+ def test_routes
+ assert_routing(
+ { :path => "/preferences", :method => :get },
+ { :controller => "preferences", :action => "show" }
+ )
+
+ assert_routing(
+ { :path => "/preferences/edit", :method => :get },
+ { :controller => "preferences", :action => "edit" }
+ )
+
+ assert_routing(
+ { :path => "/preferences", :method => :put },
+ { :controller => "preferences", :action => "update" }
+ )
+ end
+
+ def test_update_preferred_editor
+ user = create(:user, :languages => [])
+ session_for(user)
+
+ # Changing to a invalid editor should fail
+ user.preferred_editor = "unknown"
+ put preferences_path, :params => { :user => user.attributes }
+ assert_response :success
+ assert_template :edit
+ assert_select ".notice", false
+ assert_select ".error", true
+ assert_select "form > div.form-group > select#user_preferred_editor > option[selected]", false
+
+ # Changing to a valid editor should work
+ user.preferred_editor = "id"
+ put preferences_path, :params => { :user => user.attributes }
+ assert_response :redirect
+ assert_redirected_to preferences_path
+ follow_redirect!
+ assert_template :show
+ assert_select ".notice", /^Preferences updated/
+ assert_select "dd", "iD (in-browser editor)"
+
+ # Changing to the default editor should work
+ user.preferred_editor = "default"
+ put preferences_path, :params => { :user => user.attributes }
+ assert_response :redirect
+ assert_redirected_to preferences_path
+ follow_redirect!
+ assert_template :show
+ assert_select ".notice", /^Preferences updated/
+ assert_select "dd", "Default (currently iD)"
+ end
+end
assert_select ".notice", /^User information updated successfully/
assert_select "form#accountForm > div.form-group > div#user_description_container > div#user_description_content > textarea#user_description", user.description
- # Changing to a invalid editor should fail
- user.preferred_editor = "unknown"
- post user_account_path(user), :params => { :user => user.attributes }
- assert_response :success
- assert_template :account
- assert_select ".notice", false
- assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected]", false
-
- # Changing to a valid editor should work
- user.preferred_editor = "id"
- post user_account_path(user), :params => { :user => user.attributes }
- assert_response :redirect
- assert_redirected_to user_account_url(user)
- get user_account_path(user)
- assert_response :success
- assert_template :account
- assert_select ".notice", /^User information updated successfully/
- assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected][value=?]", "id"
-
- # Changing to the default editor should work
- user.preferred_editor = "default"
- post user_account_path(user), :params => { :user => user.attributes }
- assert_response :redirect
- assert_redirected_to user_account_url(user)
- get user_account_path(user)
- assert_response :success
- assert_template :account
- assert_select ".notice", /^User information updated successfully/
- assert_select "form#accountForm > div.form-group > select#user_preferred_editor > option[selected]", false
-
# Changing to an uploaded image should work
image = Rack::Test::UploadedFile.new("test/gpx/fixtures/a.gif", "image/gif")
post user_account_path(user), :params => { :avatar_action => "new", :user => user.attributes.merge(:avatar => image) }