Skip to content

Commit

Permalink
Merge pull request #346 from OPUS4/4.7.0.1
Browse files Browse the repository at this point in the history
4.7.0.1 Release Patches
  • Loading branch information
j3nsch authored Aug 27, 2020
2 parents 47fdc40 + d1d9ca9 commit 5a06305
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 6 deletions.
12 changes: 12 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# OPUS 4 Change Log

---

## Patches for 4.7 - 2020-08-27

### Aufgaben

* [OPUSVIER-4293] - Login-Status in XSLT abfragen

### Bugs

* [OPUSVIER-4304] - Inhalte der angepassten Leitlinien / Policies werden beim Update auf OPUS 4.7 nicht importiert

---

## Release 4.7 - 2020-07-31
Expand Down
4 changes: 2 additions & 2 deletions application/configs/help/metadata.en.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Metadata can be defined as

<ul>
<li>data describing one or more ressources or as</li>
<li>data describing one or more resources or as</li>
<li>data associated with an object and describing it</li>
</ul>

Expand All @@ -11,7 +11,7 @@ Bibliographic data sets and catalog entries in library catalogs can be seen as a

<p>
This repository is using metadata in the <a href="http://dublincore.org/" target="_blank">Dublin
Core Metedata Element Set</a> (short Dublin Core (DC)) which has fifteen basic elements. Dublin
Core Metadata Element Set</a> (short Dublin Core (DC)) which has fifteen basic elements. Dublin
Core is the result of international efforts to reach a collective consensus in describing electronic
objects (in the broadest sense). The Library of Congress (LoC), the Online Cataloging Library Center (OCLC)
and several national libraries are dealing with Dublin Core in many projects and are close to introduce the
Expand Down
2 changes: 1 addition & 1 deletion application/configs/help/publicationprocess.en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Please click on the publication link on the start page.<br/>
First you are requested to choose a document type. Right beneath that you can upload your document files. Having done
so you may click on "send". What follows now is the actual form.
You have to fill in data about your publication here (so called metadata), which is used to describe your work in
catalouges and other bibliographic
cataloges and other bibliographic
directories. Describe the document you want to upload using the categories and fields on the publication form.
Depending on the document type, some of
these fields are <span class="required">mandatory</span> and therefore have to be filled in. Please describe your
Expand Down
17 changes: 17 additions & 0 deletions library/Application/Update/ImportHelpFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,23 @@ public function importFiles($key, $files, $module)
$content = file_get_contents($path);
$values[$lang] = $content;
$this->removeFile($path);
} else {
// OPUSVIER-4304 Try to see if there is a file after all.
$this->log("Trying to resolve default file for key '$key' in language '$lang'.");
$prefix = 'help_content_';
if (substr($key, 0, strlen($prefix)) == $prefix) {
$baseName = substr($key, strlen($prefix));
$fileName = "$baseName.{$lang}.txt";
$path = $helpPath . $fileName;
if (is_readable($path)) {
$this->log("Default file '$fileName' found.");
$content = trim(file_get_contents($path));
$values[$lang] = $content;
$this->removeFile($path);
} else {
$this->log("Default file '$fileName' not found.");
}
}
}
}

Expand Down
48 changes: 48 additions & 0 deletions library/Application/View/Helper/IsAuthenticated.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
* the Federal Department of Higher Education and Research and the Ministry
* of Science, Research and the Arts of the State of Baden-Wuerttemberg.
*
* OPUS 4 is a complete rewrite of the original OPUS software and was developed
* by the Stuttgart University Library, the Library Service Center
* Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg,
* the Saarland University and State Library, the Saxon State Library -
* Dresden State and University Library, the Bielefeld University Library and
* the University Library of Hamburg University of Technology with funding from
* the German Research Foundation and the European Regional Development Fund.
*
* LICENCE
* OPUS is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or any later version.
* OPUS 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 OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @category Application
* @package Application_View_Helper
* @author Jens Schwidder <schwidder@zib.de>
* @copyright Copyright (c) 2020, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

