Skip to content

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

chore: update sign-in frequency setting UI (#7292)

boojackd84cfcafe842
diff --git a/frontend/src/components/GeneralSetting/SecuritySetting.vue b/frontend/src/components/GeneralSetting/SecuritySetting.vue
index 13f1803bbe..712f30ff2c 100644
--- a/frontend/src/components/GeneralSetting/SecuritySetting.vue
+++ b/frontend/src/components/GeneralSetting/SecuritySetting.vue
@@ -88,31 +88,7 @@
{{ $t("settings.general.workspace.require-2fa.description") }}
</div>
</div>
- <div class="mb-7 mt-5 lg:mt-0">
- <label
- class="flex items-center gap-x-2 tooltip-wrapper"
- :class="[allowEdit ? 'cursor-pointer' : 'cursor-not-allowed']"
- >
- <NCheckbox
- :disabled="!allowEdit"
- :checked="shortRefreshTokenEnabled"
- @update:checked="handleShortRefreshTokenToggle"
- />
- <span class="font-medium">{{
- "Expire refresh token in 8 hours"
- }}</span>
- <FeatureBadge feature="bb.feature.secure-token" />
- <span
- v-if="!allowEdit"
- class="text-sm text-gray-400 -translate-y-2 tooltip"
- >
- {{ $t("settings.general.workspace.only-owner-can-edit") }}
- </span>
- </label>
- <div class="mb-3 text-sm text-gray-400">
- Expire refresh token in 8 hours
- </div>
- </div>
+ <SignInFrequencySetting />
</div>
</div>
@@ -137,6 +113,7 @@ import { hasWorkspacePermissionV1 } from "@/utils";
import { useI18n } from "vue-i18n";
import { FeatureType } from "@/types";
import { useSettingV1Store } from "@/store/modules/v1/setting";
+import SignInFrequencySetting from "./SignInFrequencySetting.vue";
interface LocalState {
featureNameForModal?: FeatureType;
@@ -150,7 +127,6 @@ const actuatorStore = useActuatorV1Store();
const { isSaaSMode } = storeToRefs(actuatorStore);
const hasWatermarkFeature = featureToRef("bb.feature.branding");
const has2FAFeature = featureToRef("bb.feature.2fa");
-const hasSecureTokenFeature = featureToRef("bb.feature.secure-token");
const hasDisallowSignupFeature = featureToRef("bb.feature.disallow-signup");
const allowEdit = computed((): boolean => {
@@ -171,12 +147,6 @@ const disallowSignupEnabled = computed((): boolean => {
const require2FAEnabled = computed((): boolean => {
return settingV1Store.workspaceProfileSetting?.require2fa ?? false;
});
-const shortRefreshTokenEnabled = computed((): boolean => {
- return (
- (settingV1Store.workspaceProfileSetting?.refreshTokenDuration?.seconds ||
- 0) > 0
- );
-});
const handleDisallowSignupToggle = async (on: boolean) => {
if (!hasDisallowSignupFeature.value) {
@@ -209,22 +179,6 @@ const handleRequire2FAToggle = async (on: boolean) => {
});
};
-const handleShortRefreshTokenToggle = async (on: boolean) => {
- if (!hasSecureTokenFeature.value) {
- state.featureNameForModal = "bb.feature.secure-token";
- return;
- }
-
- await settingV1Store.updateWorkspaceProfile({
- refreshTokenDuration: { seconds: on ? 8 * 60 * 60 : 0, nanos: 0 },
- });
- pushNotification({
- module: "bytebase",
- style: "SUCCESS",
- title: t("settings.general.workspace.config-updated"),
- });
-};
-
const handleWatermarkToggle = async (on: boolean) => {
if (!hasWatermarkFeature.value) {
state.featureNameForModal = "bb.feature.watermark";
diff --git a/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue b/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
new file mode 100644
index 0000000000..a93e58a5f9
--- /dev/null
+++ b/frontend/src/components/GeneralSetting/SignInFrequencySetting.vue
@@ -0,0 +1,103 @@
+<template>
+ <div class="mb-7 mt-5 lg:mt-0">
+ <p class="font-medium">{{ "Sign-in frequency" }}</p>
+ <p class="text-sm text-gray-400">
+ {{ "Sign-in frequency is the period before a user must sign in again." }}
+ </p>
+ <div class="mt-4 w-full flex flex-row justify-start items-center">
+ <NInputNumber
+ v-model:value="state.inputValue"
+ class="w-20 mr-4"
+ :disabled="!allowEdit"
+ :min="1"
+ :max="state.timeFormat === 'HOURS' ? 23 : undefined"
+ />
+ <NRadioGroup v-model:value="state.timeFormat" :disabled="!allowEdit">
+ <NRadio :value="'HOURS'" :label="'Hour(s)'" />
+ <NRadio :value="'DAYS'" :label="'Day(s)'" />
+ </NRadioGroup>
+ </div>
+ </div>
+
+ <FeatureModal
+ :open="state.featureNameForModal"
+ :feature="state.featureNameForModal"
+ @cancel="state.featureNameForModal = undefined"
+ />
+</template>
+
+<script lang="ts" setup>
+import { useDebounceFn } from "@vueuse/core";
+import { computed, reactive, onMounted, watch } from "vue";
+import { useI18n } from "vue-i18n";
+import { NInputNumber, NRadioGroup, NRadio } from "naive-ui";
+import { featureToRef, pushNotification, useCurrentUserV1 } from "@/store";
+import { hasWorkspacePermissionV1 } from "@/utils";
+import { FeatureType } from "@/types";
+import { useSettingV1Store } from "@/store/modules/v1/setting";
+
+interface LocalState {
+ inputValue: number;
+ timeFormat: "HOURS" | "DAYS";
+ featureNameForModal?: FeatureType;
+}
+
+const { t } = useI18n();
+const settingV1Store = useSettingV1Store();
+const currentUserV1 = useCurrentUserV1();
+const state = reactive<LocalState>({
+ inputValue: 7,
+ timeFormat: "DAYS",
+});
+
+// TODO(steven): update feature name.
+const hasSecureTokenFeature = featureToRef("bb.feature.secure-token");
+
+const allowEdit = computed((): boolean => {
+ return hasWorkspacePermissionV1(
+ "bb.permission.workspace.manage-general",
+ currentUserV1.value.userRole
+ );
+});
+
+onMounted(() => {
+ const seconds =
+ settingV1Store.workspaceProfileSetting?.refreshTokenDuration?.seconds;
+ if (seconds && seconds > 0) {
+ if (seconds < 60 * 60 * 24) {
+ state.inputValue = Math.floor(seconds / (60 * 60)) || 1;
+ state.timeFormat = "HOURS";
+ } else {
+ state.inputValue = Math.floor(seconds / (60 * 60 * 24)) || 1;
+ state.timeFormat = "DAYS";
+ }
+ }
+});
+
+const handleFrequencySettingChange = useDebounceFn(async () => {
+ if (!hasSecureTokenFeature.value) {
+ state.featureNameForModal = "bb.feature.secure-token";
+ return;
+ }
+
+ const seconds =
+ state.timeFormat === "HOURS"
+ ? state.inputValue * 60 * 60
+ : state.inputValue * 24 * 60 * 60;
+ await settingV1Store.updateWorkspaceProfile({
+ refreshTokenDuration: { seconds: seconds, nanos: 0 },
+ });
+ pushNotification({
+ module: "bytebase",
+ style: "SUCCESS",
+ title: t("settings.general.workspace.config-updated"),
+ });
+}, 2000);
+
+watch(
+ () => [state.inputValue, state.timeFormat],
+ () => {
+ handleFrequencySettingChange();
+ }
+);
+</script>