Skip to content

Commit 34a0c65

Browse files
committed
Name sync option
1 parent a8e8e53 commit 34a0c65

7 files changed

Lines changed: 57 additions & 14 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,15 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
88
### Added
99
- Users can confirm passwords
1010
- Support Nextcloud password_policy
11-
- Extend user/group search
1211
- Support for Nextcloud 18
13-
- Do not include users which are disabled
12+
- Name sync option
1413

1514
### Fixed
1615
- Getting user display names backend
16+
- Do not include users which are disabled
17+
18+
### Changed
19+
- Extend user/group search
1720

1821
## [4.3.0] - 2018-12-30
1922
### Added
@@ -30,9 +33,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
3033
### Added
3134
- Support for Nextcloud 15
3235
- Redmine, SHA-256, SHA-512 hash algorithms
36+
3337
### Fixed
3438
- Loading user list when display name is null
3539
- Hide "password change form" when "Allow password change" not set
40+
3641
### Changed
3742
- Append salt only when checked. Not by default
3843

@@ -42,6 +47,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
4247
- 'Prepend salt' toggle
4348
- Drupal 7 hash algorithm
4449
- 'Case-insensitive username' option
50+
4551
### Fixed
4652
- Error when 'Display name' not set
4753
- 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.
6268
### Changed
6369
- Example SQL script in README file
6470
- Fixed misspelling
65-
66-
### Changed
6771
- Support for Nextcloud 14 only
6872
- Group backend implementation
6973
- User backend implementation

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Name | Description | Details
5454
**Reverse active column** | Reverse value of active column in user table. | Optional.<br/>Default: false.
5555
**Use cache** | Use database query results cache. The cache can be cleared any time with the *Clear cache* button click. | Optional.<br/>Default: false.
5656
**Hash algorithm** | How users passwords are stored in the database. See [Hash algorithms](#hash-algorithms). | Mandatory.
57+
**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.
5758
**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.
5859
**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.
5960
**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
123124
home TEXT NULL,
124125
password TEXT NOT NULL,
125126
active TINYINT(1) NOT NULL DEFAULT '1',
127+
disabled TINYINT(1) NOT NULL DEFAULT '0',
126128
provide_avatar BOOLEAN NOT NULL DEFAULT FALSE,
127129
salt TEXT NULL
128130
);

lib/Action/EmailSync.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ public function doAction(User $user)
9999
$this->config->setUserValue(
100100
$user->uid, "settings", "email", $user->email
101101
);
102+
\OC::$server->getUserManager()->get($user->uid)->triggerChange(
103+
'eMailAddress', $user->email, null
104+
);
102105
}
103106

104107
$result = true;
@@ -120,7 +123,9 @@ public function doAction(User $user)
120123
$this->config->setUserValue(
121124
$user->uid, "settings", "email", $user->email
122125
);
123-
\OC::$server->getUserManager()->get($user->uid)->triggerChange('eMailAddress', $user->email, null);
126+
\OC::$server->getUserManager()->get($user->uid)->triggerChange(
127+
'eMailAddress', $user->email, null
128+
);
124129
}
125130

126131
$result = true;

lib/Action/NameSync.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,44 @@ public function doAction(User $user)
9393

9494
$result = false;
9595

96-
if (!empty($user->name) && $user->name !== $ncName) {
97-
$this->config->setUserValue(
98-
$user->uid, "settings", "displayName", $user->name
99-
);
100-
\OC::$server->getUserManager()->get($user->uid)->triggerChange('displayName', $user->name, null);
101-
}
96+
switch ($this->properties[Opt::NAME_SYNC]) {
97+
case App::SYNC_INITIAL:
98+
if (empty($ncName) && !empty($user->name)) {
99+
$this->config->setUserValue(
100+
$user->uid, "settings", "displayName", $user->name
101+
);
102+
\OC::$server->getUserManager()->get($user->uid)->triggerChange(
103+
'displayName', $user->name, null
104+
);
105+
}
106+
107+
$result = true;
108+
break;
109+
case App::SYNC_FORCE_NC:
110+
if (!empty($ncName) && $user->name !== $ncName) {
111+
$user = $this->userRepository->findByUid($user->uid);
112+
if (!($user instanceof User)) {
113+
break;
114+
}
102115

103-
$result = true;
116+
$user->name = $ncName;
117+
$result = $this->userRepository->save($user, UserRepository::DISPLAY_NAME_FIELD);
118+
}
104119

120+
break;
121+
case App::SYNC_FORCE_SQL:
122+
if (!empty($user->name) && $user->name !== $ncName) {
123+
$this->config->setUserValue(
124+
$user->uid, "settings", "displayName", $user->name
125+
);
126+
\OC::$server->getUserManager()->get($user->uid)->triggerChange(
127+
'displayName', $user->name, null
128+
);
129+
}
130+
131+
$result = true;
132+
break;
133+
}
105134

106135
$this->logger->debug(
107136
"Returning NameSync#doAction($user->uid): " . ($result ? "true"

lib/Backend/UserBackend.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
use OC\User\Backend;
2525
use OCA\UserSQL\Action\EmailSync;
2626
use OCA\UserSQL\Action\IUserAction;
27-
use OCA\UserSQL\Action\QuotaSync;
2827
use OCA\UserSQL\Action\NameSync;
28+
use OCA\UserSQL\Action\QuotaSync;
2929
use OCA\UserSQL\Cache;
3030
use OCA\UserSQL\Constant\App;
3131
use OCA\UserSQL\Constant\DB;
@@ -152,7 +152,8 @@ private function initActions()
152152
$this->userRepository
153153
);
154154
}
155-
if (!empty($this->properties[DB::USER_NAME_COLUMN])
155+
if (!empty($this->properties[Opt::NAME_SYNC])
156+
&& !empty($this->properties[DB::USER_NAME_COLUMN])
156157
) {
157158
$this->actions[] = new NameSync(
158159
$this->appName, $this->logger, $this->properties, $this->config,

lib/Constant/Opt.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ final class Opt
3838
const HOME_LOCATION = "opt.home_location";
3939
const HOME_MODE = "opt.home_mode";
4040
const NAME_CHANGE = "opt.name_change";
41+
const NAME_SYNC = "opt.name_sync";
4142
const PASSWORD_CHANGE = "opt.password_change";
4243
const PREPEND_SALT = "opt.prepend_salt";
4344
const PROVIDE_AVATAR = "opt.provide_avatar";

templates/admin.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ function print_select_options(
138138
</div>
139139
<fieldset id="opt-crypto_params_content" class="inner-fieldset" style="display: none"></fieldset>
140140
<?php
141+
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"]);
141142
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"]);
142143
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"]);
143144
print_select_options($l, "opt-home_mode", "Home mode", ["" => "Default", "query" => "Query", "static" => "Static"], $_["opt.home_mode"]);

0 commit comments

Comments
 (0)