Skip to content

Commit

Permalink
Merge pull request #341 from OPUS4/OPUSVIER-4293
Browse files Browse the repository at this point in the history
OPUSVIER-4293 Add 'accessAllowed' function for export XSLT.
  • Loading branch information
j3nsch authored Aug 14, 2020
2 parents 47fdc40 + dd0b2f5 commit 32fb54c
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
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'
]);
}
}
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 32fb54c

Please sign in to comment.