Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Create a dedicate FAKE_API_CALLER_ID user for representing the caller

天舟e88eda603db4
diff --git a/frontend/src/miragejs/fixtures/memberList.json b/frontend/src/miragejs/fixtures/memberList.json
index af2f3cd499..68fa35be8c 100644
--- a/frontend/src/miragejs/fixtures/memberList.json
+++ b/frontend/src/miragejs/fixtures/memberList.json
@@ -68,5 +68,15 @@
"principalId": "6",
"updaterId": "1",
"creatorId": "1"
+ },
+ {
+ "id": "8",
+ "workspaceId": "1",
+ "createdTs": 1609603200000,
+ "lastUpdatedTs": 1609646400000,
+ "role": "DBA",
+ "principalId": "7",
+ "updaterId": "1",
+ "creatorId": "1"
}
]
diff --git a/frontend/src/miragejs/fixtures/userList.json b/frontend/src/miragejs/fixtures/userList.json
index 3924c56ab4..51d8648791 100644
--- a/frontend/src/miragejs/fixtures/userList.json
+++ b/frontend/src/miragejs/fixtures/userList.json
@@ -40,5 +40,12 @@
"name": "Bob Invited",
"email": "[email protected]",
"passwordHash": "aaa"
+ },
+ {
+ "id": "7",
+ "status": "ACTIVE",
+ "name": "Fake API caller DBA",
+ "email": "[email protected]",
+ "passwordHash": "aaa"
}
]
diff --git a/frontend/src/miragejs/routes/environment.js b/frontend/src/miragejs/routes/environment.js
index 5a85c9a956..458c135618 100644
--- a/frontend/src/miragejs/routes/environment.js
+++ b/frontend/src/miragejs/routes/environment.js
@@ -1,6 +1,6 @@
import { Response } from "miragejs";
import { postMessageToOwnerAndDBA } from "../utils";
-import { WORKSPACE_ID, OWNER_ID } from "./index";
+import { WORKSPACE_ID, FAKE_API_CALLER_ID } from "./index";
import { EnvironmentBuiltinFieldId } from "../../types";
export default function configureEnvironment(route) {
@@ -48,8 +48,6 @@ export default function configureEnvironment(route) {
};
const createdEnvironment = schema.environments.create(newEnvironment);
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
const ts = Date.now();
const messageTemplate = {
containerId: createdEnvironment.id,
@@ -57,13 +55,13 @@ export default function configureEnvironment(route) {
lastUpdatedTs: ts,
type: "bb.msg.environment.create",
status: "DELIVERED",
- creatorId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
workspaceId: WORKSPACE_ID,
payload: {
environmentName: createdEnvironment.name,
},
};
- postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ postMessageToOwnerAndDBA(schema, FAKE_API_CALLER_ID, messageTemplate);
return createdEnvironment;
});
@@ -128,8 +126,6 @@ export default function configureEnvironment(route) {
const updatedEnvironment = environment.update(attrs);
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
const ts = Date.now();
const messageTemplate = {
containerId: environment.id,
@@ -137,14 +133,14 @@ export default function configureEnvironment(route) {
lastUpdatedTs: ts,
type,
status: "DELIVERED",
- creatorId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
workspaceId: WORKSPACE_ID,
payload: {
environmentName: updatedEnvironment.name,
changeList,
},
};
- postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ postMessageToOwnerAndDBA(schema, FAKE_API_CALLER_ID, messageTemplate);
return updatedEnvironment;
});
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index 681178f9eb..483d483026 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -17,7 +17,8 @@ import configureDataSource from "./dataSource";
export const WORKSPACE_ID = 1;
-export const OWNER_ID = 1;
+// NOTE, in actual implementation, we need to fetch the user from the auth context.
+export const FAKE_API_CALLER_ID = 7;
export default function routes() {
// Change this value to simulate response delay.
diff --git a/frontend/src/miragejs/routes/instance.js b/frontend/src/miragejs/routes/instance.js
index 6a2f53f79a..d91472908f 100644
--- a/frontend/src/miragejs/routes/instance.js
+++ b/frontend/src/miragejs/routes/instance.js
@@ -1,6 +1,6 @@
import { Response } from "miragejs";
import { postMessageToOwnerAndDBA } from "../utils";
-import { WORKSPACE_ID, OWNER_ID } from "./index";
+import { WORKSPACE_ID, FAKE_API_CALLER_ID } from "./index";
import { DEFAULT_PROJECT_ID, InstanceBuiltinFieldId } from "../../types";
export default function configurInstance(route) {
@@ -45,8 +45,6 @@ export default function configurInstance(route) {
});
route.post("/instance", function (schema, request) {
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
const attrs = this.normalizedRequestAttrs("instance-new");
const ts = Date.now();
const createdInstance = schema.instances.create({
@@ -56,8 +54,8 @@ export default function configurInstance(route) {
host: attrs.host,
port: attrs.port,
rowStatus: "NORMAL",
- creatorId: callerId,
- updaterId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
+ updaterId: FAKE_API_CALLER_ID,
createdTs: ts,
lastUpdatedTs: ts,
workspaceId: WORKSPACE_ID,
@@ -86,13 +84,13 @@ export default function configurInstance(route) {
lastUpdatedTs: ts,
type: "bb.msg.instance.create",
status: "DELIVERED",
- creatorId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
workspaceId: WORKSPACE_ID,
payload: {
instanceName: createdInstance.name,
},
};
- postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ postMessageToOwnerAndDBA(schema, FAKE_API_CALLER_ID, messageTemplate);
return createdInstance;
});
@@ -237,8 +235,6 @@ export default function configurInstance(route) {
dataSource.update(dataSourceAttrs);
}
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
const ts = Date.now();
const messageTemplate = {
containerId: updatedInstance.id,
@@ -246,14 +242,14 @@ export default function configurInstance(route) {
lastUpdatedTs: ts,
type,
status: "DELIVERED",
- creatorId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
workspaceId: WORKSPACE_ID,
payload: {
instanceName: updatedInstance.name,
changeList,
},
};
- postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ postMessageToOwnerAndDBA(schema, FAKE_API_CALLER_ID, messageTemplate);
return updatedInstance;
});
@@ -271,8 +267,6 @@ export default function configurInstance(route) {
);
}
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
// Delete data source and database before instance itself.
// Otherwise, the instanceId will be set to null.
const dataSourceList = schema.dataSources.where({
@@ -294,12 +288,12 @@ export default function configurInstance(route) {
lastUpdatedTs: ts,
type: "bb.msg.instance.delete",
status: "DELIVERED",
- creatorId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
workspaceId: WORKSPACE_ID,
payload: {
instanceName: instance.name,
},
};
- postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ postMessageToOwnerAndDBA(schema, FAKE_API_CALLER_ID, messageTemplate);
});
}
diff --git a/frontend/src/miragejs/routes/member.js b/frontend/src/miragejs/routes/member.js
index d18cd9ac31..c6ed96d2ee 100644
--- a/frontend/src/miragejs/routes/member.js
+++ b/frontend/src/miragejs/routes/member.js
@@ -1,5 +1,5 @@
import { Response } from "miragejs";
-import { WORKSPACE_ID, OWNER_ID } from "./index";
+import { WORKSPACE_ID, FAKE_API_CALLER_ID } from "./index";
import { postMessageToOwnerAndDBA } from "../utils";
export default function configureMember(route) {
@@ -20,11 +20,9 @@ export default function configureMember(route) {
return member;
}
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
const newMember = {
- creatorId: callerId,
- updaterId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
+ updaterId: FAKE_API_CALLER_ID,
createdTs: ts,
lastUpdatedTs: ts,
role: attrs.role,
@@ -46,14 +44,14 @@ export default function configureMember(route) {
lastUpdatedTs: ts,
type,
status: "DELIVERED",
- creatorId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
workspaceId: WORKSPACE_ID,
payload: {
principalId: attrs.principalId,
newRole: attrs.role,
},
};
- postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ postMessageToOwnerAndDBA(schema, FAKE_API_CALLER_ID, messageTemplate);
return createdMember;
});
@@ -72,10 +70,8 @@ export default function configureMember(route) {
const oldRole = member.role;
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
const attrs = this.normalizedRequestAttrs("member");
- attrs.updaterId = callerId;
+ attrs.updaterId = FAKE_API_CALLER_ID;
const updatedMember = member.update(attrs);
@@ -115,8 +111,6 @@ export default function configureMember(route) {
const oldRole = member.role;
member.destroy();
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
const ts = Date.now();
const messageTemplate = {
containerId: WORKSPACE_ID,
@@ -124,13 +118,13 @@ export default function configureMember(route) {
lastUpdatedTs: ts,
type: "bb.msg.member.revoke",
status: "DELIVERED",
- creatorId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
workspaceId: WORKSPACE_ID,
payload: {
principalId: member.principalId,
oldRole,
},
};
- postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ postMessageToOwnerAndDBA(schema, FAKE_API_CALLER_ID, messageTemplate);
});
}
diff --git a/frontend/src/miragejs/routes/projectMember.js b/frontend/src/miragejs/routes/projectMember.js
index 7f9bf6e2eb..11df8fcb73 100644
--- a/frontend/src/miragejs/routes/projectMember.js
+++ b/frontend/src/miragejs/routes/projectMember.js
@@ -1,5 +1,5 @@
import { Response } from "miragejs";
-import { WORKSPACE_ID, OWNER_ID } from "./index";
+import { WORKSPACE_ID, FAKE_API_CALLER_ID } from "./index";
import { postMessageToOwnerAndDBA } from "../utils";
export default function configureProrjectMember(route) {
@@ -49,12 +49,10 @@ export default function configureProrjectMember(route) {
return member;
}
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
const newMember = {
...attrs,
- creatorId: callerId,
- updaterId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
+ updaterId: FAKE_API_CALLER_ID,
createdTs: ts,
lastUpdatedTs: ts,
role: attrs.role,
@@ -71,14 +69,14 @@ export default function configureProrjectMember(route) {
lastUpdatedTs: ts,
type: "bb.msg.project.member.create",
status: "DELIVERED",
- creatorId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
workspaceId: WORKSPACE_ID,
payload: {
principalId: attrs.principalId,
newRole: attrs.role,
},
};
- postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ postMessageToOwnerAndDBA(schema, FAKE_API_CALLER_ID, messageTemplate);
return createdMember;
});
@@ -110,10 +108,8 @@ export default function configureProrjectMember(route) {
}
const oldRole = member.role;
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
const attrs = this.normalizedRequestAttrs("project-member");
- attrs.updaterId = callerId;
+ attrs.updaterId = FAKE_API_CALLER_ID;
const updatedMember = member.update(attrs);
const ts = Date.now();
@@ -169,8 +165,6 @@ export default function configureProrjectMember(route) {
const oldRole = member.role;
member.destroy();
- // NOTE, in actual implementation, we need to fetch the user from the auth context.
- const callerId = OWNER_ID;
const ts = Date.now();
const messageTemplate = {
containerId: request.params.projectId,
@@ -178,14 +172,14 @@ export default function configureProrjectMember(route) {
lastUpdatedTs: ts,
type: "bb.msg.project.member.revoke",
status: "DELIVERED",
- creatorId: callerId,
+ creatorId: FAKE_API_CALLER_ID,
workspaceId: WORKSPACE_ID,
payload: {
principalId: member.principalId,
oldRole,
},
};
- postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ postMessageToOwnerAndDBA(schema, FAKE_API_CALLER_ID, messageTemplate);
}
);
}