Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat: add skeleton for 2FA setup page (#5002)
boojackfd13501797f6
diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vueindex 8ce1137693..9fae05ac57 100644--- a/frontend/src/components/ProfileDropdown.vue+++ b/frontend/src/components/ProfileDropdown.vue@@ -6,15 +6,15 @@class="flex text-sm text-white focus:outline-none focus:shadow-solid"aria-label="User menu"aria-haspopup="true"- @click.prevent="$refs.menu.toggle($event)"- @contextmenu.capture.prevent="$refs.menu.toggle($event)"+ @click.prevent="menu.toggle()"+ @contextmenu.capture.prevent="menu.toggle()"><PrincipalAvatar :principal="currentUser" /></button><BBContextMenu ref="menu" class="origin-top-left mt-2 w-48"><router-linkclass="px-4 py-3 menu-item"- :to="`/u/${currentUser.id}`"+ to="/setting/profile"role="menuitem"><p class="text-sm flex justify-between">@@ -45,14 +45,14 @@}}</router-link><divclass="menu-item relative"- @mouseenter="$refs.languageMenu.toggle($event)"- @mouseleave="$refs.languageMenu.toggle($event)"- @click.capture.prevent="$refs.languageMenu.toggle($event)"+ @mouseenter="languageMenu.toggle()"+ @mouseleave="languageMenu.toggle()"+ @click.capture.prevent="languageMenu.toggle()"><span>{{ $t("common.language") }}</span><BBContextMenuref="languageMenu"- class="origin-left absolute left-0 top-0 -translate-x-48 transform"+ class="origin-left absolute left-0 -top-1 -translate-x-48 transform"><divclass="menu-item px-3 py-1 hover:bg-gray-100"@@ -94,7 +94,7 @@<div class="border-t border-gray-100"></div><div v-if="allowToggleDebug" class="py-1 menu-item"><div class="flex flex-row items-center space-x-2 justify-between">- <span> Debug </span>+ <span>Debug</span><BBSwitch :value="isDebug" @toggle="switchDebug" /></div></div>@@ -108,8 +108,8 @@</div></template>-<script lang="ts">-import { computed, defineComponent, ref } from "vue";+<script lang="ts" setup>+import { computed, ref } from "vue";import { useRouter } from "vue-router";import { storeToRefs } from "pinia";import { ServerInfo } from "@/types";@@ -125,95 +125,76 @@ import {} from "@/store";import PrincipalAvatar from "./PrincipalAvatar.vue";-export default defineComponent({- name: "ProfileDropdown",- components: { PrincipalAvatar },- setup() {- const actuatorStore = useActuatorStore();- const authStore = useAuthStore();- const debugStore = useDebugStore();- const uiStateStore = useUIStateStore();- const router = useRouter();- const { setLocale, locale } = useLanguage();- const languageMenu = ref();- const currentUser = useCurrentUser();+const actuatorStore = useActuatorStore();+const authStore = useAuthStore();+const debugStore = useDebugStore();+const uiStateStore = useUIStateStore();+const router = useRouter();+const { setLocale, locale } = useLanguage();+const menu = ref();+const languageMenu = ref();+const currentUser = useCurrentUser();- // For now, debug mode is a global setting and will affect all users.- // So we only allow DBA and Owner to toggle it.- const allowToggleDebug = computed(() => {- return hasWorkspacePermission(- "bb.permission.workspace.debug",- currentUser.value.role- );- });-- const showQuickstart = computed(() => !actuatorStore.isDemo);+// For now, debug mode is a global setting and will affect all users.+// So we only allow DBA and Owner to toggle it.+const allowToggleDebug = computed(() => {+ return hasWorkspacePermission(+ "bb.permission.workspace.debug",+ currentUser.value.role+ );+});- const logout = () => {- authStore.logout().then(() => {- router.push({ name: "auth.signin" });- });- };+const showQuickstart = computed(() => !actuatorStore.isDemo);- const resetQuickstart = () => {- const keys = [- "issue.visit",- "project.visit",- "environment.visit",- "instance.visit",- "database.visit",- "member.addOrInvite",- "hidden",- "guide.project",- "guide.environment",- "guide.instance",- "guide.database",- "kbar.open",- ];- keys.forEach((key) => {- uiStateStore.saveIntroStateByKey({- key,- newState: false,- });- });- };+const logout = () => {+ authStore.logout().then(() => {+ router.push({ name: "auth.signin" });+ });+};- const { isDebug } = storeToRefs(debugStore);+const resetQuickstart = () => {+ const keys = [+ "issue.visit",+ "project.visit",+ "environment.visit",+ "instance.visit",+ "database.visit",+ "member.addOrInvite",+ "hidden",+ "guide.project",+ "guide.environment",+ "guide.instance",+ "guide.database",+ "kbar.open",+ ];+ keys.forEach((key) => {+ uiStateStore.saveIntroStateByKey({+ key,+ newState: false,+ });+ });+};- const switchDebug = () => {- debugStore.patchDebug({- isDebug: !isDebug.value,- });- };+const { isDebug } = storeToRefs(debugStore);- const ping = () => {- actuatorStore.fetchServerInfo().then((info: ServerInfo) => {- pushNotification({- module: "bytebase",- style: "SUCCESS",- title: JSON.stringify(info, null, 4),- });- });- };+const switchDebug = () => {+ debugStore.patchDebug({+ isDebug: !isDebug.value,+ });+};- const toggleLocale = (lang: string) => {- setLocale(lang);- languageMenu.value.toggle();- };+const ping = () => {+ actuatorStore.fetchServerInfo().then((info: ServerInfo) => {+ pushNotification({+ module: "bytebase",+ style: "SUCCESS",+ title: JSON.stringify(info, null, 4),+ });+ });+};- return {- currentUser,- allowToggleDebug,- showQuickstart,- resetQuickstart,- logout,- isDebug,- switchDebug,- ping,- toggleLocale,- languageMenu,- locale,- };- },-});+const toggleLocale = (lang: string) => {+ setLocale(lang);+ languageMenu.value.toggle();+};</script>diff --git a/frontend/src/locales/en-US.json b/frontend/src/locales/en-US.jsonindex 506da15854..ece56b79ae 100644--- a/frontend/src/locales/en-US.json+++ b/frontend/src/locales/en-US.json@@ -1926,5 +1926,13 @@"minlength": "The {resource} ID is too short. It should have at least 1 character.","overflow": "The {resource} ID is too long. It should have less than 64 characters."}+ },+ "two-factor": {+ "self": "Two-factor authentication",+ "description": "Two-factor authentication provides an extra layer of security for member accounts. When signing in, you will be required to enter the security code generated by your Authenticator App.",+ "setup-steps": {+ "setup-auth-app": "Setup authenticator app",+ "download-recovery-codes": "Download your recovery codes"+ }}}diff --git a/frontend/src/locales/zh-CN.json b/frontend/src/locales/zh-CN.jsonindex 793bef2f6e..a71a6e737b 100644--- a/frontend/src/locales/zh-CN.json+++ b/frontend/src/locales/zh-CN.json@@ -1925,5 +1925,13 @@"minlength": "{resource} ID 至少包含 1 个字符。","overflow": "{resource} ID 应该少于 64 个字符。"}+ },+ "two-factor": {+ "self": "双重认证",+ "description": "双重认证为系统成员提供了一个额外的安全层。在登录时,用户需要输入由认证器应用程序生成的安全代码。",+ "setup-steps": {+ "setup-auth-app": "设置认证器应用程序",+ "download-recovery-codes": "下载恢复码"+ }}}diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex 9b57fa05f6..f1bbf25a8b 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -299,6 +299,15 @@ const routes: Array<RouteRecordRaw> = [alias: "profile",props: true,},+ {+ path: "profile/two-factor",+ name: "setting.profile.two-factor",+ meta: {+ title: () => t("two-factor.self"),+ },+ component: () => import("../views/TwoFactorSetup.vue"),+ props: true,+ },{path: "general",name: "setting.workspace.general",diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vueindex 2a152180e6..a841057bcd 100644--- a/frontend/src/views/ProfileDashboard.vue+++ b/frontend/src/views/ProfileDashboard.vue@@ -3,194 +3,209 @@class="flex-1 relative z-0 overflow-auto focus:outline-none xl:order-last"tabindex="0">- <article>- <!-- Profile header -->- <div>- <div class="h-32 w-full bg-accent lg:h-48"></div>- <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">- <div class="-mt-20 sm:flex sm:items-end sm:space-x-5">- <PrincipalAvatar :principal="principal" :size="'HUGE'" />- <div- class="mt-6 sm:flex-1 sm:min-w-0 sm:flex sm:items-center sm:justify-end sm:space-x-6 sm:pb-1"- >- <div class="mt-6 flex flex-row justify-stretch space-x-4">- <button v-if="false" type="button" class="btn-normal">- <!-- Heroicon name: solid/mail -->- <heroicons-solid:mail- class="-ml-1 mr-2 h-5 w-5 text-control-light"- />- <span>Message</span>- </button>- <template v-if="allowEdit">- <template v-if="state.editing">- <button- type="button"- class="btn-normal"- @click.prevent="cancelEdit"- >- {{ $t("common.cancel") }}- </button>- <button- type="button"- class="btn-normal"- :disabled="!allowSaveEdit"- @click.prevent="saveEdit"- >- <!-- Heroicon name: solid/save -->- <heroicons-solid:save- class="-ml-1 mr-2 h-5 w-5 text-control-light"- />- <span>{{ $t("common.save") }}</span>- </button>- </template>+ <!-- Profile header -->+ <div>+ <div class="h-32 w-full bg-accent lg:h-48"></div>+ <div class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8">+ <div class="-mt-20 sm:flex sm:items-end sm:space-x-5">+ <PrincipalAvatar :principal="principal" :size="'HUGE'" />+ <div+ class="mt-6 sm:flex-1 sm:min-w-0 sm:flex sm:items-center sm:justify-end sm:space-x-6 sm:pb-1"+ >+ <div class="mt-6 flex flex-row justify-stretch space-x-4">+ <template v-if="allowEdit">+ <template v-if="state.editing"><button- v-elsetype="button"class="btn-normal"- @click.prevent="editUser"+ @click.prevent="cancelEdit">- <!-- Heroicon name: solid/pencil -->- <heroicons-solid:pencil+ {{ $t("common.cancel") }}+ </button>+ <button+ type="button"+ class="btn-normal"+ :disabled="!allowSaveEdit"+ @click.prevent="saveEdit"+ >+ <heroicons-solid:saveclass="-ml-1 mr-2 h-5 w-5 text-control-light"/>- <span>{{ $t("common.edit") }}</span>+ <span>{{ $t("common.save") }}</span></button></template>- </div>+ <button+ v-else+ type="button"+ class="btn-normal"+ @click.prevent="editUser"+ >+ <heroicons-solid:pencil+ class="-ml-1 mr-2 h-5 w-5 text-control-light"+ />+ <span>{{ $t("common.edit") }}</span>+ </button>+ </template></div></div>- <div class="block mt-6 min-w-0 flex-1">+ </div>+ <div class="block mt-6 min-w-0 flex-1">+ <input+ v-if="state.editing"+ id="name"+ ref="editNameTextField"+ required+ autocomplete="off"+ name="name"+ type="text"+ class="textfield"+ :value="state.editingPrincipal?.name"+ @input="(e: any)=>updatePrincipal('name', e.target.value)"+ />+ <h1 v-else class="pb-1.5 text-2xl font-bold text-main truncate">+ {{ principal.name }}+ </h1>+ <span+ v-if="principal.type === 'SERVICE_ACCOUNT'"+ class="inline-flex items-center px-2 py-0.5 rounded-lg text-xs font-semibold bg-green-100 text-green-800"+ >+ {{ $t("settings.members.service-account") }}+ </span>+ </div>+ </div>+ </div>++ <!-- Description list -->+ <div+ v-if="principal.type === 'END_USER'"+ class="mt-6 mb-2 max-w-5xl mx-auto px-4 sm:px-6 lg:px-8"+ >+ <dl class="grid grid-cols-1 gap-x-4 gap-y-8 sm:grid-cols-2">+ <div class="sm:col-span-1">+ <dt class="text-sm font-medium text-control-light">+ {{ $t("settings.profile.role") }}+ </dt>+ <dd class="mt-1 text-sm text-main">+ <router-link+ :to="'/setting/member'"+ class="normal-link capitalize"+ >{{+ $t(`common.role.${principal.role.toLowerCase()}`)+ }}</router-link+ >+ <router-link+ v-if="!hasRBACFeature"+ :to="'/setting/subscription'"+ class="normal-link"+ >+ {{ $t("settings.profile.subscription") }}+ </router-link>+ </dd>+ </div>++ <div class="sm:col-span-1">+ <dt class="text-sm font-medium text-control-light">+ {{ $t("settings.profile.email") }}+ </dt>+ <dd class="mt-1 text-sm text-main"><inputv-if="state.editing"- id="name"- ref="editNameTextField"+ id="email"requiredautocomplete="off"- name="name"+ name="email"type="text"class="textfield"- :value="state.editingPrincipal?.name"- @input="(e: any)=>updatePrincipal('name', e.target.value)"+ :value="state.editingPrincipal?.email"+ @input="(e: any)=>updatePrincipal('email', e.target.value)"/>- <!-- pb-1.5 is to avoid flicking when entering/existing the editing state -->- <h1 v-else class="pb-1.5 text-2xl font-bold text-main truncate">- {{ principal.name }}- </h1>- <span- v-if="principal.type === 'SERVICE_ACCOUNT'"- class="inline-flex items-center px-2 py-0.5 rounded-lg text-xs font-semibold bg-green-100 text-green-800"- >- {{ $t("settings.members.service-account") }}- </span>- </div>+ <template v-else>+ {{ principal.email }}+ </template>+ </dd></div>- </div>- <!-- Description list -->- <div- v-if="principal.type == 'END_USER'"- class="mt-6 mb-2 max-w-5xl mx-auto px-4 sm:px-6 lg:px-8"- >- <dl class="grid grid-cols-1 gap-x-4 gap-y-8 sm:grid-cols-2">+ <template v-if="state.editing"><div class="sm:col-span-1"><dt class="text-sm font-medium text-control-light">- {{ $t("settings.profile.role") }}+ {{ $t("settings.profile.password") }}</dt><dd class="mt-1 text-sm text-main">- <router-link- :to="'/setting/member'"- class="normal-link capitalize"- >{{- $t(`common.role.${principal.role.toLowerCase()}`)- }}</router-link- >- <router-link- v-if="!hasRBACFeature"- :to="'/setting/subscription'"- class="normal-link"- >- {{ $t("settings.profile.subscription") }}- </router-link>+ <input+ id="password"+ name="password"+ type="text"+ class="textfield mt-1 w-full"+ autocomplete="off"+ :placeholder="$t('common.sensitive-placeholder')"+ :value="state.editingPrincipal?.password"+ @input="(e: any) => updatePrincipal('password', e.target.value)"+ /></dd></div><div class="sm:col-span-1"><dt class="text-sm font-medium text-control-light">- {{ $t("settings.profile.email") }}+ {{ $t("settings.profile.password-confirm") }}+ <span v-if="passwordMismatch" class="text-error">{{+ $t("settings.profile.password-mismatch")+ }}</span></dt><dd class="mt-1 text-sm text-main"><input- v-if="state.editing"- id="email"- required- autocomplete="off"- name="email"+ id="password-confirm"+ name="password-confirm"type="text"- class="textfield"- :value="state.editingPrincipal?.email"- @input="(e: any)=>updatePrincipal('email', e.target.value)"+ class="textfield mt-1 w-full"+ autocomplete="off"+ :placeholder="+ $t('settings.profile.password-confirm-placeholder')+ "+ :value="state.passwordConfirm"+ @input="(e: any) => state.passwordConfirm = e.target.value"/>- <template v-else>- {{ principal.email }}- </template></dd></div>+ </template>+ </dl>+ </div>- <template v-if="state.editing">- <div class="sm:col-span-1">- <dt class="text-sm font-medium text-control-light">- {{ $t("settings.profile.password") }}- </dt>- <dd class="mt-1 text-sm text-main">- <input- id="password"- name="password"- type="text"- class="textfield mt-1 w-full"- autocomplete="off"- :placeholder="$t('common.sensitive-placeholder')"- :value="state.editingPrincipal?.password"- @input="(e: any) => updatePrincipal('password', e.target.value)"- />- </dd>- </div>-- <div class="sm:col-span-1">- <dt class="text-sm font-medium text-control-light">- {{ $t("settings.profile.password-confirm") }}- <span v-if="passwordMismatch" class="text-error">{{- $t("settings.profile.password-mismatch")- }}</span>- </dt>- <dd class="mt-1 text-sm text-main">- <input- id="password-confirm"- name="password-confirm"- type="text"- class="textfield mt-1 w-full"- autocomplete="off"- :placeholder="- $t('settings.profile.password-confirm-placeholder')- "- :value="state.passwordConfirm"- @input="(e: any) => state.passwordConfirm = e.target.value"- />- </dd>- </div>- </template>- </dl>+ <!-- 2FA setting section -->+ <div+ v-if="isDev"+ class="max-w-5xl mx-auto px-4 sm:px-6 lg:px-8 border-t mt-16 pt-8 pb-4"+ >+ <div class="w-full flex flex-row justify-between items-center">+ <span class="text-lg font-medium">{{ $t("two-factor.self") }}</span>+ <BBSwitch+ :value="isMFAEnabled"+ @toggle="handle2FAEnableStatusChanged"+ /></div>- </article>+ <p class="mt-4 text-sm text-gray-500">+ {{ $t("two-factor.description") }}+ <!-- TODO(steven): update the docs link -->+ <LearnMoreLink url="docs-link" />+ </p>+ </div></main></template><script lang="ts" setup>-import { nextTick, computed, onMounted, onUnmounted, reactive, ref } from "vue";import { cloneDeep, isEmpty, isEqual } from "lodash-es";+import { nextTick, computed, onMounted, onUnmounted, reactive, ref } from "vue";import { PrincipalPatch } from "../types";import { hasWorkspacePermission } from "../utils";-import { featureToRef, useCurrentUser, usePrincipalStore } from "@/store";+import {+ featureToRef,+ useAuthStore,+ useCurrentUser,+ usePrincipalStore,+} from "@/store";+import { BBSwitch } from "@/bbkit";import PrincipalAvatar from "../components/PrincipalAvatar.vue";+import LearnMoreLink from "@/components/LearnMoreLink.vue";+import { useRouter } from "vue-router";interface LocalState {editing: boolean;@@ -202,6 +217,8 @@ const props = defineProps<{principalId?: string;}>();+const router = useRouter();+const authStore = useAuthStore();const currentUser = useCurrentUser();const principalStore = usePrincipalStore();const state = reactive<LocalState>({@@ -212,9 +229,9 @@ const editNameTextField = ref();const keyboardHandler = (e: KeyboardEvent) => {if (state.editing) {- if (e.code == "Escape") {+ if (e.code === "Escape") {cancelEdit();- } else if (e.code == "Enter" && e.metaKey) {+ } else if (e.code === "Enter" && e.metaKey) {if (allowSaveEdit.value) {saveEdit();}@@ -232,6 +249,10 @@ onUnmounted(() => {const hasRBACFeature = featureToRef("bb.feature.rbac");+const isMFAEnabled = computed(() => {+ return authStore.currentUser.mfaEnabled;+});+const principal = computed(() => {if (props.principalId) {return principalStore.principalById(parseInt(props.principalId));@@ -250,7 +271,7 @@ const passwordMismatch = computed(() => {// Besides, owner can also change anyone's info. This is for resetting password in case user forgets.const allowEdit = computed(() => {return (- currentUser.value.id == principal.value.id ||+ currentUser.value.id === principal.value.id ||hasWorkspacePermission("bb.permission.workspace.manage-member",currentUser.value.role@@ -261,8 +282,8 @@ const allowEdit = computed(() => {const allowSaveEdit = computed(() => {return (!isEqual(principal.value, state.editingPrincipal) &&- (state.passwordConfirm == "" ||- state.passwordConfirm == state.editingPrincipal?.password)+ (state.passwordConfirm === "" ||+ state.passwordConfirm === state.editingPrincipal?.password));});@@ -295,4 +316,12 @@ const saveEdit = async () => {state.editingPrincipal = undefined;state.editing = false;};++const handle2FAEnableStatusChanged = (enabled: boolean) => {+ if (enabled) {+ router.push({ name: "setting.profile.two-factor" });+ } else {+ // TODO(steven): double confirm user to disable 2FA.+ }+};</script>diff --git a/frontend/src/views/TwoFactorSetup.vue b/frontend/src/views/TwoFactorSetup.vuenew file mode 100644index 0000000000..279c1d2aba--- /dev/null+++ b/frontend/src/views/TwoFactorSetup.vue@@ -0,0 +1,31 @@+<template>+ <p class="text-sm text-gray-500 mb-4">+ {{ $t("two-factor.description") }}+ <LearnMoreLink url="doc-link" />+ </p>+ <BBStepTab+ :step-item-list="stepTabList"+ :allow-next="true"+ :finish-title="$t('common.confirm-and-add')"+ >+ <template #0>+ <!-- placeholder -->+ </template>+ <template #1>+ <!-- placeholder -->+ </template>+ </BBStepTab>+</template>++<script lang="ts" setup>+import { useI18n } from "vue-i18n";+import { BBStepTabItem } from "@/bbkit";+import LearnMoreLink from "@/components/LearnMoreLink.vue";++const { t } = useI18n();++const stepTabList: BBStepTabItem[] = [+ { title: t("two-factor.setup-steps.setup-auth-app") },+ { title: t("two-factor.setup-steps.download-recovery-codes") },+];+</script>