Commit 4b12fa4bc0eb36f8b8c631c7c18f4db4ae4ca7e3
1 parent
10a5d66a
Allow for groups to be added from an external authentication provider
(e.g. LDAP) git-svn-id: https://kt-dms.svn.sourceforge.net/svnroot/kt-dms/trunk@4833 c91229c3-7414-0410-bfa2-8a42b809f60b
Showing
1 changed file
with
87 additions
and
8 deletions
plugins/ktcore/admin/groupManagement.php
| @@ -10,7 +10,12 @@ require_once(KT_LIB_DIR . "/dispatcher.inc.php"); | @@ -10,7 +10,12 @@ require_once(KT_LIB_DIR . "/dispatcher.inc.php"); | ||
| 10 | require_once(KT_LIB_DIR . "/templating/kt3template.inc.php"); | 10 | require_once(KT_LIB_DIR . "/templating/kt3template.inc.php"); |
| 11 | require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php"); | 11 | require_once(KT_LIB_DIR . "/widgets/fieldWidgets.php"); |
| 12 | 12 | ||
| 13 | +require_once(KT_LIB_DIR . "/authentication/authenticationsource.inc.php"); | ||
| 14 | +require_once(KT_LIB_DIR . "/authentication/authenticationproviderregistry.inc.php"); | ||
| 15 | +require_once(KT_LIB_DIR . "/authentication/builtinauthenticationprovider.inc.php"); | ||
| 16 | + | ||
| 13 | class KTGroupAdminDispatcher extends KTAdminDispatcher { | 17 | class KTGroupAdminDispatcher extends KTAdminDispatcher { |
| 18 | + // {{{ do_main | ||
| 14 | function do_main() { | 19 | function do_main() { |
| 15 | $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management')); | 20 | $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management')); |
| 16 | $this->oPage->setBreadcrumbDetails(_('select a group')); | 21 | $this->oPage->setBreadcrumbDetails(_('select a group')); |
| @@ -48,9 +53,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -48,9 +53,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 48 | ); | 53 | ); |
| 49 | return $oTemplate->render($aTemplateData); | 54 | return $oTemplate->render($aTemplateData); |
| 50 | } | 55 | } |
| 56 | + // }}} | ||
| 51 | 57 | ||
| 52 | - | ||
| 53 | - | 58 | + // {{{ do_editGroup |
| 54 | function do_editGroup() { | 59 | function do_editGroup() { |
| 55 | $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management')); | 60 | $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management')); |
| 56 | $this->oPage->setBreadcrumbDetails(_('edit group')); | 61 | $this->oPage->setBreadcrumbDetails(_('edit group')); |
| @@ -89,7 +94,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -89,7 +94,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 89 | ); | 94 | ); |
| 90 | return $oTemplate->render($aTemplateData); | 95 | return $oTemplate->render($aTemplateData); |
| 91 | } | 96 | } |
| 97 | + // }}} | ||
| 92 | 98 | ||
| 99 | + // {{{ do_saveGroup | ||
| 93 | function do_saveGroup() { | 100 | function do_saveGroup() { |
| 94 | $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | 101 | $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); |
| 95 | $oGroup = Group::get($group_id); | 102 | $oGroup = Group::get($group_id); |
| @@ -122,19 +129,46 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -122,19 +129,46 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 122 | $this->commitTransaction(); | 129 | $this->commitTransaction(); |
| 123 | $this->successRedirectToMain(_('Group details updated.')); | 130 | $this->successRedirectToMain(_('Group details updated.')); |
| 124 | } | 131 | } |
| 132 | + // }}} | ||
| 133 | + function _do_manageUsers_source() { | ||
| 134 | + $oGroup =& $this->oValidator->validateGroup($_REQUEST['group_id']); | ||
| 135 | + | ||
| 136 | + $aGroupUsers = $oGroup->getMembers(); | ||
| 137 | + | ||
| 138 | + $oTemplate = $this->oValidator->validateTemplate("ktcore/principals/groups_sourceusers"); | ||
| 139 | + $aTemplateData = array( | ||
| 140 | + "context" => $this, | ||
| 141 | + 'group_users' => $aGroupUsers, | ||
| 142 | + 'group' => $oGroup, | ||
| 143 | + ); | ||
| 144 | + return $oTemplate->render($aTemplateData); | ||
| 145 | + } | ||
| 125 | 146 | ||
| 147 | + function do_synchroniseGroup() { | ||
| 148 | + require_once(KT_LIB_DIR . '/authentication/authenticationutil.inc.php'); | ||
| 149 | + $oGroup =& $this->oValidator->validateGroup($_REQUEST['group_id']); | ||
| 150 | + $res = KTAuthenticationUtil::synchroniseGroupToSource($oGroup); | ||
| 151 | + $this->successRedirectTo('manageusers', 'Group synchronised', sprintf('group_id=%d', $oGroup->getId())); | ||
| 152 | + exit(0); | ||
| 153 | + } | ||
| 126 | 154 | ||
| 155 | + // {{{ do_manageusers | ||
| 127 | function do_manageusers() { | 156 | function do_manageusers() { |
| 128 | $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | 157 | $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); |
| 129 | $oGroup = Group::get($group_id); | 158 | $oGroup = Group::get($group_id); |
| 130 | if ((PEAR::isError($oGroup)) || ($oGroup === false)) { | 159 | if ((PEAR::isError($oGroup)) || ($oGroup === false)) { |
| 131 | $this->errorRedirectToMain(_('No such group.')); | 160 | $this->errorRedirectToMain(_('No such group.')); |
| 132 | } | 161 | } |
| 133 | - | 162 | + |
| 163 | + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management')); | ||
| 134 | $this->aBreadcrumbs[] = array('name' => $oGroup->getName()); | 164 | $this->aBreadcrumbs[] = array('name' => $oGroup->getName()); |
| 135 | $this->oPage->setBreadcrumbDetails(_('manage members')); | 165 | $this->oPage->setBreadcrumbDetails(_('manage members')); |
| 136 | $this->oPage->setTitle(sprintf(_('Manage members of group %s'), $oGroup->getName())); | 166 | $this->oPage->setTitle(sprintf(_('Manage members of group %s'), $oGroup->getName())); |
| 137 | - | 167 | + |
| 168 | + $iSourceId = $oGroup->getAuthenticationSourceId(); | ||
| 169 | + if (!empty($iSourceId)) { | ||
| 170 | + return $this->_do_manageUsers_source(); | ||
| 171 | + } | ||
| 138 | 172 | ||
| 139 | // FIXME replace OptionTransfer.js. me no-likey. | 173 | // FIXME replace OptionTransfer.js. me no-likey. |
| 140 | 174 | ||
| @@ -173,8 +207,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -173,8 +207,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 173 | ); | 207 | ); |
| 174 | return $oTemplate->render($aTemplateData); | 208 | return $oTemplate->render($aTemplateData); |
| 175 | } | 209 | } |
| 210 | + // }}} | ||
| 176 | 211 | ||
| 177 | - | 212 | + // {{{ do_updateUserMembers |
| 178 | function do_updateUserMembers() { | 213 | function do_updateUserMembers() { |
| 179 | $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | 214 | $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); |
| 180 | $oGroup = Group::get($group_id); | 215 | $oGroup = Group::get($group_id); |
| @@ -221,9 +256,10 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -221,9 +256,10 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 221 | $this->commitTransaction(); | 256 | $this->commitTransaction(); |
| 222 | $this->successRedirectToMain($msg); | 257 | $this->successRedirectToMain($msg); |
| 223 | } | 258 | } |
| 259 | + // }}} | ||
| 224 | 260 | ||
| 225 | - | ||
| 226 | // FIXME copy-paste ... | 261 | // FIXME copy-paste ... |
| 262 | + // {{{ do_managesubgroups | ||
| 227 | function do_managesubgroups() { | 263 | function do_managesubgroups() { |
| 228 | $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | 264 | $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); |
| 229 | $oGroup = Group::get($group_id); | 265 | $oGroup = Group::get($group_id); |
| @@ -274,7 +310,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -274,7 +310,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 274 | ); | 310 | ); |
| 275 | return $oTemplate->render($aTemplateData); | 311 | return $oTemplate->render($aTemplateData); |
| 276 | } | 312 | } |
| 313 | + // }}} | ||
| 277 | 314 | ||
| 315 | + // {{{ _getUnitName | ||
| 278 | function _getUnitName($oGroup) { | 316 | function _getUnitName($oGroup) { |
| 279 | $iUnitId = $oGroup->getUnitId(); | 317 | $iUnitId = $oGroup->getUnitId(); |
| 280 | if (empty($iUnitId)) { | 318 | if (empty($iUnitId)) { |
| @@ -284,8 +322,10 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -284,8 +322,10 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 284 | 322 | ||
| 285 | return $u->getName(); | 323 | return $u->getName(); |
| 286 | } | 324 | } |
| 325 | + // }}} | ||
| 287 | 326 | ||
| 288 | // FIXME copy-paste ... | 327 | // FIXME copy-paste ... |
| 328 | + // {{{ do_updateGroupMembers | ||
| 289 | function do_updateGroupMembers() { | 329 | function do_updateGroupMembers() { |
| 290 | $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); | 330 | $group_id = KTUtil::arrayGet($_REQUEST, 'group_id'); |
| 291 | $oGroup = Group::get($group_id); | 331 | $oGroup = Group::get($group_id); |
| @@ -335,8 +375,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -335,8 +375,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 335 | 375 | ||
| 336 | $this->successRedirectToMain($msg); | 376 | $this->successRedirectToMain($msg); |
| 337 | } | 377 | } |
| 378 | + // }}} | ||
| 338 | 379 | ||
| 339 | - | 380 | + // {{{ do_addGroup |
| 340 | function do_addGroup() { | 381 | function do_addGroup() { |
| 341 | $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management')); | 382 | $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management')); |
| 342 | $this->oPage->setBreadcrumbDetails(_('Add a new group')); | 383 | $this->oPage->setBreadcrumbDetails(_('Add a new group')); |
| @@ -348,16 +389,30 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -348,16 +389,30 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 348 | $add_fields[] = new KTStringWidget(_('Group Name'),_('A short name for the group. e.g. <strong>administrators</strong>.'), 'group_name', null, $this->oPage, true); | 389 | $add_fields[] = new KTStringWidget(_('Group Name'),_('A short name for the group. e.g. <strong>administrators</strong>.'), 'group_name', null, $this->oPage, true); |
| 349 | $add_fields[] = new KTCheckboxWidget(_('Unit Administrators'),_('Should all the members of this group be given <strong>unit</strong> administration privileges?'), 'is_unitadmin', false, $this->oPage, false); | 390 | $add_fields[] = new KTCheckboxWidget(_('Unit Administrators'),_('Should all the members of this group be given <strong>unit</strong> administration privileges?'), 'is_unitadmin', false, $this->oPage, false); |
| 350 | $add_fields[] = new KTCheckboxWidget(_('System Administrators'),_('Should all the members of this group be given <strong>system</strong> administration privileges?'), 'is_sysadmin', false, $this->oPage, false); | 391 | $add_fields[] = new KTCheckboxWidget(_('System Administrators'),_('Should all the members of this group be given <strong>system</strong> administration privileges?'), 'is_sysadmin', false, $this->oPage, false); |
| 392 | + | ||
| 393 | + $aAuthenticationSources = array(); | ||
| 394 | + $aAllAuthenticationSources =& KTAuthenticationSource::getList(); | ||
| 395 | + foreach ($aAllAuthenticationSources as $oSource) { | ||
| 396 | + $sProvider = $oSource->getAuthenticationProvider(); | ||
| 397 | + $oRegistry =& KTAuthenticationProviderRegistry::getSingleton(); | ||
| 398 | + $oProvider =& $oRegistry->getAuthenticationProvider($sProvider); | ||
| 399 | + if ($oProvider->bGroupSource) { | ||
| 400 | + $aAuthenticationSources[] = $oSource; | ||
| 401 | + } | ||
| 402 | + } | ||
| 351 | 403 | ||
| 352 | $oTemplating = new KTTemplating; | 404 | $oTemplating = new KTTemplating; |
| 353 | $oTemplate = $oTemplating->loadTemplate("ktcore/principals/addgroup"); | 405 | $oTemplate = $oTemplating->loadTemplate("ktcore/principals/addgroup"); |
| 354 | $aTemplateData = array( | 406 | $aTemplateData = array( |
| 355 | "context" => $this, | 407 | "context" => $this, |
| 356 | "add_fields" => $add_fields, | 408 | "add_fields" => $add_fields, |
| 409 | + "authentication_sources" => $aAuthenticationSources, | ||
| 357 | ); | 410 | ); |
| 358 | return $oTemplate->render($aTemplateData); | 411 | return $oTemplate->render($aTemplateData); |
| 359 | } | 412 | } |
| 413 | + // }}} | ||
| 360 | 414 | ||
| 415 | + // {{{ do_createGroup | ||
| 361 | function do_createGroup() { | 416 | function do_createGroup() { |
| 362 | 417 | ||
| 363 | $group_name = KTUtil::arrayGet($_REQUEST, 'group_name'); | 418 | $group_name = KTUtil::arrayGet($_REQUEST, 'group_name'); |
| @@ -380,7 +435,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -380,7 +435,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 380 | $this->commitTransaction(); | 435 | $this->commitTransaction(); |
| 381 | $this->successRedirectToMain(sprintf(_('Group "%s" created.'), $group_name)); | 436 | $this->successRedirectToMain(sprintf(_('Group "%s" created.'), $group_name)); |
| 382 | } | 437 | } |
| 438 | + // }}} | ||
| 383 | 439 | ||
| 440 | + // {{{ do_deleteGroup | ||
| 384 | function do_deleteGroup() { | 441 | function do_deleteGroup() { |
| 385 | $aErrorOptions = array( | 442 | $aErrorOptions = array( |
| 386 | 'redirect_to' => array('main'), | 443 | 'redirect_to' => array('main'), |
| @@ -391,7 +448,29 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | @@ -391,7 +448,29 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher { | ||
| 391 | $this->oValidator->notError($res, $aErrorOptions); | 448 | $this->oValidator->notError($res, $aErrorOptions); |
| 392 | $this->successRedirectToMain(sprintf(_('Group "%s" deleted.'), $sGroupName)); | 449 | $this->successRedirectToMain(sprintf(_('Group "%s" deleted.'), $sGroupName)); |
| 393 | } | 450 | } |
| 394 | - | 451 | + // }}} |
| 452 | + | ||
| 453 | + // {{{ authentication provider stuff | ||
| 454 | + | ||
| 455 | + // {{{ do_addGroupFromSource | ||
| 456 | + function do_addGroupFromSource() { | ||
| 457 | + $oSource =& KTAuthenticationSource::get($_REQUEST['source_id']); | ||
| 458 | + $sProvider = $oSource->getAuthenticationProvider(); | ||
| 459 | + $oRegistry =& KTAuthenticationProviderRegistry::getSingleton(); | ||
| 460 | + $oProvider =& $oRegistry->getAuthenticationProvider($sProvider); | ||
| 461 | + | ||
| 462 | + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management')); | ||
| 463 | + $this->aBreadcrumbs[] = array('url' => KTUtil::addQueryStringSelf('action=addGroup'), 'name' => _('add a new group')); | ||
| 464 | + $oProvider->aBreadcrumbs = $this->aBreadcrumbs; | ||
| 465 | + $oProvider->oPage->setBreadcrumbDetails($oSource->getName()); | ||
| 466 | + $oProvider->oPage->setTitle(_("Modify Group Details")); | ||
| 467 | + | ||
| 468 | + $oProvider->dispatch(); | ||
| 469 | + exit(0); | ||
| 470 | + } | ||
| 471 | + // }}} | ||
| 472 | + | ||
| 473 | + // }}} | ||
| 395 | } | 474 | } |
| 396 | 475 | ||
| 397 | ?> | 476 | ?> |