Skip to content

feat(UserMigration): Overwork migration to include all settings (trusted senders)#12782

Open
DerDreschner wants to merge 2 commits intofeat/user-migration-appsettingsfrom
feat/user-migration-trusted-senders
Open

feat(UserMigration): Overwork migration to include all settings (trusted senders)#12782
DerDreschner wants to merge 2 commits intofeat/user-migration-appsettingsfrom
feat/user-migration-trusted-senders

Conversation

@DerDreschner
Copy link
Copy Markdown
Contributor

This PR belongs to a series of PRs that will enhance the user migration to include all settings.

Included changes in this PR:

  • Remove all trusted senders for the user before import
  • Allow export of trusted senders
  • Allow import of trusted senders
  • Unit tests for import and export

I didn't include any unit tests for the removal code as that only calls another function.

Please ignore the failed CI run regarding the unconventional commit message. That happens as I tag another feature branch for better overview here.

Refs #12001

Copilot AI review requested due to automatic review settings April 21, 2026 11:11
@DerDreschner DerDreschner force-pushed the feat/user-migration-trusted-senders branch from 23fa5cd to 8118180 Compare April 21, 2026 11:13
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

Extends the mail user-migration flow to include “trusted senders” settings by exporting/importing them and clearing existing entries before import.

Changes:

  • Add TrustedSendersMigrationService to export/import/remove trusted senders during migration.
  • Wire the service into MailAccountMigrator export/import/delete flows.
  • Add PHPUnit unit tests covering trusted senders export/import scenarios and invalid inputs.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.

File Description
lib/UserMigration/Service/TrustedSendersMigrationService.php Implements export/import/removal of trusted senders and validates import structure.
lib/UserMigration/MailAccountMigrator.php Integrates trusted senders migration into the overall mail migrator lifecycle.
tests/Unit/UserMigration/Service/TrustedSendersMigrationServiceTest.php Adds unit tests for trusted senders export/import behavior and error cases.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread lib/UserMigration/Service/TrustedSendersMigrationService.php Outdated
Comment thread lib/UserMigration/Service/TrustedSendersMigrationService.php Outdated
Comment thread lib/UserMigration/Service/TrustedSendersMigrationService.php Outdated
Comment thread lib/UserMigration/Service/TrustedSendersMigrationService.php Outdated
Comment on lines +100 to +104
$trustedSenderArrayIsValid = is_array($trustedSender);
$emailIsValid = array_key_exists('email', $trustedSender) && is_string($trustedSender['email']);
$typeIsValid = array_key_exists('type', $trustedSender) && is_string($trustedSender['type']);

if (!$trustedSenderArrayIsValid || !$emailIsValid || !$typeIsValid) {
Copy link

Copilot AI Apr 21, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new validation logic has multiple branches that aren’t covered by the current unit tests (e.g., an entry that is not an array, missing email/type, or non-string values). Add unit tests that assert UserMigrationException is thrown for these specific malformed structures (and that non-array items don’t cause a TypeError once fixed).

Suggested change
$trustedSenderArrayIsValid = is_array($trustedSender);
$emailIsValid = array_key_exists('email', $trustedSender) && is_string($trustedSender['email']);
$typeIsValid = array_key_exists('type', $trustedSender) && is_string($trustedSender['type']);
if (!$trustedSenderArrayIsValid || !$emailIsValid || !$typeIsValid) {
if (!is_array($trustedSender)) {
throw new UserMigrationException('Invalid trusted sender entry');
}
$emailIsValid = array_key_exists('email', $trustedSender) && is_string($trustedSender['email']);
$typeIsValid = array_key_exists('type', $trustedSender) && is_string($trustedSender['type']);
if (!$emailIsValid || !$typeIsValid) {

Copilot uses AI. Check for mistakes.
Comment thread tests/Unit/UserMigration/Service/TrustedSendersMigrationServiceTest.php Outdated
Comment thread tests/Unit/UserMigration/Service/TrustedSendersMigrationServiceTest.php Outdated
@DerDreschner DerDreschner force-pushed the feat/user-migration-trusted-senders branch 2 times, most recently from a67fc2b to 650d9b1 Compare April 21, 2026 11:41
@DerDreschner DerDreschner force-pushed the feat/user-migration-trusted-senders branch 3 times, most recently from 451cab5 to d87ab82 Compare April 21, 2026 16:29
@DerDreschner DerDreschner force-pushed the feat/user-migration-appsettings branch from 00fcc54 to 8eb6d2c Compare April 21, 2026 16:30
@DerDreschner DerDreschner force-pushed the feat/user-migration-appsettings branch from 8eb6d2c to d06d535 Compare April 21, 2026 16:57
…c changes)

Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
…ted senders)

Signed-off-by: David Dreschner <david.dreschner@nextcloud.com>
@DerDreschner DerDreschner force-pushed the feat/user-migration-trusted-senders branch from d87ab82 to dbd5edd Compare April 21, 2026 17:00
private function validateTrustedSenders(mixed $trustedSenders): void {
$trustedSendersArrayIsValid = is_array($trustedSenders) && array_is_list($trustedSenders);
if (!$trustedSendersArrayIsValid) {
throw new UserMigrationException('Invalid trusted senders export structure');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If throwing an exception in this method aborts the import, I would suggest to ignore the exception, catch it, or just go ahead. While losing all trusted senders might be annoying, not being able to complete the import might be even more annoying.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants