Commit a3c24add466eeea2cb2ba6c828298f9cee197805
Committed by
Larissa Reis
1 parent
955d5e2a
Exists in
federation-webfinger
Ticket #262: Fixed link to profile image
Showing
4 changed files
with
54 additions
and
0 deletions
Show diff stats
app/controllers/public/profile_controller.rb
@@ -395,6 +395,17 @@ class ProfileController < PublicController | @@ -395,6 +395,17 @@ class ProfileController < PublicController | ||
395 | end | 395 | end |
396 | end | 396 | end |
397 | 397 | ||
398 | + def icon | ||
399 | + size = params[:size] || :portrait | ||
400 | + image, mime = profile_icon(profile, size.to_sym, true) | ||
401 | + | ||
402 | + unless image.match(/^\/\/www\.gravatar\.com/).nil? | ||
403 | + redirect_to 'https:' + image | ||
404 | + else | ||
405 | + @file = File.join(Rails.root, 'public', image) | ||
406 | + send_file @file, type: mime, disposition: 'inline' | ||
407 | + end | ||
408 | + end | ||
398 | 409 | ||
399 | protected | 410 | protected |
400 | 411 |
config/routes.rb
@@ -86,6 +86,9 @@ Noosfero::Application.routes.draw do | @@ -86,6 +86,9 @@ Noosfero::Application.routes.draw do | ||
86 | 86 | ||
87 | # comments | 87 | # comments |
88 | match 'profile/:profile/comment/:action/:id', controller: 'comment', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all | 88 | match 'profile/:profile/comment/:action/:id', controller: 'comment', profile: /#{Noosfero.identifier_format_in_url}/i, via: :all |
89 | + | ||
90 | + # icon | ||
91 | + match 'profile/:profile/icon(/:size)', controller: 'profile', action: 'icon', size: /(big|minor|thumb|portrait|icon)/, profile: /#{Noosfero.identifier_format_in_url}/i, via: :get | ||
89 | 92 | ||
90 | # public profile information | 93 | # public profile information |
91 | match 'profile/:profile(/:action(/:id))', controller: 'profile', action: 'index', id: /[^\/]*/, profile: /#{Noosfero.identifier_format_in_url}/i, as: :profile, via: :all | 94 | match 'profile/:profile(/:action(/:id))', controller: 'profile', action: 'index', id: /[^\/]*/, profile: /#{Noosfero.identifier_format_in_url}/i, as: :profile, via: :all |
test/functional/profile_controller_test.rb
@@ -1932,4 +1932,37 @@ class ProfileControllerTest < ActionController::TestCase | @@ -1932,4 +1932,37 @@ class ProfileControllerTest < ActionController::TestCase | ||
1932 | assert_redirected_to :controller => 'account', :action => 'login' | 1932 | assert_redirected_to :controller => 'account', :action => 'login' |
1933 | end | 1933 | end |
1934 | 1934 | ||
1935 | + should 'return portrait icon if size is not provided and there is a profile image' do | ||
1936 | + img = Image.create!(uploaded_data: fixture_file_upload('/files/rails.png', 'image/png')) | ||
1937 | + profile = fast_create(Person, image_id: img.id) | ||
1938 | + | ||
1939 | + get :icon, profile: profile.identifier, size: nil | ||
1940 | + assert_response :success | ||
1941 | + assert_equal 'image/png', @response.header['Content-Type'] | ||
1942 | + assert File.exists?(assigns(:file)) | ||
1943 | + end | ||
1944 | + | ||
1945 | + should 'return icon in provided size if there is a profile image' do | ||
1946 | + img = Image.create!(uploaded_data: fixture_file_upload('/files/rails.png', 'image/png')) | ||
1947 | + profile = fast_create(Person, image_id: img.id) | ||
1948 | + | ||
1949 | + get :icon, profile: profile.identifier, size: :big | ||
1950 | + assert_response :success | ||
1951 | + assert_equal 'image/png', @response.header['Content-Type'] | ||
1952 | + assert File.exists?(assigns(:file)) | ||
1953 | + end | ||
1954 | + | ||
1955 | + should 'return icon from gravatar without size if there is no profile image' do | ||
1956 | + profile = fast_create(Person) | ||
1957 | + | ||
1958 | + get :icon, profile: profile.identifier | ||
1959 | + assert_redirected_to /^https:\/\/www\.gravatar\.com\/.*/ | ||
1960 | + end | ||
1961 | + | ||
1962 | + should 'return icon from gravatar with size if there is no profile image' do | ||
1963 | + profile = fast_create(Person) | ||
1964 | + | ||
1965 | + get :icon, profile: profile.identifier, size: :thumb | ||
1966 | + assert_redirected_to /^https:\/\/www\.gravatar\.com\/.*/ | ||
1967 | + end | ||
1935 | end | 1968 | end |
test/integration/routing_test.rb
@@ -276,4 +276,11 @@ class RoutingTest < ActionDispatch::IntegrationTest | @@ -276,4 +276,11 @@ class RoutingTest < ActionDispatch::IntegrationTest | ||
276 | assert_routing('/profile/~', :controller => 'profile', :profile => '~', :action => 'index') | 276 | assert_routing('/profile/~', :controller => 'profile', :profile => '~', :action => 'index') |
277 | end | 277 | end |
278 | 278 | ||
279 | + should 'have route to profile icon without size' do | ||
280 | + assert_routing('/profile/ze/icon', controller: 'profile', profile: 'ze', action: 'icon') | ||
281 | + end | ||
282 | + | ||
283 | + should 'have route to profile icon with supported size' do | ||
284 | + assert_routing('/profile/ze/icon/big', controller: 'profile', profile: 'ze', action: 'icon', size: 'big') | ||
285 | + end | ||
279 | end | 286 | end |