Skip to content
Snippets Groups Projects
Commit e2b152e6 authored by Patrick Barroca's avatar Patrick Barroca :grin:
Browse files

Merge branch 'hotline#95613_vincent_acces_aux_pieces_jointes_de_la_forge_via_bokeh' into 'hotline'

hotline#95613 : redmine add download attachment

See merge request !3214
parents dbe18294 d12f6928
Branches
Tags
3 merge requests!3297WIP: Master,!3244Master,!3214hotline#95613 : redmine add download attachment
Pipeline #8162 passed with stage
in 35 minutes and 38 seconds
- ticket #95613 : Redmine : accès aux pièces jointes de la forge via Bokeh
\ No newline at end of file
......@@ -175,6 +175,21 @@ class Admin_RedmineController extends ZendAfi_Controller_Action {
}
public function downloadFileAction() {
$library = Class_Bib::find($this->_getParam('id_lib', 0));
$service = new Class_WebService_Redmine($library);
$fileid = $this->_getParam('fileid');
if (!$content = $service->downloadFile($fileid)) {
$this->_helper->notify($this->_('Impossible de télécharger cette pièce jointe'));
$this->_redirectToReferer();
return;
}
$this->_helper->binaryDownload($content, $this->_getParam('filename'));
}
public function uploadFileAction() {
if (!$this->_request->isPost())
return $this->_jsonError($this->_('La requête doit être de type POST'));
......
......@@ -20,7 +20,7 @@
*/
class Class_WebService_Redmine extends Class_WebService_Abstract {
use Trait_Translator;
use Trait_Translator;
const CUSTOM_PRIORITY_ID = 5;
const CUSTOM_MODULE_ID = 37;
......@@ -381,8 +381,12 @@ class Class_WebService_Redmine extends Class_WebService_Abstract {
public function uploadFile($json) {
return $this->_getAttachmentApi()
->upload($json);
return $this->_getAttachmentApi()->upload($json);
}
public function downloadFile($fileid) {
return $this->_getAttachmentApi()->download($fileid);
}
......
......@@ -139,10 +139,12 @@ class Class_WebService_Redmine_Issue extends Class_Entity {
return $view->tag('del',
$this->_('Pièce jointe : "%s"', $attachment->getold_value()));
$show_url = sprintf('%s/attachments/download/%s/%s',
Class_AdminVar::get('REDMINE_SERVER_URL'),
$attachment->getname(),
$attachment->getnew_value());
$show_url = Class_Url::absolute(['module' => 'admin',
'controller' => 'redmine',
'action' => 'download-file',
'id_lib' => $this->getLibrary()->getId(),
'fileid' => $attachment->getname(),
'filename' => $attachment->getnew_value()],null,true);
return $view->tagAnchor($show_url,
$this->_('Pièce jointe : "%s"', $attachment->getnew_value()), ['target' => '_blank']);
......
......@@ -52,6 +52,7 @@ abstract class Admin_RedmineControllerTestCase extends Admin_AbstractControllerT
class Admin_RedmineControllerTestActionWithNoBibTest extends Admin_RedmineControllerTestCase {
public function setUp() {
parent::setUp();
......@@ -67,6 +68,7 @@ class Admin_RedmineControllerTestActionWithNoBibTest extends Admin_RedmineContro
abstract class Admin_RedmineControllerWithAnnecyLibraryTestCase extends Admin_RedmineControllerTestCase {
public function setUp() {
......@@ -560,6 +562,13 @@ class Admin_RedmineControllerEditIssue34247Test extends Admin_RedmineControllerF
public function historyShouldBePresent() {
$this->assertXPathContentContains('//legend', 'Historique');
}
/** @test */
public function attachmentShouldLinkToDownloadFile() {
$this->assertXPathContentContains('//a[contains(@href,"download-file/id_lib/1/fileid/456789/filename/proof.jpg")]', 'proof.jpg', $this->_response->getBody());
}
}
......@@ -863,3 +872,74 @@ class Admin_RedmineControllerPostEditIssue34247WithAttachmentTest extends Admin_
$this->assertRedirect();
}
}
class Admin_RedmineControllerTestActionDownloadAttachmentTest
extends Admin_RedmineControllerWithAnnecyLibraryTestCase {
public function setUp() {
parent::setUp();
$redmine_api = $this->mock()
->whenCalled('download')
->with(123)
->answers('toto');
$redmine_client = $this->mock()
->whenCalled('api')
->answers($redmine_api);
Class_WebService_Redmine::setClient($redmine_client);
$this->dispatch('/admin/redmine/download-file/id_lib/1/fileid/123/filename/test.txt', true);
}
/** @test */
public function responseBodyShouldBeToto() {
$this->assertEquals('toto', $this->_response->getBody());
}
/** @test */
public function contentTypeShouldBeApplicationOctetStream() {
$this->assertEquals('application/octet-stream; name="test.txt"',
$this->_response->getHeaders()[0]['value']);
}
}
class Admin_RedmineControllerTestActionDownloadEmptyAttachmentTest
extends Admin_RedmineControllerWithAnnecyLibraryTestCase {
public function setUp() {
parent::setUp();
$redmine_api = $this->mock()
->whenCalled('download')
->with(123)
->answers('');
$redmine_client = $this->mock()
->whenCalled('api')
->answers($redmine_api);
Class_WebService_Redmine::setClient($redmine_client);
$this->dispatch('/admin/redmine/download-file/id_lib/1/fileid/123/filename/test.txt', true);
}
/** @test */
public function shouldNotifyError() {
$this->assertFlashMessengerContentContains('Impossible de télécharger cette pièce jointe');
}
/** @test */
public function shouldRedirect() {
$this->assertRedirect();
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment