diff options
author | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-10-30 02:43:55 +0300 |
---|---|---|
committer | Benjamin Neff <benjamin@coding4coffee.ch> | 2022-10-30 02:45:27 +0300 |
commit | f6105e54a9964dd15793a6376094309d608b86d9 (patch) | |
tree | d5a77d11d603d7c3daf1a49770a0ba30c964b6f0 | |
parent | abcbfcef1565d35e1ae00ac6a3d01ced963685f0 (diff) | |
parent | cbbb0a55c2b6a75206d26e541183cdbfffa2c23d (diff) |
Merge pull request #8400 from SuperTux88/8352-mobile-photo-url-redirect
Add redirect to mobile-only photo URL when in desktop UI
-rw-r--r-- | Changelog.md | 1 | ||||
-rw-r--r-- | app/controllers/photos_controller.rb | 10 | ||||
-rw-r--r-- | spec/controllers/photos_controller_spec.rb | 13 |
3 files changed, 23 insertions, 1 deletions
diff --git a/Changelog.md b/Changelog.md index c84cf2c32..350946272 100644 --- a/Changelog.md +++ b/Changelog.md @@ -52,6 +52,7 @@ We use yarn to install the frontend dependencies now, so you need to have that i * Photo-upload file picker now correctly restricts possible file types [#8205](https://github.com/diaspora/diaspora/pull/8205) * Make inline code inside links show the link color [#8387](https://github.com/diaspora/diaspora/pull/8387) * Fix fetching public posts on first account search was missing some data [#8390](https://github.com/diaspora/diaspora/pull/8390) +* Add redirect from mobile UI photo URLs to post when not using mobile UI [#8400](https://github.com/diaspora/diaspora/pull/8400) ## Features * Add client-side cropping of profile image uploads [#7581](https://github.com/diaspora/diaspora/pull/7581) diff --git a/app/controllers/photos_controller.rb b/app/controllers/photos_controller.rb index c9447b495..e7a827de4 100644 --- a/app/controllers/photos_controller.rb +++ b/app/controllers/photos_controller.rb @@ -13,9 +13,17 @@ class PhotosController < ApplicationController current_user.photos_from(Person.find_by(guid: params[:person_id])).where(id: params[:id]).first else Photo.where(id: params[:id], public: true).first - end + end raise ActiveRecord::RecordNotFound unless @photo + + respond_to do |format| + format.html { + post = @photo.status_message + redirect_to post ? post_path(post) : @photo.url + } + format.mobile { render "photos/show" } + end end def index diff --git a/spec/controllers/photos_controller_spec.rb b/spec/controllers/photos_controller_spec.rb index 4d76435fa..4b6ca7fe4 100644 --- a/spec/controllers/photos_controller_spec.rb +++ b/spec/controllers/photos_controller_spec.rb @@ -230,6 +230,19 @@ describe PhotosController, :type => :controller do expect(response).to be_successful end + it "should redirect to the post of the photo when not on mobile" do + alices_post = alice.post(:status_message, text: "Post with photo", to: alice.aspects.first.id, public: false) + @alices_photo.update(status_message: alices_post) + + get :show, params: {person_id: alice.person.guid, id: @alices_photo.id} + expect(response).to redirect_to(post_path(alices_post)) + end + + it "should redirect to the photo file when not on mobile and no post exists" do + get :show, params: {person_id: alice.person.guid, id: @alices_photo.id} + expect(response).to redirect_to(@alices_photo.url) + end + it "doesn't leak private photos to the public" do sign_out :user expect { |