[Git][noosfero/noosfero][stable-1.10] Merge branch 'chat-avatar' into 'master'

Rodrigo Souto gitlab at mg.gitlab.com
Fri Nov 10 14:48:36 BRST 2017


Rodrigo Souto pushed to branch stable-1.10 at Noosfero / noosfero


Commits:
1fbc7ca1 by Rodrigo Souto at 2017-11-10T16:48:32+00:00
Merge branch 'chat-avatar' into 'master'

chat: avoid avatar request crashes

Closes #280

See merge request noosfero/noosfero!1347

(cherry picked from commit 3c5273bf84a1642f666632b5e87f768dc02fafc2)

c856b517 chat: avoid avatar request crashes
- - - - -


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/commit/1fbc7ca1bdc7d457a49771b4a18a082f5c585caa

---
View it on GitLab: https://gitlab.com/noosfero/noosfero/commit/1fbc7ca1bdc7d457a49771b4a18a082f5c585caa
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/f7f2d15b/attachment-0001.html>


More information about the Noosfero-dev mailing list