Skip to content

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

Post create/delete environment message to the owner and dba inbox

天舟8ac03d5c7d7e
diff --git a/frontend/src/miragejs/routes/environment.js b/frontend/src/miragejs/routes/environment.js
index 8cda48249d..82fbc1ce48 100644
--- a/frontend/src/miragejs/routes/environment.js
+++ b/frontend/src/miragejs/routes/environment.js
@@ -1,4 +1,5 @@
-import { WORKSPACE_ID } from "./index";
+import { postMessageToOwnerAndDBA } from "../utils";
+import { WORKSPACE_ID, OWNER_ID } from "./index";
export default function configureEnvironment(route) {
route.get("/environment", function (schema, request) {
@@ -22,7 +23,26 @@ export default function configureEnvironment(route) {
workspaceId: WORKSPACE_ID,
order,
};
- return schema.environments.create(newEnvironment);
+ 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,
+ createdTs: ts,
+ lastUpdatedTs: ts,
+ type: "bb.msg.environment.create",
+ status: "DELIVERED",
+ creatorId: callerId,
+ workspaceId: WORKSPACE_ID,
+ payload: {
+ environmentName: createdEnvironment.name,
+ },
+ };
+ postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+
+ return createdEnvironment;
});
route.patch("/environment/batch", function (schema, request) {
@@ -50,6 +70,27 @@ export default function configureEnvironment(route) {
});
route.delete("/environment/:environmentId", function (schema, request) {
- return schema.environments.find(request.params.environmentId).destroy();
+ const environment = schema.environments.find(request.params.environmentId);
+
+ if (environment) {
+ environment.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: environment.id,
+ createdTs: ts,
+ lastUpdatedTs: ts,
+ type: "bb.msg.environment.delete",
+ status: "DELIVERED",
+ creatorId: callerId,
+ workspaceId: WORKSPACE_ID,
+ payload: {
+ environmentName: environment.name,
+ },
+ };
+ postMessageToOwnerAndDBA(schema, callerId, messageTemplate);
+ }
});
}
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index f2fd409fb5..ec7303fb1b 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -512,16 +512,31 @@ export type ActivityPatch = {
};
// Message
+export type EnvironmentMessageType =
+ | "bb.msg.environment.create"
+ | "bb.msg.environment.delete";
+
+export type InstanceMessageType =
+ | "bb.msg.instance.create"
+ | "bb.msg.instance.delete";
+
export type TaskMessageType =
| "bb.msg.task.assign"
| "bb.msg.task.updatestatus"
| "bb.msg.task.comment";
-export type InstanceMessageType =
- | "bb.msg.instance.create"
- | "bb.msg.instance.delete";
+export type MessageType =
+ | EnvironmentMessageType
+ | InstanceMessageType
+ | TaskMessageType;
-export type MessageType = TaskMessageType | InstanceMessageType;
+export type EnvironmentMessagePayload = {
+ environmentName: string;
+};
+
+export type InstanceMessagePaylaod = {
+ instanceName: string;
+};
export type TaskAssignMessagePayload = {
taskName: string;
@@ -539,15 +554,12 @@ export type TaskCommentMessagePayload = {
taskName: string;
};
-export type InstanceMessagePaylaod = {
- instanceName: string;
-};
-
export type MessagePayload =
+ | EnvironmentMessagePayload
+ | InstanceMessagePaylaod
| TaskAssignMessagePayload
| TaskUpdateStatusMessagePayload
- | TaskCommentMessagePayload
- | InstanceMessagePaylaod;
+ | TaskCommentMessagePayload;
export type MessageStatus = "DELIVERED" | "CONSUMED";
diff --git a/frontend/src/views/Inbox.vue b/frontend/src/views/Inbox.vue
index d4c1007b89..3ffd5b1d4f 100644
--- a/frontend/src/views/Inbox.vue
+++ b/frontend/src/views/Inbox.vue
@@ -43,7 +43,36 @@
<span class="font-medium text-main">{{
message.creator.name
}}</span>
- <template v-if="message.type == 'bb.msg.task.assign'">
+ <template v-if="message.type == 'bb.msg.environment.create'">
+ <span class="ml-1"> created environment</span>
+ <router-link :to="`/environment`" class="normal-link ml-1">
+ {{ message.payload.environmentName }}
+ </router-link>
+ </template>
+ <template
+ v-else-if="message.type == 'bb.msg.environment.delete'"
+ >
+ <span class="ml-1"> deleted environment</span>
+ <span class="font-medium text-main ml-1">
+ {{ message.payload.environmentName }}
+ </span>
+ </template>
+ <template v-else-if="message.type == 'bb.msg.instance.create'">
+ <span class="ml-1"> created instance</span>
+ <router-link
+ :to="`/instance/${message.containerId}`"
+ class="normal-link ml-1"
+ >
+ {{ message.payload.instanceName }}
+ </router-link>
+ </template>
+ <template v-else-if="message.type == 'bb.msg.instance.delete'">
+ <span class="ml-1"> deleted instance</span>
+ <span class="font-medium text-main ml-1">
+ {{ message.payload.instanceName }}
+ </span>
+ </template>
+ <template v-else-if="message.type == 'bb.msg.task.assign'">
<span class="text-sm ml-1">
<template
v-if="
@@ -124,21 +153,6 @@
{{ message.payload.taskName }}
</router-link>
</template>
- <template v-else-if="message.type == 'bb.msg.instance.create'">
- <span class="ml-1"> created instance</span>
- <router-link
- :to="`/instance/${message.containerId}`"
- class="normal-link ml-1"
- >
- {{ message.payload.instanceName }}
- </router-link>
- </template>
- <template v-else-if="message.type == 'bb.msg.instance.delete'">
- <span class="ml-1"> deleted instance</span>
- <span class="font-medium text-main ml-1">
- {{ message.payload.instanceName }}
- </span>
- </template>
<span
v-if="message.status == 'DELIVERED'"
class="ml-2 mt-1 h-3 w-3 rounded-full bg-accent"