Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
chore: export full audit logs (#14251)
ecmadaof51cfb599df5
diff --git a/backend/api/v1/audit_log_service.go b/backend/api/v1/audit_log_service.goindex 097572e07e..36feefa769 100644--- a/backend/api/v1/audit_log_service.go+++ b/backend/api/v1/audit_log_service.go@@ -149,7 +149,7 @@ func (s *AuditLogService) ExportAuditLogs(ctx context.Context, request *v1pb.Expreturn nil, status.Errorf(codes.InvalidArgument, "unsupported export format: %s", request.Format.String())}- return &v1pb.ExportAuditLogsResponse{Content: content}, nil+ return &v1pb.ExportAuditLogsResponse{Content: content, NextPageToken: searchAuditLogsResult.NextPageToken}, nil}func convertToAuditLogs(ctx context.Context, stores *store.Store, auditLogs []*store.AuditLog) ([]*v1pb.AuditLog, error) {diff --git a/frontend/src/components/DataExportButton.vue b/frontend/src/components/DataExportButton.vueindex 1014bcc8d6..45186a1975 100644--- a/frontend/src/components/DataExportButton.vue+++ b/frontend/src/components/DataExportButton.vue@@ -107,7 +107,6 @@<script lang="ts" setup>import { asyncComputed } from "@vueuse/core";-import dayjs from "dayjs";import type { FormInst, FormRules } from "naive-ui";import {NButton,@@ -123,7 +122,7 @@ import { useI18n } from "vue-i18n";import { BBModal, BBTextField } from "@/bbkit";import { pushNotification } from "@/store";import { ExportFormat, exportFormatToJSON } from "@/types/proto/v1/common";-import { defer, isNullOrUndefined } from "@/utils";+import { isNullOrUndefined } from "@/utils";import MaxRowCountSelect from "./GrantRequestPanel/MaxRowCountSelect.vue";import { Drawer, DrawerContent, ErrorTipsButton } from "./v2";@@ -164,7 +163,7 @@ const emit = defineEmits<{(event: "export",options: ExportOption,- download: (content: BinaryLike | Blob, options: ExportOption) => void+ download: (content: BinaryLike | Blob, filename: string) => void): Promise<void>;}>();@@ -252,33 +251,21 @@ const handleClickExportButton = (e: MouseEvent) => {state.showDrawer = true;};-const emitExportEventAsPromise = (- options: ExportOption,- download: (content: BinaryLike | Blob, options: ExportOption) => void-) => {- const d = defer<void>();-- emit(- "export",- options,- (content: BinaryLike | Blob, options: ExportOption) => {- d.resolve();- download(content, options);- }- );-- return d.promise;-};-const doExport = async () => {if (state.isRequesting) {return;}state.isRequesting = true;-+ const options = { ...formData.value };try {- await emitExportEventAsPromise({ ...formData.value }, doDownload);+ await emit(+ "export",+ options,+ (content: BinaryLike | Blob, filename: string) => {+ doDownload(content, options, filename);+ }+ );} catch (error) {pushNotification({module: "bytebase",@@ -309,7 +296,11 @@ const getExportFileType = (format: ExportFormat) => {}};-const doDownload = (content: BinaryLike | Blob, options: ExportOption) => {+const doDownload = (+ content: BinaryLike | Blob,+ options: ExportOption,+ filename: string+) => {const isZip = downloadFileAsZip(options);const fileType = isZip? "application/zip"@@ -320,8 +311,6 @@ const doDownload = (content: BinaryLike | Blob, options: ExportOption) => {const url = window.URL.createObjectURL(blob);const fileFormat = exportFormatToJSON(options.format).toLowerCase();- const formattedDateString = dayjs(new Date()).format("YYYY-MM-DDTHH-mm-ss");- const filename = `export-data-${formattedDateString}`;const link = document.createElement("a");link.download = `${filename}.${isZip ? "zip" : fileFormat}`;link.href = url;diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex a40016fe5e..baecb5d1ff 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -3049,6 +3049,7 @@"audit-log": {"no-logs": "No audit logs","audit-log-detail": "Audit Log Details",+ "export-finished": "Export finished","table": {"created-ts": "Time","created-time": "Created Time",diff --git a/frontend/src/locales/es-ES.json b/frontend/src/locales/es-ES.jsonindex a907765038..7ef0b967bf 100644--- a/frontend/src/locales/es-ES.json+++ b/frontend/src/locales/es-ES.json@@ -3049,6 +3049,7 @@"audit-log": {"no-logs": "Sin registros de auditoría","audit-log-detail": "Detalles del registro de auditoría",+ "export-finished": "Exportación finalizada","table": {"created-ts": "Hora","created-time": "Hora de creación",@@ -3839,4 +3840,4 @@"setup": {"self": "Configuración"}-}+}\ No newline at end of filediff --git a/frontend/src/locales/ja-JP.json b/frontend/src/locales/ja-JP.jsonindex da5c52bfb3..da5b93b73f 100644--- a/frontend/src/locales/ja-JP.json+++ b/frontend/src/locales/ja-JP.json@@ -3049,6 +3049,7 @@"audit-log": {"no-logs": "監査ログはまだありません","audit-log-detail": "監査の詳細",+ "export-finished": "エクスポートが完了しました","table": {"created-ts": "時間","created-time": "作成時間",diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 5b98b3fb6e..1eb33ece01 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -3049,6 +3049,7 @@"audit-log": {"no-logs": "暂无审计日志","audit-log-detail": "审计详情",+ "export-finished": "导出完成","table": {"created-ts": "时间","created-time": "创建时间",@@ -3839,4 +3840,4 @@"setup": {"self": "设置"}-}+}\ No newline at end of filediff --git a/frontend/src/store/modules/v1/auditLog.ts b/frontend/src/store/modules/v1/auditLog.tsindex 583e92aaa8..43c10df19e 100644--- a/frontend/src/store/modules/v1/auditLog.ts+++ b/frontend/src/store/modules/v1/auditLog.ts@@ -1,5 +1,6 @@import dayjs from "dayjs";import utc from "dayjs/plugin/utc";+import type { BinaryLike } from "node:crypto";import { defineStore } from "pinia";import { reactive } from "vue";import { auditLogServiceClient } from "@/grpcweb";@@ -56,16 +57,17 @@ export const useAuditLogStore = defineStore("audit_log", () => {const exportAuditLogs = async (search: SearchAuditLogsParams,format: ExportFormat- ) => {- const { content } = await auditLogServiceClient.exportAuditLogs({+ ): Promise<{+ content: BinaryLike | Blob;+ nextPageToken: string;+ }> => {+ return await auditLogServiceClient.exportAuditLogs({parent: search.parent,filter: buildFilter(search),orderBy: search.order ? `create_time ${search.order}` : undefined,format,- // TODO: paginationpageSize: 1000,});- return content;};return {diff --git a/frontend/src/views/SettingWorkspaceAuditLog.vue b/frontend/src/views/SettingWorkspaceAuditLog.vueindex 313711cb78..333a162e0d 100644--- a/frontend/src/views/SettingWorkspaceAuditLog.vue+++ b/frontend/src/views/SettingWorkspaceAuditLog.vue@@ -33,8 +33,10 @@</template><script lang="ts" setup>+import dayjs from "dayjs";import type { BinaryLike } from "node:crypto";import { reactive, computed } from "vue";+import { useI18n } from "vue-i18n";import AuditLogDataTable from "@/components/AuditLog/AuditLogDataTable.vue";import AuditLogSearch from "@/components/AuditLog/AuditLogSearch";import { buildSearchAuditLogParams } from "@/components/AuditLog/AuditLogSearch/utils";@@ -42,7 +44,7 @@ import type { ExportOption } from "@/components/DataExportButton.vue";import DataExportButton from "@/components/DataExportButton.vue";import { FeatureAttention } from "@/components/FeatureGuard";import PagedAuditLogTable from "@/components/PagedAuditLogTable.vue";-import { featureToRef, useAuditLogStore } from "@/store";+import { featureToRef, useAuditLogStore, pushNotification } from "@/store";import type { SearchAuditLogsParams } from "@/types";import { ExportFormat } from "@/types/proto/v1/common";import { type SearchParams } from "@/utils";@@ -62,7 +64,7 @@ const defaultSearchParams = () => {const state = reactive<LocalState>({params: defaultSearchParams(),});-+const { t } = useI18n();const auditLogStore = useAuditLogStore();const hasAuditLogFeature = featureToRef("bb.feature.audit-log");@@ -76,12 +78,29 @@ const searchAuditLogs = computed((): SearchAuditLogsParams => {const handleExport = async (options: ExportOption,- callback: (content: BinaryLike | Blob, options: ExportOption) => void+ callback: (content: BinaryLike | Blob, filename: string) => void) => {- const content = await auditLogStore.exportAuditLogs(- searchAuditLogs.value,- options.format- );- callback(content, options);+ let pageToken = "";+ let i = 0;++ while (i === 0 || pageToken !== "") {+ i++;+ const { content, nextPageToken } = await auditLogStore.exportAuditLogs(+ searchAuditLogs.value,+ options.format+ );+ pageToken = nextPageToken;+ callback(+ content,+ `audit-log${!pageToken && i === 1 ? "" : `.file${i}`}.${dayjs(new Date()).format("YYYY-MM-DDTHH-mm-ss")}`+ );+ }++ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.success"),+ description: t("audit-log.export-finished"),+ });};</script>diff --git a/frontend/src/views/project/ProjectAuditLogDashboard.vue b/frontend/src/views/project/ProjectAuditLogDashboard.vueindex 2b661402a6..5f8e849f7e 100644--- a/frontend/src/views/project/ProjectAuditLogDashboard.vue+++ b/frontend/src/views/project/ProjectAuditLogDashboard.vue@@ -23,7 +23,7 @@<PagedAuditLogTablev-if="hasAuditLogFeature":search-audit-logs="searchAuditLogs"- session-key="bb.page-audit-log-table.settings-audit-log-v1-table"+ :session-key="`bb.page-audit-log-table.settings-audit-log-v1-table.${projectId}`":page-size="10"><template #table="{ list }">@@ -45,8 +45,10 @@</template><script setup lang="ts">+import dayjs from "dayjs";import type { BinaryLike } from "node:crypto";import { computed, reactive } from "vue";+import { useI18n } from "vue-i18n";import AuditLogDataTable from "@/components/AuditLog/AuditLogDataTable.vue";import AuditLogSearch from "@/components/AuditLog/AuditLogSearch";import { buildSearchAuditLogParams } from "@/components/AuditLog/AuditLogSearch/utils";@@ -54,7 +56,7 @@ import type { ExportOption } from "@/components/DataExportButton.vue";import DataExportButton from "@/components/DataExportButton.vue";import { FeatureAttention } from "@/components/FeatureGuard";import PagedAuditLogTable from "@/components/PagedAuditLogTable.vue";-import { featureToRef, useAuditLogStore } from "@/store";+import { featureToRef, useAuditLogStore, pushNotification } from "@/store";import { type SearchAuditLogsParams } from "@/types";import { ExportFormat } from "@/types/proto/v1/common";import type { SearchParams, SearchScope } from "@/utils";@@ -82,7 +84,7 @@ const defaultSearchParams = () => {const state = reactive<LocalState>({params: defaultSearchParams(),});-+const { t } = useI18n();const hasAuditLogFeature = featureToRef("bb.feature.audit-log");const auditLogStore = useAuditLogStore();@@ -96,12 +98,29 @@ const searchAuditLogs = computed((): SearchAuditLogsParams => {const handleExport = async (options: ExportOption,- callback: (content: BinaryLike | Blob, options: ExportOption) => void+ callback: (content: BinaryLike | Blob, filename: string) => void) => {- const content = await auditLogStore.exportAuditLogs(- searchAuditLogs.value,- options.format- );- callback(content, options);+ let pageToken = "";+ let i = 0;++ while (i === 0 || pageToken !== "") {+ i++;+ const { content, nextPageToken } = await auditLogStore.exportAuditLogs(+ searchAuditLogs.value,+ options.format+ );+ pageToken = nextPageToken;+ callback(+ content,+ `audit-log${!pageToken && i === 1 ? "" : `.file${i}`}.${dayjs(new Date()).format("YYYY-MM-DDTHH-mm-ss")}`+ );+ }++ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: t("common.success"),+ description: t("audit-log.export-finished"),+ });};</script>diff --git a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vueindex 2274ac56db..5f9d0c7fda 100644--- a/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue+++ b/frontend/src/views/sql-editor/EditorCommon/ResultView/SingleResultViewV1.vue@@ -188,6 +188,7 @@ import {useVueTable,} from "@tanstack/vue-table";import { useDebounceFn, useLocalStorage } from "@vueuse/core";+import dayjs from "dayjs";import { isEmpty } from "lodash-es";import { ExternalLinkIcon } from "lucide-vue-next";import {@@ -439,7 +440,7 @@ const pageSizeOptions = computed(() => {const handleExportBtnClick = async (options: ExportOption,- callback: (content: BinaryLike | Blob, options: ExportOption) => void+ callback: (content: BinaryLike | Blob, filename: string) => void) => {// If props.database is specified and it's not unknown database// the query is executed on database level@@ -466,7 +467,10 @@ const handleExportBtnClick = async (password: options.password,});- callback(content, options);+ callback(+ content,+ `export-data.${dayjs(new Date()).format("YYYY-MM-DDTHH-mm-ss")}`+ );};const handleRequestExport = async () => {