Update files to PSR-2 standards
This commit is contained in:
parent
d640cc1eee
commit
37aa8b05f8
|
@ -100,7 +100,7 @@ class LoginController extends Controller
|
|||
// ldap groups refresh
|
||||
if (config('services.ldap.user_to_groups') !== false && $request->filled('username')) {
|
||||
$ldapRepo = new LdapRepo($this->userRepo);
|
||||
$ldapRepo->syncGroups($user,$request->input('username'));
|
||||
$ldapRepo->syncGroups($user, $request->input('username'));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -38,7 +38,7 @@ class LdapRepo
|
|||
return null;
|
||||
}
|
||||
|
||||
return call_user_func_array(array($this,$method),$arguments);
|
||||
return call_user_func_array(array($this,$method), $arguments);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -47,12 +47,12 @@ class LdapRepo
|
|||
* @param string $userName
|
||||
* @throws \BookStack\Exceptions\NotFoundException
|
||||
*/
|
||||
public function syncGroups($user,$userName)
|
||||
public function syncGroups($user, $userName)
|
||||
{
|
||||
$userLdapGroups = $this->ldapService->getUserGroups($userName);
|
||||
$userLdapGroups = $this->groupNameFilter($userLdapGroups);
|
||||
// get the ids for the roles from the names
|
||||
$ldapGroupsAsRoles = Role::whereIn('name',$userLdapGroups)->pluck('id');
|
||||
$ldapGroupsAsRoles = Role::whereIn('name', $userLdapGroups)->pluck('id');
|
||||
// sync groups
|
||||
if ($this->config['remove_from_groups']) {
|
||||
$user->roles()->sync($ldapGroupsAsRoles);
|
||||
|
@ -62,8 +62,8 @@ class LdapRepo
|
|||
}
|
||||
|
||||
// make the user an admin?
|
||||
if (in_array($this->config['admin'],$userLdapGroups)) {
|
||||
$this->userRepo->attachSystemRole($user,'admin');
|
||||
if (in_array($this->config['admin'], $userLdapGroups)) {
|
||||
$this->userRepo->attachSystemRole($user, 'admin');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ class LdapService
|
|||
* @return null|array
|
||||
* @throws LdapException
|
||||
*/
|
||||
private function getUserWithAttributes($userName,$attributes)
|
||||
private function getUserWithAttributes($userName, $attributes)
|
||||
{
|
||||
$ldapConnection = $this->getConnection();
|
||||
$this->bindSystemUser($ldapConnection);
|
||||
|
@ -196,7 +196,7 @@ class LdapService
|
|||
}
|
||||
|
||||
$userGroups = $this->groupFilter($user);
|
||||
$userGroups = $this->getGroupsRecursive($userGroups,[]);
|
||||
$userGroups = $this->getGroupsRecursive($userGroups, []);
|
||||
return $userGroups;
|
||||
}
|
||||
|
||||
|
@ -206,19 +206,22 @@ class LdapService
|
|||
* @param array $checked
|
||||
* @return array
|
||||
*/
|
||||
private function getGroupsRecursive($groupsArray,$checked) {
|
||||
private function getGroupsRecursive($groupsArray, $checked)
|
||||
{
|
||||
$groups_to_add = [];
|
||||
foreach ($groupsArray as $groupName) {
|
||||
if (in_array($groupName,$checked)) continue;
|
||||
if (in_array($groupName, $checked)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$groupsToAdd = $this->getGroupGroups($groupName);
|
||||
$groups_to_add = array_merge($groups_to_add,$groupsToAdd);
|
||||
$groups_to_add = array_merge($groups_to_add, $groupsToAdd);
|
||||
$checked[] = $groupName;
|
||||
}
|
||||
$groupsArray = array_unique(array_merge($groupsArray,$groups_to_add), SORT_REGULAR);
|
||||
$groupsArray = array_unique(array_merge($groupsArray, $groups_to_add), SORT_REGULAR);
|
||||
|
||||
if (!empty($groups_to_add)) {
|
||||
return $this->getGroupsRecursive($groupsArray,$checked);
|
||||
return $this->getGroupsRecursive($groupsArray, $checked);
|
||||
} else {
|
||||
return $groupsArray;
|
||||
}
|
||||
|
@ -260,14 +263,15 @@ class LdapService
|
|||
$groupsAttr = strtolower($this->config['group_attribute']);
|
||||
$ldapGroups = [];
|
||||
$count = 0;
|
||||
if (isset($ldapSearchReturn[$groupsAttr]['count'])) $count = (int) $ldapSearchReturn[$groupsAttr]['count'];
|
||||
for ($i=0;$i<$count;$i++) {
|
||||
$dnComponents = ldap_explode_dn($ldapSearchReturn[$groupsAttr][$i],1);
|
||||
if (!in_array($dnComponents[0],$ldapGroups)) {
|
||||
if (isset($ldapSearchReturn[$groupsAttr]['count'])) {
|
||||
$count = (int) $ldapSearchReturn[$groupsAttr]['count'];
|
||||
}
|
||||
for ($i=0; $i<$count; $i++) {
|
||||
$dnComponents = ldap_explode_dn($ldapSearchReturn[$groupsAttr][$i], 1);
|
||||
if (!in_array($dnComponents[0], $ldapGroups)) {
|
||||
$ldapGroups[] = $dnComponents[0];
|
||||
}
|
||||
}
|
||||
return $ldapGroups;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue