diff --git a/include/simpleplugin/class_simplePlugin.inc b/include/simpleplugin/class_simplePlugin.inc index ce0481daf6c3f6becaa1fb4db49ee2236a594a3a..e93ed9aa43c6be833a41d2abd8581177298f68dc 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 = []; + // Thisb bolean allows children class to get readOnly automatically via static state or class-level state. + private static $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 68cd5254431c604563a7cadf1e3c46bfbded22b8..91074042bb3d250b5e1c7d9cdc16a445f6eddfe6 100644 --- a/plugins/personal/generic/class_user.inc +++ b/plugins/personal/generic/class_user.inc @@ -45,25 +45,26 @@ 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 { return [ - 'plShortName' => _('User'), + 'plShortName' => _('User'), 'plDescription' => _('User account information'), - 'plIcon' => 'geticon.php?context=applications&icon=user-info&size=48', - 'plSmallIcon' => 'geticon.php?context=applications&icon=user-info&size=16', - 'plSelfModify' => TRUE, + 'plIcon' => 'geticon.php?context=applications&icon=user-info&size=48', + 'plSmallIcon' => 'geticon.php?context=applications&icon=user-info&size=16', + 'plSelfModify' => TRUE, 'plObjectClass' => ['inetOrgPerson', 'organizationalPerson', 'person'], - 'plFilter' => '(objectClass=inetOrgPerson)', - 'plObjectType' => ['user' => [ - 'name' => _('User'), + 'plFilter' => '(objectClass=inetOrgPerson)', + 'plObjectType' => ['user' => [ + 'name' => _('User'), 'description' => _('User account'), - 'mainAttr' => 'uid', - 'nameAttr' => 'cn', - 'icon' => 'geticon.php?context=types&icon=user&size=16', - 'ou' => get_ou('userRDN'), + 'mainAttr' => 'uid', + 'nameAttr' => 'cn', + 'icon' => 'geticon.php?context=types&icon=user&size=16', + 'ou' => get_ou('userRDN'), ]], 'plForeignKeys' => [ 'manager' => ['user', 'dn', 'manager=%oldvalue%', '*'] @@ -84,9 +85,9 @@ class user extends simplePlugin asort($languages); $languages = array_merge(['' => ''], $languages); $attributesInfo = [ - 'perso' => [ - 'name' => _('Personal information'), - 'icon' => 'geticon.php?context=types&icon=user&size=16', + 'perso' => [ + 'name' => _('Personal information'), + 'icon' => 'geticon.php?context=types&icon=user&size=16', 'attrs' => [ new HiddenAttribute('cn'), new StringAttribute( @@ -115,9 +116,9 @@ class user extends simplePlugin ), ] ], - 'contact' => [ - 'name' => _('Organizational contact information'), - 'icon' => 'geticon.php?context=types&icon=user&size=16', + 'contact' => [ + 'name' => _('Organizational contact information'), + 'icon' => 'geticon.php?context=types&icon=user&size=16', 'attrs' => [ new StringAttribute( _('Location'), _('Location'), @@ -161,9 +162,9 @@ class user extends simplePlugin ), ] ], - 'account' => [ - 'name' => _('Account information'), - 'icon' => 'geticon.php?context=applications&icon=ldap&size=16', + 'account' => [ + 'name' => _('Account information'), + 'icon' => 'geticon.php?context=applications&icon=ldap&size=16', 'attrs' => [ new BaseSelectorAttribute(get_ou("userRDN")), new UidAttribute( @@ -181,9 +182,9 @@ class user extends simplePlugin ), ] ], - 'homecontact' => [ - 'name' => _('Personal contact information'), - 'icon' => 'geticon.php?context=types&icon=user&size=16', + 'homecontact' => [ + 'name' => _('Personal contact information'), + 'icon' => 'geticon.php?context=types&icon=user&size=16', 'attrs' => [ new StringAttribute( _('Display name'), _('Name this user should appear as. Used by Exchange.'), @@ -200,8 +201,8 @@ class user extends simplePlugin ] ], 'organization' => [ - 'name' => _('Organizational information'), - 'icon' => 'geticon.php?context=places&icon=folder&size=16', + 'name' => _('Organizational information'), + 'icon' => 'geticon.php?context=places&icon=folder&size=16', 'attrs' => [ new SetAttribute( new StringAttribute( @@ -262,6 +263,15 @@ 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%'); } @@ -273,7 +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(); + // 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') {