Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fetch default privacy scopes and set properties appropriate #1048

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions lib/Service/ProvisioningService.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

namespace OCA\UserOIDC\Service;

use OC\Accounts\AccountManager;
use OCA\UserOIDC\AppInfo\Application;
use OCA\UserOIDC\Db\UserMapper;
use OCA\UserOIDC\Event\AttributeMappedEvent;
Expand Down Expand Up @@ -151,7 +152,12 @@ public function provisionUser(string $tokenUserId, int $providerId, object $idTo
}

$account = $this->accountManager->getAccount($user);
$scope = 'v2-local';
$fallbackScope = 'v2-local';
$defaultScopes = array_merge(
AccountManager::DEFAULT_SCOPES,
$this->config->getSystemValue('account_manager.default_property_scope', []) ?? []
);


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

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

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

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

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

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

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

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

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

$this->session->set('user_oidc.oidcUserData', $oidcGssUserData);
Expand Down
1 change: 1 addition & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<referencedClass name="GuzzleHttp\Exception\ServerException" />
<referencedClass name="Symfony\Component\Console\Helper\Table" />
<referencedClass name="Symfony\Component\Console\Question\ConfirmationQuestion" />
<referencedClass name="OC\Accounts\AccountManager" />
</errorLevel>
</UndefinedClass>
<UndefinedDocblockClass>
Expand Down
Loading