-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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
[stable24] Allow to tweak default scopes for accounts #32448
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
* @author Lukas Reschke <[email protected]> | ||
* @author Morris Jobke <[email protected]> | ||
* @author Roeland Jago Douma <[email protected]> | ||
* @author Thomas Citharel <[email protected]> | ||
* @author Vincent Petry <[email protected]> | ||
* | ||
* @license AGPL-3.0 | ||
|
@@ -119,6 +120,23 @@ class AccountManager implements IAccountManager { | |
private $l10nfactory; | ||
private CappedMemoryCache $internalCache; | ||
|
||
/** | ||
* The list of default scopes for each property. | ||
*/ | ||
public const DEFAULT_SCOPES = [ | ||
self::PROPERTY_DISPLAYNAME => self::SCOPE_FEDERATED, | ||
self::PROPERTY_ADDRESS => self::SCOPE_LOCAL, | ||
self::PROPERTY_WEBSITE => self::SCOPE_LOCAL, | ||
self::PROPERTY_EMAIL => self::SCOPE_FEDERATED, | ||
self::PROPERTY_AVATAR => self::SCOPE_FEDERATED, | ||
self::PROPERTY_PHONE => self::SCOPE_LOCAL, | ||
self::PROPERTY_TWITTER => self::SCOPE_LOCAL, | ||
self::PROPERTY_ORGANISATION => self::SCOPE_LOCAL, | ||
self::PROPERTY_ROLE => self::SCOPE_LOCAL, | ||
self::PROPERTY_HEADLINE => self::SCOPE_LOCAL, | ||
self::PROPERTY_BIOGRAPHY => self::SCOPE_LOCAL, | ||
]; | ||
|
||
public function __construct( | ||
IDBConnection $connection, | ||
IConfig $config, | ||
|
@@ -649,81 +667,84 @@ protected function writeUserDataProperties(IQueryBuilder $query, array $data): v | |
|
||
/** | ||
* build default user record in case not data set exists yet | ||
* | ||
* @param IUser $user | ||
* @return array | ||
*/ | ||
protected function buildDefaultUserRecord(IUser $user) { | ||
protected function buildDefaultUserRecord(IUser $user): array { | ||
$scopes = array_merge(self::DEFAULT_SCOPES, array_filter($this->config->getSystemValue('account_manager.default_property_scope', []), static function (string $scope, string $property) { | ||
return in_array($property, self::ALLOWED_PROPERTIES, true) && in_array($scope, self::ALLOWED_SCOPES, true); | ||
}, ARRAY_FILTER_USE_BOTH)); | ||
|
||
return [ | ||
[ | ||
'name' => self::PROPERTY_DISPLAYNAME, | ||
'value' => $user->getDisplayName(), | ||
'scope' => self::SCOPE_FEDERATED, | ||
// Display name must be at least SCOPE_LOCAL | ||
'scope' => $scopes[self::PROPERTY_DISPLAYNAME] === self::SCOPE_PRIVATE ? self::SCOPE_LOCAL : $scopes[self::PROPERTY_DISPLAYNAME], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
|
||
[ | ||
'name' => self::PROPERTY_ADDRESS, | ||
'value' => '', | ||
'scope' => self::SCOPE_LOCAL, | ||
'scope' => $scopes[self::PROPERTY_ADDRESS], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
|
||
[ | ||
'name' => self::PROPERTY_WEBSITE, | ||
'value' => '', | ||
'scope' => self::SCOPE_LOCAL, | ||
'scope' => $scopes[self::PROPERTY_WEBSITE], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
|
||
[ | ||
'name' => self::PROPERTY_EMAIL, | ||
'value' => $user->getEMailAddress(), | ||
'scope' => self::SCOPE_FEDERATED, | ||
// Email must be at least SCOPE_LOCAL | ||
'scope' => $scopes[self::PROPERTY_EMAIL] === self::SCOPE_PRIVATE ? self::SCOPE_LOCAL : $scopes[self::PROPERTY_EMAIL], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
|
||
[ | ||
'name' => self::PROPERTY_AVATAR, | ||
'scope' => self::SCOPE_FEDERATED | ||
'scope' => $scopes[self::PROPERTY_AVATAR], | ||
], | ||
|
||
[ | ||
'name' => self::PROPERTY_PHONE, | ||
'value' => '', | ||
'scope' => self::SCOPE_LOCAL, | ||
'scope' => $scopes[self::PROPERTY_PHONE], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
|
||
[ | ||
'name' => self::PROPERTY_TWITTER, | ||
'value' => '', | ||
'scope' => self::SCOPE_LOCAL, | ||
'scope' => $scopes[self::PROPERTY_TWITTER], | ||
'verified' => self::NOT_VERIFIED, | ||
], | ||
|
||
[ | ||
'name' => self::PROPERTY_ORGANISATION, | ||
'value' => '', | ||
'scope' => self::SCOPE_LOCAL, | ||
'scope' => $scopes[self::PROPERTY_ORGANISATION], | ||
], | ||
|
||
[ | ||
'name' => self::PROPERTY_ROLE, | ||
'value' => '', | ||
'scope' => self::SCOPE_LOCAL, | ||
'scope' => $scopes[self::PROPERTY_ROLE], | ||
], | ||
|
||
[ | ||
'name' => self::PROPERTY_HEADLINE, | ||
'value' => '', | ||
'scope' => self::SCOPE_LOCAL, | ||
'scope' => $scopes[self::PROPERTY_HEADLINE], | ||
], | ||
|
||
[ | ||
'name' => self::PROPERTY_BIOGRAPHY, | ||
'value' => '', | ||
'scope' => self::SCOPE_LOCAL, | ||
'scope' => $scopes[self::PROPERTY_BIOGRAPHY], | ||
], | ||
|
||
[ | ||
|
@@ -790,17 +811,8 @@ public function updateAccount(IAccount $account): void { | |
// valid case, nothing to do | ||
} | ||
|
||
static $allowedScopes = [ | ||
self::SCOPE_PRIVATE, | ||
self::SCOPE_LOCAL, | ||
self::SCOPE_FEDERATED, | ||
self::SCOPE_PUBLISHED, | ||
self::VISIBILITY_PRIVATE, | ||
self::VISIBILITY_CONTACTS_ONLY, | ||
self::VISIBILITY_PUBLIC, | ||
]; | ||
foreach ($account->getAllProperties() as $property) { | ||
$this->testPropertyScope($property, $allowedScopes, true); | ||
$this->testPropertyScope($property, self::ALLOWED_SCOPES, true); | ||
} | ||
|
||
$oldData = $this->getUser($account->getUser(), false); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
* @author Christoph Wurst <[email protected]> | ||
* @author Joas Schilling <[email protected]> | ||
* @author Julius Härtl <[email protected]> | ||
* @author Thomas Citharel <[email protected]> | ||
* @author Vincent Petry <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
|
@@ -89,6 +90,21 @@ interface IAccountManager { | |
*/ | ||
public const VISIBILITY_PUBLIC = 'public'; | ||
|
||
/** | ||
* The list of allowed scopes | ||
* | ||
* @since 25.0.0 | ||
*/ | ||
public const ALLOWED_SCOPES = [ | ||
self::SCOPE_PRIVATE, | ||
self::SCOPE_LOCAL, | ||
self::SCOPE_FEDERATED, | ||
self::SCOPE_PUBLISHED, | ||
self::VISIBILITY_PRIVATE, | ||
self::VISIBILITY_CONTACTS_ONLY, | ||
self::VISIBILITY_PUBLIC, | ||
]; | ||
|
||
public const PROPERTY_AVATAR = 'avatar'; | ||
public const PROPERTY_DISPLAYNAME = 'displayname'; | ||
public const PROPERTY_PHONE = 'phone'; | ||
|
@@ -122,6 +138,26 @@ interface IAccountManager { | |
*/ | ||
public const PROPERTY_PROFILE_ENABLED = 'profile_enabled'; | ||
|
||
/** | ||
* The list of allowed properties | ||
* | ||
* @since 25.0.0 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. needs adjustment |
||
*/ | ||
public const ALLOWED_PROPERTIES = [ | ||
self::PROPERTY_AVATAR, | ||
self::PROPERTY_DISPLAYNAME, | ||
self::PROPERTY_PHONE, | ||
self::PROPERTY_EMAIL, | ||
self::PROPERTY_WEBSITE, | ||
self::PROPERTY_ADDRESS, | ||
self::PROPERTY_TWITTER, | ||
self::PROPERTY_ORGANISATION, | ||
self::PROPERTY_ROLE, | ||
self::PROPERTY_HEADLINE, | ||
self::PROPERTY_BIOGRAPHY, | ||
self::PROPERTY_PROFILE_ENABLED, | ||
]; | ||
|
||
public const COLLECTION_EMAIL = 'additional_mail'; | ||
|
||
public const NOT_VERIFIED = '0'; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
needs adjustment