diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index ce0481daf6c3f6becaa1fb4db49ee2236a594a3a..ca45083d8ec48c0bacb777050a583289517e0edf 100644 --- a/include/simpleplugin/class_simplePlugin.inc +++ b/include/simpleplugin/class_simplePlugin.inc @@ -38,6 +38,8 @@ class simplePlugin implements SimpleTab * associative array that stores attributeLdapName => reference on object */ 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 @@ -158,6 +160,11 @@ class simplePlugin implements SimpleTab $this->parent = $parent; $this->mainTab = $mainTab; + // This class-level state allows children to get readOnly automatically. + if (self::$user_locked) { + $this->read_only = true; + } + try { $plInfo = pluglist::pluginInfos(get_class($this)); } catch (UnknownClassException $e) { @@ -299,6 +306,12 @@ class simplePlugin implements SimpleTab } } + + public static function setUserLocked(bool $locked): void + { + self::$user_locked = $locked; + } + protected function loadAttributes () { // We load attributes values diff --git a/plugins/personal/generic/class_user.inc b/plugins/personal/generic/class_user.inc index 8ddca7a4bdd65759175d32460f42451f0602e9bf..9ad6f87ff592f0ec71ed9a79003b40b71113e23b 100644 --- a/plugins/personal/generic/class_user.inc +++ b/plugins/personal/generic/class_user.inc @@ -45,6 +45,7 @@ class PostalAddressAttribute extends TextAreaAttribute 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; static function plInfo (): array @@ -262,6 +263,14 @@ class user extends simplePlugin global $config; 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) { $this->attributesAccess['userPassword']->setValue('%askme%'); @@ -274,13 +283,7 @@ class user extends simplePlugin $filename = './plugins/users/images/default.jpg'; $fd = fopen($filename, 'rb'); $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) if ($this->is_template !== TRUE && $this->dn !== 'new') {