Skip to content

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

chore: support multiply domain (#16692)

ecmadao96a42a3206e6
diff --git a/frontend/src/components/EmailInput.vue b/frontend/src/components/EmailInput.vue
index 7242c4ba95..ef615c99a5 100644
--- a/frontend/src/components/EmailInput.vue
+++ b/frontend/src/components/EmailInput.vue
@@ -1,45 +1,55 @@
<template>
- <NInputGroup v-if="showDomainLabel">
+ <NInputGroup v-if="enforceDomain && !readonly">
<NInput
v-model:value="state.shortValue"
:size="size"
- :readonly="readonly"
:disabled="readonly"
/>
- <NInputGroupLabel :size="size"> @{{ domain }} </NInputGroupLabel>
+ <NInputGroupLabel :size="size"> @ </NInputGroupLabel>
+ <NSelect
+ :size="size"
+ v-model:value="state.domain"
+ :options="domainSelectOptions"
+ :disabled="readonly"
+ />
</NInputGroup>
<NInput
v-else
v-model:value="state.value"
:size="size"
- :readonly="readonly"
:disabled="readonly"
/>
</template>
<script lang="ts" setup>
-import { NInput, NInputGroup, NInputGroupLabel } from "naive-ui";
-import { reactive, watch, ref, onMounted } from "vue";
+import { NInput, NInputGroup, NInputGroupLabel, NSelect } from "naive-ui";
+import { reactive, watch, computed, watchEffect } from "vue";
+import { useSettingV1Store } from "@/store";
interface LocalState {
// The full email value.
value: string;
// The short value without the domain.
shortValue: string;
+ domain: string;
}
const props = withDefaults(
defineProps<{
size?: "small" | "medium" | "large";
- domain?: string;
value?: string;
readonly?: boolean;
+ domainPrefix?: string;
+ fallbackDomain?: string;
+ showDomain?: boolean;
}>(),
{
size: "medium",
- domain: undefined,
value: "",
readonly: false,
+ domainPrefix: "",
+ fallbackDomain: "",
+ showDomain: false,
}
);
@@ -50,21 +60,49 @@ const emit = defineEmits<{
const state: LocalState = reactive({
value: props.value,
shortValue: props.value.split("@")[0],
+ domain: props.value.split("@")[1],
+});
+const settingV1Store = useSettingV1Store();
+
+const enforceDomain = computed(() => {
+ return (
+ (settingV1Store.workspaceProfileSetting?.enforceIdentityDomain ?? false) ||
+ props.showDomain
+ );
+});
+
+const domainSelectOptions = computed(() => {
+ const domains = (
+ settingV1Store.workspaceProfileSetting?.domains ?? []
+ ).filter((domain) => domain && domain.trim() !== "");
+ if (domains.length === 0 && props.fallbackDomain) {
+ domains.push(props.fallbackDomain);
+ }
+ return domains.map((domain) => {
+ const value = props.domainPrefix
+ ? `${props.domainPrefix}.${domain.trim()}`
+ : domain.trim();
+ return {
+ label: value,
+ value,
+ };
+ });
});
-const showDomainLabel = ref(false);
-onMounted(() => {
- if (props.domain) {
- if (!props.value || props.value.endsWith(`@${props.domain}`)) {
- showDomainLabel.value = true;
+watchEffect(() => {
+ if (domainSelectOptions.value.length > 0) {
+ if (
+ !domainSelectOptions.value.find((option) => option.value === state.domain)
+ ) {
+ state.domain = domainSelectOptions.value[0].value;
}
}
});
watch([() => state.value, () => state.shortValue], () => {
- const email = showDomainLabel.value
+ const email = enforceDomain.value
? state.shortValue
- ? `${state.shortValue}@${props.domain}`
+ ? `${state.shortValue}@${state.domain}`
: ""
: state.value;
emit("update:value", email);
diff --git a/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue b/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue
index 5149955fb4..3f8441d464 100644
--- a/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue
+++ b/frontend/src/components/GeneralSetting/DomainRestrictionSetting.vue
@@ -12,21 +12,41 @@
{{ $t("settings.general.workspace.domain-restriction.description") }}
</p>
<div class="w-full flex flex-col gap-2 mt-2">
- <NInput
- v-model:value="state.domain"
- :disabled="!allowEdit"
- :placeholder="
- $t(
- 'settings.general.workspace.domain-restriction.domain-input-placeholder'
- )
- "
- type="text"
- />
+ <div
+ v-for="(domain, i) in state.domains"
+ :key="i"
+ class="w-full flex items-center justify-center space-x-1"
+ >
+ <NInput
+ :value="domain"
+ :disabled="!allowEdit"
+ :placeholder="
+ $t(
+ 'settings.general.workspace.domain-restriction.domain-input-placeholder'
+ )
+ "
+ type="text"
+ @update:value="($event) => updateDomain(i, $event)"
+ />
+ <NButton quaternary size="small" @click="removeDomain(i)">
+ <template #icon>
+ <XIcon class="w-4" />
+ </template>
+ </NButton>
+ </div>
+ <div>
+ <NButton tertiary size="small" @click="addDomain">
+ <template #icon>
+ <PlusIcon class="w-4" />
+ </template>
+ Add domain
+ </NButton>
+ </div>
<div class="w-full flex flex-row justify-between items-center">
<NCheckbox
v-model:checked="state.enableRestriction"
- :disabled="!state.domain || !hasFeature || !allowEdit"
+ :disabled="validDomains.length === 0 || !hasFeature || !allowEdit"
>
<div class="font-medium flex items-center gap-x-2">
{{
@@ -34,7 +54,9 @@
"settings.general.workspace.domain-restriction.members-restriction.self"
)
}}
- <FeatureBadge :feature="PlanFeature.FEATURE_USER_EMAIL_DOMAIN_RESTRICTION" />
+ <FeatureBadge
+ :feature="PlanFeature.FEATURE_USER_EMAIL_DOMAIN_RESTRICTION"
+ />
</div>
<p class="text-sm text-gray-400 leading-tight">
{{
@@ -50,8 +72,9 @@
</template>
<script lang="ts" setup>
-import { head, isEqual } from "lodash-es";
-import { NCheckbox, NInput } from "naive-ui";
+import { isEqual, cloneDeep } from "lodash-es";
+import { PlusIcon, XIcon } from "lucide-vue-next";
+import { NCheckbox, NInput, NButton } from "naive-ui";
import { computed, reactive } from "vue";
import { featureToRef } from "@/store";
import { useSettingV1Store } from "@/store/modules/v1/setting";
@@ -60,15 +83,11 @@ import { FeatureBadge } from "../FeatureGuard";
const initialState = computed((): LocalState => {
const defaultState: LocalState = {
- domain: "",
+ domains: [],
enableRestriction: false,
};
- if (
- Array.isArray(settingV1Store.workspaceProfileSetting?.domains) &&
- settingV1Store.workspaceProfileSetting?.domains.length > 0
- ) {
- defaultState.domain =
- head(settingV1Store.workspaceProfileSetting?.domains) || "";
+ if (Array.isArray(settingV1Store.workspaceProfileSetting?.domains)) {
+ defaultState.domains = [...settingV1Store.workspaceProfileSetting?.domains];
defaultState.enableRestriction =
settingV1Store.workspaceProfileSetting?.enforceIdentityDomain || false;
}
@@ -76,7 +95,7 @@ const initialState = computed((): LocalState => {
});
interface LocalState {
- domain: string;
+ domains: string[];
enableRestriction: boolean;
}
@@ -85,14 +104,44 @@ defineProps<{
}>();
const settingV1Store = useSettingV1Store();
-const state = reactive<LocalState>(initialState.value);
+const state = reactive<LocalState>(cloneDeep(initialState.value));
+
+const hasFeature = featureToRef(
+ PlanFeature.FEATURE_USER_EMAIL_DOMAIN_RESTRICTION
+);
+
+const updateDomain = (index: number, domain: string) => {
+ state.domains[index] = domain;
+};
+
+const addDomain = () => {
+ state.domains.push("");
+};
-const hasFeature = featureToRef(PlanFeature.FEATURE_USER_EMAIL_DOMAIN_RESTRICTION);
+const removeDomain = (index: number) => {
+ state.domains.splice(index, 1);
+ if (validDomains.value.length === 0) {
+ state.enableRestriction = false;
+ }
+};
+
+const validDomains = computed(() => {
+ return state.domains.filter((domain) => !!domain);
+});
defineExpose({
- isDirty: computed(() => !isEqual(state, initialState.value)),
+ isDirty: computed(
+ () =>
+ !isEqual(
+ {
+ ...state,
+ domains: validDomains.value,
+ },
+ initialState.value
+ )
+ ),
update: async () => {
- if (state.domain.length === 0) {
+ if (validDomains.value.length === 0) {
state.enableRestriction = false;
}
const updateMask: string[] = [];
@@ -101,13 +150,14 @@ defineExpose({
"value.workspace_profile_setting_value.enforce_identity_domain"
);
}
- if (initialState.value.domain !== state.domain) {
+
+ if (!isEqual(validDomains.value, initialState.value.domains)) {
updateMask.push("value.workspace_profile_setting_value.domains");
}
if (updateMask.length > 0) {
await settingV1Store.updateWorkspaceProfile({
payload: {
- domains: state.domain ? [state.domain] : [],
+ domains: validDomains.value,
enforceIdentityDomain: state.enableRestriction,
},
updateMask,
diff --git a/frontend/src/components/User/Settings/CreateGroupDrawer.vue b/frontend/src/components/User/Settings/CreateGroupDrawer.vue
index 95eda950ec..b4cd986926 100644
--- a/frontend/src/components/User/Settings/CreateGroupDrawer.vue
+++ b/frontend/src/components/User/Settings/CreateGroupDrawer.vue
@@ -23,7 +23,7 @@
<EmailInput
v-model:value="state.group.email"
:readonly="!isCreating"
- :domain="workspaceDomain"
+ :show-domain="true"
/>
</div>
<div class="flex flex-col gap-y-2">
@@ -131,7 +131,7 @@
</template>
<script lang="ts" setup>
-import { cloneDeep, head, isEqual } from "lodash-es";
+import { cloneDeep, isEqual } from "lodash-es";
import { Trash2Icon } from "lucide-vue-next";
import { NButton, NInput, NTooltip } from "naive-ui";
import { computed, reactive } from "vue";
@@ -144,7 +144,6 @@ import {
useCurrentUserV1,
pushNotification,
useUserStore,
- useSettingV1Store,
} from "@/store";
import {
userNamePrefix,
@@ -179,7 +178,6 @@ const emit = defineEmits<{
}>();
const { t } = useI18n();
-const settingV1Store = useSettingV1Store();
const userStore = useUserStore();
const groupStore = useGroupStore();
const currentUserV1 = useCurrentUserV1();
@@ -203,10 +201,6 @@ const state = reactive<LocalState>({
const isCreating = computed(() => !props.group);
-const workspaceDomain = computed(() =>
- head(settingV1Store.workspaceProfileSetting?.domains)
-);
-
const disallowEditMember = computed(() => !!props.group?.source);
const isGroupOwner = computed(() => {
diff --git a/frontend/src/components/User/Settings/CreateUserDrawer.vue b/frontend/src/components/User/Settings/CreateUserDrawer.vue
index 0b84ff2856..5a1b14fcc1 100644
--- a/frontend/src/components/User/Settings/CreateUserDrawer.vue
+++ b/frontend/src/components/User/Settings/CreateUserDrawer.vue
@@ -41,20 +41,19 @@
{{ $t("common.email") }}
<span class="text-red-600 ml-0.5">*</span>
</label>
- <div
- v-if="state.user.userType === UserType.SERVICE_ACCOUNT"
- class="w-full flex flex-col items-start"
- >
- <EmailInput
- v-model:value="state.user.email"
- :domain="serviceAccountDomain"
- />
- </div>
<EmailInput
- v-else
v-model:value="state.user.email"
- :readonly="false"
- :domain="enforceIdentityDomain ? workspaceDomain : undefined"
+ :domain-prefix="
+ state.user.userType === UserType.SERVICE_ACCOUNT
+ ? 'service'
+ : ''
+ "
+ :fallback-domain="
+ state.user.userType === UserType.SERVICE_ACCOUNT
+ ? 'bytebase.com'
+ : ''
+ "
+ :show-domain="state.user.userType === UserType.SERVICE_ACCOUNT"
/>
</div>
@@ -116,7 +115,6 @@
</template>
<script lang="ts" setup>
-import { head } from "lodash-es";
import { NButton, NInput, NRadioGroup, NRadio } from "naive-ui";
import { computed, reactive, ref } from "vue";
import { useI18n } from "vue-i18n";
@@ -163,23 +161,6 @@ const passwordRestrictionSetting = computed(
() => settingV1Store.passwordRestriction
);
-const enforceIdentityDomain = computed(() => {
- return Boolean(settingV1Store.workspaceProfileSetting?.enforceIdentityDomain);
-});
-
-const workspaceDomain = computed(() => {
- return head(settingV1Store.workspaceProfileSetting?.domains);
-});
-
-// For service account, we use the domain of the workspace if it exists.
-// Otherwise, we use the default domain.
-const serviceAccountDomain = computed(() => {
- if (workspaceDomain.value) {
- return "service." + workspaceDomain.value;
- }
- return "service.bytebase.com";
-});
-
const allowConfirm = computed(() => {
if (!state.user.email) {
return false;
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index 9d8cc877e6..d37c9f6355 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -67,10 +67,7 @@
</div>
<!-- Description list -->
- <div
- v-if="user.userType === UserType.USER"
- class="mt-6 mb-2 max-w-5xl mx-auto px-4 sm:px-6 lg:px-8"
- >
+ <div 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-3">
<div class="sm:col-span-1">
<dt class="text-sm font-medium text-control-light">
@@ -106,7 +103,6 @@
<EmailInput
v-if="state.editing"
v-model:value="state.editingUser!.email"
- :domain="workspaceDomain"
/>
<template v-else>
{{ user.email }}
@@ -114,7 +110,7 @@
</dd>
</div>
- <div class="sm:col-span-1">
+ <div v-if="user.userType === UserType.USER" class="sm:col-span-1">
<dt class="text-sm font-medium text-control-light">
{{ $t("settings.profile.phone") }}
</dt>
@@ -222,7 +218,7 @@
<script lang="ts" setup>
import { computedAsync, useTitle } from "@vueuse/core";
-import { cloneDeep, head, isEqual } from "lodash-es";
+import { cloneDeep, isEqual } from "lodash-es";
import type { DropdownOption } from "naive-ui";
import { NButton, NDropdown, NInput, NTag } from "naive-ui";
import { computed, nextTick, onMounted, onUnmounted, reactive, ref } from "vue";
@@ -257,7 +253,6 @@ import {
unknownUser,
} from "@/types";
import { State } from "@/types/proto-es/v1/common_pb";
-import { convertStateToOld } from "@/utils/v1/common-conversions";
import { PlanFeature } from "@/types/proto-es/v1/subscription_service_pb";
import {
UpdateUserRequest,
@@ -265,6 +260,7 @@ import {
type User,
} from "@/types/proto/v1/user_service";
import { displayRoleTitle, hasWorkspacePermissionV2, sortRoles } from "@/utils";
+import { convertStateToOld } from "@/utils/v1/common-conversions";
interface LocalState {
editing: boolean;
@@ -299,10 +295,6 @@ const state = reactive<LocalState>({
const editNameTextField = ref<InstanceType<typeof NInput>>();
const userPasswordRef = ref<InstanceType<typeof UserPassword>>();
-const workspaceDomain = computed(() =>
- head(settingV1Store.workspaceProfileSetting?.domains)
-);
-
const passwordRestrictionSetting = computed(
() => settingV1Store.passwordRestriction
);
@@ -356,7 +348,8 @@ const isSelf = computed(() => currentUser.value.name === user.value.name);
const allowEdit = computed(() => {
if (
user.value.name === SYSTEM_BOT_USER_NAME ||
- user.value.email === ALL_USERS_USER_EMAIL
+ user.value.email === ALL_USERS_USER_EMAIL ||
+ user.value.userType !== UserType.USER
) {
return false;
}