Commit 431f85f5 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Html export: add files not owned by exporting user to special directory (bug #688304)



Sometimes an html export is allowed to include files that are not part of the
exporting user's portfolio, e.g. when the user has permission to publish a
group file in a personal view.  Make sure these files are included in the
export tarball, but keep them separate from the user's personal files.

Change-Id: Ic9bb7a5d059c9c39d0fb71e58e843dc048cbdfb8
Signed-off-by: default avatarRichard Mansfield <richard.mansfield@catalyst.net.nz>
parent ecc78b86
......@@ -36,13 +36,21 @@ class HtmlExportFile extends HtmlExportArtefactPlugin {
private $artefactdata = array();
private $owner;
// Keep track of files not owned by the exporting user. These should be included in the
// export tarball, but should not appear in the browseable folder structure.
private $otherfiles = array();
public function dump_export_data() {
$this->owner = $this->exporter->get('user')->get('id');
foreach ($this->exporter->get('artefacts') as $artefact) {
if (in_array($artefact->get('artefacttype'), PluginArtefactFile::get_artefact_types())) {
$this->artefactdata[$artefact->get('id')] = $artefact;
$id = $artefact->get('id');
$this->artefactdata[$id] = $artefact;
if ($artefact->get('owner') != $this->owner) {
$this->otherfiles[$id] = $id;
}
}
}
......@@ -51,7 +59,7 @@ class HtmlExportFile extends HtmlExportArtefactPlugin {
if ($this->exporter->get('artefactexportmode') != PluginExport::EXPORT_ALL_ARTEFACTS && $this->artefactdata) {
$folderids = array();
foreach (array_keys($this->artefactdata) as $artefactid) {
if ($this->artefactdata[$artefactid]->get('owner') == $this->owner) {
if (!isset($this->otherfiles[$artefactid])) {
$folderids = array_merge($folderids, array_keys(artefact_get_parents_for_cache($artefactid)));
}
}
......@@ -74,6 +82,16 @@ class HtmlExportFile extends HtmlExportArtefactPlugin {
$this->create_index_for_directory($this->fileroot, 0, null);
$this->populate_filedir($this->fileroot, 0, null);
// Copy other users' files into the extrafileroot directory
foreach ($this->otherfiles as $id) {
if (!$this->artefactdata[$id] instanceof ArtefactTypeFile) {
continue;
}
$dest = $this->extrafileroot . $id . '-' . PluginExportHtml::sanitise_path($this->artefactdata[$id]->get('title'));
if (!copy($this->artefactdata[$id]->get_path(), $dest)) {
throw new SystemException("Unable to copy artefact $id's file");
}
}
}
public function get_summary() {
......
......@@ -495,6 +495,10 @@ abstract class HtmlExportArtefactPlugin {
if (!check_dir_exists($this->fileroot)) {
throw new SystemException("Could not create the temporary export directory $this->fileroot");
}
$this->extrafileroot = $this->exporter->get('exportdir') . '/' . $this->exporter->get('rootdir') . '/files/extra/';
if (!check_dir_exists($this->extrafileroot)) {
throw new SystemException("Could not create the temporary export directory $this->extrafileroot");
}
}
abstract public function dump_export_data();
......
Markdown is supported
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