Skip to content

Commit 69f9d60

Browse files
committed
Set ghost agent as the current actor for root user creation from app
1 parent ee2851c commit 69f9d60

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

src/components/admin/admin.edgedb.repository.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,16 @@ import { ID, Role } from '~/common';
33
import { RootUserAlias } from '~/core/config/root-user.config';
44
import { disableAccessPolicies, e, EdgeDB } from '~/core/edgedb';
55
import { AuthenticationRepository } from '../authentication/authentication.repository';
6+
import { ActorRepository } from '../user/actor.repository';
67

78
@Injectable()
89
export class AdminEdgeDBRepository {
910
private readonly db: EdgeDB;
10-
constructor(edgedb: EdgeDB, readonly auth: AuthenticationRepository) {
11+
constructor(
12+
edgedb: EdgeDB,
13+
readonly auth: AuthenticationRepository,
14+
readonly actors: ActorRepository,
15+
) {
1116
this.db = edgedb.withOptions(disableAccessPolicies);
1217
}
1318

@@ -33,6 +38,8 @@ export class AdminEdgeDBRepository {
3338
}
3439

3540
async createRootUser(id: ID, email: string, passwordHash: string) {
41+
const ghost = await this.actors.getGhost();
42+
3643
const newUser = e.insert(e.User, {
3744
id,
3845
email,
@@ -45,8 +52,12 @@ export class AdminEdgeDBRepository {
4552
target: newUser,
4653
});
4754
await this.db
48-
// eslint-disable-next-line @typescript-eslint/naming-convention
49-
.withOptions((o) => o.withConfig({ allow_user_specified_id: true }))
55+
.withOptions((o) =>
56+
o
57+
// eslint-disable-next-line @typescript-eslint/naming-convention
58+
.withConfig({ allow_user_specified_id: true })
59+
.withGlobals({ currentActorId: ghost.id }),
60+
)
5061
.run(query);
5162
await this.auth.savePasswordHashOnUser(id, passwordHash);
5263
}

src/components/admin/admin.module.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Module } from '@nestjs/common';
22
import { splitDb } from '~/core';
33
import { AuthorizationModule } from '../authorization/authorization.module';
4+
import { UserModule } from '../user/user.module';
45
import { AdminEdgeDBRepository } from './admin.edgedb.repository';
56
import { AdminEdgeDBService } from './admin.edgedb.service';
67
import { AdminRepository } from './admin.repository';
@@ -9,7 +10,7 @@ import { NormalizeCreatorBaseNodeMigration } from './migrations/normalize-creato
910
import { NormalizeCreatorMigration } from './migrations/normalize-creator.migration';
1011

1112
@Module({
12-
imports: [AuthorizationModule],
13+
imports: [AuthorizationModule, UserModule],
1314
providers: [
1415
splitDb(AdminService, AdminEdgeDBService),
1516
splitDb(

0 commit comments

Comments
 (0)