Skip to content

Commit a8e8e53

Browse files
authored
Merge pull request #113 from Isolus/propagate
fix for email and display name sync
2 parents b7a7ede + 41bf081 commit a8e8e53

3 files changed

Lines changed: 123 additions & 0 deletions

File tree

lib/Action/EmailSync.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ public function doAction(User $user)
120120
$this->config->setUserValue(
121121
$user->uid, "settings", "email", $user->email
122122
);
123+
\OC::$server->getUserManager()->get($user->uid)->triggerChange('eMailAddress', $user->email, null);
123124
}
124125

125126
$result = true;

lib/Action/NameSync.php

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
<?php
2+
/**
3+
* Nextcloud - user_sql
4+
*
5+
* @copyright 2019 Björn Kinscher <dev@bjoern-kinscher.de>
6+
* @author Björn Kinscher <dev@bjoern-kinscher.de>
7+
*
8+
* This program is free software: you can redistribute it and/or modify
9+
* it under the terms of the GNU Affero General Public License as
10+
* published by the Free Software Foundation, either version 3 of the
11+
* License, or (at your option) any later version.
12+
*
13+
* This program is distributed in the hope that it will be useful,
14+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16+
* GNU Affero General Public License for more details.
17+
*
18+
* You should have received a copy of the GNU Affero General Public License
19+
* along with this program. If not, see <https://www.gnu.org/licenses/>.
20+
*/
21+
22+
namespace OCA\UserSQL\Action;
23+
24+
use OCA\UserSQL\Constant\App;
25+
use OCA\UserSQL\Constant\Opt;
26+
use OCA\UserSQL\Model\User;
27+
use OCA\UserSQL\Properties;
28+
use OCA\UserSQL\Repository\UserRepository;
29+
use OCP\IConfig;
30+
use OCP\ILogger;
31+
32+
/**
33+
* Synchronizes the user name.
34+
*
35+
* @author Björn Kinscher <dev@bjoern-kinscher.de>
36+
*/
37+
class NameSync implements IUserAction
38+
{
39+
/**
40+
* @var string The application name.
41+
*/
42+
private $appName;
43+
/**
44+
* @var ILogger The logger instance.
45+
*/
46+
private $logger;
47+
/**
48+
* @var Properties The properties array.
49+
*/
50+
private $properties;
51+
/**
52+
* @var IConfig The config instance.
53+
*/
54+
private $config;
55+
/**
56+
* @var UserRepository The user repository.
57+
*/
58+
private $userRepository;
59+
60+
/**
61+
* The default constructor.
62+
*
63+
* @param string $appName The application name.
64+
* @param ILogger $logger The logger instance.
65+
* @param Properties $properties The properties array.
66+
* @param IConfig $config The config instance.
67+
* @param UserRepository $userRepository The user repository.
68+
*/
69+
public function __construct(
70+
$appName, ILogger $logger, Properties $properties, IConfig $config,
71+
UserRepository $userRepository
72+
) {
73+
$this->appName = $appName;
74+
$this->logger = $logger;
75+
$this->properties = $properties;
76+
$this->config = $config;
77+
$this->userRepository = $userRepository;
78+
}
79+
80+
/**
81+
* @inheritdoc
82+
* @throws \OCP\PreConditionNotMetException
83+
*/
84+
public function doAction(User $user)
85+
{
86+
$this->logger->debug(
87+
"Entering NameSync#doAction($user->uid)", ["app" => $this->appName]
88+
);
89+
90+
$ncName = $this->config->getUserValue(
91+
$user->uid, "settings", "displayName", ""
92+
);
93+
94+
$result = false;
95+
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+
}
102+
103+
$result = true;
104+
105+
106+
$this->logger->debug(
107+
"Returning NameSync#doAction($user->uid): " . ($result ? "true"
108+
: "false"),
109+
["app" => $this->appName]
110+
);
111+
112+
return $result;
113+
}
114+
}

lib/Backend/UserBackend.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
use OCA\UserSQL\Action\EmailSync;
2626
use OCA\UserSQL\Action\IUserAction;
2727
use OCA\UserSQL\Action\QuotaSync;
28+
use OCA\UserSQL\Action\NameSync;
2829
use OCA\UserSQL\Cache;
2930
use OCA\UserSQL\Constant\App;
3031
use OCA\UserSQL\Constant\DB;
@@ -151,6 +152,13 @@ private function initActions()
151152
$this->userRepository
152153
);
153154
}
155+
if (!empty($this->properties[DB::USER_NAME_COLUMN])
156+
) {
157+
$this->actions[] = new NameSync(
158+
$this->appName, $this->logger, $this->properties, $this->config,
159+
$this->userRepository
160+
);
161+
}
154162
}
155163

156164
/**

0 commit comments

Comments
 (0)