/**
* Returns true if current user is authenticated (logged in).
*/
class Application_View_Helper_IsAuthenticated extends Zend_View_Helper_Abstract
{

/**
* Returns true if the current user is logged in.
*/
public function isAuthenticated()
{
$identity = Zend_Auth::getInstance()->getIdentity();
return empty($identity) === false;
}
}
12 changes: 12 additions & 0 deletions modules/export/models/XmlExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function init()
// Initialize member variables.
$this->_xml = new DomDocument();
$this->_proc = new XSLTProcessor();
$this->registerPhpFunctions();
}

/**
Expand Down Expand Up @@ -501,4 +502,15 @@ public function buildStylesheetPath($stylesheet, $path)
$scriptPath = substr($path, 0, ++$pos);
return $scriptPath . 'stylesheets' . DIRECTORY_SEPARATOR . 'raw.xslt';
}

/**
* TODO create test verifying expected functions are available
*/
protected function registerPhpFunctions()
{
Application_Xslt::registerViewHelper($this->_proc, [
'accessAllowed',
'isAuthenticated'
]);
}
}
6 changes: 3 additions & 3 deletions modules/help/language/help.tmx
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ gestattet!</b> Dies können Sie zum Beispiel mit Hilfe der
First you are requested to choose a document type. Right beneath that you can upload your document files. Having done
so you may click on "send". What follows now is the actual form.
You have to fill in data about your publication here (so called metadata), which is used to describe your work in
catalouges and other bibliographic
cataloges and other bibliographic
directories. Describe the document you want to upload using the categories and fields on the publication form.
Depending on the document type, some of
these fields are <span class="required">mandatory</span> and therefore have to be filled in. Please describe your
Expand Down Expand Up @@ -197,7 +197,7 @@ Cookies müssen im Webbrowser eingeschaltet sein, um Dokumente über das Veröff
<seg><![CDATA[Metadata can be defined as
<ul>
<li>data describing one or more ressources or as</li>
<li>data describing one or more resources or as</li>
<li>data associated with an object and describing it</li>
</ul>
Expand All @@ -207,7 +207,7 @@ Bibliographic data sets and catalog entries in library catalogs can be seen as a
<p>
This repository is using metadata in the <a href="http://dublincore.org/" target="_blank">Dublin
Core Metedata Element Set</a> (short Dublin Core (DC)) which has fifteen basic elements. Dublin
Core Metadata Element Set</a> (short Dublin Core (DC)) which has fifteen basic elements. Dublin
Core is the result of international efforts to reach a collective consensus in describing electronic
objects (in the broadest sense). The Library of Congress (LoC), the Online Cataloging Library Center (OCLC)
and several national libraries are dealing with Dublin Core in many projects and are close to introduce the
Expand Down
92 changes: 92 additions & 0 deletions tests/library/Application/Update/ImportHelpFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,96 @@ public function testGetHelpFilesForDefaultSetup()
}
}
}

/**
* OPUSVIER-4304
*
* Sometimes help files have been changed directly without copying the keys to `language_custom`. In that case,
* it is not possible to detect the customization during the update. However we should assume that this might
* have happened and import the files anyway.
*/
public function testImportChangedHelpFilesWithoutCustomizedKeys()
{
$database = new Opus_Translate_Dao();
$database->removeAll();

$helpPath = $this->createTestFolder();

$generalDe = $this->createTestFile('general.de.txt', 'Allgemein', $helpPath);
$generalEn = $this->createTestFile('general.en.txt', 'General', $helpPath);
$policiesDe = $this->createTestFile('policies.de.txt', 'Leitlinien', $helpPath);
$policiesEn = $this->createTestFile('policies.en.txt', 'Policies', $helpPath);

$helpConfig = 'help_index_general[] = \'general\'' . PHP_EOL;
$helpConfig .= 'help_index_misc[] = \'policies\'' . PHP_EOL;
$helpIni = $this->createTestFile('help.ini', $helpConfig, $helpPath);

$database->setTranslation('help_content_general', [
'en' => 'general.en.txt',
'de' => 'general.de.txt'
], 'help');
// no custom key for `help_content_policies`

$update = new Application_Update_ImportHelpFiles();
$update->setHelpPath($helpPath);
$update->setQuietMode(true);
$update->run();

$this->assertFileNotExists($generalDe);
$this->assertFileExists($generalDe . '.imported');
$this->assertFileNotExists($generalEn);
$this->assertFileExists($generalEn . '.imported');
$this->assertFileNotExists($policiesDe);
$this->assertFileExists($policiesDe . '.imported');
$this->assertFileNotExists($policiesEn);
$this->assertFileExists($policiesEn . '.imported');

$translations = $database->getTranslations();
$this->assertArrayHasKey('help_content_general', $translations);
$this->assertArrayHasKey('help_content_policies', $translations);

$translations = $database->getTranslation('help_content_general');
$this->assertEquals([
'en' => 'General',
'de' => 'Allgemein'
], $translations);

$translations = $database->getTranslation('help_content_policies');
$this->assertEquals([
'en' => 'Policies',
'de' => 'Leitlinien'
], $translations);
}

/**
* The help content in txt files and defined in TMX files needs to match perfectly, so the default
* content will not be imported into the database.
*/
public function testTmxContentMatchesHelpFiles()
{
$database = new Opus_Translate_Dao();
$database->removeAll();

$update = new Application_Update_ImportHelpFiles();
$update->setRemoveFilesEnabled(false);
$update->setQuietMode(true);

$files = $update->getHelpFiles();
$helpPath = $update->getHelpPath();
$prefix = 'help_content_';

foreach ($files as $key => $translations) {
foreach ($translations as $lang => $value) {
if (substr($key, 0, strlen($prefix)) == $prefix) {
$baseName = substr($key, strlen($prefix));
$fileName = "$baseName.{$lang}.txt";
$path = $helpPath . $fileName;
if (is_readable($path)) {
$fileContent = trim(file_get_contents($path));
}
}
$this->assertEquals($fileContent, $value, "File and TMX for '$key' in '$lang' do not match.");
}
}
}
}
63 changes: 63 additions & 0 deletions tests/library/Application/View/Helper/IsAuthenticatedTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php
/**
* This file is part of OPUS. The software OPUS has been originally developed
* at the University of Stuttgart with funding from the German Research Net,
* the Federal Department of Higher Education and Research and the Ministry
* of Science, Research and the Arts of the State of Baden-Wuerttemberg.
*
* OPUS 4 is a complete rewrite of the original OPUS software and was developed
* by the Stuttgart University Library, the Library Service Center
* Baden-Wuerttemberg, the Cooperative Library Network Berlin-Brandenburg,
* the Saarland University and State Library, the Saxon State Library -
* Dresden State and University Library, the Bielefeld University Library and
* the University Library of Hamburg University of Technology with funding from
* the German Research Foundation and the European Regional Development Fund.
*
* LICENCE
* OPUS is free software; you can redistribute it and/or modify it under the
* terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the Licence, or any later version.
* OPUS 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 OPUS; if not, write to the Free Software Foundation, Inc., 51
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @category Application Unit Tests
* @author Jens Schwidder <schwidder@zib.de>
* @copyright Copyright (c) 2020, OPUS 4 development team
* @license http://www.gnu.org/licenses/gpl.html General Public License
*/

/**
*
*/
class Application_View_Helper_IsAuthenticatedTest extends ControllerTestCase
{

protected $additionalResources = ['database', 'authz', 'view'];

private $helper;

public function setUp()
{
parent::setUp();
$this->helper = new Application_View_Helper_IsAuthenticated();
}

public function testIsAuthenticated()
{
$helper = $this->helper;

$this->assertFalse($helper->isAuthenticated());

$this->loginUser('security1', 'security1pwd');

$this->assertTrue($helper->isAuthenticated());

$this->logoutUser();

$this->assertFalse($helper->isAuthenticated());
}
}

0 comments on commit 5a06305

Please sign in to comment.