Skip to content

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

fix: only allow update single user (#13584)

ecmadao6ff426ec8976
diff --git a/frontend/src/components/Member/MembersBindingSelect.vue b/frontend/src/components/Member/MembersBindingSelect.vue
index d36bd979e6..1a3ebb0467 100644
--- a/frontend/src/components/Member/MembersBindingSelect.vue
+++ b/frontend/src/components/Member/MembersBindingSelect.vue
@@ -7,6 +7,7 @@
<NRadioGroup
:value="memberType"
class="space-x-2"
+ :disabled="disabled"
@update:value="onTypeChange"
>
<NRadio value="USERS">{{ $t("common.users") }}</NRadio>
@@ -25,6 +26,7 @@
key="user-select"
:users="memberList"
:multiple="true"
+ :disabled="disabled"
:include-all-users="includeAllUsers"
:include-service-account="includeServiceAccount"
:allowed-workspace-role-list="[]"
@@ -40,6 +42,7 @@
<GroupSelect
key="group-select"
:value="memberList"
+ :disabled="disabled"
:multiple="true"
@update:value="onMemberListUpdate($event as string[])"
/>
@@ -69,11 +72,13 @@ const props = withDefaults(
// We don't support mixed data.
value: string[];
required: boolean;
+ disabled?: boolean;
allowChangeType?: boolean;
includeAllUsers?: boolean;
includeServiceAccount?: boolean;
}>(),
{
+ disabled: false,
allowChangeType: true,
includeAllUsers: false,
includeServiceAccount: false,
diff --git a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue
index be7b540e86..97b79c2f7d 100644
--- a/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue
+++ b/frontend/src/components/ProjectMember/AddProjectMember/AddProjectMembersPanel.vue
@@ -56,7 +56,7 @@ import {
import type { ComposedProject } from "@/types";
import { PresetRoleType } from "@/types";
import { Binding } from "@/types/proto/v1/iam_policy";
-import { displayRoleTitle } from "@/utils";
+import { getBindingIdentifier } from "../utils";
import AddProjectMemberForm from "./AddProjectMemberForm.vue";
const props = defineProps<{
@@ -117,14 +117,10 @@ const handleRemove = (index: number) => {
state.bindings.splice(index, 1);
};
-const getBindingKey = (binding: Binding): string => {
- return binding.condition?.title ?? displayRoleTitle(binding.role);
-};
-
const mergePolicyBinding = () => {
const bindingMap = new Map<string, Binding>();
for (const binding of state.bindings) {
- const key = getBindingKey(binding);
+ const key = getBindingIdentifier(binding);
if (!bindingMap.has(key)) {
bindingMap.set(key, binding);
} else {
@@ -134,7 +130,7 @@ const mergePolicyBinding = () => {
const policy = cloneDeep(iamPolicy.value);
for (const binding of policy.bindings) {
- const key = getBindingKey(binding);
+ const key = getBindingIdentifier(binding);
if (bindingMap.has(key)) {
binding.members = [
...new Set([
diff --git a/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue b/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue
index cf55be6a80..f16d81b77a 100644
--- a/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue
+++ b/frontend/src/components/ProjectMember/ProjectMemberRolePanel/EditProjectRolePanel.vue
@@ -73,7 +73,8 @@
</div>
<MembersBindingSelect
- v-model:value="state.memberList"
+ :value="binding.members"
+ :disabled="true"
:required="true"
:allow-change-type="false"
:include-all-users="true"
@@ -129,6 +130,7 @@ import { State } from "@/types/proto/v1/common";
import type { Binding } from "@/types/proto/v1/iam_policy";
import { displayRoleTitle } from "@/utils";
import { convertFromExpr } from "@/utils/issue/cel";
+import { getBindingIdentifier } from "../utils";
const props = defineProps<{
project: ComposedProject;
@@ -142,7 +144,6 @@ const emit = defineEmits<{
interface LocalState {
title: string;
description: string;
- memberList: string[];
expirationTimestamp?: number;
// Querier and exporter options.
databaseResourceCondition?: string;
@@ -156,7 +157,6 @@ const { t } = useI18n();
const state = reactive<LocalState>({
title: "",
description: "",
- memberList: props.binding.members,
maxRowCount: 1000,
});
const isLoading = ref(true);
@@ -182,7 +182,8 @@ const allowRemoveRole = () => {
};
const allowConfirm = computed(() => {
- return state.memberList.length > 0;
+ // only allow update current single user.
+ return props.binding.members.length === 1;
});
onMounted(() => {
@@ -220,13 +221,29 @@ const handleDeleteRole = async () => {
};
const handleUpdateRole = async () => {
+ const member = props.binding.members[0];
const newBinding = cloneDeep(props.binding);
if (!newBinding.condition) {
newBinding.condition = Expr.fromPartial({});
}
newBinding.condition.title = state.title;
newBinding.condition.description = state.description;
- newBinding.members = state.memberList;
+ newBinding.members = [member];
+
+ const policy = cloneDeep(iamPolicy.value);
+ const oldBindingIndex = policy.bindings.findIndex(
+ (binding) =>
+ getBindingIdentifier(binding) === getBindingIdentifier(props.binding)
+ );
+
+ if (oldBindingIndex >= 0) {
+ policy.bindings[oldBindingIndex].members = policy.bindings[
+ oldBindingIndex
+ ].members.filter((m) => m !== member);
+ if (policy.bindings[oldBindingIndex].members.length === 0) {
+ policy.bindings.splice(oldBindingIndex, 1);
+ }
+ }
const expression: string[] = [];
if (state.expirationTimestamp) {
@@ -255,10 +272,6 @@ const handleUpdateRole = async () => {
newBinding.condition.expression = "";
}
- const policy = cloneDeep(iamPolicy.value);
- policy.bindings = policy.bindings.filter(
- (binding) => !isEqual(binding, props.binding)
- );
policy.bindings.push(newBinding);
await useProjectIamPolicyStore().updateProjectIamPolicy(
diff --git a/frontend/src/components/ProjectMember/ProjectMemberRolePanel/index.vue b/frontend/src/components/ProjectMember/ProjectMemberRolePanel/index.vue
index e6d9ae4cbc..7d1fa8dc50 100644
--- a/frontend/src/components/ProjectMember/ProjectMemberRolePanel/index.vue
+++ b/frontend/src/components/ProjectMember/ProjectMemberRolePanel/index.vue
@@ -185,7 +185,10 @@
<EditProjectRolePanel
v-if="editingBinding"
:project="project"
- :binding="editingBinding"
+ :binding="{
+ ...editingBinding,
+ members: [binding.binding],
+ }"
@close="editingBinding = null"
/>
diff --git a/frontend/src/components/ProjectMember/utils.ts b/frontend/src/components/ProjectMember/utils.ts
new file mode 100644
index 0000000000..96f8adaabf
--- /dev/null
+++ b/frontend/src/components/ProjectMember/utils.ts
@@ -0,0 +1,10 @@
+import type { Binding } from "@/types/proto/v1/iam_policy";
+import { displayRoleTitle } from "@/utils";
+
+export const getBindingIdentifier = (binding: Binding): string => {
+ const identifier = [displayRoleTitle(binding.role)];
+ if (binding.condition && binding.condition.expression) {
+ identifier.push(binding.condition.expression);
+ }
+ return identifier.join(".");
+};