Skip to content

Commit

Permalink
refactor(user): Update user_dn_hash directly in pre_addInDB/pre_updat…
Browse files Browse the repository at this point in the history
…eInDB
  • Loading branch information
ccailly committed Dec 21, 2023
1 parent 3618847 commit 70983fa
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,14 @@ public function computeCloneName(
);
}

public function pre_addInDB()
{
// Hash user_dn if set
if (isset($this->input['user_dn']) && is_string($this->input['user_dn']) && strlen($this->input['user_dn']) > 0) {
$this->input['user_dn_hash'] = md5($this->input['user_dn']);
}
}

public function post_addItem()
{

Expand Down Expand Up @@ -895,14 +903,6 @@ public function post_addItem()
$right->add($affectation);
}
}

// Hash user_dn if set
if (isset($this->input['user_dn']) && is_string($this->input['user_dn']) && strlen($this->input['user_dn']) > 0) {
$this->update([
'id' => $this->fields['id'],
'user_dn_hash' => md5($this->input['user_dn'])
]);
}
}


Expand Down Expand Up @@ -1198,18 +1198,8 @@ public function post_updateItem($history = true)
true
);
}

// Hash user_dn if is updated
if (in_array('user_dn', $this->updates)) {
$this->update([
'id' => $this->fields['id'],
'user_dn_hash' => is_string($this->fields['user_dn']) && strlen($this->fields['user_dn']) > 0 ? md5($this->fields['user_dn']) : null,
]);
}
}



/**
* Apply rules to determine dynamic rights of the user.
*
Expand Down Expand Up @@ -3504,6 +3494,12 @@ public function pre_updateInDB()
unset($this->oldvalues['comment']);
}
}

// Hash user_dn if is updated
if (in_array('user_dn', $this->updates)) {
$this->updates[] = 'user_dn_hash';
$this->fields['user_dn_hash'] = is_string($this->input['user_dn']) && strlen($this->input['user_dn']) > 0 ? md5($this->input['user_dn']) : null;
}
}

public function getSpecificMassiveActions($checkitem = null)
Expand Down

0 comments on commit 70983fa

Please sign in to comment.