]> source.dussan.org Git - redmine.git/commitdiff
Allow attachment thumbnails from REST API (#18707).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 26 Dec 2014 11:26:24 +0000 (11:26 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 26 Dec 2014 11:26:24 +0000 (11:26 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13806 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/attachments_controller.rb
app/helpers/attachments_helper.rb
test/integration/api_test/attachments_test.rb
test/test_helper.rb

index d9357fbbdd4a9b169693577334649bda43122ea6..e622d80862d735f19add9fcd1507e0f7e59f6ae5 100644 (file)
@@ -22,7 +22,7 @@ class AttachmentsController < ApplicationController
   before_filter :delete_authorize, :only => :destroy
   before_filter :authorize_global, :only => :upload
 
-  accept_api_auth :show, :download, :upload
+  accept_api_auth :show, :download, :thumbnail, :upload
 
   def show
     respond_to do |format|
index 387ed99d768da73b84fc182cd6c4285b0a5bbf8c..ed362e2e8438116413243ce28c3ca4dcadcf5b3f 100644 (file)
@@ -54,6 +54,10 @@ module AttachmentsHelper
       api.content_type attachment.content_type
       api.description attachment.description
       api.content_url download_named_attachment_url(attachment, attachment.filename)
+      if attachment.thumbnailable?
+        api.thumbnail_url thumbnail_url(attachment)
+      end
+      api.content_url download_named_attachment_url(attachment, attachment.filename)
       api.author(:id => attachment.author.id, :name => attachment.author.name) if attachment.author
       api.created_on attachment.created_on
     end
index bff956e8018d6606d002a3b0759cf89bbca1f17d..ed6ebec9525fe81d6f6b4ec12dffcd38901dda45 100644 (file)
@@ -47,6 +47,15 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
     end
   end
 
+  test "GET /attachments/:id.xml for image should include thumbnail_url" do
+    get '/attachments/16.xml', {}, credentials('jsmith')
+    assert_response :success
+    assert_equal 'application/xml', @response.content_type
+    assert_select 'attachment id:content(16)' do
+      assert_select '~ thumbnail_url', :text => 'http://www.example.com/attachments/thumbnail/16'
+    end
+  end
+
   test "GET /attachments/:id.xml should deny access without credentials" do
     get '/attachments/7.xml'
     assert_response 401
@@ -66,6 +75,12 @@ class Redmine::ApiTest::AttachmentsTest < Redmine::ApiTest::Base
     set_tmp_attachments_directory
   end
 
+  test "GET /attachments/thumbnail/:id should return the thumbnail" do
+    skip unless convert_installed?
+    get '/attachments/thumbnail/16', {}, credentials('jsmith')
+    assert_response :success
+  end
+
   test "POST /uploads.xml should return the token" do
     set_tmp_attachments_directory
     assert_difference 'Attachment.count' do
index 22b96a809734b4cf16fb72d018122f45d56ad254..bc2d178c14247fa08fc50e038fcff962f90de8f2 100644 (file)
@@ -131,6 +131,10 @@ class ActiveSupport::TestCase
     Redmine::Thumbnail.convert_available?
   end
 
+  def convert_installed?
+    self.class.convert_installed?
+  end
+
   # Returns the path to the test +vendor+ repository
   def self.repository_path(vendor)
     path = Rails.root.join("tmp/test/#{vendor.downcase}_repository").to_s