ObjectsController: allow admins to download JSON

fixes #1226
This commit is contained in:
Thomas Gelf 2017-10-11 10:55:20 +02:00
parent bab0ebc6c1
commit fb72a6e293
3 changed files with 28 additions and 0 deletions

View File

@ -13,6 +13,10 @@ before switching to a new version.
### Permissions and Restrictions
* FEATURE: Showing the executed SQL query now requires the `showsql` permission
### UI features
* Admins have now access to JSON download links in many places
* Users equipped with related permissions can toggle "Show SQL" in the GUI
1.4.1
-----
### Fixed issues

View File

@ -78,7 +78,18 @@ abstract class ObjectsController extends ActionController
$this->apiRequestHandler()->dispatch();
return;
}
$type = $this->getType();
if ($this->params->get('format') === 'json') {
$filename = sprintf(
"director-${type}_%s.json",
date('YmdHis')
);
$this->getResponse()->setHeader('Content-disposition', "attachment; filename=$filename", true);
$this->apiRequestHandler()->dispatch();
return;
}
$this
->addObjectsTabs()
->setAutorefreshInterval(10)

View File

@ -28,6 +28,9 @@ class AdditionalTableActions
public function appendTo(Html $parent)
{
$links = [];
if ($this->hasPermission('director/admin')) {
$links[] = $this->createDownloadJsonLink();
}
if ($this->hasPermission('director/showsql')) {
$links[] = $this->createShowSqlToggle();
}
@ -39,6 +42,16 @@ class AdditionalTableActions
return $this;
}
protected function createDownloadJsonLink()
{
return Link::create(
$this->translate('Download as JSON'),
$this->url->with('format', 'json'),
null,
['target' => '_blank']
);
}
protected function createShowSqlToggle()
{
if ($this->url->getParam('format') === 'sql') {