Render system user avatars using redirects
This commit is contained in:
@@ -7,7 +7,9 @@ class Users::AvatarsController < ApplicationController
|
||||
before_action :ensure_permission_to_administer_user, only: :destroy
|
||||
|
||||
def show
|
||||
if @user.avatar.attached?
|
||||
if @user.system?
|
||||
redirect_to "/apple-touch-icon.png"
|
||||
elsif @user.avatar.attached?
|
||||
redirect_to rails_blob_url(@user.avatar.variant(:thumb), disposition: "inline")
|
||||
elsif stale? @user, cache_control: cache_control
|
||||
render_initials
|
||||
|
||||
+1
-10
@@ -18,16 +18,7 @@ class Account < ApplicationRecord
|
||||
class << self
|
||||
def create_with_admin_user(account:, owner:)
|
||||
create!(**account).tap do |account|
|
||||
system_user = account.users.create!(role: :system, name: "System")
|
||||
|
||||
Current.with_account(account) do
|
||||
system_user.avatar.attach(
|
||||
io: File.open(Rails.root.join("public", "apple-touch-icon.png")),
|
||||
filename: "apple-touch-icon.png",
|
||||
content_type: "image/png"
|
||||
)
|
||||
end
|
||||
|
||||
account.users.create!(role: :system, name: "System")
|
||||
account.users.create!(**owner.reverse_merge(role: "admin"))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -10,7 +10,7 @@ module User::Role
|
||||
|
||||
class_methods do
|
||||
def system
|
||||
find_or_create_by!(role: :system) { it.name = "System" }
|
||||
find_or_create_by!(account: Current.account, role: :system) { it.name = "System" }
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -5,6 +5,13 @@ class Users::AvatarsControllerTest < ActionDispatch::IntegrationTest
|
||||
sign_in_as :david
|
||||
end
|
||||
|
||||
test "show system user" do
|
||||
get user_avatar_path(users(:system))
|
||||
|
||||
assert_response :redirect
|
||||
assert_redirected_to "/apple-touch-icon.png"
|
||||
end
|
||||
|
||||
test "show own initials without caching" do
|
||||
get user_avatar_path(users(:david))
|
||||
assert_match "image/svg+xml", @response.content_type
|
||||
|
||||
Reference in New Issue
Block a user