diff options
| author | Hazelnoot <acomputerdog@gmail.com> | 2025-04-03 22:04:11 -0400 |
|---|---|---|
| committer | Hazelnoot <acomputerdog@gmail.com> | 2025-04-03 22:06:37 -0400 |
| commit | 3eeb53ff63a5e776327a9fd067d0c74b9dc727f4 (patch) | |
| tree | 9b4ee01e1aaf1ab7b4a24ab897ccf14e1aa19a40 /packages/backend/src/core/AccountMoveService.ts | |
| parent | refactor bubble-timeline.ts to match global-timeline.ts and local-timeline.ts (diff) | |
| parent | New Crowdin updates (#15740) (diff) | |
| download | sharkey-3eeb53ff63a5e776327a9fd067d0c74b9dc727f4.tar.gz sharkey-3eeb53ff63a5e776327a9fd067d0c74b9dc727f4.tar.bz2 sharkey-3eeb53ff63a5e776327a9fd067d0c74b9dc727f4.zip | |
Merge branch 'misskey-develop' into merge/2025-03-24
# Conflicts:
# package.json
# packages/backend/src/core/AccountMoveService.ts
# packages/frontend/src/components/MkDateSeparatedList.vue
# packages/misskey-js/etc/misskey-js.api.md
# pnpm-lock.yaml
Diffstat (limited to 'packages/backend/src/core/AccountMoveService.ts')
| -rw-r--r-- | packages/backend/src/core/AccountMoveService.ts | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/packages/backend/src/core/AccountMoveService.ts b/packages/backend/src/core/AccountMoveService.ts index 2dbd16b5fe..5128caff60 100644 --- a/packages/backend/src/core/AccountMoveService.ts +++ b/packages/backend/src/core/AccountMoveService.ts @@ -24,6 +24,7 @@ import { FederatedInstanceService } from '@/core/FederatedInstanceService.js'; import InstanceChart from '@/core/chart/charts/instance.js'; import PerUserFollowingChart from '@/core/chart/charts/per-user-following.js'; import { SystemAccountService } from '@/core/SystemAccountService.js'; +import { RoleService } from '@/core/RoleService.js'; @Injectable() export class AccountMoveService { @@ -64,6 +65,7 @@ export class AccountMoveService { private relayService: RelayService, private queueService: QueueService, private systemAccountService: SystemAccountService, + private roleService: RoleService, ) { } @@ -123,6 +125,7 @@ export class AccountMoveService { this.copyBlocking(src, dst), this.copyMutings(src, dst), this.deleteScheduledNotes(src), + this.copyRoles(src, dst), this.updateLists(src, dst), ]); } catch { @@ -220,6 +223,32 @@ export class AccountMoveService { }); } + @bindThis + public async copyRoles(src: ThinUser, dst: ThinUser): Promise<void> { + // Insert new roles with the same values except userId + // role service may have cache for roles so retrieve roles from service + const [oldRoleAssignments, roles] = await Promise.all([ + this.roleService.getUserAssigns(src.id), + this.roleService.getRoles(), + ]); + + if (oldRoleAssignments.length === 0) return; + + // No promise all since the only async operation is writing to the database + for (const oldRoleAssignment of oldRoleAssignments) { + const role = roles.find(x => x.id === oldRoleAssignment.roleId); + if (role == null) continue; // Very unlikely however removing role may cause this case + if (!role.preserveAssignmentOnMoveAccount) continue; + + try { + await this.roleService.assign(dst.id, role.id, oldRoleAssignment.expiresAt); + } catch (e) { + if (e instanceof RoleService.AlreadyAssignedError) continue; + throw e; + } + } + } + /** * Update lists while moving accounts. * - No removal of the old account from the lists |