-
Notifications
You must be signed in to change notification settings - Fork 3
chore: Mark IUserConfig entries as lazy #173
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| <?php | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| /** | ||
| * SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-or-later | ||
| */ | ||
| namespace OCA\Zammad\Migration; | ||
|
|
||
| use Closure; | ||
| use OCA\Zammad\AppInfo\Application; | ||
| use OCP\Config\IUserConfig; | ||
| use OCP\IAppConfig; | ||
| use OCP\Migration\IOutput; | ||
| use OCP\Migration\SimpleMigrationStep; | ||
| use OCP\Security\ICrypto; | ||
|
|
||
| class Version040000Date20260129225956 extends SimpleMigrationStep { | ||
|
|
||
| public function __construct( | ||
| private ICrypto $crypto, | ||
| private IUserConfig $userConfig, | ||
| private IAppConfig $appConfig, | ||
| ) { | ||
| } | ||
|
|
||
| /** | ||
| * @param IOutput $output | ||
| * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` | ||
| * @param array $options | ||
| */ | ||
| public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options) { | ||
| foreach ($this->userConfig->getUserIds(Application::APP_ID) as $userId) { | ||
| // store user config as lazy and sensitive | ||
| foreach (['token', 'refresh_token'] as $key) { | ||
| if ($this->userConfig->hasKey($userId, Application::APP_ID, $key)) { | ||
| $value = $this->userConfig->getValueString($userId, Application::APP_ID, $key); | ||
| $decryptedValue = $this->crypto->decrypt($value); | ||
| $this->userConfig->setValueString($userId, Application::APP_ID, $key, $decryptedValue, lazy: true, flags: IUserConfig::FLAG_SENSITIVE); | ||
| } | ||
| } | ||
| // store user config as lazy (except 'navigation_enabled' and 'url') | ||
| foreach (['token_type', 'token_expires_at', 'oauth_state', 'redirect_uri', 'search_enabled', 'link_preview_enabled', 'notification_enabled', 'user_id', 'user_name', 'last_open_check'] as $key) { | ||
| if ($this->userConfig->hasKey($userId, Application::APP_ID, $key)) { | ||
| $value = $this->userConfig->getValueString($userId, Application::APP_ID, $key); | ||
| $this->userConfig->setValueString($userId, Application::APP_ID, $key, $value, lazy: true); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| // store oauth_instance_url as non-lazy | ||
|
Member
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. Maybe do the same for the I know those values are not supposed to have been stored previously as lazy but why not?
Member
Author
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. They are queried on each request, that's why I didn't make them lazy.
Member
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. Sorry for the confusion. I'm not saying
Member
Author
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. But they're not stored as lazy? :D |
||
| foreach (['oauth_instance_url'] as $key) { | ||
| if ($this->appConfig->hasKey(Application::APP_ID, $key, lazy: true)) { | ||
| $this->appConfig->deleteKey(Application::APP_ID, $key); | ||
| $this->appConfig->setValueString(Application::APP_ID, $key, $value, lazy: false); | ||
| } | ||
| } | ||
| } | ||
| } | ||
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.
Oh nice, i didn't know about
userConfig->getUserIds.