Skip to content

Commit

Permalink
AIP Download feature, refs #13351
Browse files Browse the repository at this point in the history
This commit adds Storage Service integration to AtoM for the purpose of
downloading AIPs and objects from within those AIPs. AIP and Object
downloading is only available to users in specific user groups -
by default this is the administrator group only.

A new Storage Service settings menu appears when the Storage Service
plugin is enabled, This settings menu is used to set the storage service
API connection details and to activate the feature.

When the feature is enabled and the user's group is specified in the
storage service plugin's security.yml file, two new links will appear
on the detail page from which the user can initiate download of the
specific object, or the entire AIP.

Modifications have been made to AtoM so that the UUID and paths are
stored in the DB during Archivematica's DIP Upload process. The UUID and
paths are used when requesting the files from the Storage Service API.

Co-authored-by: David Juhasz <[email protected]>
  • Loading branch information
sbreker and djjuhasz committed Aug 11, 2020
1 parent 1b57c30 commit d8f09de
Show file tree
Hide file tree
Showing 17 changed files with 591 additions and 5 deletions.
20 changes: 18 additions & 2 deletions apps/qubit/modules/digitalobject/templates/_metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,24 @@
<?php endif; ?>

<?php if ($sf_user->isAuthenticated() && $relatedToIo): ?>
<?php echo render_show(__('Object UUID'), render_value($resource->object->objectUUID), array('fieldLabel' => 'objectUUID')) ?>
<?php echo render_show(__('AIP UUID'), render_value($resource->object->aipUUID), array('fieldLabel' => 'aipUUID')) ?>
<?php if ($this->context->getConfiguration()->isPluginEnabled('arStorageServicePlugin')
&& arStorageServiceUtils::getAipDownloadEnabled()): ?>
<?php include_partial(
'arStorageService/aipDownload', ['resource' => $resource]
) ?>
<?php else: // arStorageService is disabled ?>
<?php echo render_show(
__('Object UUID'),
render_value($resource->object->objectUUID),
array('fieldLabel' => 'objectUUID')
) ?>
<?php echo render_show(
__('AIP UUID'),
render_value($resource->object->aipUUID),
array('fieldLabel' => 'aipUUID')
) ?>
<?php endif; // arStorageService is disabled ?>

<?php echo render_show(__('Format name'), render_value($resource->object->formatName), array('fieldLabel' => 'formatName')) ?>
<?php echo render_show(__('Format version'), render_value($resource->object->formatVersion), array('fieldLabel' => 'formatVersion')) ?>
<?php echo render_show(__('Format registry key'), render_value($resource->object->formatRegistryKey), array('fieldLabel' => 'formatRegistryKey')) ?>
Expand Down
5 changes: 4 additions & 1 deletion apps/qubit/modules/settings/actions/editAction.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,10 @@ public function execute($request)
$this->getUser()->setFlash('notice', $this->updateMessage);
}

$this->redirect(array('module' => 'settings', 'action' => $this->getContext()->getActionName()));
$this->redirect(array(
'module' => $this->getContext()->getModuleName(),
'action' => $this->getContext()->getActionName()
));
}
}

Expand Down
10 changes: 9 additions & 1 deletion apps/qubit/modules/settings/actions/menuComponent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ public function execute($request)
array(
'label' => $i18n->__('Clipboard'),
'action' => 'clipboard'
),
array(
'label' => $i18n->__('Storage service'),
'module' => 'arStorageServiceSettings',
'action' => 'settings',
'hide' => !$this->context->getConfiguration()->isPluginEnabled(
'arStorageServicePlugin'
)
)
);

Expand All @@ -121,7 +129,7 @@ public function execute($request)

// Sort alphabetically
usort($this->nodes, function($el1, $el2) {
return strnatcmp( $el1['label'], $el2['label']);
return strnatcmp($el1['label'], $el2['label']);
});
}
}
5 changes: 4 additions & 1 deletion apps/qubit/modules/settings/templates/_menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
<tr>
<?php endif; ?>
<td>
<?php echo link_to($node['label'], array('module' => 'settings', 'action' => $node['action'])) ?>
<?php echo link_to($node['label'], array(
'module' => $node['module'] ?? 'settings',
'action' => $node['action']
)) ?>
</td>
</tr>
<?php endforeach; ?>
Expand Down
1 change: 1 addition & 0 deletions css/classic.css
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ form .field > div
}

form .field > h3
form .field > label
{
/* Reset h3 */

Expand Down
1 change: 1 addition & 0 deletions lib/model/QubitInformationObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public function __get($name)
case 'formatRegistryName':
case 'objectUUID':
case 'aipUUID':
case 'relativePathWithinAip':

if (!isset($this->values[$name]))
{
Expand Down
18 changes: 18 additions & 0 deletions plugins/arDominionPlugin/css/less/scaffolding.less
Original file line number Diff line number Diff line change
Expand Up @@ -1620,6 +1620,24 @@ body.login #content {
}
}

// Storage Service AIP and object download links

.aip-download {
> a {
padding-left: 5px;

i {
font-size: 15px;
padding-right: 3px;
color: @grayLight;
}

&:hover > i {
color: @orange;
}
}
}

// Plugin manager (sfPluginAdminPlugin/plugins)

