From c7aa86f5be2730359cad1d2b701e5f74261b743d Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Wed, 28 May 2025 16:14:07 +0300 Subject: [PATCH] Remove /edit from profile form path This makes it similar to account and preferences paths that also don't have /edit. Getting /profile is now allowed, making it possible to reload the profile edit form page. --- app/abilities/ability.rb | 3 +-- app/controllers/confirmations_controller.rb | 4 ++-- app/controllers/profiles_controller.rb | 2 +- app/views/dashboards/show.html.erb | 2 +- .../profiles/{edit.html.erb => show.html.erb} | 0 app/views/users/show.html.erb | 2 +- config/locales/en.yml | 2 +- config/routes.rb | 5 +++-- test/controllers/profiles_controller_test.rb | 14 ++++++++------ test/system/user_location_change_test.rb | 2 +- 10 files changed, 19 insertions(+), 17 deletions(-) rename app/views/profiles/{edit.html.erb => show.html.erb} (100%) diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 673fe5afa..7d61ff373 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -40,14 +40,13 @@ class Ability can :update, :account_terms can :create, :account_pd_declaration can :read, :dashboard + can [:read, :update], [:preference, :profile] can [:create, :subscribe, :unsubscribe], DiaryEntry can :update, DiaryEntry, :user => user can [:create], DiaryComment can [:show, :create, :destroy], Follow can [:read, :create, :destroy], Message can [:close, :reopen], Note - can [:read, :update], :preference - can :update, :profile can :create, Report can [:mine, :create, :update, :destroy], Trace can [:account, :go_public], User diff --git a/app/controllers/confirmations_controller.rb b/app/controllers/confirmations_controller.rb index 675d8dd90..964f0cc4f 100644 --- a/app/controllers/confirmations_controller.rb +++ b/app/controllers/confirmations_controller.rb @@ -101,9 +101,9 @@ class ConfirmationsController < ApplicationController # display a message about the current status of the Gravatar setting def gravatar_status_message(user) if user.image_use_gravatar - t "profiles.edit.gravatar.enabled" + t "profiles.show.gravatar.enabled" else - t "profiles.edit.gravatar.disabled" + t "profiles.show.gravatar.disabled" end end end diff --git a/app/controllers/profiles_controller.rb b/app/controllers/profiles_controller.rb index 89e154e6b..8270916bf 100644 --- a/app/controllers/profiles_controller.rb +++ b/app/controllers/profiles_controller.rb @@ -9,7 +9,7 @@ class ProfilesController < ApplicationController before_action :check_database_readable before_action :check_database_writable, :only => [:update] - def edit; end + def show; end def update social_links_params = params.permit(:user => [:social_links_attributes => [:id, :url, :_destroy]]) diff --git a/app/views/dashboards/show.html.erb b/app/views/dashboards/show.html.erb index 7f5071cab..52d4f3edc 100644 --- a/app/views/dashboards/show.html.erb +++ b/app/views/dashboards/show.html.erb @@ -8,7 +8,7 @@
<% if !current_user.home_location? %>
-

<%= t(".no_home_location_html", :edit_profile_link => link_to(t(".edit_your_profile"), edit_profile_path)) %>

+

<%= t(".no_home_location_html", :edit_profile_link => link_to(t(".edit_your_profile"), profile_path)) %>

<% else %> <% content_for :head do %> diff --git a/app/views/profiles/edit.html.erb b/app/views/profiles/show.html.erb similarity index 100% rename from app/views/profiles/edit.html.erb rename to app/views/profiles/show.html.erb diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index 857facafc..e9809fed1 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -265,6 +265,6 @@ <% if current_user and @user.id == current_user.id %>
- <%= link_to t(".edit_profile"), edit_profile_path, :class => "btn btn-outline-primary" %> + <%= link_to t(".edit_profile"), profile_path, :class => "btn btn-outline-primary" %>
<% end %> diff --git a/config/locales/en.yml b/config/locales/en.yml index 388f6adfd..6110bdd30 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1966,7 +1966,7 @@ en: update_success_flash: message: Preferences updated. profiles: - edit: + show: title: Edit Profile save: Update Profile cancel: Cancel diff --git a/config/routes.rb b/config/routes.rb index 436e9a308..32d0b17b2 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -316,8 +316,9 @@ OpenStreetMap::Application.routes.draw do resource :dashboard, :only => [:show] resource :preferences, :only => [:show, :update] - get "/preferences/edit", :to => redirect(:path => "/preferences") - resource :profile, :only => [:edit, :update] + get "/preferences/edit", :to => redirect(:path => "/preferences"), :as => nil + resource :profile, :only => [:show, :update] + get "/profile/edit", :to => redirect(:path => "/profile"), :as => nil # friendships scope "/user/:display_name" do diff --git a/test/controllers/profiles_controller_test.rb b/test/controllers/profiles_controller_test.rb index b5ea4b54a..849d1e099 100644 --- a/test/controllers/profiles_controller_test.rb +++ b/test/controllers/profiles_controller_test.rb @@ -5,14 +5,16 @@ class ProfilesControllerTest < ActionDispatch::IntegrationTest # test all routes which lead to this controller def test_routes assert_routing( - { :path => "/profile/edit", :method => :get }, - { :controller => "profiles", :action => "edit" } + { :path => "/profile", :method => :get }, + { :controller => "profiles", :action => "show" } ) - assert_routing( { :path => "/profile", :method => :put }, { :controller => "profiles", :action => "update" } ) + + get "/profile/edit" + assert_redirected_to "/profile" end def test_update @@ -36,7 +38,7 @@ class ProfilesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_template :show assert_select ".alert-success", /^Profile updated./ - get edit_profile_path + get profile_path assert_select "form > fieldset > div > div.col-sm-10 > div.form-check > input[name=avatar_action][checked][value=?]", "keep" # Changing to a gravatar image should work @@ -46,7 +48,7 @@ class ProfilesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_template :show assert_select ".alert-success", /^Profile updated./ - get edit_profile_path + get profile_path assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked][value=?]", "gravatar" # Removing the image should work @@ -56,7 +58,7 @@ class ProfilesControllerTest < ActionDispatch::IntegrationTest assert_response :success assert_template :show assert_select ".alert-success", /^Profile updated./ - get edit_profile_path + get profile_path assert_select "form > fieldset > div > div.col-sm-10 > div > input[name=avatar_action][checked]", false assert_select "form > fieldset > div > div.col-sm-10 > div > div.form-check > input[name=avatar_action][checked]", false diff --git a/test/system/user_location_change_test.rb b/test/system/user_location_change_test.rb index d35ac434d..24e829360 100644 --- a/test/system/user_location_change_test.rb +++ b/test/system/user_location_change_test.rb @@ -15,7 +15,7 @@ class UserLocationChangeTest < ApplicationSystemTestCase assert_no_selector ".bi.bi-geo-alt-fill" end - visit edit_profile_path + visit profile_path fill_in "Home location name", :with => "Test Location" click_on "Update Profile" -- 2.39.5