mirror of
https://github.com/n8n-io/n8n.git
synced 2025-03-05 20:50:17 -08:00
feat: share unshared credentials with owner on reset (#4216)
This commit is contained in:
parent
8bd99e0600
commit
3b7de6db72
|
@ -1,5 +1,6 @@
|
||||||
import { Not } from 'typeorm';
|
import { Not } from 'typeorm';
|
||||||
import { Db } from '../../src';
|
import { Db } from '../../src';
|
||||||
|
import { CredentialsEntity } from '../../src/databases/entities/CredentialsEntity';
|
||||||
import { BaseCommand } from '../BaseCommand';
|
import { BaseCommand } from '../BaseCommand';
|
||||||
|
|
||||||
export class Reset extends 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.delete({ id: Not(owner.id) });
|
||||||
await Db.collections.User.save(Object.assign(owner, this.defaultUserProps));
|
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(
|
await Db.collections.Settings.update(
|
||||||
{ key: 'userManagement.isInstanceOwnerSetUp' },
|
{ key: 'userManagement.isInstanceOwnerSetUp' },
|
||||||
{ value: 'false' },
|
{ value: 'false' },
|
||||||
|
|
Loading…
Reference in a new issue