Skip to content

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

Reveal readonly mode in frontend

天舟31c508ef8ce5
diff --git a/api/actuator.go b/api/actuator.go
index bf2778d267..22df2f5590 100644
--- a/api/actuator.go
+++ b/api/actuator.go
@@ -2,6 +2,7 @@ package api
// Actuator concept is similar to the Spring Boot Actuator
type ServerInfo struct {
+ Readonly bool `json:"readonly"`
Demo bool `json:"demo"`
Host string `json:"host"`
Port string `json:"port"`
diff --git a/frontend/src/components/RequestDatabasePrepForm.vue b/frontend/src/components/RequestDatabasePrepForm.vue
index 25546ebca8..c61245757c 100644
--- a/frontend/src/components/RequestDatabasePrepForm.vue
+++ b/frontend/src/components/RequestDatabasePrepForm.vue
@@ -92,10 +92,10 @@
/>
<BBSwitch
:label="'Read only'"
- :value="state.readOnly"
+ :value="state.readonly"
@toggle="
(on) => {
- state.readOnly = on;
+ state.readonly = on;
}
"
/>
@@ -142,7 +142,7 @@ interface LocalState {
create: "ON" | "OFF";
databaseName: string;
databaseId: DatabaseId;
- readOnly: boolean;
+ readonly: boolean;
}
export default {
@@ -176,7 +176,7 @@ export default {
create: "ON",
databaseName: "",
databaseId: UNKNOWN_ID,
- readOnly: true,
+ readonly: true,
});
const alreadyGranted = computed(() => {
@@ -191,7 +191,7 @@ export default {
return allowDatabaseAccess(
store.getters["database/databaseById"](state.databaseId),
currentUser.value,
- state.readOnly ? "RO" : "RW"
+ state.readonly ? "RO" : "RW"
);
});
@@ -241,12 +241,12 @@ export default {
query: {
template: "bb.issue.database.grant",
name: `[${environment.name}] Request database '${database.name}' ${
- state.readOnly ? "Read Only access" : "Read & Write access"
+ state.readonly ? "Readonly access" : "Read & Write access"
}`,
environment: state.environmentId,
project: state.projectId,
databaseList: state.databaseId,
- readonly: state.readOnly ? "true" : "false",
+ readonly: state.readonly ? "true" : "false",
},
});
}
diff --git a/frontend/src/layouts/DashboardLayout.vue b/frontend/src/layouts/DashboardLayout.vue
index 15e63588e9..11e31c5efc 100644
--- a/frontend/src/layouts/DashboardLayout.vue
+++ b/frontend/src/layouts/DashboardLayout.vue
@@ -1,6 +1,26 @@
<template>
<div class="relative h-screen overflow-hidden flex flex-col">
- <BannerDemo v-if="isDemo" />
+ <template v-if="isDemo">
+ <BannerDemo />
+ </template>
+ <template v-else-if="isReadonly">
+ <div
+ class="
+ h-12
+ w-full
+ text-lg
+ font-medium
+ bg-yellow-500
+ text-white
+ flex
+ justify-center
+ items-center
+ "
+ >
+ Server is in readonly mode. You can still view the console, but any
+ change attempt will fail.
+ </div>
+ </template>
<nav class="bg-white border-b border-block-border">
<div class="max-w-full mx-auto px-4">
<DashboardHeader />
@@ -54,9 +74,12 @@ export default {
const isDemo = computed(() => store.getters["actuator/isDemo"]());
+ const isReadonly = computed(() => store.getters["actuator/isReadonly"]());
+
return {
ping,
isDemo,
+ isReadonly,
};
},
};
diff --git a/frontend/src/plugins/issue/DatabaseGrantTemplate.ts b/frontend/src/plugins/issue/DatabaseGrantTemplate.ts
index 7d81467bb1..acb8a096ee 100644
--- a/frontend/src/plugins/issue/DatabaseGrantTemplate.ts
+++ b/frontend/src/plugins/issue/DatabaseGrantTemplate.ts
@@ -77,13 +77,13 @@ const template: IssueTemplate = {
const issue = ctx.issue as Issue;
const database = issue.pipeline.stageList[0].taskList[0].database!;
- const readOnly = issue.payload[INPUT_READ_ONLY_FIELD_ID];
+ const readonly = issue.payload[INPUT_READ_ONLY_FIELD_ID];
let dataSourceId;
for (const dataSource of database.dataSourceList) {
- if (readOnly && dataSource.type == "RO") {
+ if (readonly && dataSource.type == "RO") {
dataSourceId = dataSource.id;
break;
- } else if (!readOnly && dataSource.type == "RW") {
+ } else if (!readonly && dataSource.type == "RW") {
dataSourceId = dataSource.id;
break;
}
diff --git a/frontend/src/store/modules/actuator.ts b/frontend/src/store/modules/actuator.ts
index 9beb03f602..8ddfcfd0dc 100644
--- a/frontend/src/store/modules/actuator.ts
+++ b/frontend/src/store/modules/actuator.ts
@@ -12,6 +12,9 @@ const getters = {
isDemo: (state: ActuatorState) => (): boolean => {
return state.serverInfo?.demo || false;
},
+ isReadonly: (state: ActuatorState) => (): boolean => {
+ return state.serverInfo?.readonly || false;
+ },
};
const actions = {
diff --git a/frontend/src/types/actuator.ts b/frontend/src/types/actuator.ts
index 577c44a7c1..62ca0748c0 100644
--- a/frontend/src/types/actuator.ts
+++ b/frontend/src/types/actuator.ts
@@ -1,4 +1,5 @@
export type ServerInfo = {
+ readonly: boolean;
demo: boolean;
host: string;
port: string;
diff --git a/frontend/src/views/BannerDemo.vue b/frontend/src/views/BannerDemo.vue
index 539c7f8297..354bcd499d 100644
--- a/frontend/src/views/BannerDemo.vue
+++ b/frontend/src/views/BannerDemo.vue
@@ -3,47 +3,68 @@
<div class="max-w-7xl mx-auto py-3 px-3">
<div class="flex items-center justify-between flex-wrap">
<div class="w-0 flex-1 flex items-center">
- <span class="flex p-2 rounded-lg bg-accent-hover">
- <!-- Heroicon name: outline/speakerphone -->
- <svg
- class="h-6 w-6 text-white"
- xmlns="http://www.w3.org/2000/svg"
- fill="none"
- viewBox="0 0 24 24"
- stroke="currentColor"
- aria-hidden="true"
- >
- <path
- stroke-linecap="round"
- stroke-linejoin="round"
- stroke-width="2"
- d="M11 5.882V19.24a1.76 1.76 0 01-3.417.592l-2.147-6.15M18 13a3 3 0 100-6M5.436 13.683A4.001 4.001 0 017 6h1.832c4.1 0 7.625-1.234 9.168-3v14c-1.543-1.766-5.067-3-9.168-3H7a3.988 3.988 0 01-1.564-.317z"
- />
- </svg>
- </span>
<p class="ml-3 font-medium text-white truncate">
<span>
- You are trying a DEMO version. Feel free to make whatever changes
- and all data will be reset after reloading the page.</span
- >
+ {{
+ isReadonly
+ ? "You are trying a DEMO version in readonly mode."
+ : "You are trying a DEMO version."
+ }}
+ </span>
</p>
</div>
<div
- v-if="false"
class="order-3 mt-2 flex-shrink-0 w-full sm:order-2 sm:mt-0 sm:w-auto"
>
<a
href="https://github.com/bytebase/bytebase"
target="_blank"
- class="flex items-center justify-center px-4 py-2 border border-transparent rounded-md shadow-sm text-sm font-medium text-accent bg-white hover:bg-indigo-50"
+ class="
+ flex
+ items-center
+ justify-center
+ pl-4
+ pr-2
+ py-2
+ border border-transparent
+ rounded-md
+ shadow-sm
+ text-base
+ font-medium
+ text-accent
+ bg-white
+ hover:bg-indigo-50
+ "
>
- Deploy Yours ->
+ Deploy yours in 15 seconds
+ <svg
+ class="ml-1 w-6 h-6"
+ fill="none"
+ stroke="currentColor"
+ viewBox="0 0 24 24"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ stroke-linecap="round"
+ stroke-linejoin="round"
+ stroke-width="2"
+ d="M13 10V3L4 14h7v7l9-11h-7z"
+ ></path>
+ </svg>
</a>
</div>
<div class="order-2 flex-shrink-0 sm:order-3 sm:ml-3">
<button
type="button"
- class="-mr-1 flex p-2 rounded-md hover:bg-accent-hover focus:outline-none focus:ring-2 focus:ring-white sm:-mr-2"
+ class="
+ -mr-1
+ flex
+ p-2
+ rounded-md
+ hover:bg-accent-hover
+ focus:outline-none focus:ring-2 focus:ring-white
+ sm:-mr-2
+ "
@click.prevent="show = false"
>
<span class="sr-only">Dismiss</span>
@@ -71,14 +92,19 @@
</template>
<script lang="ts">
-import { ref } from "vue";
+import { computed, ref } from "vue";
+import { useStore } from "vuex";
export default {
name: "BannerDemo",
props: {},
setup(props, ctx) {
+ const store = useStore();
const show = ref(true);
- return { show };
+
+ const isReadonly = computed(() => store.getters["actuator/isReadonly"]());
+
+ return { show, isReadonly };
},
};
</script>
diff --git a/frontend/src/views/DatabaseDetail.vue b/frontend/src/views/DatabaseDetail.vue
index 5c26fe2d62..334963fe0a 100644
--- a/frontend/src/views/DatabaseDetail.vue
+++ b/frontend/src/views/DatabaseDetail.vue
@@ -7,9 +7,7 @@
px-4
pb-4
border-b border-block-border
- md:flex
- md:items-center
- md:justify-between
+ md:flex md:items-center md:justify-between
"
>
<div class="flex-1 min-w-0">
@@ -37,8 +35,7 @@
class="
flex flex-col
space-y-1
- md:space-y-0
- md:flex-row md:flex-wrap
+ md:space-y-0 md:flex-row md:flex-wrap
"
>
<dt class="sr-only">Environment</dt>
@@ -160,7 +157,7 @@
<template
v-for="(item, index) of [
{ type: 'RW', list: readWriteDataSourceList },
- { type: 'RO', list: readOnlyDataSourceList },
+ { type: 'RO', list: readonlyDataSourceList },
]"
:key="index"
>
@@ -407,7 +404,7 @@ export default {
});
});
- const readOnlyDataSourceList = computed(() => {
+ const readonlyDataSourceList = computed(() => {
return dataSourceList.value.filter((dataSource: DataSource) => {
return dataSource.type == "RO";
});
@@ -483,7 +480,7 @@ export default {
allowViewDataSource,
allowChangeDataSource,
readWriteDataSourceList,
- readOnlyDataSourceList,
+ readonlyDataSourceList,
tryTransferProject,
updateProject,
isEditingDataSource,
diff --git a/server/actuator.go b/server/actuator.go
index d203b96e55..2d19ab7b66 100644
--- a/server/actuator.go
+++ b/server/actuator.go
@@ -11,6 +11,7 @@ import (
func (s *Server) registerActuatorRoutes(g *echo.Group) {
g.GET("/actuator/info", func(c echo.Context) error {
serverInfo := api.ServerInfo{
+ Readonly: s.readonly,
Demo: s.demo,
Host: s.host,
Port: strconv.Itoa(s.port),