Queue XmppSetAvatarJob when new avatar is uploaded
And let job do nothing in development for now
This commit is contained in:
parent
5916969447
commit
5f276ff349
@ -36,6 +36,7 @@ class SettingsController < ApplicationController
|
|||||||
if @user.avatar_new.present?
|
if @user.avatar_new.present?
|
||||||
if store_user_avatar
|
if store_user_avatar
|
||||||
LdapManager::UpdateAvatar.call(user: @user)
|
LdapManager::UpdateAvatar.call(user: @user)
|
||||||
|
XmppSetAvatarJob.perform_later(user: @user)
|
||||||
else
|
else
|
||||||
@validation_errors = @user.errors
|
@validation_errors = @user.errors
|
||||||
render :show, status: :unprocessable_entity and return
|
render :show, status: :unprocessable_entity and return
|
||||||
|
@ -5,11 +5,12 @@ class XmppSetAvatarJob < ApplicationJob
|
|||||||
queue_as :default
|
queue_as :default
|
||||||
|
|
||||||
def perform(user:, overwrite: false)
|
def perform(user:, overwrite: false)
|
||||||
|
return if Rails.env.development?
|
||||||
@user = user
|
@user = user
|
||||||
|
|
||||||
unless overwrite
|
unless overwrite
|
||||||
current_avatar = get_current_avatar
|
current_avatar = get_current_avatar
|
||||||
Rails.logger.debug { "User #{user.cn} already has an avatar set. Nothing to do." }
|
Rails.logger.info { "User #{user.cn} already has an avatar set" }
|
||||||
return if current_avatar.present?
|
return if current_avatar.present?
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -56,6 +57,7 @@ class XmppSetAvatarJob < ApplicationJob
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# See https://xmpp.org/extensions/xep-0084.html
|
||||||
def build_xep0084_stanzas
|
def build_xep0084_stanzas
|
||||||
img_data = process_avatar
|
img_data = process_avatar
|
||||||
sha1_hash = Digest::SHA1.hexdigest(img_data)
|
sha1_hash = Digest::SHA1.hexdigest(img_data)
|
||||||
|
@ -46,6 +46,8 @@ RSpec.describe 'Profile settings', type: :feature do
|
|||||||
|
|
||||||
feature "Update avatar" do
|
feature "Update avatar" do
|
||||||
scenario "fails with validation error for wrong content type" do
|
scenario "fails with validation error for wrong content type" do
|
||||||
|
expect(LdapManager::UpdateAvatar).not_to receive(:call)
|
||||||
|
|
||||||
visit setting_path(:profile)
|
visit setting_path(:profile)
|
||||||
attach_file "Avatar", "#{Rails.root}/spec/fixtures/files/bitcoin.pdf"
|
attach_file "Avatar", "#{Rails.root}/spec/fixtures/files/bitcoin.pdf"
|
||||||
click_button "Save"
|
click_button "Save"
|
||||||
@ -57,8 +59,7 @@ RSpec.describe 'Profile settings', type: :feature do
|
|||||||
end
|
end
|
||||||
|
|
||||||
scenario "fails with validation error for file size too large" do
|
scenario "fails with validation error for file size too large" do
|
||||||
expect_any_instance_of(LdapManager::UpdateAvatar)
|
expect(LdapManager::UpdateAvatar).not_to receive(:call)
|
||||||
.not_to receive(:replace_attribute).and_return(true)
|
|
||||||
|
|
||||||
visit setting_path(:profile)
|
visit setting_path(:profile)
|
||||||
attach_file "Avatar", "#{Rails.root}/spec/fixtures/files/fsociety-irc.png"
|
attach_file "Avatar", "#{Rails.root}/spec/fixtures/files/fsociety-irc.png"
|
||||||
@ -73,8 +74,12 @@ RSpec.describe 'Profile settings', type: :feature do
|
|||||||
scenario 'works with valid JPG file' do
|
scenario 'works with valid JPG file' do
|
||||||
file_path = "#{Rails.root}/spec/fixtures/files/taipei.jpg"
|
file_path = "#{Rails.root}/spec/fixtures/files/taipei.jpg"
|
||||||
|
|
||||||
expect_any_instance_of(LdapManager::UpdateAvatar)
|
expect(LdapManager::UpdateAvatar)
|
||||||
.to receive(:replace_attribute).and_return(true)
|
.to receive(:call).with(user: user)
|
||||||
|
.and_return(true)
|
||||||
|
expect(XmppSetAvatarJob)
|
||||||
|
.to receive(:perform_later).with(user: user)
|
||||||
|
.and_return(true)
|
||||||
|
|
||||||
visit setting_path(:profile)
|
visit setting_path(:profile)
|
||||||
attach_file "Avatar", file_path
|
attach_file "Avatar", file_path
|
||||||
@ -89,8 +94,12 @@ RSpec.describe 'Profile settings', type: :feature do
|
|||||||
scenario 'works with valid PNG file' do
|
scenario 'works with valid PNG file' do
|
||||||
file_path = "#{Rails.root}/spec/fixtures/files/bender.png"
|
file_path = "#{Rails.root}/spec/fixtures/files/bender.png"
|
||||||
|
|
||||||
expect_any_instance_of(LdapManager::UpdateAvatar)
|
expect(LdapManager::UpdateAvatar)
|
||||||
.to receive(:replace_attribute).and_return(true)
|
.to receive(:call).with(user: user)
|
||||||
|
.and_return(true)
|
||||||
|
expect(XmppSetAvatarJob)
|
||||||
|
.to receive(:perform_later).with(user: user)
|
||||||
|
.and_return(true)
|
||||||
|
|
||||||
visit setting_path(:profile)
|
visit setting_path(:profile)
|
||||||
attach_file "Avatar", file_path
|
attach_file "Avatar", file_path
|
||||||
|
Loading…
x
Reference in New Issue
Block a user