The personal finance app for everyone (by everyone)
Ruby
feat(admin): show profile pictures in user management list (#3467)
Justin McBride3ff1525702e0
diff --git a/app/controllers/admin/users_controller.rb b/app/controllers/admin/users_controller.rbindex 15f34f4566..384b7ae6ab 100644--- a/app/controllers/admin/users_controller.rb+++ b/app/controllers/admin/users_controller.rb@@ -9,6 +9,7 @@ module Adminscope = policy_scope(User).left_joins(family: :subscription).includes(:oidc_identities, family: :subscription)+ .with_attached_profile_imagescope = scope.where(role: params[:role]) if params[:role].present?scope = apply_trial_filter(scope) if params[:trial_status].present?diff --git a/app/views/admin/users/index.html.erb b/app/views/admin/users/index.html.erbindex 8018f836ba..977c4c6567 100644--- a/app/views/admin/users/index.html.erb+++ b/app/views/admin/users/index.html.erb@@ -103,8 +103,8 @@<tr><td class="px-4 py-3"><div class="flex items-center gap-3">- <div class="w-8 h-8 rounded-full bg-surface flex items-center justify-center shrink-0">- <span class="text-sm font-medium text-primary"><%= user.initials %></span>+ <div class="w-8 h-8 shrink-0">+ <%= render "settings/user_avatar", avatar_url: user.profile_image&.variant(:small)&.url, initials: user.initials, lazy: true %></div><div><div class="flex items-center gap-2">diff --git a/test/controllers/admin/users_controller_test.rb b/test/controllers/admin/users_controller_test.rbindex abc7588ba7..5601d349c2 100644--- a/test/controllers/admin/users_controller_test.rb+++ b/test/controllers/admin/users_controller_test.rb@@ -94,6 +94,41 @@ class Admin::UsersControllerTest < ActionDispatch::IntegrationTestassert_match(/Delete unused family/, response.body)end+ test "index renders the profile picture of users who have one" do+ user = users(:family_admin)+ user.profile_image.attach(+ io: File.open(Rails.root.join("test/fixtures/files/profile_image.png")),+ filename: "profile_image.png",+ content_type: "image/png"+ )+ # The disk service URL embeds a token signed with an expiry, so freeze time+ # to keep the expected URL identical to the one rendered by the request.+ travel_to Time.current do+ variant = user.profile_image.variant(:small).processed+ ActiveStorage::Current.url_options = { host: "www.example.com", protocol: "http" }+ expected_src = variant.url++ get admin_users_url+ assert_response :success++ assert_select "img[src=?]", expected_src, { count: 1 },+ "User management should render the small profile image variant for users who have one"+ end+ end++ test "index falls back to initials for users without a profile picture" do+ user = users(:family_admin)+ assert_not user.profile_image.attached?++ get admin_users_url+ assert_response :success++ assert_match user.initials, response.body,+ "User management should fall back to initials when there is no profile picture"+ assert_select "img[src*=?]", "active_storage", { count: 0 },+ "No avatar image should render for users without a profile picture"+ end+test "update can move a user to an existing family" do