mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-27 09:12:41 +01:00
Refactor methods, fix style issues
This commit is contained in:
parent
51d2d06e37
commit
42dfee38e7
2 changed files with 40 additions and 67 deletions
|
@ -25,47 +25,16 @@ final class PhabricatorPeopleLdapController
|
|||
|
||||
private $view;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->view = idx($data, 'view');
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$admin = $request->getUser();
|
||||
|
||||
$base_uri = '/people/edit/';
|
||||
|
||||
$content = array();
|
||||
|
||||
|
||||
$response = $this->processBasicRequest();
|
||||
|
||||
if ($response instanceof AphrontResponse) {
|
||||
return $response;
|
||||
}
|
||||
|
||||
$content[] = $response;
|
||||
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$content,
|
||||
array(
|
||||
'title' => 'Import Ldap Users',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Displays a ldap login form, as we need to auth before we can search
|
||||
*/
|
||||
private function processBasicRequest() {
|
||||
$panels = array();
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$admin = $request->getUser();
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setAction($request->getRequestURI()
|
||||
->alter('search', 'true')->alter('import', null))
|
||||
->setUser($admin)
|
||||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
|
@ -78,8 +47,8 @@ final class PhabricatorPeopleLdapController
|
|||
->appendChild(
|
||||
id(new AphrontFormTextControl())
|
||||
->setLabel('LDAP query')
|
||||
->setCaption('A filter such as (objectClass=*)')
|
||||
->setName('query'))
|
||||
->setAction($request->getRequestURI()->alter('search', 'true')->alter('import', null))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue('Search'));
|
||||
|
@ -90,17 +59,20 @@ final class PhabricatorPeopleLdapController
|
|||
|
||||
|
||||
if ($request->getStr('import')) {
|
||||
$panels[] = $this->processImportRequest($request);
|
||||
$content[] = $this->processImportRequest($request);
|
||||
}
|
||||
|
||||
$panels[] = $panel;
|
||||
$content[] = $panel;
|
||||
|
||||
if ($request->getStr('search')) {
|
||||
$panels[] = $this->processSearchRequest($request);
|
||||
$content[] = $this->processSearchRequest($request);
|
||||
}
|
||||
|
||||
return $panels;
|
||||
|
||||
return $this->buildStandardPageResponse(
|
||||
$content,
|
||||
array(
|
||||
'title' => 'Import Ldap Users',
|
||||
));
|
||||
}
|
||||
|
||||
private function processImportRequest($request) {
|
||||
|
@ -112,7 +84,7 @@ final class PhabricatorPeopleLdapController
|
|||
$panel = new AphrontErrorView();
|
||||
$panel->setSeverity(AphrontErrorView::SEVERITY_NOTICE);
|
||||
$panel->setTitle("Import Successful");
|
||||
$errors = array("Successfully imported users from ldap");
|
||||
$errors = array("Successfully imported users from LDAP");
|
||||
|
||||
|
||||
foreach ($usernames as $username) {
|
||||
|
@ -132,7 +104,7 @@ final class PhabricatorPeopleLdapController
|
|||
$ldap_info->setLDAPUsername($username);
|
||||
$ldap_info->setUserID($user->getID());
|
||||
$ldap_info->save();
|
||||
$errors[] = 'Succesfully added ' . $username;
|
||||
$errors[] = 'Successfully added ' . $username;
|
||||
} catch (Exception $ex) {
|
||||
$errors[] = 'Failed to add ' . $username . ' ' . $ex->getMessage();
|
||||
}
|
||||
|
@ -153,9 +125,9 @@ final class PhabricatorPeopleLdapController
|
|||
$search = $request->getStr('query');
|
||||
|
||||
try {
|
||||
$ldapProvider = new PhabricatorLDAPProvider();
|
||||
$ldapProvider->auth($username, $password);
|
||||
$results = $ldapProvider->search($search);
|
||||
$ldap_provider = new PhabricatorLDAPProvider();
|
||||
$ldap_provider->auth($username, $password);
|
||||
$results = $ldap_provider->search($search);
|
||||
foreach ($results as $key => $result) {
|
||||
$results[$key][] = $this->renderUserInputs($result);
|
||||
}
|
||||
|
@ -172,7 +144,8 @@ final class PhabricatorPeopleLdapController
|
|||
'',
|
||||
));
|
||||
$form->appendChild($table);
|
||||
$form->setAction($request->getRequestURI()->alter('import', 'true')->alter('search', null))
|
||||
$form->setAction($request->getRequestURI()
|
||||
->alter('import', 'true')->alter('search', null))
|
||||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue('Import'));
|
||||
|
|
|
@ -135,7 +135,7 @@ final class PhabricatorPeopleListController
|
|||
phutil_render_tag(
|
||||
'a',
|
||||
array(
|
||||
'href' => '/people/ldap',
|
||||
'href' => '/people/ldap/',
|
||||
'class' => 'button green'
|
||||
),
|
||||
'Import from Ldap'));
|
||||
|
|
Loading…
Reference in a new issue