Skip to content

Commit

Permalink
tweak(Admin/Import/User): add emailForwardOnly and generatePolicyConf…
Browse files Browse the repository at this point in the history
…ormPassword

- also adds docs for admin_user_import_csv_for_emailuser import definition
  • Loading branch information
pschuele committed Feb 25, 2025
1 parent 56b4ada commit c32204b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
17 changes: 15 additions & 2 deletions docs/admins/import/Import_Users.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tine Admin docs: Admin
tine Admin docs: Admin User Import
=================

Version: Pino 2022.11
Version: Pelle 2024.11

HowTo: set passwords for users
=================
Expand Down Expand Up @@ -39,3 +39,16 @@ Anastasia,Baleva,[email protected],abelava
~~~
method=Admin.importUser [-d] [-v] userlist.csv -- definition=admin_user_import_csv [password=PWFORALLNEWUSERS]
~~~

HowTo: import list of users with email data and autogenerated password
=================

userlist.csv:
~~~
lastname,email,emailForwards,emailForwardOnly
administrator,[email protected],[email protected] [email protected],1
~~~

~~~
method=Admin.importUser [-d] [-v] userlist.csv -- definition=admin_user_import_csv_for_emailuser.xml
~~~
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<headline>1</headline>
<dryrun>0</dryrun>
<extension>csv</extension>
<passwordGenerator>\Tinebase_User_PasswordPolicy::generatePolicyConformPassword</passwordGenerator>
<mapping>
<field>
<source>firstname</source>
Expand Down Expand Up @@ -35,5 +36,9 @@
<source>emailForwards</source>
<destination>emailForwards</destination>
</field>
<field>
<source>emailForwardOnly</source>
<destination>emailForwardOnly</destination>
</field>
</mapping>
</config>
10 changes: 9 additions & 1 deletion tine20/Tinebase/Model/FullUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,15 @@ public function applyOptionsAndGeneratePassword($options, $password = NULL)
} elseif (! empty($options['password'])) {
$userPassword = $options['password'];
} elseif (! empty($options['passwordGenerator']) && is_callable($options['passwordGenerator'])) {
$userPassword = $options['passwordGenerator']($this);
if (is_string($options['passwordGenerator']) && str_contains($options['passwordGenerator'],
'Tinebase_User_PasswordPolicy::generatePolicyConformPassword')
) {
// TODO maybe the default should be a function call without param? how can we detect this?
$userPassword = $options['passwordGenerator']();
} else {
// passwordGenerator function expects user as its param
$userPassword = $options['passwordGenerator']($this);
}
}

$this->_addEmailUser($userPassword);
Expand Down
2 changes: 1 addition & 1 deletion tine20/Tinebase/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ static public function createSystemUser(string $accountLoginName, Tinebase_Model
* @param int $upperCase
* @return string
*
* TODO should have a param "usePWPolicy"
* @deprecated replace with Tinebase_User_PasswordPolicy::generatePolicyConformPassword
*/
public static function generateRandomPassword($length = 12, $numSpecialChar = 1, $upperCase = 1)
{
Expand Down

0 comments on commit c32204b

Please sign in to comment.