Commit 4b12fa4bc0eb36f8b8c631c7c18f4db4ae4ca7e3

Authored by Neil Blakey-Milner
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
plugins/ktcore/admin/groupManagement.php
... ... @@ -10,7 +10,12 @@ require_once(KT_LIB_DIR . "/dispatcher.inc.php");
10 10 require_once(KT_LIB_DIR . "/templating/kt3template.inc.php");
11 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 17 class KTGroupAdminDispatcher extends KTAdminDispatcher {
  18 + // {{{ do_main
14 19 function do_main() {
15 20 $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management'));
16 21 $this->oPage->setBreadcrumbDetails(_('select a group'));
... ... @@ -48,9 +53,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
48 53 );
49 54 return $oTemplate->render($aTemplateData);
50 55 }
  56 + // }}}
51 57  
52   -
53   -
  58 + // {{{ do_editGroup
54 59 function do_editGroup() {
55 60 $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management'));
56 61 $this->oPage->setBreadcrumbDetails(_('edit group'));
... ... @@ -89,7 +94,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
89 94 );
90 95 return $oTemplate->render($aTemplateData);
91 96 }
  97 + // }}}
92 98  
  99 + // {{{ do_saveGroup
93 100 function do_saveGroup() {
94 101 $group_id = KTUtil::arrayGet($_REQUEST, 'group_id');
95 102 $oGroup = Group::get($group_id);
... ... @@ -122,19 +129,46 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
122 129 $this->commitTransaction();
123 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 156 function do_manageusers() {
128 157 $group_id = KTUtil::arrayGet($_REQUEST, 'group_id');
129 158 $oGroup = Group::get($group_id);
130 159 if ((PEAR::isError($oGroup)) || ($oGroup === false)) {
131 160 $this->errorRedirectToMain(_('No such group.'));
132 161 }
133   -
  162 +
  163 + $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management'));
134 164 $this->aBreadcrumbs[] = array('name' => $oGroup->getName());
135 165 $this->oPage->setBreadcrumbDetails(_('manage members'));
136 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 173 // FIXME replace OptionTransfer.js. me no-likey.
140 174  
... ... @@ -173,8 +207,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
173 207 );
174 208 return $oTemplate->render($aTemplateData);
175 209 }
  210 + // }}}
176 211  
177   -
  212 + // {{{ do_updateUserMembers
178 213 function do_updateUserMembers() {
179 214 $group_id = KTUtil::arrayGet($_REQUEST, 'group_id');
180 215 $oGroup = Group::get($group_id);
... ... @@ -221,9 +256,10 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
221 256 $this->commitTransaction();
222 257 $this->successRedirectToMain($msg);
223 258 }
  259 + // }}}
224 260  
225   -
226 261 // FIXME copy-paste ...
  262 + // {{{ do_managesubgroups
227 263 function do_managesubgroups() {
228 264 $group_id = KTUtil::arrayGet($_REQUEST, 'group_id');
229 265 $oGroup = Group::get($group_id);
... ... @@ -274,7 +310,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
274 310 );
275 311 return $oTemplate->render($aTemplateData);
276 312 }
  313 + // }}}
277 314  
  315 + // {{{ _getUnitName
278 316 function _getUnitName($oGroup) {
279 317 $iUnitId = $oGroup->getUnitId();
280 318 if (empty($iUnitId)) {
... ... @@ -284,8 +322,10 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
284 322  
285 323 return $u->getName();
286 324 }
  325 + // }}}
287 326  
288 327 // FIXME copy-paste ...
  328 + // {{{ do_updateGroupMembers
289 329 function do_updateGroupMembers() {
290 330 $group_id = KTUtil::arrayGet($_REQUEST, 'group_id');
291 331 $oGroup = Group::get($group_id);
... ... @@ -335,8 +375,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
335 375  
336 376 $this->successRedirectToMain($msg);
337 377 }
  378 + // }}}
338 379  
339   -
  380 + // {{{ do_addGroup
340 381 function do_addGroup() {
341 382 $this->aBreadcrumbs[] = array('url' => $_SERVER['PHP_SELF'], 'name' => _('Group Management'));
342 383 $this->oPage->setBreadcrumbDetails(_('Add a new group'));
... ... @@ -348,16 +389,30 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
348 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 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 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 404 $oTemplating = new KTTemplating;
353 405 $oTemplate = $oTemplating->loadTemplate("ktcore/principals/addgroup");
354 406 $aTemplateData = array(
355 407 "context" => $this,
356 408 "add_fields" => $add_fields,
  409 + "authentication_sources" => $aAuthenticationSources,
357 410 );
358 411 return $oTemplate->render($aTemplateData);
359 412 }
  413 + // }}}
360 414  
  415 + // {{{ do_createGroup
361 416 function do_createGroup() {
362 417  
363 418 $group_name = KTUtil::arrayGet($_REQUEST, 'group_name');
... ... @@ -380,7 +435,9 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
380 435 $this->commitTransaction();
381 436 $this->successRedirectToMain(sprintf(_('Group "%s" created.'), $group_name));
382 437 }
  438 + // }}}
383 439  
  440 + // {{{ do_deleteGroup
384 441 function do_deleteGroup() {
385 442 $aErrorOptions = array(
386 443 'redirect_to' => array('main'),
... ... @@ -391,7 +448,29 @@ class KTGroupAdminDispatcher extends KTAdminDispatcher {
391 448 $this->oValidator->notError($res, $aErrorOptions);
392 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 ?>
... ...