Plugin: adapt userremoteservice plugin to enable redirect and adding an option to hide links from main menu -refs BT#20171

pull/4401/head
NicoDucou 3 years ago
parent bb1fa6f5db
commit 873a81bc64
  1. 41
      plugin/userremoteservice/Entity/UserRemoteService.php
  2. 3
      plugin/userremoteservice/README.md
  3. 6
      plugin/userremoteservice/index.php
  4. 4
      plugin/userremoteservice/lang/english.php
  5. 2
      plugin/userremoteservice/lang/french.php
  6. 27
      plugin/userremoteservice/src/user_remote_service_plugin.class.php

@ -96,6 +96,15 @@ class UserRemoteService
return $this; return $this;
} }
/**
* @return string
*/
public function getAccessURL($pluginName)
{
$accessUrl = api_get_path(WEB_PLUGIN_PATH) . $pluginName . "/redirect.php?serviceId=" . $this->getId();
return $accessUrl;
}
/** /**
* Returns a user-specific URL, with two extra query string parameters : 'username' and 'hash'. * Returns a user-specific URL, with two extra query string parameters : 'username' and 'hash'.
@ -128,4 +137,36 @@ class UserRemoteService
) )
); );
} }
/**
* Returns a user-specific URL, with two extra query string parameters : 'uid' and 'hash'.
* 'hash' is generated using $salt and $userId.
*
* @param string $userId the user identifier, to build the hash and to include for the uid parameter
* @param string $salt the salt, to build the hash
*
* @throws Exception on hash generation failure
*
* @return string the custom user redirect URL
*/
public function getCustomUserRedirectURL($userId, $salt)
{
$hash = password_hash($salt.$userId, PASSWORD_BCRYPT);
if (false === $hash) {
throw new Exception('hash generation failed');
}
return sprintf(
'%s%s%s',
$this->url,
false === strpos($this->url, '?') ? '?' : '&',
http_build_query(
[
'uid' => $userId,
'hash' => $hash,
]
)
);
}
} }

@ -2,8 +2,9 @@ User Remote Service Plugin
========================== ==========================
Appends site-specific iframe-targetted user-identifying links to the menu bar. Appends site-specific iframe-targetted user-identifying links to the menu bar.
You can also hide the link from the menu and use the redirect link to use it as a link in a course.
After activation, configure a __salt__ then select region __menu_administrator__. After activation, configure a __salt__ then select region __menu_administrator__.
In the __Administration__ menu, in block __Plugins__, In the __Administration__ menu, in block __Plugins__,
you will find link __User Remote Services__ to manage the services to be shown in the main menu (title and URL). you will find link __User Remote Services__ to manage the services to be shown in the main menu (title and URL) and also get the redirect URL to use in a course.

@ -3,6 +3,8 @@
require_once __DIR__.'/config.php'; require_once __DIR__.'/config.php';
foreach (UserRemoteServicePlugin::create()->getNavigationMenu() as $key => $menu) { if ('true' !== UserRemoteServicePlugin::create()->get_hide_link_from_navigation_menu()) {
$template->params['menu'][$key] = $menu; foreach (UserRemoteServicePlugin::create()->getNavigationMenu() as $key => $menu) {
$template->params['menu'][$key] = $menu;
}
} }

@ -3,7 +3,7 @@
$strings['plugin_title'] = 'User Remote Services'; $strings['plugin_title'] = 'User Remote Services';
$strings['plugin_comment'] = 'Appends site-specific iframe-targetted user-identifying links to the menu bar.'; $strings['plugin_comment'] = 'Appends site-specific iframe-targetted user-identifying links to the menu bar.';
$strings['salt'] = 'Salt'; $strings['salt'] = 'Salt';
$strings['salt_help'] = $strings['salt_help'] =
'Secret character string, used to generate the <em>hash</em> URL parameter. The longest, the best. 'Secret character string, used to generate the <em>hash</em> URL parameter. The longest, the best.
@ -13,6 +13,7 @@ $strings['salt_help'] =
<br/><code>$salt</code> is this input value, <br/><code>$salt</code> is this input value,
<br/><code>$userId</code> is the number of the user referenced by the <em>username</em> URL parameter value and <br/><code>$userId</code> is the number of the user referenced by the <em>username</em> URL parameter value and
<br/><code>$hash</code> contains the <em>hash</em> URL parameter value.'; <br/><code>$hash</code> contains the <em>hash</em> URL parameter value.';
$strings['hide_link_from_navigation_menu'] = 'hide links from the menu';
// Please keep alphabetically sorted // Please keep alphabetically sorted
$strings['CreateService'] = 'Add service to menu bar'; $strings['CreateService'] = 'Add service to menu bar';
@ -20,3 +21,4 @@ $strings['DeleteServices'] = 'Remove services from menu bar';
$strings['ServicesToDelete'] = 'Services to remove from menu bar'; $strings['ServicesToDelete'] = 'Services to remove from menu bar';
$strings['ServiceTitle'] = 'Service title'; $strings['ServiceTitle'] = 'Service title';
$strings['ServiceURL'] = 'Service web site location (URL)'; $strings['ServiceURL'] = 'Service web site location (URL)';
$strings['RedirectAccessURL'] = "URL to use in Chamilo to redirect user to the service (URL)";

@ -15,6 +15,7 @@ $strings['salt_help'] =
<br/><code>$salt</code> est la valeur saisie ici, <br/><code>$salt</code> est la valeur saisie ici,
<br/><code>$userId</code> est le numéro de l\'utilisateur auquel fait référence le paramètre d\'URL <em>username</em> et <br/><code>$userId</code> est le numéro de l\'utilisateur auquel fait référence le paramètre d\'URL <em>username</em> et
<br/><code>$hash</code> représente la valeur du paramètre d\'URL <em>hash</em>.'; <br/><code>$hash</code> représente la valeur du paramètre d\'URL <em>hash</em>.';
$strings['hide_link_from_navigation_menu'] = 'Masquer les liens dans le menu';
// Please keep alphabetically sorted // Please keep alphabetically sorted
$strings['CreateService'] = "Ajouter le service au menu"; $strings['CreateService'] = "Ajouter le service au menu";
@ -22,3 +23,4 @@ $strings['DeleteServices'] = "Retirer les services du menu";
$strings['ServicesToDelete'] = "Services à retirer du menu"; $strings['ServicesToDelete'] = "Services à retirer du menu";
$strings['ServiceTitle'] = "Titre du service"; $strings['ServiceTitle'] = "Titre du service";
$strings['ServiceURL'] = "Adresse web du service (URL)"; $strings['ServiceURL'] = "Adresse web du service (URL)";
$strings['RedirectAccessURL'] = "Adresse à utiliser pour rediriger l'utilisateur au service (URL)";

@ -18,6 +18,7 @@ class UserRemoteServicePlugin extends Plugin
'Sébastien Ducoulombier', 'Sébastien Ducoulombier',
[ [
'salt' => 'text', 'salt' => 'text',
'hide_link_from_navigation_menu' => 'boolean',
] ]
); );
$this->isAdminPlugin = true; $this->isAdminPlugin = true;
@ -68,6 +69,14 @@ class UserRemoteServicePlugin extends Plugin
return $this->get('salt'); return $this->get('salt');
} }
/**
* @return boolean the value of hide_link_from_navigation_menu setting
*/
public function get_hide_link_from_navigation_menu()
{
return $this->get('hide_link_from_navigation_menu');
}
/** /**
* Retrieves the list of all services. * Retrieves the list of all services.
* *
@ -229,6 +238,7 @@ class UserRemoteServicePlugin extends Plugin
[ [
get_lang('ServiceTitle'), get_lang('ServiceTitle'),
get_lang('ServiceURL'), get_lang('ServiceURL'),
get_lang('RedirectAccessURL'),
], ],
null, null,
'th' 'th'
@ -237,6 +247,7 @@ class UserRemoteServicePlugin extends Plugin
$table->addRow([ $table->addRow([
$service->getTitle(), $service->getTitle(),
$service->getURL(), $service->getURL(),
$service->getAccessURL($this->get_name()),
]); ]);
} }
$html = $table->toHtml(); $html = $table->toHtml();
@ -279,4 +290,20 @@ class UserRemoteServicePlugin extends Plugin
)->getCustomUserURL($userInfo['username'], $userInfo['id'], $this->salt()) )->getCustomUserURL($userInfo['username'], $userInfo['id'], $this->salt())
); );
} }
/**
* Generates the redirect user specific URL for redirection.
*
* @throws Exception on hash generation failure
*
* @return string the specific user redirect URL
*/
public function getActiveServiceSpecificUserUrl()
{
$userInfo = api_get_user_info();
return $this->getService(
$this->getActiveServiceId()
)->getCustomUserRedirectURL($userInfo['id'], $this->salt());
}
} }

Loading…
Cancel
Save