Skip to content

Commit d1bdb8f

Browse files
authored
Merge pull request #1048 from bjalbor/feat/1047/user-provisioning-privacy-scopes
Fetch default privacy scopes and set properties appropriate
2 parents 02f052e + 802f2fe commit d1bdb8f

2 files changed

Lines changed: 19 additions & 10 deletions

File tree

lib/Service/ProvisioningService.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
namespace OCA\UserOIDC\Service;
99

10+
use OC\Accounts\AccountManager;
1011
use OCA\UserOIDC\AppInfo\Application;
1112
use OCA\UserOIDC\Db\UserMapper;
1213
use OCA\UserOIDC\Event\AttributeMappedEvent;
@@ -151,7 +152,12 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
151152
}
152153

153154
$account = $this->accountManager->getAccount($user);
154-
$scope = 'v2-local';
155+
$fallbackScope = 'v2-local';
156+
$defaultScopes = array_merge(
157+
AccountManager::DEFAULT_SCOPES,
158+
$this->config->getSystemValue('account_manager.default_property_scope', []) ?? []
159+
);
160+
155161

156162
// Update displayname
157163
if (isset($userName)) {
@@ -227,7 +233,7 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
227233
$this->eventDispatcher->dispatchTyped($event);
228234
$this->logger->debug('Phone mapping event dispatched');
229235
if ($event->hasValue()) {
230-
$account->setProperty('phone', $event->getValue(), $scope, '1', '');
236+
$account->setProperty('phone', $event->getValue(), $defaultScopes[IAccountManager::PROPERTY_PHONE] ?? $fallbackScope, '1', '');
231237
}
232238

233239
$addressParts = null;
@@ -266,15 +272,15 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
266272
$this->eventDispatcher->dispatchTyped($event);
267273
$this->logger->debug('Address mapping event dispatched');
268274
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
269-
$account->setProperty('address', $event->getValue(), $scope, '1', '');
275+
$account->setProperty('address', $event->getValue(), $defaultScopes[IAccountManager::PROPERTY_ADDRESS] ?? $fallbackScope, '1', '');
270276
}
271277

272278
// Update the website
273279
$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_WEBSITE, $idTokenPayload, $website);
274280
$this->eventDispatcher->dispatchTyped($event);
275281
$this->logger->debug('Website mapping event dispatched');
276282
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
277-
$account->setProperty('website', $event->getValue(), $scope, '1', '');
283+
$account->setProperty('website', $event->getValue(), $defaultScopes[IAccountManager::PROPERTY_WEBSITE] ?? $fallbackScope, '1', '');
278284
}
279285

280286
// Update the avatar
@@ -290,23 +296,23 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
290296
$this->eventDispatcher->dispatchTyped($event);
291297
$this->logger->debug('Twitter mapping event dispatched');
292298
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
293-
$account->setProperty('twitter', $event->getValue(), $scope, '1', '');
299+
$account->setProperty('twitter', $event->getValue(), $defaultScopes[IAccountManager::PROPERTY_TWITTER] ?? $fallbackScope, '1', '');
294300
}
295301

296302
// Update fediverse
297303
$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_FEDIVERSE, $idTokenPayload, $fediverse);
298304
$this->eventDispatcher->dispatchTyped($event);
299305
$this->logger->debug('Fediverse mapping event dispatched');
300306
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
301-
$account->setProperty('fediverse', $event->getValue(), $scope, '1', '');
307+
$account->setProperty('fediverse', $event->getValue(), $defaultScopes[IAccountManager::PROPERTY_FEDIVERSE] ?? $fallbackScope, '1', '');
302308
}
303309

304310
// Update the organisation
305311
$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_ORGANISATION, $idTokenPayload, $organisation);
306312
$this->eventDispatcher->dispatchTyped($event);
307313
$this->logger->debug('Organisation mapping event dispatched');
308314
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
309-
$account->setProperty('organisation', $event->getValue(), $scope, '1', '');
315+
$account->setProperty('organisation', $event->getValue(), $defaultScopes[IAccountManager::PROPERTY_ORGANISATION] ?? $fallbackScope, '1', '');
310316
}
311317

312318
// Update role
@@ -322,23 +328,25 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
322328
$this->eventDispatcher->dispatchTyped($event);
323329
$this->logger->debug('Headline mapping event dispatched');
324330
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
325-
$account->setProperty('headline', $event->getValue(), $scope, '1', '');
331+
$account->setProperty('headline', $event->getValue(), $defaultScopes[IAccountManager::PROPERTY_HEADLINE] ?? $fallbackScope, '1', '');
326332
}
327333

328334
// Update the biography
329335
$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_BIOGRAPHY, $idTokenPayload, $biography);
330336
$this->eventDispatcher->dispatchTyped($event);
331337
$this->logger->debug('Biography mapping event dispatched');
332338
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
333-
$account->setProperty('biography', $event->getValue(), $scope, '1', '');
339+
$account->setProperty('biography', $event->getValue(), $defaultScopes[IAccountManager::PROPERTY_BIOGRAPHY] ?? $fallbackScope, '1', '');
334340
}
335341

336342
// Update the gender
343+
// Since until now there is no default for property for gender we have to use default
344+
// In v31 there will be introduced PRONOUNS, which could be of better use
337345
$event = new AttributeMappedEvent(ProviderService::SETTING_MAPPING_GENDER, $idTokenPayload, $gender);
338346
$this->eventDispatcher->dispatchTyped($event);
339347
$this->logger->debug('Gender mapping event dispatched');
340348
if ($event->hasValue() && $event->getValue() !== null && $event->getValue() !== '') {
341-
$account->setProperty('gender', $event->getValue(), $scope, '1', '');
349+
$account->setProperty('gender', $event->getValue(), $fallbackScope, '1', '');
342350
}
343351

344352
$this->session->set('user_oidc.oidcUserData', $oidcGssUserData);

psalm.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
<referencedClass name="GuzzleHttp\Exception\ServerException" />
4545
<referencedClass name="Symfony\Component\Console\Helper\Table" />
4646
<referencedClass name="Symfony\Component\Console\Question\ConfirmationQuestion" />
47+
<referencedClass name="OC\Accounts\AccountManager" />
4748
</errorLevel>
4849
</UndefinedClass>
4950
<UndefinedDocblockClass>

0 commit comments

Comments
 (0)