Skip to content

Commit

Permalink
feat: share unshared credentials with owner on reset (#4216)
Browse files Browse the repository at this point in the history
  • Loading branch information
valya authored Sep 29, 2022
1 parent 8bd99e0 commit 3b7de6d
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions packages/cli/commands/user-management/reset.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Not } from 'typeorm';
import { Db } from '../../src';
import { CredentialsEntity } from '../../src/databases/entities/CredentialsEntity';
import { BaseCommand } from '../BaseCommand';

export class Reset extends BaseCommand {
Expand Down Expand Up @@ -31,6 +32,20 @@ export class Reset extends BaseCommand {
await Db.collections.User.delete({ id: Not(owner.id) });
await Db.collections.User.save(Object.assign(owner, this.defaultUserProps));

const danglingCredentials: CredentialsEntity[] =
(await Db.collections.Credentials.createQueryBuilder('credentials')
.leftJoinAndSelect('credentials.shared', 'shared')
.where('shared.credentialsId is null')
.getMany()) as CredentialsEntity[];
const newSharedCredentials = danglingCredentials.map((credentials) =>
Db.collections.SharedCredentials.create({
credentials,
user: owner,
role: ownerCredentialRole,
}),
);
await Db.collections.SharedCredentials.save(newSharedCredentials);

await Db.collections.Settings.update(
{ key: 'userManagement.isInstanceOwnerSetUp' },
{ value: 'false' },
Expand Down

0 comments on commit 3b7de6d

Please sign in to comment.