From 7819498e38b5de4824ac2b3612de40eaeb5c918c Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Tue, 1 Jul 2025 18:12:29 +0300 Subject: [PATCH] Add "Edit Description" button to user profile --- app/views/users/show.html.erb | 10 ++- config/locales/en.yml | 1 + .../system/profile_description_change_test.rb | 66 +++++++++++++++++++ 3 files changed, 75 insertions(+), 2 deletions(-) create mode 100644 test/system/profile_description_change_test.rb diff --git a/app/views/users/show.html.erb b/app/views/users/show.html.erb index aed26de2e..edc744f83 100644 --- a/app/views/users/show.html.erb +++ b/app/views/users/show.html.erb @@ -234,7 +234,8 @@ <% end %> -<% if @user.home_location_name&.strip.present? || @user.company&.strip.present? || !@user.social_links.empty? %> +<% owned = current_user && @user == current_user %> +<% if @user.home_location_name&.strip.present? || @user.company&.strip.present? || !@user.social_links.empty? || owned %>
<% if @user.home_location_name&.strip.present? %> @@ -272,6 +273,11 @@
<%= @user.description.to_html %>
+ <% if owned %> +
+ <%= link_to t(".edit_description"), profile_description_path, :class => "btn btn-outline-primary" %> +
+ <% end %>
<% else %> @@ -284,7 +290,7 @@ <%= render :partial => "diary_entries/profile_diaries", :locals => { :diary_entries => @user.diary_entries.visible.order(:created_at => :desc).limit(4) } %> -<% if current_user and @user.id == current_user.id %> +<% if owned %>
<%= link_to t(".edit_profile"), profile_description_path, :class => "btn btn-outline-primary" %>
diff --git a/config/locales/en.yml b/config/locales/en.yml index 47cd7ae31..95e109dc3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -3076,6 +3076,7 @@ en: delete_user: "Delete this User" confirm: "Confirm" report: Report this User + edit_description: Edit Description contributions: one: "%{count} contribution in the last year" other: "%{count} contributions in the last year" diff --git a/test/system/profile_description_change_test.rb b/test/system/profile_description_change_test.rb new file mode 100644 index 000000000..79f10ef96 --- /dev/null +++ b/test/system/profile_description_change_test.rb @@ -0,0 +1,66 @@ +require "application_system_test_case" + +class ProfileLinksChangeTest < ApplicationSystemTestCase + test "can't change description when unauthorized" do + user = create(:user) + + visit user_path(user) + + within_content_body do + assert_no_link "Edit Description" + end + end + + test "can't change description of another user" do + user = create(:user) + another_user = create(:user) + + sign_in_as(user) + visit user_path(another_user) + + within_content_body do + assert_no_link "Edit Description" + end + end + + test "can change description" do + user = create(:user) + check_description_change(user) + end + + test "can change description when have a description" do + user = create(:user, :description => "My old profile description") + check_description_change(user) + end + + test "can change description when have a link" do + user = create(:user) + create(:social_link, :user => user) + check_description_change(user) + end + + test "can change description when have a description and a link" do + user = create(:user, :description => "My old profile description") + create(:social_link, :user => user) + check_description_change(user) + end + + private + + def check_description_change(user) + sign_in_as(user) + visit user_path(user) + + within_content_body do + click_on "Edit Description" + fill_in "Profile Description", :with => "This is my updated OSM profile!" + click_on "Update Profile" + end + + assert_text "Profile description updated." + + within_content_body do + assert_text "This is my updated OSM profile!" + end + end +end -- 2.39.5