Skip to content

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

chore: use `auditLogService` in frontend (#11863)

boojack55d6f8856085
diff --git a/frontend/src/components/AuditLog/AuditLogDataTable.vue b/frontend/src/components/AuditLog/AuditLogDataTable.vue
new file mode 100644
index 0000000000..2b9b7295eb
--- /dev/null
+++ b/frontend/src/components/AuditLog/AuditLogDataTable.vue
@@ -0,0 +1,123 @@
+<template>
+ <NDataTable
+ size="small"
+ :columns="columnList"
+ :data="auditLogList"
+ :striped="true"
+ :row-key="(data: AuditLog) => data.name"
+ />
+</template>
+
+<script lang="tsx" setup>
+import dayjs from "dayjs";
+import { NDataTable, type DataTableColumn } from "naive-ui";
+import { computed } from "vue";
+import { useI18n } from "vue-i18n";
+import BBAvatar from "@/bbkit/BBAvatar.vue";
+import { extractUserEmail, useProjectV1Store, useUserStore } from "@/store";
+import { projectNamePrefix } from "@/store/modules/v1/common";
+import type { AuditLog } from "@/types/proto/v1/audit_log_service";
+import { extractProjectResourceName } from "@/utils";
+import JSONStringView from "./JSONStringView.vue";
+
+type ProjectDataTableColumn = DataTableColumn<AuditLog> & {
+ hide?: boolean;
+};
+
+const props = withDefaults(
+ defineProps<{
+ auditLogList: AuditLog[];
+ showProject?: boolean;
+ }>(),
+ {
+ showProject: true,
+ }
+);
+
+const { t } = useI18n();
+const projectStore = useProjectV1Store();
+const userStore = useUserStore();
+
+const columnList = computed((): ProjectDataTableColumn[] => {
+ return (
+ [
+ {
+ key: "created-ts",
+ title: t("audit-log.table.created-ts"),
+ width: 240,
+ render: (auditLog) =>
+ dayjs(auditLog.createTime).format("YYYY-MM-DD HH:mm:ss Z"),
+ },
+ {
+ key: "severity",
+ width: 96,
+ title: t("audit-log.table.level"),
+ render: (auditLog) => auditLog.severity,
+ },
+ {
+ key: "project",
+ width: 96,
+ title: t("common.project"),
+ hide: !props.showProject,
+ render: (auditLog) => {
+ const projectName = extractProjectResourceName(auditLog.name);
+ if (!projectName) {
+ return <span>-</span>;
+ }
+ const project = projectStore.getProjectByName(
+ `${projectNamePrefix}${projectName}`
+ );
+ return <span>{project.title}</span>;
+ },
+ },
+ {
+ key: "method",
+ width: 256,
+ title: t("audit-log.table.method"),
+ render: (auditLog) => auditLog.method,
+ },
+ {
+ key: "actor",
+ width: 128,
+ title: t("audit-log.table.actor"),
+ render: (auditLog) => {
+ const user = userStore.getUserByEmail(
+ extractUserEmail(auditLog.user)
+ );
+ if (!user) {
+ return <span>-</span>;
+ }
+ return (
+ <div class="flex flex-row items-center overflow-hidden gap-x-1">
+ <BBAvatar size="SMALL" username={user.title} />
+ <span class="truncate">{user.title}</span>
+ </div>
+ );
+ },
+ },
+ {
+ key: "request",
+ minWidth: 256,
+ title: t("audit-log.table.request"),
+ render: (auditLog) =>
+ auditLog.request.length > 0 ? (
+ <JSONStringView jsonString={auditLog.request} />
+ ) : (
+ "-"
+ ),
+ },
+ {
+ key: "response",
+ minWidth: 256,
+ title: t("audit-log.table.response"),
+ render: (auditLog) =>
+ auditLog.response.length > 0 ? (
+ <JSONStringView jsonString={auditLog.response} />
+ ) : (
+ "-"
+ ),
+ },
+ ] as ProjectDataTableColumn[]
+ ).filter((column) => !column.hide);
+});
+</script>
diff --git a/frontend/src/components/AuditLog/AuditLogTable.vue b/frontend/src/components/AuditLog/AuditLogTable.vue
deleted file mode 100644
index 0110826bb1..0000000000
--- a/frontend/src/components/AuditLog/AuditLogTable.vue
+++ /dev/null
@@ -1,112 +0,0 @@
-<template>
- <BBTable
- class="mt-2"
- :column-list="columnList"
- :data-source="auditLogList"
- :show-header="true"
- :row-clickable="false"
- >
- <template #body="{ rowData: auditLog }: { rowData: LogEntity }">
- <BBTableCell :left-padding="4" class="table-cell w-56">
- <div>
- {{ dayjs(auditLog.createTime).format("YYYY-MM-DD HH:mm:ss Z") }}
- </div>
- </BBTableCell>
- <BBTableCell class="table-cell w-24">
- <span
- :class="`inline-flex items-center px-2 py-1 rounded-lg text-xs font-semibold whitespace-nowrap ${
- auditLevelColorMap[auditLog.level]
- }`"
- >{{ logEntity_LevelToJSON(auditLog.level) }}</span
- >
- </BBTableCell>
- <BBTableCell class="table-cell w-28 whitespace-nowrap">
- {{ t(AuditActivityTypeI18nNameMap.get(auditLog.action) ?? "") }}
- </BBTableCell>
- <BBTableCell class="table-cell w-20">
- <UserByEmail :email="auditLog.creator" :plain="true" />
- </BBTableCell>
- <BBTableCell class="table-cell w-36">
- <div v-if="auditLog.comment">
- {{ auditLog.comment }}
- </div>
- <span v-else class="italic text-gray-500">{{
- $t("audit-log.table.empty")
- }}</span>
- </BBTableCell>
- <BBTableCell class="table-cell w-28">
- <NTooltip>
- <template #trigger>
- <NButton
- @click.stop="
- () => {
- $emit('view-detail', auditLog);
- }
- "
- >
- <heroicons-outline:document-magnifying-glass class="h-5 w-5" />
- </NButton>
- </template>
- <span class="whitespace-nowrap">
- {{ $t("audit-log.table.view-details") }}
- </span>
- </NTooltip>
- </BBTableCell>
- </template>
- </BBTable>
-</template>
-
-<script lang="ts" setup>
-import type { PropType } from "vue";
-import { computed } from "vue";
-import { useI18n } from "vue-i18n";
-import { AuditActivityTypeI18nNameMap } from "@/types";
-import type { LogEntity } from "@/types/proto/v1/logging_service";
-import {
- LogEntity_Level,
- logEntity_LevelToJSON,
-} from "@/types/proto/v1/logging_service";
-import { UserByEmail } from "../v2";
-
-defineProps({
- auditLogList: {
- type: Array as PropType<LogEntity[]>,
- required: true,
- },
-});
-
-defineEmits<{
- (event: "view-detail", log: LogEntity): void;
-}>();
-
-const { t } = useI18n();
-
-const auditLevelColorMap: Record<LogEntity_Level, string> = {
- [LogEntity_Level.LEVEL_UNSPECIFIED]: "bg-gray-100 text-gray-800",
- [LogEntity_Level.UNRECOGNIZED]: "bg-gray-100 text-gray-800",
- [LogEntity_Level.LEVEL_INFO]: "bg-gray-100 text-gray-800",
- [LogEntity_Level.LEVEL_WARNING]: "bg-yellow-100 text-yellow-800",
- [LogEntity_Level.LEVEL_ERROR]: "bg-red-100 text-red-800",
-};
-
-const columnList = computed(() => [
- {
- title: t("audit-log.table.created-ts"),
- },
- {
- title: t("audit-log.table.level"),
- },
- {
- title: t("audit-log.table.type"),
- },
- {
- title: t("audit-log.table.actor"),
- },
- {
- title: t("audit-log.table.comment"),
- },
- {
- title: t("audit-log.table.payload"),
- },
-]);
-</script>
diff --git a/frontend/src/components/AuditLog/JSONStringView.vue b/frontend/src/components/AuditLog/JSONStringView.vue
new file mode 100644
index 0000000000..0486fda9ad
--- /dev/null
+++ b/frontend/src/components/AuditLog/JSONStringView.vue
@@ -0,0 +1,48 @@
+<template>
+ <div
+ class="group grow-0 w-full flex flex-row justify-start items-center gap-2"
+ >
+ <p class="line-clamp-2">
+ <code class="text-sm break-all">{{ jsonString }}</code>
+ </p>
+ <div class="hidden group-hover:block shrink-0">
+ <NButton :size="'tiny'" @click="showModal = true">
+ <template #icon>
+ <Maximize2Icon />
+ </template>
+ </NButton>
+ </div>
+ </div>
+
+ <BBModal
+ :show="showModal"
+ :title="$t('common.view-details')"
+ @close="showModal = false"
+ >
+ <div style="width: calc(100vw - 12rem); height: calc(100vh - 12rem)">
+ <MonacoEditor
+ :content="formatedJSONString"
+ :readonly="true"
+ language="json"
+ class="border w-full h-full grow"
+ />
+ </div>
+ </BBModal>
+</template>
+
+<script setup lang="ts">
+import { Maximize2Icon } from "lucide-vue-next";
+import { NButton } from "naive-ui";
+import { computed, ref } from "vue";
+import { MonacoEditor } from "@/components/MonacoEditor";
+
+const props = defineProps<{
+ jsonString: string;
+}>();
+
+const showModal = ref(false);
+
+const formatedJSONString = computed(() => {
+ return JSON.stringify(JSON.parse(props.jsonString), null, 2);
+});
+</script>
diff --git a/frontend/src/components/AuditLog/TypeSelect.vue b/frontend/src/components/AuditLog/TypeSelect.vue
deleted file mode 100644
index 91a8195465..0000000000
--- a/frontend/src/components/AuditLog/TypeSelect.vue
+++ /dev/null
@@ -1,42 +0,0 @@
-<template>
- <NSelect
- v-bind="$attrs"
- multiple
- :value="selected"
- :options="options"
- :disabled="disabled"
- max-tag-count="responsive"
- :placeholder="$t('audit-log.table.select-type')"
- @update:value="$emit('update:selected', $event)"
- />
-</template>
-
-<script lang="ts" setup>
-import type { SelectOption } from "naive-ui";
-import { NSelect } from "naive-ui";
-import { computed } from "vue";
-import { useI18n } from "vue-i18n";
-import { AuditActivityTypeI18nNameMap } from "@/types";
-import type { LogEntity_Action } from "@/types/proto/v1/logging_service";
-
-defineProps<{
- selected: LogEntity_Action[];
- disabled: boolean;
-}>();
-defineEmits<{
- (event: "update:selected", selected: LogEntity_Action[]): void;
-}>();
-
-const { t } = useI18n();
-
-const options = computed(() => {
- const resp: SelectOption[] = [];
- for (const [key, val] of AuditActivityTypeI18nNameMap.entries()) {
- resp.push({
- value: key,
- label: t(val),
- });
- }
- return resp;
-});
-</script>
diff --git a/frontend/src/components/IssueV1/components/Sidebar/Assignee/Assignee.vue b/frontend/src/components/IssueV1/components/Sidebar/Assignee/Assignee.vue
index d1b127acbc..1602d94ac5 100644
--- a/frontend/src/components/IssueV1/components/Sidebar/Assignee/Assignee.vue
+++ b/frontend/src/components/IssueV1/components/Sidebar/Assignee/Assignee.vue
@@ -28,7 +28,6 @@
:fallback-option="fallbackUser"
:clearable="true"
:auto-reset="false"
- style="width: 100%"
@update:user="changeAssigneeUID"
/>
</template>
diff --git a/frontend/src/components/PagedActivityTable.vue b/frontend/src/components/PagedAuditLogTable.vue
similarity index 74%
rename from frontend/src/components/PagedActivityTable.vue
rename to frontend/src/components/PagedAuditLogTable.vue
index cb7487f9e0..9896d9a34e 100644
--- a/frontend/src/components/PagedActivityTable.vue
+++ b/frontend/src/components/PagedAuditLogTable.vue
@@ -29,23 +29,16 @@ import { useSessionStorage } from "@vueuse/core";
import { stringify } from "qs";
import type { PropType } from "vue";
import { computed, reactive, watch } from "vue";
-import { useIsLoggedIn, useActivityV1Store } from "@/store";
-import type { FindActivityMessage } from "@/types";
-import type { LogEntity } from "@/types/proto/v1/logging_service";
+import { useIsLoggedIn, useAuditLogStore } from "@/store";
+import type { SearchAuditLogsParams } from "@/types";
+import type { AuditLog } from "@/types/proto/v1/audit_log_service";
type LocalState = {
loading: boolean;
- auditLogList: LogEntity[];
+ auditLogList: AuditLog[];
paginationToken: string;
};
-/**
- * It's complex and dangerous to cache the activity list.
- * So we just memorize how many times the user clicks the "load more" button.
- * And load the first N pages in the first fetch.
- * E.g., the user clicked "load more" 4 times, then the first time will set limit
- * to `pageSize * 5`.
- */
type SessionState = {
// How many times the user clicks the "load more" button.
page: number;
@@ -62,8 +55,8 @@ const props = defineProps({
type: String,
required: true,
},
- activityFind: {
- type: Object as PropType<FindActivityMessage>,
+ searchAuditLogs: {
+ type: Object as PropType<SearchAuditLogsParams>,
default: () => ({
order: "desc",
}),
@@ -79,7 +72,7 @@ const props = defineProps({
});
const emit = defineEmits<{
- (event: "list:update", list: LogEntity[]): void;
+ (event: "list:update", list: AuditLog[]): void;
}>();
const state = reactive<LocalState>({
@@ -93,7 +86,7 @@ const sessionState = useSessionStorage<SessionState>(props.sessionKey, {
updatedTs: 0,
});
-const activityV1Store = useActivityV1Store();
+const auditLogStore = useAuditLogStore();
const isLoggedIn = useIsLoggedIn();
const limit = computed(() => {
@@ -102,11 +95,11 @@ const limit = computed(() => {
});
const condition = computed(() => {
- const activityFind = {
- ...props.activityFind,
+ const searchAuditLogs = {
+ ...props.searchAuditLogs,
limit: limit.value,
};
- return stringify(activityFind, {
+ return stringify(searchAuditLogs, {
arrayFormat: "repeat",
});
});
@@ -122,19 +115,18 @@ const fetchData = async (refresh = false) => {
limit.value;
try {
- const { nextPageToken, logEntities } =
- await activityV1Store.fetchActivityList({
- ...props.activityFind,
- pageSize: expectedRowCount,
- pageToken: state.paginationToken,
- });
+ const { nextPageToken, auditLogs } = await auditLogStore.fetchAuditLogs({
+ ...props.searchAuditLogs,
+ pageSize: expectedRowCount,
+ pageToken: state.paginationToken,
+ });
if (refresh) {
- state.auditLogList = logEntities;
+ state.auditLogList = auditLogs;
} else {
- state.auditLogList.push(...logEntities);
+ state.auditLogList.push(...auditLogs);
}
- if (!isFirstFetch && logEntities.length === expectedRowCount) {
+ if (!isFirstFetch && auditLogs.length === expectedRowCount) {
// If we didn't reach the end, memorize we've clicked the "load more" button.
sessionState.value.page++;
}
diff --git a/frontend/src/components/Project/ProjectSidebarV1.vue b/frontend/src/components/Project/ProjectSidebarV1.vue
index d012f5b406..5a9d030672 100644
--- a/frontend/src/components/Project/ProjectSidebarV1.vue
+++ b/frontend/src/components/Project/ProjectSidebarV1.vue
@@ -33,7 +33,6 @@ import projectV1Routes, {
PROJECT_V1_ROUTE_SYNC_SCHEMA,
PROJECT_V1_ROUTE_SLOW_QUERIES,
PROJECT_V1_ROUTE_ANOMALIES,
- PROJECT_V1_ROUTE_ACTIVITIES,
PROJECT_V1_ROUTE_GITOPS,
PROJECT_V1_ROUTE_MEMBERS,
PROJECT_V1_ROUTE_SETTINGS,
@@ -43,6 +42,7 @@ import projectV1Routes, {
PROJECT_V1_ROUTE_DATABASE_GROUPS,
PROJECT_V1_ROUTE_DEPLOYMENT_CONFIG,
PROJECT_V1_ROUTE_EXPORT_CENTER,
+ PROJECT_V1_ROUTE_AUDIT_LOGS,
} from "@/router/dashboard/projectV1";
import { useCurrentUserV1 } from "@/store";
import { getProjectName } from "@/store/modules/v1/common";
@@ -261,8 +261,8 @@ const projectSidebarItemList = computed((): ProjectSidebarItem[] => {
type: "div",
},
{
- title: t("common.activities"),
- path: PROJECT_V1_ROUTE_ACTIVITIES,
+ title: t("settings.sidebar.audit-log"),
+ path: PROJECT_V1_ROUTE_AUDIT_LOGS,
type: "div",
},
],
diff --git a/frontend/src/components/ProjectActivityPanel.vue b/frontend/src/components/ProjectActivityPanel.vue
deleted file mode 100644
index b7d7899872..0000000000
--- a/frontend/src/components/ProjectActivityPanel.vue
+++ /dev/null
@@ -1,30 +0,0 @@
-<template>
- <div>
- <div class="space-y-2">
- <PagedActivityTable
- :activity-find="{
- resource: project.name,
- order: 'desc',
- }"
- session-key="bb.page-activity-table.project-activity-panel"
- :page-size="10"
- >
- <template #table="{ list }">
- <ActivityTable :activity-list="list" />
- </template>
- </PagedActivityTable>
- </div>
- </div>
-</template>
-
-<script lang="ts" setup>
-import type { PropType } from "vue";
-import type { Project } from "@/types/proto/v1/project_service";
-
-defineProps({
- project: {
- required: true,
- type: Object as PropType<Project>,
- },
-});
-</script>
diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
index 8497122a6a..62c491e588 100644
--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMemberForm.vue
@@ -13,7 +13,6 @@
<UserSelect
v-model:users="state.userUidList"
class="mt-2"
- style="width: 100%"
:multiple="true"
:include-all-users="true"
:include-service-account="true"
diff --git a/frontend/src/components/ProjectMember/EditProjectRolePanel.vue b/frontend/src/components/ProjectMember/EditProjectRolePanel.vue
index b83bf392f7..2bea83276d 100644
--- a/frontend/src/components/ProjectMember/EditProjectRolePanel.vue
+++ b/frontend/src/components/ProjectMember/EditProjectRolePanel.vue
@@ -82,7 +82,6 @@
</p>
<UserSelect
v-model:users="state.userUidList"
- style="width: 100%"
:multiple="true"
:include-all="false"
/>
diff --git a/frontend/src/components/SensitiveData/GrantAccessDrawer.vue b/frontend/src/components/SensitiveData/GrantAccessDrawer.vue
index 73ab04c84f..1d47a30d23 100644
--- a/frontend/src/components/SensitiveData/GrantAccessDrawer.vue
+++ b/frontend/src/components/SensitiveData/GrantAccessDrawer.vue
@@ -61,7 +61,6 @@
</p>
<UserSelect
v-model:users="state.userUidList"
- style="width: 100%"
:multiple="true"
:include-all="false"
/>
diff --git a/frontend/src/components/v2/Select/UserSelect.vue b/frontend/src/components/v2/Select/UserSelect.vue
index 4207fcef2d..ef0010876e 100644
--- a/frontend/src/components/v2/Select/UserSelect.vue
+++ b/frontend/src/components/v2/Select/UserSelect.vue
@@ -11,7 +11,6 @@
:render-label="renderLabel"
:placeholder="$t('principal.select')"
class="bb-user-select"
- style="width: 12rem"
@update:show="
(show: boolean) => {
showStatus = show;
@@ -21,11 +20,11 @@
/>
</template>
-<script lang="ts" setup>
+<script lang="tsx" setup>
import { intersection } from "lodash-es";
import type { SelectGroupOption, SelectOption, SelectProps } from "naive-ui";
import { NSelect } from "naive-ui";
-import { computed, watch, watchEffect, h, ref } from "vue";
+import { computed, watch, watchEffect, ref } from "vue";
import { useI18n } from "vue-i18n";
import UserIcon from "~icons/heroicons-outline/user";
import UserAvatar from "@/components/User/UserAvatar.vue";
@@ -239,22 +238,15 @@ const handleValueUpdated = (value: string | string[]) => {
const renderAvatar = (user: User) => {
if (user.name === UNKNOWN_USER_NAME) {
- return h(
- "div",
- {
- class:
- "bb-user-select--avatar w-6 h-6 rounded-full border-2 border-current flex justify-center items-center select-none bg-white",
- },
- h(UserIcon, {
- class: "w-4 h-4 text-main text-current",
- })
+ return (
+ <div class="bb-user-select--avatar w-6 h-6 rounded-full border-2 border-current flex justify-center items-center select-none bg-white">
+ <UserIcon class="w-4 h-4 text-main text-current" />
+ </div>
);
} else {
- return h(UserAvatar, {
- class: "bb-user-select--avatar",
- user,
- size: "SMALL",
- });
+ return (
+ <UserAvatar class="bb-user-select--avatar" user={user} size="SMALL" />
+ );
}
};
@@ -268,30 +260,22 @@ const renderLabel = (option: SelectOption) => {
user.name === SYSTEM_BOT_USER_NAME
? t("settings.members.system-bot")
: user.title;
- const children = [h("span", { class: "max-w-[10rem] truncate" }, title)];
+ const children = [<span class="truncate">{title}</span>];
if (user.name !== UNKNOWN_USER_NAME && user.name !== SYSTEM_BOT_USER_NAME) {
children.push(
- h("span", { class: "text-gray-400 truncate" }, `(${user.email})`)
+ <span class="text-gray-400 truncate">{`(${user.email})`}</span>
);
}
if (user.userType === UserType.SERVICE_ACCOUNT) {
- children.push(h(ServiceAccountTag));
+ children.push(<ServiceAccountTag />);
}
- return h(
- "div",
- {
- class: "w-full flex items-center gap-x-2",
- },
- [
- avatar,
- h(
- "div",
- {
- class: "flex flex-row justify-start items-center gap-x-0.5 truncate",
- },
- children
- ),
- ]
+ return (
+ <div class="w-full flex items-center gap-x-2">
+ {avatar}
+ <div class="flex flex-row justify-start items-center gap-x-0.5 truncate">
+ {children}
+ </div>
+ </div>
);
};
diff --git a/frontend/src/layouts/ProjectV1Layout.vue b/frontend/src/layouts/ProjectV1Layout.vue
index a01f99e83c..b78f448722 100644
--- a/frontend/src/layouts/ProjectV1Layout.vue
+++ b/frontend/src/layouts/ProjectV1Layout.vue
@@ -151,7 +151,7 @@ onMounted(async () => {
style: "INFO",
title: activityName(activity.action),
manualHide: true,
- link: `/${project.value.name}/activities`,
+ link: `/${project.value.name}/audit-logs`,
linkTitle: t("common.view"),
});
break;
diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.json
index 2bed04d200..1093905eef 100644
--- a/frontend/src/locales/en-US.json
+++ b/frontend/src/locales/en-US.json
@@ -2766,12 +2766,15 @@
"updated-time": "Updated Time",
"actor": "Actor",
"type": "Audit Type",
- "level": "Audit Level",
+ "level": "Level",
"comment": "Comment",
"payload": "Payload",
"empty": "<Empty>",
"view-details": "View Details",
- "select-type": "Select Type"
+ "select-type": "Select Type",
+ "method": "Method",
+ "request": "Request",
+ "response": "Response"
},
"type": {
"workspace": {
diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.json
index ca73a3178a..318a062d49 100644
--- a/frontend/src/locales/es-ES.json
+++ b/frontend/src/locales/es-ES.json
@@ -2771,7 +2771,10 @@
"payload": "Datos",
"empty": "<Vacío>",
"view-details": "Ver detalles",
- "select-type": "Seleccionar tipo"
+ "select-type": "Seleccionar tipo",
+ "method": "Método",
+ "request": "Pedido",
+ "response": "Respuesta"
},
"type": {
"workspace": {
@@ -3463,4 +3466,4 @@
"drop-partition-with-subpartitions-confirm": "También eliminará todas sus subparticiones."
}
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.json
index 2c1a2f2805..98739bfa06 100644
--- a/frontend/src/locales/ja-JP.json
+++ b/frontend/src/locales/ja-JP.json
@@ -2771,7 +2771,10 @@
"payload": "ペイロード",
"empty": "<空>",
"view-details": "詳細を確認する",
- "select-type": "タイプを選択してください"
+ "select-type": "タイプを選択してください",
+ "method": "方法",
+ "request": "リクエスト",
+ "response": "応答"
},
"type": {
"workspace": {
@@ -3463,4 +3466,4 @@
"drop-partition-with-subpartitions-confirm": "すべてのサブパーティションが同時に削除されます。"
}
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/sql-review/zh-CN.json b/frontend/src/locales/sql-review/zh-CN.json
index b7221cb975..433ea92baf 100644
--- a/frontend/src/locales/sql-review/zh-CN.json
+++ b/frontend/src/locales/sql-review/zh-CN.json
@@ -99,15 +99,6 @@
}
}
},
- "table-disallow-dml": {
- "title": "禁止 DML",
- "description": "配置哪些表禁止执行 DML。建议错误级别:警告",
- "component": {
- "list": {
- "title": "表名"
- }
- }
- },
"table-limit-size": {
"title": "限制对数据量大的表执行 DDL 操作",
"description": "配置可执行 DDL 的表的最大数据量。建议错误级别:警告",
@@ -117,6 +108,15 @@
}
}
},
+ "table-disallow-dml": {
+ "title": "禁止 DML",
+ "description": "配置哪些表禁止执行 DML。建议错误级别:警告",
+ "component": {
+ "list": {
+ "title": "表名"
+ }
+ }
+ },
"naming-table": {
"title": "强制表命名格式",
"description": "默认格式为全小写字母,单词之间以下划线分割,长度不超过 63 个字符,例如 \"abc\",\"abc_def\"。建议错误等级:警告",
diff --git a/frontend/src/locales/vi-VN.json b/frontend/src/locales/vi-VN.json
index b1c6faa0b0..adc0b7339c 100644
--- a/frontend/src/locales/vi-VN.json
+++ b/frontend/src/locales/vi-VN.json
@@ -2771,7 +2771,10 @@
"payload": "Khối hàng",
"empty": "<Trống>",
"view-details": "Xem chi tiết",
- "select-type": "Lựa chọn đối tượng"
+ "select-type": "Lựa chọn đối tượng",
+ "method": "Phương pháp",
+ "request": "Lời yêu cầu",
+ "response": "Phản ứng"
},
"type": {
"workspace": {
@@ -3463,4 +3466,4 @@
"drop-partition-with-subpartitions-confirm": "Cũng sẽ bỏ tất cả các phân vùng của nó."
}
}
-}
+}
\ No newline at end of file
diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.json
index 4561a7f27a..6e93adfb25 100644
--- a/frontend/src/locales/zh-CN.json
+++ b/frontend/src/locales/zh-CN.json
@@ -2771,7 +2771,10 @@
"payload": "Payload",
"empty": "<空>",
"view-details": "查看详情",
- "select-type": "选择类型"
+ "select-type": "选择类型",
+ "method": "操作",
+ "request": "请求信息",
+ "response": "响应信息"
},
"type": {
"workspace": {
diff --git a/frontend/src/router/dashboard/projectV1.ts b/frontend/src/router/dashboard/projectV1.ts
index d281e351bc..d9921e7e68 100644
--- a/frontend/src/router/dashboard/projectV1.ts
+++ b/frontend/src/router/dashboard/projectV1.ts
@@ -24,7 +24,7 @@ export const PROJECT_V1_ROUTE_CHANGELIST_DETAIL = `${PROJECT_V1_ROUTE_DASHBOARD}
export const PROJECT_V1_ROUTE_SYNC_SCHEMA = `${PROJECT_V1_ROUTE_DASHBOARD}.sync-schema`;
export const PROJECT_V1_ROUTE_SLOW_QUERIES = `${PROJECT_V1_ROUTE_DASHBOARD}.slow-queries`;
export const PROJECT_V1_ROUTE_ANOMALIES = `${PROJECT_V1_ROUTE_DASHBOARD}.anomalies`;
-export const PROJECT_V1_ROUTE_ACTIVITIES = `${PROJECT_V1_ROUTE_DASHBOARD}.activities`;
+export const PROJECT_V1_ROUTE_AUDIT_LOGS = `${PROJECT_V1_ROUTE_DASHBOARD}.audit-logs`;
export const PROJECT_V1_ROUTE_GITOPS = `${PROJECT_V1_ROUTE_DASHBOARD}.gitops`;
export const PROJECT_V1_ROUTE_GITOPS_CREATE = `${PROJECT_V1_ROUTE_GITOPS}.create`;
export const PROJECT_V1_ROUTE_GITOPS_DETAIL = `${PROJECT_V1_ROUTE_GITOPS}.detail`;
@@ -296,13 +296,13 @@ const projectV1Routes: RouteRecordRaw[] = [
props: true,
},
{
- path: "activities",
- name: PROJECT_V1_ROUTE_ACTIVITIES,
+ path: "audit-logs",
+ name: PROJECT_V1_ROUTE_AUDIT_LOGS,
meta: {
overrideTitle: true,
requiredProjectPermissionList: () => ["bb.projects.get"],
},
- component: () => import("@/views/project/ProjectActivityDashboard.vue"),
+ component: () => import("@/views/project/ProjectAuditLogDashboard.vue"),
props: true,
},
{
diff --git a/frontend/src/store/modules/v1/activity.ts b/frontend/src/store/modules/v1/activity.ts
index c43cc0deee..93d4c3f72a 100644
--- a/frontend/src/store/modules/v1/activity.ts
+++ b/frontend/src/store/modules/v1/activity.ts
@@ -3,15 +3,13 @@ import utc from "dayjs/plugin/utc";
import { defineStore } from "pinia";
import { reactive } from "vue";
import { loggingServiceClient } from "@/grpcweb";
-import type { IdType, FindActivityMessage, ComposedIssue } from "@/types";
-import type { ExportFormat } from "@/types/proto/v1/common";
+import type { FindActivityMessage } from "@/types";
import type { LogEntity } from "@/types/proto/v1/logging_service";
import {
logEntity_ActionToJSON,
logEntity_LevelToJSON,
} from "@/types/proto/v1/logging_service";
-import { isDatabaseChangeRelatedIssue, extractRolloutUID } from "@/utils";
-import { userNamePrefix, getLogId } from "./common";
+import { userNamePrefix } from "./common";
dayjs.extend(utc);
@@ -48,6 +46,7 @@ const buildFilter = (find: FindActivityMessage): string => {
return filter.join(" && ");
};
+// TODO(steven): migrate to `useAuditLogStore`.
export const useActivityV1Store = defineStore("activity_v1", () => {
const activityListByIssueV1 = reactive(new Map<string, LogEntity[]>());
@@ -65,61 +64,9 @@ export const useActivityV1Store = defineStore("activity_v1", () => {
const getActivityListByIssueV1 = (uid: string): LogEntity[] => {
return activityListByIssueV1.get(uid) || [];
};
- const fetchActivityListForIssueV1 = async (issue: ComposedIssue) => {
- const requests = [
- fetchActivityList({
- resource: `issues/${issue.uid}`,
- order: "asc",
- pageSize: 1000, // Pagination is complex, and not high priority
- }).then((resp) => resp.logEntities),
- ];
- if (isDatabaseChangeRelatedIssue(issue) && issue.rollout) {
- const pipelineUID = extractRolloutUID(issue.rollout);
- requests.push(
- fetchActivityList({
- resource: `pipelines/${pipelineUID}`,
- order: "asc",
- pageSize: 1000, // Pagination is complex, and not high priority
- }).then((resp) => resp.logEntities)
- );
- } else {
- requests.push(Promise.resolve([]));
- }
-
- const [listForIssue, listForPipeline] = await Promise.all(requests);
- const mergedList = [...listForIssue, ...listForPipeline];
- mergedList.sort((a, b) => {
- return getLogId(a.name) - getLogId(b.name);
- });
-
- activityListByIssueV1.set(issue.uid, mergedList);
- return mergedList;
- };
-
- const getResourceId = (activity: LogEntity): IdType => {
- return activity.resource.split("/").slice(-1)[0];
- };
-
- const exportData = async ({
- find,
- format,
- }: {
- find: FindActivityMessage;
- format: ExportFormat;
- }) => {
- const resp = await loggingServiceClient.exportLogs({
- orderBy: find.order ? `create_time ${find.order}` : "",
- filter: buildFilter(find),
- format,
- });
- return resp.content;
- };
return {
fetchActivityList,
- fetchActivityListForIssueV1,
getActivityListByIssueV1,
- getResourceId,
- exportData,
};
});
diff --git a/frontend/src/store/modules/v1/auditLog.ts b/frontend/src/store/modules/v1/auditLog.ts
index 8752a5c50b..74023a1d26 100644
--- a/frontend/src/store/modules/v1/auditLog.ts
+++ b/frontend/src/store/modules/v1/auditLog.ts
@@ -11,8 +11,8 @@ dayjs.extend(utc);
const buildFilter = (search: SearchAuditLogsParams): string => {
const filter: string[] = [];
- if (search.resource) {
- filter.push(`resource == "${search.resource}"`);
+ if (search.parent) {
+ filter.push(`parent == "${search.parent}"`);
}
if (search.creatorEmail) {
filter.push(`user == "${userNamePrefix}${search.creatorEmail}"`);
diff --git a/frontend/src/types/auditLog.ts b/frontend/src/types/auditLog.ts
index 9a765cf5d1..cfb018cada 100644
--- a/frontend/src/types/auditLog.ts
+++ b/frontend/src/types/auditLog.ts
@@ -47,7 +47,7 @@ export const AuditActivityTypeI18nNameMap: Map<LogEntity_Action, string> =
]);
export interface SearchAuditLogsParams {
- resource?: string;
+ parent?: string;
creatorEmail?: string;
order?: "asc" | "desc";
pageSize?: number;
diff --git a/frontend/src/views/SettingWorkspaceAuditLog.vue b/frontend/src/views/SettingWorkspaceAuditLog.vue
index 1a5c0580b5..edde560018 100644
--- a/frontend/src/views/SettingWorkspaceAuditLog.vue
+++ b/frontend/src/views/SettingWorkspaceAuditLog.vue
@@ -2,262 +2,55 @@
<div class="w-full space-y-4">
<FeatureAttention feature="bb.feature.audit-log" />
<div class="flex justify-end items-center space-x-2">
- <UserSelect
- v-model:user="state.userUid"
- :multiple="false"
- :include-all="true"
- />
- <div class="w-52">
- <TypeSelect
- v-model:selected="state.selectedAuditTypeList"
- :disabled="!hasAuditLogFeature"
+ <div class="w-72">
+ <UserSelect
+ v-model:user="state.userUid"
+ :multiple="false"
+ :include-all="true"
/>
</div>
- <div class="hidden sm:block w-112">
- <NDatePicker
- v-model:value="selectedTimeRange"
- type="datetimerange"
- :on-confirm="confirmDatePicker"
- :on-clear="clearDatePicker"
- clearable
- >
- </NDatePicker>
- </div>
- <DataExportButton
- size="medium"
- :file-type="'raw'"
- :support-formats="[
- ExportFormat.CSV,
- ExportFormat.JSON,
- ExportFormat.XLSX,
- ]"
- :disabled="!hasAuditLogFeature"
- @export="handleExport"
- />
</div>
- <PagedActivityTable
+ <PagedAuditLogTable
v-if="hasAuditLogFeature"
- :activity-find="activityFind"
- session-key="bb.page-audit-log-table.settings-audit-log-table"
+ :search-audit-logs="searchAuditLogs"
+ session-key="bb.page-audit-log-table.settings-audit-log-v1-table"
:page-size="10"
>
<template #table="{ list }">
- <AuditLogTable :audit-log-list="list" @view-detail="handleViewDetail" />
+ <AuditLogDataTable :audit-log-list="list" />
</template>
- </PagedActivityTable>
+ </PagedAuditLogTable>
<template v-else>
- <AuditLogTable :audit-log-list="[]" />
+ <AuditLogDataTable :audit-log-list="[]" />
</template>
-
- <BBDialog
- ref="dialog"
- :title="$t('audit-log.audit-log-detail')"
- data-label="bb-audit-log-detail-dialog"
- :closable="true"
- :show-negative-btn="false"
- >
- <div class="w-192 font-mono">
- <dl>
- <dd
- v-for="(value, key) in state.modalContent"
- :key="key"
- class="flex items-start text-sm md:mr-4 mb-1"
- >
- <NGrid x-gap="20" :cols="20">
- <NGi span="3">
- <span class="textlabel whitespace-nowrap">{{
- logKeyMap[key]
- }}</span
- ><span class="mr-1">:</span>
- </NGi>
- <NGi span="17">
- <span v-if="value !== ''">
- {{ value }}
- </span>
- <span v-else class="italic text-gray-500">
- {{ $t("audit-log.table.empty") }}
- </span>
- </NGi>
- </NGrid>
- </dd>
- </dl>
- </div>
- </BBDialog>
</div>
</template>
<script lang="ts" setup>
-import dayjs from "dayjs";
-import { NGrid, NGi, NDatePicker } from "naive-ui";
-import type { BinaryLike } from "node:crypto";
-import { reactive, ref, computed, watch } from "vue";
-import { useI18n } from "vue-i18n";
-import { useRoute, useRouter } from "vue-router";
-import { BBDialog } from "@/bbkit";
-import type { ExportOption } from "@/components/DataExportButton.vue";
-import { WORKSPACE_ROUTE_AUDIT_LOG } from "@/router/dashboard/workspaceRoutes";
-import { featureToRef, useUserStore, useActivityV1Store } from "@/store";
-import type { FindActivityMessage } from "@/types";
-import {
- AuditActivityTypeList,
- UNKNOWN_ID,
- AuditActivityTypeI18nNameMap,
-} from "@/types";
-import { ExportFormat } from "@/types/proto/v1/common";
-import type {
- LogEntity,
- LogEntity_Action,
-} from "@/types/proto/v1/logging_service";
-import { logEntity_LevelToJSON } from "@/types/proto/v1/logging_service";
+import { reactive, computed } from "vue";
+import AuditLogDataTable from "@/components/AuditLog/AuditLogDataTable.vue";
+import PagedAuditLogTable from "@/components/PagedAuditLogTable.vue";
+import { featureToRef, useUserStore } from "@/store";
+import type { SearchAuditLogsParams } from "@/types";
+import { UNKNOWN_ID } from "@/types";
-const dialog = ref<InstanceType<typeof BBDialog> | null>(null);
const state = reactive({
- modalContent: {},
userUid: String(UNKNOWN_ID),
- selectedAuditTypeList: [] as LogEntity_Action[],
});
-const { t } = useI18n();
-const router = useRouter();
-const route = useRoute();
const userStore = useUserStore();
-const activityV1Store = useActivityV1Store();
const hasAuditLogFeature = featureToRef("bb.feature.audit-log");
-const logKeyMap = {
- createdTs: t("audit-log.table.created-time"),
- level: t("audit-log.table.level"),
- action: t("audit-log.table.type"),
- creator: t("audit-log.table.actor"),
- comment: t("audit-log.table.comment"),
- payload: t("audit-log.table.payload"),
-};
-
-watch(
- () => state.userUid,
- (uid) => {
- router.replace({
- name: WORKSPACE_ROUTE_AUDIT_LOG,
- query: {
- ...route.query,
- user: parseInt(uid, 10) > 0 ? uid : undefined,
- },
- });
- }
-);
-
-watch(
- () => state.selectedAuditTypeList,
- (list) => {
- router.replace({
- name: WORKSPACE_ROUTE_AUDIT_LOG,
- query: {
- ...route.query,
- type: list.join(","),
- },
- });
- }
-);
-
const selectedUserEmail = computed((): string => {
- const id = route.query.user as string;
- const selected = userStore.getUserById(id);
+ const selected = userStore.getUserById(state.userUid);
return selected?.email ?? "";
});
-const selectedTimeRange = computed((): [number, number] => {
- const defaultTimeRange = [0, Date.now()] as [number, number];
- const createdTsAfter = route.query.createdTsAfter as string;
- if (createdTsAfter) {
- defaultTimeRange[0] = parseInt(createdTsAfter, 10);
- }
- const createdTsBefore = route.query.createdTsBefore as string;
- if (createdTsBefore) {
- defaultTimeRange[1] = parseInt(createdTsBefore, 10);
- }
- return defaultTimeRange;
-});
-
-const handleViewDetail = (log: LogEntity) => {
- // Display detail fields in the same order as logKeyMap.
- state.modalContent = Object.fromEntries(
- Object.keys(logKeyMap)
- .map((logKey) => {
- switch (logKey) {
- case "createdTs":
- return [
- logKey,
- dayjs(log.createTime).format("YYYY-MM-DD HH:mm:ss Z"),
- ];
- case "level":
- return [logKey, logEntity_LevelToJSON(log.level)];
- case "action":
- return [
- logKey,
- t(AuditActivityTypeI18nNameMap.get(log.action) ?? ""),
- ];
- case "creator":
- return [logKey, log.creator];
- case "comment":
- return [logKey, log.comment];
- case "payload":
- return [logKey, log.payload];
- }
- return [];
- })
- .filter((arr) => arr.length === 2)
- );
- dialog.value!.open();
-};
-
-const confirmDatePicker = (value: [number, number]) => {
- router.replace({
- name: WORKSPACE_ROUTE_AUDIT_LOG,
- query: {
- ...route.query,
- createdTsAfter: value[0],
- createdTsBefore: value[1],
- },
- });
-};
-
-const clearDatePicker = () => {
- router.replace({
- name: WORKSPACE_ROUTE_AUDIT_LOG,
- query: {
- ...route.query,
- createdTsAfter: 0,
- createdTsBefore: Date.now(),
- },
- });
-};
-
-const activityFind = computed((): FindActivityMessage => {
+const searchAuditLogs = computed((): SearchAuditLogsParams => {
return {
- action:
- state.selectedAuditTypeList.length > 0
- ? state.selectedAuditTypeList
- : AuditActivityTypeList,
creatorEmail: selectedUserEmail.value,
order: "desc",
- createdTsAfter: selectedTimeRange.value
- ? selectedTimeRange.value[0]
- : undefined,
- createdTsBefore: selectedTimeRange.value
- ? selectedTimeRange.value[1]
- : undefined,
};
});
-
-const handleExport = async (
- options: ExportOption,
- callback: (content: BinaryLike | Blob, options: ExportOption) => void
-) => {
- const content = await activityV1Store.exportData({
- find: activityFind.value,
- format: options.format,
- });
- callback(content, options);
-};
</script>
diff --git a/frontend/src/views/project/ProjectActivityDashboard.vue b/frontend/src/views/project/ProjectActivityDashboard.vue
deleted file mode 100644
index 3dc05cc7d7..0000000000
--- a/frontend/src/views/project/ProjectActivityDashboard.vue
+++ /dev/null
@@ -1,21 +0,0 @@
-<template>
- <ProjectActivityPanel :project="project" />
-</template>
-
-<script setup lang="ts">
-import { computed } from "vue";
-import { useProjectV1Store } from "@/store";
-import { projectNamePrefix } from "@/store/modules/v1/common";
-
-const props = defineProps<{
- projectId: string;
-}>();
-
-const projectV1Store = useProjectV1Store();
-
-const project = computed(() => {
- return projectV1Store.getProjectByName(
- `${projectNamePrefix}${props.projectId}`
- );
-});
-</script>
diff --git a/frontend/src/views/project/ProjectAuditLogDashboard.vue b/frontend/src/views/project/ProjectAuditLogDashboard.vue
new file mode 100644
index 0000000000..bfe593a7a3
--- /dev/null
+++ b/frontend/src/views/project/ProjectAuditLogDashboard.vue
@@ -0,0 +1,45 @@
+<template>
+ <PagedAuditLogTable
+ v-if="hasAuditLogFeature"
+ :search-audit-logs="searchAuditLogs"
+ session-key="bb.page-audit-log-table.settings-audit-log-v1-table"
+ :page-size="10"
+ >
+ <template #table="{ list }">
+ <AuditLogDataTable :audit-log-list="list" :show-project="false" />
+ </template>
+ </PagedAuditLogTable>
+ <template v-else>
+ <AuditLogDataTable :audit-log-list="[]" :show-project="false" />
+ </template>
+</template>
+
+<script setup lang="ts">
+import { computed } from "vue";
+import AuditLogDataTable from "@/components/AuditLog/AuditLogDataTable.vue";
+import PagedAuditLogTable from "@/components/PagedAuditLogTable.vue";
+import { featureToRef, useProjectV1Store } from "@/store";
+import { projectNamePrefix } from "@/store/modules/v1/common";
+import type { SearchAuditLogsParams } from "@/types";
+
+const props = defineProps<{
+ projectId: string;
+}>();
+
+const hasAuditLogFeature = featureToRef("bb.feature.audit-log");
+
+const projectV1Store = useProjectV1Store();
+
+const project = computed(() => {
+ return projectV1Store.getProjectByName(
+ `${projectNamePrefix}${props.projectId}`
+ );
+});
+
+const searchAuditLogs = computed((): SearchAuditLogsParams => {
+ return {
+ parent: project.value.name,
+ order: "desc",
+ };
+});
+</script>