Commit 1fe5a05e authored by Ghislain Loas's avatar Ghislain Loas

Merge branch 'hotline#71669_probleme_de_sso_pour_la_plateforme_le_kiosk' into 'hotline'

Hotline#71669 probleme de sso pour la plateforme le kiosk

See merge request afi/opacce!2524
parents 504c1d05 a3819600
- ticket #71669 : Administration : ajout d'un tableau de bord pour les ressources numériques.
\ No newline at end of file
......@@ -42,7 +42,7 @@ class Admin_BatchController extends ZendAfi_Controller_Action {
->save();
$this->_helper->notify('Tâche activée');
$this->_redirectToIndex();
$this->_redirectToReferer();
}
......@@ -55,7 +55,7 @@ class Admin_BatchController extends ZendAfi_Controller_Action {
$batch->delete();
$this->_helper->notify('Tâche désactivée');
$this->_redirectToIndex();
$this->_redirectToReferer();
}
......
<p><?php
echo $this->_("Bokeh s'interface avec un certain nombre de ressources numériques. Les ressources numérisées sont cataloguées dans le portail et indexées dans l’OPAC comme les notices du SIGB. Ce qui constitue la force et le caractère unique de Bokeh, est sa capacité à proposer une recherche fusionnée par un métamoteur qui interroge simultanément tous les fonds et tous les contenus.");
?></p>
echo $this->_("Bokeh s'interface avec un certain nombre de ressources numériques. Les ressources numérisées sont cataloguées dans le portail et indexées dans l’OPAC comme les notices du SIGB. Ce qui constitue la force et le caractère unique de Bokeh, est sa capacité à proposer une recherche fusionnée par un métamoteur qui interroge simultanément tous les fonds et tous les contenus.");
?></p>
<p><?php
echo $this->_("Si vous souhaitez ajouter une ressource à votre portail, il vous faut contractualiser avec le fournisseur de la ressource et demander un devis pour le connecteur à <a href='mailto:cial-bib@afi-sa.fr'>votre commercial</a>.");
?></p>
echo $this->_("Si vous souhaitez ajouter une ressource à votre portail, il vous faut contractualiser avec le fournisseur de la ressource et demander un devis pour le connecteur à <a href='mailto:cial-bib@afi-sa.fr'>votre commercial</a>.");
?></p>
<?php
$datas = (new Class_WebService_BibNumerique_Connectors())->getDescription();
$datas = json_decode(json_encode($datas));
......@@ -13,15 +13,15 @@ $datas = json_decode(json_encode($datas));
<?php
foreach($datas as $code => $connector) {
$thumb = $connector->image_url
? $this->tag('img', null, ['src' => $connector->image_url,
'alt' => $connector->label,
'style' => 'width:200px;'])
: $connector->label;
? $this->tag('img', null, ['src' => $connector->image_url,
'alt' => $connector->label,
'style' => 'width:200px;'])
: $connector->label;
$thumb = $connector->url
? $this->tag('a', $thumb, ['href' => $connector->url,
'target' => '_blank'])
: $thumb;
? $this->tag('a', $thumb, ['href' => $connector->url,
'target' => '_blank'])
: $thumb;
$key_exists = function($key) use ($connector) {
return in_array($key, $connector->features);
......@@ -44,22 +44,37 @@ $datas = json_decode(json_encode($datas));
['href' => $connector->sales_contact->url,
'target' => '_blank']);
?>
<tr data-code="<?php echo strtolower($connector->code) ?>" >
<td><?php echo $thumb; ?></td>
<td><?php echo $connector->desc; ?>
<?php if ($features) { ?>
<br/><br/>
<?php echo $this->tag('strong', $this->_('Fonctionnalités : ')) . implode(', ', $features);?>
<?php } ?>
<?php if ($contact) { ?>
<br/><br/>
<?php echo $this->tag('strong', $this->_('Contact : ')) . implode(', ', $contact);}?>
<br/><br/>
<?php if ($connector->enabled) {
echo $this->tag('div', $this->_('Activé'), ['class' => 'enabled']);?>
<?php } ?>
</td>
</tr>
<?php } ?>
<tr data-code="<?php echo strtolower($connector->code) ?>" >
<td><?php echo $thumb; ?></td>
<td><?php echo $connector->desc; ?>
<?php if ($features) { ?>
<br/><br/>
<?php echo $this->tag('strong', $this->_('Fonctionnalités : ')) . implode(', ', $features);?>
<?php } ?>
<?php if ($contact) { ?>
<br/><br/>
<?php echo $this->tag('strong', $this->_('Contact : ')) . implode(', ', $contact);}?>
<br/><br/>
<?php
$label = $this->_('Désactivé');
$class = 'digital_connectors_status';
if ($connector->enabled) {
$label = $this->_('Activé');
$class .= ' enabled';
}
echo $this->button((new Class_Entity)
->setText($label)
->setAttribs(['disabled' => 'disabled',
'onclick' => 'return;',
'class' => $class]));
if(isset($connector->dashboard_url))
echo $this->button((new Class_Entity)
->setUrl($connector->dashboard_url)
->setText($this->_('Tableau de bord')));
?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<?php
echo $this->DigitalResource_Dashboard($this->config);
......@@ -798,10 +798,8 @@ class Auth_Strategy_Cas_Abstract extends Auth_Strategy_Abstract{
public function redirectMusicme() {
if (strpos($this->controller->getCasServerUrl(),'musicme') !== false) {
$module_menu = Class_DigitalResource::getInstance()->getModuleMenuFor('Musicme');
return $module_menu->getDynamiqueUrl();
}
if (strpos($this->controller->getCasServerUrl(),'musicme') !== false)
return Musicme_Config::getInstance()->getSsoUrl(Class_Users::getIdentity());
return false;
}
......
......@@ -76,20 +76,21 @@ class ModulesController extends ZendAfi_Controller_Action {
public function ssoAction() {
if (!$record = Class_Notice::find($this->_getParam('id', 0))) {
$this->_helper->notify($this->_('Document non trouvé'));
$this->_helper->notify($this->_('L\'identifiant du document demandé n\'existe pas'));
$this->_redirectToReferer();
return;
}
$sso_record = new Class_Notice_Sso($record);
if(!$module_menu = $sso_record->getModuleMenu()) {
$this->_helper->notify($this->_('Oups, l\'adresse de consultation de ce document est indeterminée'));
$this->_redirectToReferer();
return;
if(!$digital_resource_config = $sso_record->getConfig()) {
$this->_helper->notify($this->_('Ce document ne possède pas de configuration permettant d\'utiliser cette URL.'));
return $this->_redirectToReferer();
}
$module_menu->setRecord($sso_record);
$this->simple($module_menu);
$this->_forward('sso',
'index',
$digital_resource_config->getModuleName(),
$this->_request->getParams());
}
......
......@@ -303,6 +303,11 @@ class Class_DigitalResource extends Class_Entity {
}
public function getAdminVarInstance($plugin, $name) {
return Class_AdminVar::find($this->withNamespace($plugin, $name));
}
public function getDocType($plugin) {
return $plugin;
}
......
......@@ -20,7 +20,7 @@
*/
class Class_DigitalResource_Batch extends Class_Batch_RessourceNumerique{
class Class_DigitalResource_Batch extends Class_Batch_RessourceNumerique {
protected $_config;
public function __construct($config) {
......
......@@ -53,21 +53,47 @@ class Class_DigitalResource_Config extends Class_Entity {
public function registerFrontController($front_controller) {
$front_controller->addControllerDirectory((new Class_DigitalResource_Name())->getPath($this) . '/controllers',
$this->getDigitalResource()->getModuleNameFor(static::getName()));
$this->getModuleName());
return $this;
}
public function getModuleName() {
return $this->getDigitalResource()->getModuleNameFor(static::getName());
}
public function isEnabled() {
return $this->getDigitalResource()->isAdminVarOn(static::getName());
}
public function getDashboardUrl() {
return Class_Url::absolute(['module' => $this->getModuleName()],
null,
true);
}
public function getBatchInstance() {
return $this->getDigitalResource()->getBatches()[$this->getBatch()];
}
public function getAdminVar($id) {
return $this->getDigitalResource()->getAdminVar($id);
}
public function getAdminVarsInstances() {
$vars = [];
foreach($this->getAdminVars() as $key => $meta)
$vars [] = $this->getDigitalResource()->getAdminVarInstance($key);
return $vars;
}
public function hasRightAccess($user) {
return $this->getDigitalResource()->hasRightAccessPlugin($user);
}
......@@ -103,7 +129,8 @@ class Class_DigitalResource_Config extends Class_Entity {
'features' => $this->getFeatures(),
'sales_contact' => ['mail' => $this->getMail(),
'url' => $this->getMailUrl()],
'enabled' => $this->isEnabled()];
'enabled' => $this->isEnabled(),
'dashboard_url' => $this->getDashboardUrl()];
}
......@@ -162,4 +189,42 @@ class Class_DigitalResource_Config extends Class_Entity {
public function withNameSpace($value) {
return $this->getDigitalResource()->withNameSpace($value);
}
public function urlFor($user, $album = null, $record = null) {
if(!$user)
return;
if (!$this->hasRightAccess($user))
return;
if(!$this->isEnabled())
return;
if($record)
return $this->getRecordSsoUrl($user, $record);
if($album)
return $this->getAlbumSsoUrl($user, $album);
return $this->getSsoUrl($user);
}
public function getSsoUrl($user) {
return '';
}
public function getAlbumSsoUrl($user, $album) {
if(!$album)
return '';
return $album->getExternalUri();
}
public function getRecordSsoUrl($user, $record) {
return $this->getAlbumSsoUrl($suer, $record->getAlbum());
}
}
\ No newline at end of file
......@@ -25,38 +25,39 @@ class Class_DigitalResource_Controller extends ZendAfi_Controller_Action {
public function preDispatch() {
parent::preDispatch();
$this->_config = Class_DigitalResource_Config::getInstanceFromController(get_called_class());
if ($this->_config->getSsoAction() == $this->_request->getActionName())
return $this->_forward('sso');
return $this->_forward('sso',
'index',
$this->_config->getModuleName());
}
public function indexAction() {
if(!Class_Users::isCurrentUserCanAccesBackend()) {
return $this->_redirect($this->view->absoluteUrl(['module' => 'opac',
'controller' => 'auth',
'action' => 'ajax-login',
'location' => $this->_request->getModuleName()]));
}
$this->view->titre = $this->_config->getName();
$this->view->records_count = Class_Album::countBy(['type_doc_id' => $this->_config->getDocType()]);
}
if(!$user = Class_Users::getIdentity())
return $this->_javascriptAfterLoginRedirectTo($this->view->absoluteUrl(),
$this->_('Vous devez vous connecter pour accéder à cette page'));
if(!$user->isAdmin())
$this->_javascriptRedirectToIndex($this->_('Vous devez être connecté avec un compte adminitrateur pour accéder à cette page'));
public function getExternalUri($album, $module_menu) {
return $album->getExternalUri();
$this->view->titre = $this->_config->getName();
$this->view->config = $this->_config;
$this->getHelper('ViewRenderer')->renderScript('digital_resources/index.phtml');
}
public function ssoAction() {
$module = $this->_config->getModuleMenu();
$module = new $module($this->_config);
$this->willRedirectToMe($module);
if(!$user = Class_Users::getIdentity())
return $this->_javascriptAfterLoginRedirectTo($this->view->absoluteUrl(),
$this->_('Vous devez vous connecter pour accéder à cette page'));
if(!$album = Class_Album::find($this->_getParam('album_id', 0)))
return $this->checkNotifyMessage($module, $module->getDynamiqueUrl());
$url = $this->_config->urlFor($user,
Class_Album::find($this->_getParam('album_id', 0)),
Class_Notice::find($this->_getParam('id', 0)));
return $this->checkNotifyMessage($module, $this->getExternalUri($album, $module));
return $url
? $this->_javascriptRedirectTo($url)
: $this->_javascriptRedirectToIndex($this->_config->getNotAllowedMessage());
}
}
\ No newline at end of file
......@@ -29,6 +29,7 @@ class Class_DigitalResource_ModuleMenu extends Class_Systeme_ModulesMenu_SSOAbst
$this->_config = $config;
$this->_type_module = $this->_config->getName();
$this->_libelle = $this->_config->getMenuLabel();
$this->setMessage($this->_config->getNotAllowedMessage());
}
......@@ -42,20 +43,4 @@ class Class_DigitalResource_ModuleMenu extends Class_Systeme_ModulesMenu_SSOAbst
'controller' => 'modules',
'action' => $this->_config->getSsoAction()]);
}
public function urlForUser($user) {
if ($user
&& $this->_config->hasRightAccess($user)
&& $this->_config->isEnabled())
return $this->getSsoUrl($user);
$this->setMessage($this->_config->getNotAllowedMessage());
return '';
}
protected function getSsoUrl($user) {
return $this->_config->getSsoUrl($user);
}
}
......@@ -49,11 +49,11 @@ class Class_Notice_Sso extends Class_Entity {
}
public function getModuleMenu() {
public function getConfig() {
if (!$this->isValid())
return null;
return Class_DigitalResource::getInstance()
->getModuleMenuFor($this->getFirstCatalogAgency());
->configFor($this->getFirstCatalogAgency());
}
}
......@@ -46,8 +46,11 @@ class Class_Systeme_ModulesMenu_SSOAbstract extends Class_Systeme_ModulesMenu_Nu
}
public function getDynamiqueUrl() {
return ($user = Class_Users::getIdentity())
public function getDynamiqueUrl($user = null) {
if(!$user)
$user = Class_Users::getIdentity();
return $user
? $this->urlForUser($user)
: $this->loginUrl();
}
......
......@@ -111,7 +111,10 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
}
protected function _javascriptRedirectToReferrer() {
protected function _javascriptRedirectToReferrer($message = null) {
if($message)
$this->_helper->notify($message);
$this->getHelper('ViewRenderer')->renderScript('ajax_return.phtml');
}
......@@ -283,6 +286,31 @@ class ZendAfi_Controller_Action extends Zend_Controller_Action {
return $this->_redirect($this->_request->getServer('HTTP_REFERER'));
}
$this->_javascriptRedirectTo($url);
}
protected function _javascriptAfterLoginRedirectTo($url, $message = null) {
$login_url = Class_Url::absolute(['module' => 'opac',
'controller' => 'auth',
'action' => 'login'],
null,
true);
$this->_javascriptRedirectTo(sprintf('%s?redirect=%s', $login_url, rawurlencode($url)),
$message);
}
protected function _javascriptRedirectToIndex($message = null) {
$this->_javascriptRedirectTo($this->view->absoluteUrl([], null, true),
$message);
}
protected function _javascriptRedirectTo($url, $message = null) {
if($message)
$this->_helper->notify($message);
$viewRenderer = $this->getHelper('ViewRenderer');
$viewRenderer->setNoRender();
$this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8');
......
<?php
/**
* Copyright (c) 2012-2017, Agence Française Informatique (AFI). All rights reserved.
*
* BOKEH 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.
*
* There are special exceptions to the terms and conditions of the AGPL as it
* is applied to this software (see README file).
*
* BOKEH 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE
* along with BOKEH; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class ZendAfi_View_Helper_DigitalResource_Dashboard extends ZendAfi_View_Helper_BaseHelper {
protected
$_config,
$_permitted_groups;
public function DigitalResource_Dashboard($config) {
$this->_config = $config;
return implode([$this->_renderStatus(),
$this->_renderSettings(),
$this->_renderRights(),
$this->_renderSso(),
$this->_renderHarvest()]);
}
protected function _renderStatus() {
return implode([$this->_globalStatus(),
$this->_harvestStatus()]);
}
protected function _globalStatus() {
$label = $this->_('Désactivé');
$class = 'digital_connectors_status';
if ($this->_config->isEnabled()) {
$label = $this->_('Activé');
$class .= ' enabled';
}
return $this->view->button((new Class_Entity)
->setText($label)
->setAttribs(['disabled' => 'disabled',
'onclick' => 'return;',
'class' => $class]));
}
protected function _harvestStatus() {
if(!$batch = $this->_config->getBatch())
return '';
$label = $this->_('Moissonnage désactivé');
$class = 'digital_connectors_status';
if (Class_Batch::findFirstBy(['type' => $batch])) {
$label = $this->_('Moissonnage activé');
$class .= ' enabled';
}
return $this->view->button((new Class_Entity)
->setText($label)
->setAttribs(['disabled' => 'disabled',
'onclick' => 'return;',
'class' => $class]));
}
protected function _renderSettings() {
$description = (new Class_TableDescription('adminvars'))
->addColumn($this->_('description'), 'description')
->addColumn($this->_('Clef'), 'id')
->addColumn($this->_('valeur'),
function($model)
{
return ($renderer = $model->getRenderer())
? $renderer($model->getValeur(), $this->view)
: $this->view->adminVar($model);
})
->addRowAction(function($model)
{
return $this->view->renderModelActions($model,
[['url' => ['module' => 'admin',
'controller' => 'index',
'action' => 'adminvaredit',
'cle' => $model->getClef()],
'icon' => 'edit',
'anchorOptions' => ['data-popup' => true],
'label' => $this->_('Modifier "%s"', $model->getClef())]]);
});
return
$this->_tag('h3', $this->_('Paramétrage'))
. $this->view->renderTable($description, $this->_config->getAdminVarsInstances(), ['sorter' => true]);
}
protected function _renderRights() {
$html = [$this->_tag('h3',$this->_('Gestion des droits'))];
if (!$this->_config->isEnabled()) {
$html [] = $this->_tag('p', $this->_('Veuillez activer la ressource pour pouvoir gérer les droits d\'accès des groupes'), ['class' => 'error']);
return implode($html);
}
if(!$permission_label = $this->_config->getPermissionLabel()) {
$html [] = $this->_tag('p', $this->_('Cette ressource ne prend pas en charge la gestion des droits'), ['class' => 'error']) ;
return implode($html);
}
$html [] = $this->_tag('p', $this->_('Nom de la permission à donner : "%s"', $permission_label));
$groups = new Storm_Collection(Class_UserGroup::findAll());
$this->_permitted_groups = array_filter(
$groups
->select(function ($group)
{
$permission = $this->_config->getPermission();
return $group->hasPermissionOn($permission, $this->_config);