mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-09 16:32:39 +01:00
Remove the highly suspect "Import from LDAP" workflow
Summary: Depends on D20109. Ref T6703. This flow was contributed in 2012 and I'm not sure it ever worked, or at least ever worked nondestructively. For now, get rid of it. We'll do importing and external sync properly at some point (T3980, T13190). Test Plan: Grepped for `ldap/`, grepped for controller. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T6703 Differential Revision: https://secure.phabricator.com/D20110
This commit is contained in:
parent
fcd85b6d7b
commit
378a43d09c
4 changed files with 0 additions and 221 deletions
|
@ -3867,7 +3867,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPeopleInviteController' => 'applications/people/controller/PhabricatorPeopleInviteController.php',
|
||||
'PhabricatorPeopleInviteListController' => 'applications/people/controller/PhabricatorPeopleInviteListController.php',
|
||||
'PhabricatorPeopleInviteSendController' => 'applications/people/controller/PhabricatorPeopleInviteSendController.php',
|
||||
'PhabricatorPeopleLdapController' => 'applications/people/controller/PhabricatorPeopleLdapController.php',
|
||||
'PhabricatorPeopleListController' => 'applications/people/controller/PhabricatorPeopleListController.php',
|
||||
'PhabricatorPeopleLogQuery' => 'applications/people/query/PhabricatorPeopleLogQuery.php',
|
||||
'PhabricatorPeopleLogSearchEngine' => 'applications/people/query/PhabricatorPeopleLogSearchEngine.php',
|
||||
|
@ -9866,7 +9865,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorPeopleInviteController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleInviteListController' => 'PhabricatorPeopleInviteController',
|
||||
'PhabricatorPeopleInviteSendController' => 'PhabricatorPeopleInviteController',
|
||||
'PhabricatorPeopleLdapController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleListController' => 'PhabricatorPeopleController',
|
||||
'PhabricatorPeopleLogQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorPeopleLogSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
|
|
|
@ -63,7 +63,6 @@ final class PhabricatorPeopleApplication extends PhabricatorApplication {
|
|||
'welcome/(?P<id>[1-9]\d*)/' => 'PhabricatorPeopleWelcomeController',
|
||||
'create/' => 'PhabricatorPeopleCreateController',
|
||||
'new/(?P<type>[^/]+)/' => 'PhabricatorPeopleNewController',
|
||||
'ldap/' => 'PhabricatorPeopleLdapController',
|
||||
'editprofile/(?P<id>[1-9]\d*)/' =>
|
||||
'PhabricatorPeopleProfileEditController',
|
||||
'badges/(?P<id>[1-9]\d*)/' =>
|
||||
|
|
|
@ -28,10 +28,6 @@ abstract class PhabricatorPeopleController extends PhabricatorController {
|
|||
|
||||
if ($viewer->getIsAdmin()) {
|
||||
$nav->addLabel(pht('User Administration'));
|
||||
if (PhabricatorLDAPAuthProvider::getLDAPProvider()) {
|
||||
$nav->addFilter('ldap', pht('Import from LDAP'));
|
||||
}
|
||||
|
||||
$nav->addFilter('logs', pht('Activity Logs'));
|
||||
$nav->addFilter('invite', pht('Email Invitations'));
|
||||
}
|
||||
|
|
|
@ -1,214 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorPeopleLdapController
|
||||
extends PhabricatorPeopleController {
|
||||
|
||||
public function handleRequest(AphrontRequest $request) {
|
||||
$this->requireApplicationCapability(
|
||||
PeopleCreateUsersCapability::CAPABILITY);
|
||||
$admin = $request->getUser();
|
||||
|
||||
$content = array();
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setAction($request->getRequestURI()
|
||||
->alter('search', 'true')->alter('import', null))
|
||||
->setUser($admin)
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel(pht('LDAP username'))
|
||||
->setName('username'))
|
||||
->appendChild(
|
||||
id(new AphrontFormPasswordControl())
|
||||
->setDisableAutocomplete(true)
|
||||
->setLabel(pht('Password'))
|
||||
->setName('password'))
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel(pht('LDAP query'))
|
||||
->setCaption(pht('A filter such as %s.', '(objectClass=*)'))
|
||||
->setName('query'))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Search')));
|
||||
|
||||
$panel = id(new PHUIObjectBoxView())
|
||||
->setHeaderText(pht('Import LDAP Users'))
|
||||
->setForm($form);
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
$crumbs->addTextCrumb(
|
||||
pht('Import LDAP Users'),
|
||||
$this->getApplicationURI('/ldap/'));
|
||||
|
||||
$nav = $this->buildSideNavView();
|
||||
$nav->selectFilter('ldap');
|
||||
$nav->appendChild($content);
|
||||
|
||||
if ($request->getStr('import')) {
|
||||
$nav->appendChild($this->processImportRequest($request));
|
||||
}
|
||||
|
||||
$nav->appendChild($panel);
|
||||
|
||||
if ($request->getStr('search')) {
|
||||
$nav->appendChild($this->processSearchRequest($request));
|
||||
}
|
||||
|
||||
return $this->newPage()
|
||||
->setTitle(pht('Import LDAP Users'))
|
||||
->setCrumbs($crumbs)
|
||||
->setNavigation($nav);
|
||||
}
|
||||
|
||||
private function processImportRequest($request) {
|
||||
$admin = $request->getUser();
|
||||
$usernames = $request->getArr('usernames');
|
||||
$emails = $request->getArr('email');
|
||||
$names = $request->getArr('name');
|
||||
|
||||
$notice_view = new PHUIInfoView();
|
||||
$notice_view->setSeverity(PHUIInfoView::SEVERITY_NOTICE);
|
||||
$notice_view->setTitle(pht('Import Successful'));
|
||||
$notice_view->setErrors(array(
|
||||
pht('Successfully imported users from LDAP'),
|
||||
));
|
||||
|
||||
$list = new PHUIObjectItemListView();
|
||||
$list->setNoDataString(pht('No users imported?'));
|
||||
|
||||
foreach ($usernames as $username) {
|
||||
$user = new PhabricatorUser();
|
||||
$user->setUsername($username);
|
||||
$user->setRealname($names[$username]);
|
||||
|
||||
$email_obj = id(new PhabricatorUserEmail())
|
||||
->setAddress($emails[$username])
|
||||
->setIsVerified(1);
|
||||
try {
|
||||
id(new PhabricatorUserEditor())
|
||||
->setActor($admin)
|
||||
->createNewUser($user, $email_obj);
|
||||
|
||||
id(new PhabricatorExternalAccount())
|
||||
->setUserPHID($user->getPHID())
|
||||
->setAccountType('ldap')
|
||||
->setAccountDomain('self')
|
||||
->setAccountID($username)
|
||||
->save();
|
||||
|
||||
$header = pht('Successfully added %s', $username);
|
||||
$attribute = null;
|
||||
$color = 'fa-check green';
|
||||
} catch (Exception $ex) {
|
||||
$header = pht('Failed to add %s', $username);
|
||||
$attribute = $ex->getMessage();
|
||||
$color = 'fa-times red';
|
||||
}
|
||||
|
||||
$item = id(new PHUIObjectItemView())
|
||||
->setHeader($header)
|
||||
->addAttribute($attribute)
|
||||
->setStatusIcon($color);
|
||||
|
||||
$list->addItem($item);
|
||||
}
|
||||
|
||||
return array(
|
||||
$notice_view,
|
||||
$list,
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private function processSearchRequest($request) {
|
||||
$panel = new PHUIBoxView();
|
||||
$admin = $request->getUser();
|
||||
|
||||
$search = $request->getStr('query');
|
||||
|
||||
$ldap_provider = PhabricatorLDAPAuthProvider::getLDAPProvider();
|
||||
if (!$ldap_provider) {
|
||||
throw new Exception(pht('No LDAP provider enabled!'));
|
||||
}
|
||||
|
||||
$ldap_adapter = $ldap_provider->getAdapter();
|
||||
$ldap_adapter->setLoginUsername($request->getStr('username'));
|
||||
$ldap_adapter->setLoginPassword(
|
||||
new PhutilOpaqueEnvelope($request->getStr('password')));
|
||||
|
||||
// This causes us to connect and bind.
|
||||
// TODO: Clean up this discard mode stuff.
|
||||
DarkConsoleErrorLogPluginAPI::enableDiscardMode();
|
||||
$ldap_adapter->getAccountID();
|
||||
DarkConsoleErrorLogPluginAPI::disableDiscardMode();
|
||||
|
||||
$results = $ldap_adapter->searchLDAP('%Q', $search);
|
||||
|
||||
foreach ($results as $key => $record) {
|
||||
$account_id = $ldap_adapter->readLDAPRecordAccountID($record);
|
||||
if (!$account_id) {
|
||||
unset($results[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$info = array(
|
||||
$account_id,
|
||||
$ldap_adapter->readLDAPRecordEmail($record),
|
||||
$ldap_adapter->readLDAPRecordRealName($record),
|
||||
);
|
||||
$results[$key] = $info;
|
||||
$results[$key][] = $this->renderUserInputs($info);
|
||||
}
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($admin);
|
||||
|
||||
$table = new AphrontTableView($results);
|
||||
$table->setHeaders(
|
||||
array(
|
||||
pht('Username'),
|
||||
pht('Email'),
|
||||
pht('Real Name'),
|
||||
pht('Import?'),
|
||||
));
|
||||
$form->appendChild($table);
|
||||
$form->setAction($request->getRequestURI()
|
||||
->alter('import', 'true')->alter('search', null))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue(pht('Import')));
|
||||
|
||||
$panel->appendChild($form);
|
||||
|
||||
return $panel;
|
||||
}
|
||||
|
||||
private function renderUserInputs($user) {
|
||||
$username = $user[0];
|
||||
return hsprintf(
|
||||
'%s%s%s',
|
||||
phutil_tag(
|
||||
'input',
|
||||
array(
|
||||
'type' => 'checkbox',
|
||||
'name' => 'usernames[]',
|
||||
'value' => $username,
|
||||
)),
|
||||
phutil_tag(
|
||||
'input',
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => "email[$username]",
|
||||
'value' => $user[1],
|
||||
)),
|
||||
phutil_tag(
|
||||
'input',
|
||||
array(
|
||||
'type' => 'hidden',
|
||||
'name' => "name[$username]",
|
||||
'value' => $user[2],
|
||||
)));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue