[Git][noosfero/noosfero][master] 2 commits: chat: avoid avatar request crashes
Rodrigo Souto
gitlab at mg.gitlab.com
Fri Nov 10 14:48:18 BRST 2017
Rodrigo Souto pushed to branch master at Noosfero / noosfero
Commits:
c856b517 by Rodrigo Souto at 2017-11-06T15:41:08-03:00
chat: avoid avatar request crashes
- - - - -
3c5273bf by Rodrigo Souto at 2017-11-10T16:48:09+00:00
Merge branch 'chat-avatar' into 'master'
chat: avoid avatar request crashes
Closes #280
See merge request noosfero/noosfero!1347
- - - - -
2 changed files:
- app/controllers/public/chat_controller.rb
- test/functional/chat_controller_test.rb
Changes:
=====================================
app/controllers/public/chat_controller.rb
=====================================
--- a/app/controllers/public/chat_controller.rb
+++ b/app/controllers/public/chat_controller.rb
@@ -45,13 +45,17 @@ class ChatController < PublicController
def avatar
profile = environment.profiles.find_by(identifier: params[:id])
- filename, mimetype = profile_icon(profile, :minor, true)
- if filename =~ /^(https?:)?\/\//
- redirect_to filename
+ if profile.present?
+ filename, mimetype = profile_icon(profile, :minor, true)
+ if filename =~ /^(https?:)?\/\//
+ redirect_to filename
+ else
+ data = File.read(File.join(Rails.root, 'public', filename))
+ render :text => data, :layout => false, :content_type => mimetype
+ expires_in 24.hours
+ end
else
- data = File.read(File.join(Rails.root, 'public', filename))
- render :text => data, :layout => false, :content_type => mimetype
- expires_in 24.hours
+ render nothing: true
end
end
=====================================
test/functional/chat_controller_test.rb
=====================================
--- a/test/functional/chat_controller_test.rb
+++ b/test/functional/chat_controller_test.rb
@@ -206,4 +206,11 @@ class ChatControllerTest < ActionController::TestCase
assert_equal @response.body, my_chat.to_json
end
+ should 'not crash o avatar if no profile found' do
+ login_as 'testuser'
+ assert_nothing_raised do
+ get :avatar, :id => 'unexistent-user'
+ end
+ end
+
end
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/439e3f4ee06a611bf2ea63d1731ef6bf921d8d25...3c5273bf84a1642f666632b5e87f768dc02fafc2
---
View it on GitLab: https://gitlab.com/noosfero/noosfero/compare/439e3f4ee06a611bf2ea63d1731ef6bf921d8d25...3c5273bf84a1642f666632b5e87f768dc02fafc2
You're receiving this email because of your account on gitlab.com.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20171110/74e02adb/attachment-0001.html>
More information about the Noosfero-dev
mailing list