.plugin-name {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

/*
* This file is part of the Access to Memory (AtoM) software.
*
* Access to Memory (AtoM) is free software: you can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the License,
* or (at your option) any later version.
*
* Access to Memory (AtoM) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>.
*/

class arStorageServicePluginConfiguration extends sfPluginConfiguration
{
public static
$summary = 'Archivematica Storage Service integration plugin',
$version = '1.0.0';

public function initialize()
{
$enabledModules = sfConfig::get('sf_enabled_modules');
array_push($enabledModules, 'arStorageServiceSettings', 'arStorageService');
sfConfig::set('sf_enabled_modules', $enabledModules);
}
}
5 changes: 5 additions & 0 deletions plugins/arStorageServicePlugin/config/view.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
all:
javascripts:
/plugins/sfDrupalPlugin/vendor/drupal/misc/jquery.once.js:
/plugins/sfDrupalPlugin/vendor/drupal/misc/collapse:
/plugins/sfDrupalPlugin/vendor/drupal/misc/form:
104 changes: 104 additions & 0 deletions plugins/arStorageServicePlugin/lib/arStorageServiceUtils.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php

/*
* This file is part of the Access to Memory (AtoM) software.
*
* Access to Memory (AtoM) is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Access to Memory (AtoM) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>.
*/

class arStorageServiceUtils
{
const STORAGE_SERVICE_PACKAGE_PATH = 'file';

/**
* Use phpcurl to request a URL and pass the header and stream back to
* the browser.
*
*/
public static function getFileFromStorageService($url)
{
$ch = curl_init();

curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');

curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 500);
curl_setopt($ch, CURLOPT_WRITEFUNCTION, function($ch, $data) {
echo $data;

return strlen($data);
});

curl_setopt($ch, CURLOPT_HEADERFUNCTION, function($ch, $header) {
header($header);

return strlen($header);
});

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // Storage service redirects
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
sprintf(
'Authorization: ApiKey %s:%s',
(string) QubitSetting::getByName('storage_service_username'),
(string) QubitSetting::getByName('storage_service_api_key')
),
'User-Agent: DRMC',
));

curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_RESPONSE_CODE);

curl_close($ch);

return $status;
}

/**
* Return true if plugin is enabled and feature is activated.
*
*/
public static function getAipDownloadEnabled()
{
$configuration = ProjectConfiguration::getActive();

if ($configuration->isPluginEnabled('arStorageServicePlugin')
&& null !== $setting = QubitSetting::getByName('download_aip_enabled'))
{
return boolval($setting->getValue(array('sourceCulture' => true)));
}
}

public static function getStorageServiceException($status)
{
switch ($status)
{
case '400':
return new QubitApiBadRequestException("Storage service bad request");

case '404':
return new QubitApi404Exception("Storage service resource not found");

case '401':
return new QubitApiNotAuthorizedException("Storage service resource not authorized");

case '403':
return new QubitApiForbiddenException("Storage service resource forbidden");

default:
return new Exception(sprintf('Storage service error %s', (string)$status));
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

/*
* This file is part of the Access to Memory (AtoM) software.
*
* Access to Memory (AtoM) is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Access to Memory (AtoM) is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Access to Memory (AtoM). If not, see <http://www.gnu.org/licenses/>.
*/

class arStorageServiceDownloadAction extends sfAction
{
public function execute($request)
{
$view = sfView::NONE;

$this->resource = $this->getRoute()->resource;

// Check that object exists and that it is not the root
if (!isset($this->resource))
{
$this->forward404();
}

try
{
$status = $this->downloadAip($request);
}
catch (QubitApi404Exception $e)
{
$this->response->setStatusCode(404, $e->getMessage());
throw $e;
}
catch (QubitApiNotAuthorizedException $e)
{
$this->response->setStatusCode(401, $e->getMessage());
throw $e;
}
catch (QubitApiForbiddenException $e)
{
$this->response->setStatusCode(403, $e->getMessage());
throw $e;
}
catch (QubitApiBadRequestException $e)
{
$this->response->setStatusCode(400, $e->getMessage());
throw $e;
}
catch (Exception $e)
{
$this->response->setStatusCode(500, $e->getMessage());
throw $e;
}

return $view;
}

/**
* Build the request URL for the Storage Service API's 'download' endpoint
* and make the request. Ensure if there is an error that the Storage Service
* return status is passed back to the browser.
*
*/
protected function downloadAip($request)
{
if (!arStorageServiceUtils::getAipDownloadEnabled())
{
throw new QubitApiForbiddenException('AIP Download disabled');
}

if (null === $aipUUID = $this->resource->object->aipUUID)
{
throw new QubitApiBadRequestException('Missing parameter: aipuuid');
}

if (null === $baseUrl = QubitSetting::getByName('storage_service_api_url'))
{
throw new QubitApiBadRequestException('Missing setting: storage_service_api_url');
}

$url = sprintf('%s/%s/%s/download/',
trim($baseUrl, "/"),
arStorageServiceUtils::STORAGE_SERVICE_PACKAGE_PATH,
$aipUUID
);

// Check return status from Storage Service
if (200 !== $status = arStorageServiceUtils::getFileFromStorageService($url))
{
$ex = arStorageServiceUtils::getStorageServiceException($status);
throw $ex;
}

exit;
}
}
Loading

0 comments on commit d8f09de

Please sign in to comment.