Skip to content

Commit

Permalink
Move responsibility for adding new users in to the user directory
Browse files Browse the repository at this point in the history
Relates to: #55
  • Loading branch information
thomas-pike committed Nov 7, 2021
1 parent 946c6ff commit 1788054
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
10 changes: 7 additions & 3 deletions model/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ public function check_csrf_token($token) {
* @throws UserNotFoundException if the user is not found in LDAP
*/
public function get_details_from_ldap() {
global $config, $group_dir;
global $config, $group_dir, $user_dir;
$attributes = array();
$attributes[] = 'dn';
$attributes[] = $config['ldap']['user_id'];
Expand All @@ -324,13 +324,18 @@ public function get_details_from_ldap() {
} else {
$this->active = 1;
}
$this->admin = 0;
$group_member = $ldapuser[strtolower($config['ldap']['group_member_value'])];
$ldapgroups = $this->ldap->search($config['ldap']['dn_group'], LDAP::escape($config['ldap']['group_member']).'='.LDAP::escape($group_member), array('cn'));
$memberships = array();
foreach($ldapgroups as $ldapgroup) {
$memberships[$ldapgroup['cn']] = true;
}
$this->admin = isset($memberships[$config['ldap']['admin_group_cn']]);
if(isset($this->id)) {
$this->update();
} else {
$user_dir->add_user($this);
}
if(isset($config['ldap']['sync_groups']) && is_array($config['ldap']['sync_groups'])) {
$syncgroups = $config['ldap']['sync_groups'];
} else {
Expand All @@ -347,7 +352,6 @@ public function get_details_from_ldap() {
$group_dir->add_group($group);
}
if(isset($memberships[$syncgroup])) {
if($syncgroup == $config['ldap']['admin_group_cn']) $this->admin = 1;
if(!$this->member_of($group)) {
$group->add_member($this);
}
Expand Down
1 change: 0 additions & 1 deletion model/userdirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ public function get_user_by_uid($uid) {
$user->uid = $uid;
$this->cache_uid[$uid] = $user;
$user->get_details_from_ldap();
$this->add_user($user);
}
$stmt->close();
return $user;
Expand Down
1 change: 0 additions & 1 deletion scripts/ldap_update.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
$active = $user->active;
try {
$user->get_details_from_ldap();
$user->update();
if(isset($config['ldap']['user_superior'])) {
$user->get_superior_from_ldap();
}
Expand Down
1 change: 0 additions & 1 deletion views/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
} elseif(isset($_POST['edit_user']) && $active_user->admin) {
$user->force_disable = $_POST['force_disable'];
$user->get_details_from_ldap();
$user->update();
redirect('#settings');
} else {
$content = new PageSection('user');
Expand Down

0 comments on commit 1788054

Please sign in to comment.