Added groups settings/check

Page(s) creation will only occure if corresponding settings are blank or
if connected user's group(s) match at least one set group
This commit is contained in:
Simon DELAGE 2015-11-26 12:28:00 +01:00
parent 6817a7d378
commit ceda371f52
6 changed files with 61 additions and 20 deletions

View File

@ -26,7 +26,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
function init(&$event, $param) {
global $conf;
if ($this->settingsCheck(true)) {
if ($this->multiNsOk(true)) {
$this->helper = plugin_load('helper','userhomepage');
// If templates_path option starts with 'data/pages' it can automatically be adapted but should be changed
if (substr($this->getConf('templates_path'),0,10) == 'data/pages') {
@ -37,7 +37,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
}
$this->dataDir = $conf['savedir'];
// CREATE PRIVATE NAMESPACE START PAGE TEMPLATES IF NEEDED (is required by options, doesn't exist yet and a known user is logged in)
if (($this->getConf('create_private_ns')) && (!is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt')) && ($_SERVER['REMOTE_USER'] != null)) {
if (($this->getConf('create_private_ns')) && (!is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt')) && ($this->userOk())) {
// If a template exists in path as builded before 2015/05/14 version, use it as source to create userhomepage_private.txt in new templates_path
if ((is_file(DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_private.txt')) && ($this->getConf('templatepath') != null)) {
$source = DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_private.txt';
@ -51,7 +51,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
$this->copyFile($source, $dest, 'userhomepage_private.txt');
}
// CREATE PUBLIC PAGE TEMPLATES IF NEEDED (is required by options, doesn't exist yet and a known user is logged in)
if (($this->getConf('create_public_page')) && (!is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt')) && ($_SERVER['REMOTE_USER'] != null)) {
if (($this->getConf('create_public_page')) and (!is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt')) and ($this->userOk())) {
// If a template exists in path as builded before 2015/05/14 version, use it as source to create userhomepage_private.txt in new templates_path
if ((is_file(DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_public.txt')) && ($this->getConf('templatepath') != null)) {
$source = DOKU_CONF.'../'.$this->getConf('templates_path').'/userhomepage_public.txt';
@ -66,10 +66,10 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
// user:simon.txt
$this->public_page = $this->helper->getPublicID();
// If a user is logged in, store timestamp (if it wasn't stored yet)
if (($_SERVER['REMOTE_USER']!=null) && (!isset($_SESSION['uhptimestamp']))) {
if (($_SERVER['REMOTE_USER'] != null) && (!isset($_SESSION['uhptimestamp']))) {
$_SESSION['uhptimestamp'] = time();
// If no user is logged in and a timestamp exists, set timestamp to null (ensures that redirection will work if user just logged out and comes back before closing browser)
} elseif (($_SERVER['REMOTE_USER']==null) && (isset($_SESSION['uhptimestamp']))) {
} elseif (($_SERVER['REMOTE_USER'] == null) && (isset($_SESSION['uhptimestamp']))) {
$_SESSION['uhptimestamp'] = null;
}
} else {
@ -81,12 +81,12 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
global $conf;
global $lang;
if ($this->settingsCheck()) {
if ($this->multiNsOk()) {
$created = array();
// If a user is logged in and not allready requesting his private namespace start page
if (($_SERVER['REMOTE_USER']!=null)&&($_REQUEST['id']!=$this->private_page)) {
if (($this->userOk())&&($_REQUEST['id']!=$this->private_page)) {
// if private page doesn't exists, create it (from template)
if ($this->getConf('create_private_ns') && is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt') && !page_exists($this->private_page) && !checklock($this->private_page) && !checkwordblock()) {
if ($this->getConf('create_private_ns') && is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt') && !page_exists($this->private_page) && !checklock($this->private_page) && !checkwordblock() && ($this->userOk('private'))) {
// Target private start page template
$this->private_page_template = $this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_private.txt';
// Create private page
@ -99,7 +99,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
$created['private'] = page_exists($this->private_page);
}
// If private ns is managed by plugin, check for any template from skeleton that doesn't exist yet
if ($this->getConf('create_private_ns') && (is_dir($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton'))) {
if ($this->getConf('create_private_ns') && (is_dir($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton')) && ($this->userOk('private'))) {
//$files = scandir($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton/');
$path = realpath($this->dataDir.'/'.$this->getConf('templates_path').'/uhp_private_skeleton/');
$objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($path), RecursiveIteratorIterator::SELF_FIRST);
@ -127,7 +127,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
}
// Public page?
// If public page doesn't exists, create it (from template)
if ($this->getConf('create_public_page') && is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt') && !page_exists($this->public_page) && !checklock($this->public_page) && !checkwordblock()) {
if ($this->getConf('create_public_page') && is_file($this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt') && !page_exists($this->public_page) && !checklock($this->public_page) && !checkwordblock() && ($this->userOk('public'))) {
// Target public page template
$this->public_page_template = $this->dataDir.'/'.$this->getConf('templates_path').'/userhomepage_public.txt';
// Create public page
@ -167,8 +167,8 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
function acl(&$event, $param) {
global $conf;
if ($this->settingsCheck()) {
if ((!$this->getConf('no_acl')) && ($conf['useacl']) && (isset($_SERVER['REMOTE_USER']))) {
if ($this->multiNsOk()) {
if ((!$this->getConf('no_acl')) && ($conf['useacl']) && ($this->userOk())) {
$existingLines = file(DOKU_CONF.'acl.auth.php');
$newLines = array();
// ACL
@ -362,7 +362,7 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
global $INFO;
global $conf;
if ($this->settingsCheck()) {
if ($this->multiNsOk()) {
if (($conf['showuseras'] == "username_link") and ($this->getConf('userlink_replace'))) {
$classes = $this->getConf('userlink_classes');
$classes = str_replace(',', ' ', $classes);
@ -415,21 +415,19 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
}
}
} else {
return flase;
return false;
}
}
function settingsCheck($msg=false) {
global $conf;
// Error #1: Public page switched to namespace and is in conflict with Private namespace
function multiNsOk($msg=false) {
// Error: Public page switched to namespace and is in conflict with Private namespace
if (strpos($this->getConf('public_pages_ns'),':%NAME%:%START%') !== false) {
$PublicNS = str_replace(':%NAME%:%START%', '', $this->getConf('public_pages_ns'));
$PublicNS = str_replace(':', '', $PublicNS);
$PrivateNS = str_replace(':', '', $this->getConf('users_namespace'));
if ($PublicNS == $PrivateNS) {
if ($msg) {
msg("UserHomePage error #1 ! Make sure Private and Public namespaces are different. Plugin will have no effect untill this is corrected.", -1);
msg("UserHomePage settings conflict ! Make sure Private and Public namespaces are different. Plugin will have no effect untill this is corrected.", -1);
}
return false;
} else {
@ -440,4 +438,39 @@ class action_plugin_userhomepage extends DokuWiki_Action_Plugin{
}
}
function userOk($check = null) {
global $INFO;
// Proceed only if named user is connected...
if ($_SERVER['REMOTE_USER'] != null) {
// Check if user is member of a group in 'groups_private' or 'groups_public' (depending on $check)
if (($check == 'private') or ($check == 'public')) {
// Stop if 'groups_private' is set and and user is not member of at least one of said groups
$groups = $this->getConf('groups_'.$check);
$groups = str_replace(' ','', $groups);
$groups = explode(',', $groups);
$userGroups = $INFO['userinfo']['grps'];
// If UHP is set to check user's group(s)
if (($groups != null) and ($groups[0] != null) and ($userGroups != null)) {
$test = array_intersect($groups, $userGroups);
// Proceed if user is member of at least one group set UHP's corresponding setting
if (count($test) > 0) {
return true;
} else {
return false;
}
// If UHP isn't set to ckeck user's group(s) we can proceed
} else {
return true;
}
// If $check is null, we only need to know that a named user is connected (wich we allready know if we went that far)
} else {
return true;
}
// ... else stop
} else {
return false;
}
}
}

View File

@ -14,10 +14,12 @@
$conf['edit_before_create'] = 0;
$conf['acl_all_private'] = '0';
$conf['acl_user_private'] = '0';
$conf['groups_private'] = '';
$conf['create_public_page'] = 0;
$conf['public_pages_ns'] = 'user';
$conf['acl_all_public'] = '1';
$conf['acl_user_public'] = '1';
$conf['groups_public'] = '';
$conf['templates_path'] = './pages/user';
$conf['templatepath'] = 'lib/plugins/userhomepage/_template.txt';
$conf['acl_all_templates'] = '1';

View File

@ -14,10 +14,12 @@
$meta['edit_before_create'] = array('onoff');
$meta['acl_all_private'] = array('multichoice','_choices'=>array('0','1','2','4','8','16','noacl'));
$meta['acl_user_private'] = array('multichoice','_choices'=>array('0','1','2','4','8','16','noacl'));
$meta['groups_private'] = array('string');
$meta['create_public_page'] = array('onoff');
$meta['public_pages_ns'] = array('string','_pattern' => '/^(|[a-zA-Z\-:%]+)$/','_caution' => 'warning');
$meta['acl_all_public'] = array('multichoice','_choices'=>array('0','1','2','noacl'));
$meta['acl_user_public'] = array('multichoice','_choices'=>array('0','1','2','noacl'));
$meta['groups_public'] = array('string');
$meta['templates_path'] = array('string');
$meta['templatepath'] = array('string');
$meta['acl_all_templates'] = array('multichoice','_choices'=>array('0','1','2','noacl'));

View File

@ -28,6 +28,7 @@
$lang['acl_user_private_o_8'] = 'Upload';
$lang['acl_user_private_o_16'] = 'Delete';
$lang['acl_user_private_o_noacl'] = 'No automatic ACL';
$lang['groups_private'] = 'Comma separated list of user groups concerned by Private Namespace creation (leave empty to apply above settings to all users).';
$lang['create_public_page'] = 'Create a user\'s public page?';
$lang['public_pages_ns'] = 'Namespace under wich public pages are created.';
$lang['acl_all_public'] = 'Permissions for @ALL group on Public Pages';
@ -40,6 +41,7 @@
$lang['acl_user_public_o_1'] = 'Read (Default)';
$lang['acl_user_public_o_2'] = 'Edit';
$lang['acl_user_public_o_noacl'] = 'No automatic ACL';
$lang['groups_public'] = 'Comma separated list of user groups concerned by Public Page creation (leave empty to apply above settings to all users).';
$lang['templates_path'] = 'Relative path from [<code>savedir</code>] where templates will be stored (userhomepage_private.txt and userhomepage_public.txt). Examples: <code>./pages/user</code> or <code>../lib/plugins/userhomepage</code>.';
$lang['templatepath'] = 'Template path from version 3.0.4. If this file exists, it will be used as default source for new private namespace start page template (clear the path if you don\'t want to).';
$lang['acl_all_templates'] = 'Permissions for @ALL group on templates (if they are stored in <code>data/pages...</code>)';

View File

@ -28,6 +28,7 @@
$lang['acl_user_private_o_8'] = 'Envoyer';
$lang['acl_user_private_o_16'] = 'Effacer';
$lang['acl_user_private_o_noacl'] = 'Pas de gestion automatique des droits';
$lang['groups_private'] = 'Liste séparée par des virgules de groupes d\'utilisateurs concernés par la création d\'un espace privé (laisser vide pour appliquer les réglages ci-dessus à tous les utilisateurs).';
$lang['create_public_page'] = 'Créer une page publique pour chaque utilisateur?';
$lang['public_pages_ns'] = 'Espace de nom sous lequel créer les pages publiques.';
$lang['acl_all_public'] = 'Droits d\'accès pour le groupe @ALL sur les Pages Publiques';
@ -40,6 +41,7 @@
$lang['acl_user_public_o_1'] = 'Lecture (Défaut)';
$lang['acl_user_public_o_2'] = 'Écriture';
$lang['acl_user_public_o_noacl'] = 'Pas de gestion automatique des droits';
$lang['groups_public'] = 'Liste séparée par des virgules de groupes d\'utilisateurs concernés par la création d\'une page publique (laisser vide pour appliquer les réglages ci-dessus à tous les utilisateurs).';
$lang['templates_path'] = 'Chemin relatif depuis [<code>savedir</code>] où les modèles seront stockés (userhomepage_private.txt et userhomepage_public.txt). Exemples: <code>./pages/user</code> (permet d\'éditer les modèles depuis le wiki) ou <code>../lib/plugins/userhomepage</code> (pour plus de protecion ou pour les centraliser dans une ferme de wikis).';
$lang['templatepath'] = 'Chemin vers le modèle de la version 3.0.4. Si le fichier existe, il sera utilisé comme source pour le modèle des pages d\'accueil des espaces privés (videz le chemin si vous ne le souhaitez pas).';
$lang['acl_all_templates'] = 'Droits d\'accès pour le groupe @ALL sur les modèles (s\'ils sont stockés dans <code>data/pages...</code>)';

View File

@ -1,7 +1,7 @@
base userhomepage
author Simon Delage
email simon.geekitude@gmail.com
date 2015-11-23
date 2015-11-26
name User Homepage
desc Automatically create user's private namespace and/or public page and redirects users to private namespace on login.
url https://www.dokuwiki.org/plugin:userhomepage