Skip to content

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

feat: show domain name for idp user (#4631)

boojack6f1646102fde
diff --git a/backend/legacyapi/principal.go b/backend/legacyapi/principal.go
index 442bfcfe2b..68bd419140 100644
--- a/backend/legacyapi/principal.go
+++ b/backend/legacyapi/principal.go
@@ -52,7 +52,8 @@ type Principal struct {
Role Role `jsonapi:"attr,role"`
// The ServiceKey is the password, only used for SERVICE_ACCOUNT.
// We only return the service key for the first time after the creation for SERVICE_ACCOUNT.
- ServiceKey string `jsonapi:"attr,serviceKey"`
+ ServiceKey string `jsonapi:"attr,serviceKey"`
+ IdentityProviderName string `jsonapi:"attr,identityProviderName"`
}
// MarshalJSON customizes the Principal Marshal method so the returned object
diff --git a/backend/store/principal.go b/backend/store/principal.go
index f1623a96d1..614a0dc6b2 100644
--- a/backend/store/principal.go
+++ b/backend/store/principal.go
@@ -67,6 +67,9 @@ func composePrincipal(user *UserMessage) (*api.Principal, error) {
if principal.ID == api.SystemBotID {
principal.Role = api.Owner
}
+ if user.IdentityProviderResourceID != nil {
+ principal.IdentityProviderName = *user.IdentityProviderResourceID
+ }
return principal, nil
}
diff --git a/frontend/src/components/MemberTable.vue b/frontend/src/components/MemberTable.vue
index 9ae445e8e8..1696b5862e 100644
--- a/frontend/src/components/MemberTable.vue
+++ b/frontend/src/components/MemberTable.vue
@@ -56,8 +56,12 @@
<router-link
:to="`/u/${member.principal.id}`"
class="normal-link"
- >{{ member.principal.name }}</router-link
>
+ {{ member.principal.name
+ }}<span class="text-gray-400">{{
+ getUserRelatedDomainName(member.principal)
+ }}</span>
+ </router-link>
<span
v-if="currentUser.id == member.principal.id"
class="inline-flex items-center px-2 py-0.5 rounded-lg text-xs font-semibold bg-green-100 text-green-800"
@@ -184,6 +188,7 @@ import {
useMemberStore,
usePrincipalStore,
pushNotification,
+ useIdentityProviderStore,
} from "@/store";
const columnList = computed(() => [
@@ -214,9 +219,9 @@ export default defineComponent({
},
setup(props) {
const { t } = useI18n();
- const memberStore = useMemberStore();
-
const currentUser = useCurrentUser();
+ const memberStore = useMemberStore();
+ const identityProviderStore = useIdentityProviderStore();
const hasRBACFeature = featureToRef("bb.feature.rbac");
@@ -275,6 +280,16 @@ export default defineComponent({
);
});
+ const getUserRelatedDomainName = (principal: Principal) => {
+ const idp = identityProviderStore.getIdentityProviderByName(
+ `idps/${principal.identityProviderName}`
+ );
+ if (!idp) {
+ return "";
+ }
+ return `@${idp.domain}`;
+ };
+
const allowChangeRole = (member: Member) => {
if (member.principal.id === SYSTEM_BOT_ID) {
return false;
@@ -392,6 +407,7 @@ export default defineComponent({
hasRBACFeature,
dataSource,
allowEdit,
+ getUserRelatedDomainName,
allowChangeRole,
changeRoleTooltip,
allowDeactivateMember,
diff --git a/frontend/src/main.ts b/frontend/src/main.ts
index 9b1284727a..10ef370bd0 100644
--- a/frontend/src/main.ts
+++ b/frontend/src/main.ts
@@ -13,6 +13,7 @@ import {
pushNotification,
useActuatorStore,
useAuthStore,
+ useIdentityProviderStore,
useSubscriptionStore,
} from "./store";
import {
@@ -153,6 +154,11 @@ const initFeatureMatrix = () => {
const subscriptionStore = useSubscriptionStore();
return subscriptionStore.fetchFeatureMatrix();
};
+// Initial identity providers to provide sso options in signin page and user's related domain name.
+const initIdentityProvider = () => {
+ const idpStore = useIdentityProviderStore();
+ return idpStore.fetchIdentityProviderList();
+};
const restoreUser = () => {
const authStore = useAuthStore();
return authStore.restoreUser();
@@ -161,6 +167,7 @@ Promise.all([
initActuator(),
initFeatureMatrix(),
initSubscription(),
+ initIdentityProvider(),
restoreUser(),
]).finally(() => {
// Install router after the necessary data fetching is complete.
diff --git a/frontend/src/store/modules/principal.ts b/frontend/src/store/modules/principal.ts
index 57b01b76ca..cc0f6186da 100644
--- a/frontend/src/store/modules/principal.ts
+++ b/frontend/src/store/modules/principal.ts
@@ -25,6 +25,7 @@ function convert(principal: ResourceObject): Principal {
email: principal.attributes.email as string,
role: principal.attributes.role as RoleType,
serviceKey: principal.attributes.serviceKey as string,
+ identityProviderName: principal.attributes.identityProviderName as string,
};
}
diff --git a/frontend/src/types/principal.ts b/frontend/src/types/principal.ts
index ca7df1f5c7..52695e5d7c 100644
--- a/frontend/src/types/principal.ts
+++ b/frontend/src/types/principal.ts
@@ -15,6 +15,7 @@ export type Principal = {
email: string;
role: RoleType;
serviceKey: string;
+ identityProviderName: string;
};
export type PrincipalCreate = {
diff --git a/frontend/src/views/ProfileDashboard.vue b/frontend/src/views/ProfileDashboard.vue
index 5220e2cf57..1332761dc9 100644
--- a/frontend/src/views/ProfileDashboard.vue
+++ b/frontend/src/views/ProfileDashboard.vue
@@ -74,7 +74,10 @@
/>
<!-- 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 }}
+ {{ principal.name
+ }}<span class="text-gray-400">{{
+ getUserRelatedDomainName()
+ }}</span>
</h1>
<span
v-if="principal.type === 'SERVICE_ACCOUNT'"
@@ -200,6 +203,7 @@ import { hasWorkspacePermission } from "../utils";
import {
featureToRef,
useCurrentUser,
+ useIdentityProviderStore,
usePrincipalStore,
useUserStore,
} from "@/store";
@@ -218,6 +222,7 @@ const props = defineProps<{
const currentUser = useCurrentUser();
const principalStore = usePrincipalStore();
const userStore = useUserStore();
+const identityProviderStore = useIdentityProviderStore();
const state = reactive<LocalState>({
editing: false,
});
@@ -265,6 +270,16 @@ const isSSOUser = computed(() => {
return userStore.userMapByName.get(name)?.identityProvider !== "";
});
+const getUserRelatedDomainName = () => {
+ const idp = identityProviderStore.getIdentityProviderByName(
+ `idps/${principal.value.identityProviderName}`
+ );
+ if (!idp) {
+ return "";
+ }
+ return `@${idp.domain}`;
+};
+
// User can change her own info.
// Besides, owner can also change anyone's info. This is for resetting password in case user forgets.
const allowEdit = computed(() => {
diff --git a/frontend/src/views/SettingWorkspaceSSO.vue b/frontend/src/views/SettingWorkspaceSSO.vue
index 9fcc23bf84..1b29403f5c 100644
--- a/frontend/src/views/SettingWorkspaceSSO.vue
+++ b/frontend/src/views/SettingWorkspaceSSO.vue
@@ -79,7 +79,7 @@
<script lang="ts" setup>
import { head } from "lodash-es";
-import { computed, onMounted, reactive, watch, watchEffect } from "vue";
+import { computed, reactive, watch, watchEffect } from "vue";
import { useRoute, useRouter } from "vue-router";
import { useIdentityProviderStore } from "@/store/modules/idp";
import IdentityProviderCreateForm from "@/components/IdentityProviderCreateForm.vue";
@@ -113,10 +113,6 @@ const selectedIdentityProvider = computed(() => {
);
});
-onMounted(async () => {
- await identityProviderStore.fetchIdentityProviderList();
-});
-
watchEffect(() => {
const hashValue = route.hash.slice(1);
const identityProviderNameList = identityProviderList.value.map(