diff options
author | Marcin Łojewski <marcin.lojewski@mlojewski.me> | 2019-10-08 21:58:22 +0300 |
---|---|---|
committer | Marcin Łojewski <marcin.lojewski@mlojewski.me> | 2019-10-08 21:58:22 +0300 |
commit | 34a0c65be65ed0a7352c0bb2f2161e76df975cbb (patch) | |
tree | 0f518daa3565d2336d5ef5b5cc0948f482921acb | |
parent | a8e8e535382201ce14dff39cab0b79f7068c6d88 (diff) |
Name sync option
-rw-r--r-- | CHANGELOG.md | 12 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | lib/Action/EmailSync.php | 7 | ||||
-rw-r--r-- | lib/Action/NameSync.php | 43 | ||||
-rw-r--r-- | lib/Backend/UserBackend.php | 5 | ||||
-rw-r--r-- | lib/Constant/Opt.php | 1 | ||||
-rw-r--r-- | templates/admin.php | 1 |
7 files changed, 57 insertions, 14 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index f5babed..790bef7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,12 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Users can confirm passwords - Support Nextcloud password_policy -- Extend user/group search - Support for Nextcloud 18 -- Do not include users which are disabled +- Name sync option ### Fixed - Getting user display names backend +- Do not include users which are disabled + +### Changed +- Extend user/group search ## [4.3.0] - 2018-12-30 ### Added @@ -30,9 +33,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Added - Support for Nextcloud 15 - Redmine, SHA-256, SHA-512 hash algorithms + ### Fixed - Loading user list when display name is null - Hide "password change form" when "Allow password change" not set + ### Changed - Append salt only when checked. Not by default @@ -42,6 +47,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - 'Prepend salt' toggle - Drupal 7 hash algorithm - 'Case-insensitive username' option + ### Fixed - Error when 'Display name' not set - Encoding of iteration for 'Extended DES (Crypt)' @@ -62,8 +68,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. ### Changed - Example SQL script in README file - Fixed misspelling - -### Changed - Support for Nextcloud 14 only - Group backend implementation - User backend implementation @@ -54,6 +54,7 @@ Name | Description | Details **Reverse active column** | Reverse value of active column in user table. | Optional.<br/>Default: false. **Use cache** | Use database query results cache. The cache can be cleared any time with the *Clear cache* button click. | Optional.<br/>Default: false. **Hash algorithm** | How users passwords are stored in the database. See [Hash algorithms](#hash-algorithms). | Mandatory. +**Name sync** | Sync display name with the Nextcloud.<br/>- *None* - Disables this feature. This is the default option.<br/>- *Synchronise only once* - Copy the display name to the Nextcloud preferences if its not set.<br/>- *Nextcloud always wins* - Always copy the display name to the database. This updates the user table.<br/>- *SQL always wins* - Always copy the display name to the Nextcloud preferences. | Optional.<br/>Default: *None*.<br/>Requires: user *Display name* column. **Email sync** | Sync e-mail address with the Nextcloud.<br/>- *None* - Disables this feature. This is the default option.<br/>- *Synchronise only once* - Copy the e-mail address to the Nextcloud preferences if its not set.<br/>- *Nextcloud always wins* - Always copy the e-mail address to the database. This updates the user table.<br/>- *SQL always wins* - Always copy the e-mail address to the Nextcloud preferences. | Optional.<br/>Default: *None*.<br/>Requires: user *Email* column. **Quota sync** | Sync user quota with the Nextcloud.<br/>- *None* - Disables this feature. This is the default option.<br/>- *Synchronise only once* - Copy the user quota to the Nextcloud preferences if its not set.<br/>- *Nextcloud always wins* - Always copy the user quota to the database. This updates the user table.<br/>- *SQL always wins* - Always copy the user quota to the Nextcloud preferences. | Optional.<br/>Default: *None*.<br/>Requires: user *Quota* column. **Home mode** | User storage path.<br/>- *Default* - Let the Nextcloud manage this. The default option.<br/>- *Query* - Use location from the user table pointed by the *home* column.<br/>- *Static* - Use static location pointed by the *Home Location* option. | Optional<br/>Default: *Default*. @@ -123,6 +124,7 @@ CREATE TABLE sql_user home TEXT NULL, password TEXT NOT NULL, active TINYINT(1) NOT NULL DEFAULT '1', + disabled TINYINT(1) NOT NULL DEFAULT '0', provide_avatar BOOLEAN NOT NULL DEFAULT FALSE, salt TEXT NULL ); diff --git a/lib/Action/EmailSync.php b/lib/Action/EmailSync.php index e8b68ea..2a6eb48 100644 --- a/lib/Action/EmailSync.php +++ b/lib/Action/EmailSync.php @@ -99,6 +99,9 @@ class EmailSync implements IUserAction $this->config->setUserValue( $user->uid, "settings", "email", $user->email ); + \OC::$server->getUserManager()->get($user->uid)->triggerChange( + 'eMailAddress', $user->email, null + ); } $result = true; @@ -120,7 +123,9 @@ class EmailSync implements IUserAction $this->config->setUserValue( $user->uid, "settings", "email", $user->email ); - \OC::$server->getUserManager()->get($user->uid)->triggerChange('eMailAddress', $user->email, null); + \OC::$server->getUserManager()->get($user->uid)->triggerChange( + 'eMailAddress', $user->email, null + ); } $result = true; diff --git a/lib/Action/NameSync.php b/lib/Action/NameSync.php index 3005c0e..caf6987 100644 --- a/lib/Action/NameSync.php +++ b/lib/Action/NameSync.php @@ -93,15 +93,44 @@ class NameSync implements IUserAction $result = false; - if (!empty($user->name) && $user->name !== $ncName) { - $this->config->setUserValue( - $user->uid, "settings", "displayName", $user->name - ); - \OC::$server->getUserManager()->get($user->uid)->triggerChange('displayName', $user->name, null); - } + switch ($this->properties[Opt::NAME_SYNC]) { + case App::SYNC_INITIAL: + if (empty($ncName) && !empty($user->name)) { + $this->config->setUserValue( + $user->uid, "settings", "displayName", $user->name + ); + \OC::$server->getUserManager()->get($user->uid)->triggerChange( + 'displayName', $user->name, null + ); + } + + $result = true; + break; + case App::SYNC_FORCE_NC: + if (!empty($ncName) && $user->name !== $ncName) { + $user = $this->userRepository->findByUid($user->uid); + if (!($user instanceof User)) { + break; + } - $result = true; + $user->name = $ncName; + $result = $this->userRepository->save($user, UserRepository::DISPLAY_NAME_FIELD); + } + break; + case App::SYNC_FORCE_SQL: + if (!empty($user->name) && $user->name !== $ncName) { + $this->config->setUserValue( + $user->uid, "settings", "displayName", $user->name + ); + \OC::$server->getUserManager()->get($user->uid)->triggerChange( + 'displayName', $user->name, null + ); + } + + $result = true; + break; + } $this->logger->debug( "Returning NameSync#doAction($user->uid): " . ($result ? "true" diff --git a/lib/Backend/UserBackend.php b/lib/Backend/UserBackend.php index 99c860b..22dc213 100644 --- a/lib/Backend/UserBackend.php +++ b/lib/Backend/UserBackend.php @@ -24,8 +24,8 @@ namespace OCA\UserSQL\Backend; use OC\User\Backend; use OCA\UserSQL\Action\EmailSync; use OCA\UserSQL\Action\IUserAction; -use OCA\UserSQL\Action\QuotaSync; use OCA\UserSQL\Action\NameSync; +use OCA\UserSQL\Action\QuotaSync; use OCA\UserSQL\Cache; use OCA\UserSQL\Constant\App; use OCA\UserSQL\Constant\DB; @@ -152,7 +152,8 @@ final class UserBackend extends ABackend implements $this->userRepository ); } - if (!empty($this->properties[DB::USER_NAME_COLUMN]) + if (!empty($this->properties[Opt::NAME_SYNC]) + && !empty($this->properties[DB::USER_NAME_COLUMN]) ) { $this->actions[] = new NameSync( $this->appName, $this->logger, $this->properties, $this->config, diff --git a/lib/Constant/Opt.php b/lib/Constant/Opt.php index 9be2eb0..3edd4ad 100644 --- a/lib/Constant/Opt.php +++ b/lib/Constant/Opt.php @@ -38,6 +38,7 @@ final class Opt const HOME_LOCATION = "opt.home_location"; const HOME_MODE = "opt.home_mode"; const NAME_CHANGE = "opt.name_change"; + const NAME_SYNC = "opt.name_sync"; const PASSWORD_CHANGE = "opt.password_change"; const PREPEND_SALT = "opt.prepend_salt"; const PROVIDE_AVATAR = "opt.provide_avatar"; diff --git a/templates/admin.php b/templates/admin.php index a5c7c34..f88decd 100644 --- a/templates/admin.php +++ b/templates/admin.php @@ -138,6 +138,7 @@ function print_select_options( </div> <fieldset id="opt-crypto_params_content" class="inner-fieldset" style="display: none"></fieldset> <?php + print_select_options($l, "opt-name_sync", "Name sync", ["" => "None", "initial" => "Synchronise only once", "force_nc"=>"Nextcloud always wins", "force_sql"=>"SQL always wins"], $_["opt.name_sync"]); print_select_options($l, "opt-email_sync", "Email sync", ["" => "None", "initial" => "Synchronise only once", "force_nc"=>"Nextcloud always wins", "force_sql"=>"SQL always wins"], $_["opt.email_sync"]); print_select_options($l, "opt-quota_sync", "Quota sync", ["" => "None", "initial" => "Synchronise only once", "force_nc"=>"Nextcloud always wins", "force_sql"=>"SQL always wins"], $_["opt.quota_sync"]); print_select_options($l, "opt-home_mode", "Home mode", ["" => "Default", "query" => "Query", "static" => "Static"], $_["opt.home_mode"]); |