feat: share unshared credentials with owner on reset (#4216)

This commit is contained in:
Valya 2022-09-29 13:54:41 +01:00 committed by GitHub
parent 8bd99e0600
commit 3b7de6db72
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 {
@ -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' },