Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2889441
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
6 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/applications/people/controller/PhabricatorPeopleLdapController.php b/src/applications/people/controller/PhabricatorPeopleLdapController.php
index 48ed98d904..f5a2903f32 100644
--- a/src/applications/people/controller/PhabricatorPeopleLdapController.php
+++ b/src/applications/people/controller/PhabricatorPeopleLdapController.php
@@ -1,178 +1,203 @@
<?php
final class PhabricatorPeopleLdapController
extends PhabricatorPeopleController {
- private $view;
-
public function processRequest() {
$request = $this->getRequest();
$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())
->setLabel(pht('Password'))
->setName('password'))
->appendChild(
id(new AphrontFormTextControl())
->setLabel(pht('LDAP query'))
->setCaption(pht('A filter such as (objectClass=*)'))
->setName('query'))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Search')));
- $panel = new AphrontPanelView();
- $panel->setHeader(pht('Import LDAP Users'));
- $panel->appendChild($form);
+ $panel = id(new AphrontPanelView())
+ ->setHeader(pht('Import LDAP Users'))
+ ->setNoBackground()
+ ->setWidth(AphrontPanelView::WIDTH_FORM)
+ ->appendChild($form);
+ $crumbs = $this->buildApplicationCrumbs();
+ $crumbs->addCrumb(
+ id(new PhabricatorCrumbView())
+ ->setName(pht('Import Ldap Users'))
+ ->setHref($this->getApplicationURI('/ldap/')));
+
+ $nav = $this->buildSideNavView();
+ $nav->setCrumbs($crumbs);
+ $nav->selectFilter('ldap');
+ $nav->appendChild($content);
if ($request->getStr('import')) {
- $content[] = $this->processImportRequest($request);
+ $nav->appendChild($this->processImportRequest($request));
}
- $content[] = $panel;
+ $nav->appendChild($panel);
if ($request->getStr('search')) {
- $content[] = $this->processSearchRequest($request);
+ $nav->appendChild($this->processSearchRequest($request));
}
- $nav = $this->buildSideNavView();
- $nav->selectFilter('ldap');
- $nav->appendChild($content);
-
return $this->buildApplicationPage(
$nav,
array(
- 'title' => pht('Import Ldap Users'),
+ 'title' => pht('Import Ldap Users'),
'device' => true,
+ 'dust' => true,
));
}
private function processImportRequest($request) {
$admin = $request->getUser();
$usernames = $request->getArr('usernames');
$emails = $request->getArr('email');
$names = $request->getArr('name');
- $panel = new AphrontErrorView();
- $panel->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
- $panel->setTitle(pht("Import Successful"));
- $errors = array(pht("Successfully imported users from LDAP"));
+ $notice_view = new AphrontErrorView();
+ $notice_view->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
+ $notice_view->setTitle(pht("Import Successful"));
+ $notice_view->setErrors(array(
+ pht("Successfully imported users from LDAP"),
+ ));
+ $list = new PhabricatorObjectItemListView();
+ $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);
$ldap_info = new PhabricatorUserLDAPInfo();
$ldap_info->setLDAPUsername($username);
$ldap_info->setUserID($user->getID());
$ldap_info->save();
- $errors[] = pht('Successfully added %s', $username);
+
+ $header = pht('Successfully added %s', $username);
+ $attribute = null;
+ $color = 'green';
} catch (Exception $ex) {
- $errors[] = pht('Failed to add %s %s', $username, $ex->getMessage());
+ $header = pht('Failed to add %s', $username);
+ $attribute = $ex->getMessage();
+ $color = 'red';
}
+
+ $item = id(new PhabricatorObjectItemView())
+ ->setHeader($header)
+ ->addAttribute($attribute)
+ ->setBarColor($color);
+
+ $list->addItem($item);
}
- $panel->setErrors($errors);
- return $panel;
+ return array(
+ $notice_view,
+ $list,
+ );
}
private function processSearchRequest($request) {
$panel = new AphrontPanelView();
$admin = $request->getUser();
$username = $request->getStr('username');
$password = $request->getStr('password');
$search = $request->getStr('query');
try {
$ldap_provider = new PhabricatorLDAPProvider();
$envelope = new PhutilOpaqueEnvelope($password);
$ldap_provider->auth($username, $envelope);
$results = $ldap_provider->search($search);
foreach ($results as $key => $result) {
$results[$key][] = $this->renderUserInputs($result);
}
$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);
} catch (Exception $ex) {
$error_view = new AphrontErrorView();
$error_view->setTitle(pht('LDAP Search Failed'));
$error_view->setErrors(array($ex->getMessage()));
return $error_view;
}
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],
)));
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Jan 19 2025, 12:09 (4 w, 2 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1124415
Default Alt Text
(6 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment