Verified Commit 7b7a5218 authored by dockx thibault's avatar dockx thibault
Browse files

:sparkles: (User) - locking mechanism

Lock induces a read only for all tabs.
Showing with 22 additions and 6 deletions
+22 -6
...@@ -38,6 +38,8 @@ class simplePlugin implements SimpleTab ...@@ -38,6 +38,8 @@ class simplePlugin implements SimpleTab
* associative array that stores attributeLdapName => reference on object * associative array that stores attributeLdapName => reference on object
*/ */
public $attributesAccess = []; public $attributesAccess = [];
// This allows children class to get readOnly automatically via static state or class-level state
private static bool $user_locked = FALSE;
/*! /*!
\brief Mark plugin as account \brief Mark plugin as account
...@@ -158,6 +160,11 @@ class simplePlugin implements SimpleTab ...@@ -158,6 +160,11 @@ class simplePlugin implements SimpleTab
$this->parent = $parent; $this->parent = $parent;
$this->mainTab = $mainTab; $this->mainTab = $mainTab;
// This class-level state allows children to get readOnly automatically.
if (self::$user_locked) {
$this->read_only = true;
}
try { try {
$plInfo = pluglist::pluginInfos(get_class($this)); $plInfo = pluglist::pluginInfos(get_class($this));
} catch (UnknownClassException $e) { } catch (UnknownClassException $e) {
...@@ -299,6 +306,12 @@ class simplePlugin implements SimpleTab ...@@ -299,6 +306,12 @@ class simplePlugin implements SimpleTab
} }
} }
public static function setUserLocked(bool $locked): void
{
self::$user_locked = $locked;
}
protected function loadAttributes () protected function loadAttributes ()
{ {
// We load attributes values // We load attributes values
......
...@@ -45,6 +45,7 @@ class PostalAddressAttribute extends TextAreaAttribute ...@@ -45,6 +45,7 @@ class PostalAddressAttribute extends TextAreaAttribute
class user extends simplePlugin class user extends simplePlugin
{ {
// This is used to see if the password is locked. The "was" is better interpreted as "is" - it is historical here.
private $was_locked; private $was_locked;
static function plInfo (): array static function plInfo (): array
...@@ -262,6 +263,14 @@ class user extends simplePlugin ...@@ -262,6 +263,14 @@ class user extends simplePlugin
global $config; global $config;
parent::__construct($dn, $object, $parent, $mainTab); parent::__construct($dn, $object, $parent, $mainTab);
// verify if the attribute password is locked
$this->was_locked = $this->attributesAccess['userPassword']->isLocked();
if ($this->was_locked){
$this->read_only = TRUE;
// This will update the parent class (simplePlugin) via class-level state allowing children to get read only state.
self::setUserLocked(true);
}
if ($this->is_template && !$this->initially_was_account) { if ($this->is_template && !$this->initially_was_account) {
$this->attributesAccess['userPassword']->setValue('%askme%'); $this->attributesAccess['userPassword']->setValue('%askme%');
...@@ -274,13 +283,7 @@ class user extends simplePlugin ...@@ -274,13 +283,7 @@ class user extends simplePlugin
$filename = './plugins/users/images/default.jpg'; $filename = './plugins/users/images/default.jpg';
$fd = fopen($filename, 'rb'); $fd = fopen($filename, 'rb');
$this->attributesAccess['jpegPhoto']->setPlaceholder(fread($fd, filesize($filename))); $this->attributesAccess['jpegPhoto']->setPlaceholder(fread($fd, filesize($filename)));
$this->was_locked = $this->attributesAccess['userPassword']->isLocked();
if ($this->was_locked){
$this->read_only = TRUE;
$warning = new FusionDirectoryWarning(nl2br(htmlescape(sprintf(_("This user account is locked ! Unlock to edit first.")))));
$warning->display();
}
// Do not apply automatic snap on templates nor if the DN is not yet processed (new creation from template) // Do not apply automatic snap on templates nor if the DN is not yet processed (new creation from template)
if ($this->is_template !== TRUE && $this->dn !== 'new') { if ($this->is_template !== TRUE && $this->dn !== 'new') {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment