Skip to content

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

Only allow OWNER to invite and change membership

Tianzhou Chen5f569b627c58
diff --git a/frontend/src/components/MemberTable.vue b/frontend/src/components/MemberTable.vue
index 902b6293b1..d442772316 100644
--- a/frontend/src/components/MemberTable.vue
+++ b/frontend/src/components/MemberTable.vue
@@ -51,6 +51,7 @@
<BBTableCell class="">
<RoleSelect
:selectedRole="roleMapping.role"
+ :disabled="!allowEdit"
@change-role="
(role) => {
changeRole(roleMapping.id, role);
@@ -71,7 +72,11 @@
</div>
</BBTableCell>
<BBTableCell>
- <button class="btn-icon" @click.prevent="deleteRole(roleMapping.id)">
+ <button
+ v-if="allowEdit"
+ class="btn-icon"
+ @click.prevent="deleteRole(roleMapping.id)"
+ >
<svg
class="w-4 h-4"
fill="none"
@@ -96,7 +101,7 @@
import { computed, reactive, watchEffect } from "vue";
import { useStore } from "vuex";
import RoleSelect from "../components/RoleSelect.vue";
-import { RoleMappingId, RoleType } from "../types";
+import { RoleMapping, RoleMappingId, RoleType } from "../types";
import { BBTableColumn } from "../bbkit/types";
const columnList: BBTableColumn[] = [
@@ -166,6 +171,16 @@ export default {
return dataSource;
});
+ const allowEdit = computed(() => {
+ const myRoleMapping = store.getters[
+ "roleMapping/roleMappingByPrincipalId"
+ ](currentUser.value.id);
+ if (myRoleMapping.role != "OWNER") {
+ return false;
+ }
+ return true;
+ });
+
const changeRole = (id: RoleMappingId, role: RoleType) => {
store
.dispatch("roleMapping/patchRoleMapping", {
@@ -189,6 +204,7 @@ export default {
currentUser,
columnList,
dataSource,
+ allowEdit,
changeRole,
deleteRole,
};
diff --git a/frontend/src/store/modules/roleMapping.ts b/frontend/src/store/modules/roleMapping.ts
index 461933b02a..3eebb868cc 100644
--- a/frontend/src/store/modules/roleMapping.ts
+++ b/frontend/src/store/modules/roleMapping.ts
@@ -6,6 +6,7 @@ import {
RoleMappingPatch,
RoleMappingState,
ResourceObject,
+ PrincipalId,
} from "../../types";
function convert(roleMapping: ResourceObject, rootGetters: any): RoleMapping {
@@ -35,6 +36,11 @@ const getters = {
roleMappingList: (state: RoleMappingState) => () => {
return state.roleMappingList;
},
+ roleMappingByPrincipalId: (state: RoleMappingState) => (
+ id: PrincipalId
+ ): RoleMapping | undefined => {
+ return state.roleMappingList.find((item) => item.principal.id == id);
+ },
roleMappingByEmail: (state: RoleMappingState) => (
email: string
): RoleMapping | undefined => {
diff --git a/frontend/src/views/SettingWorkspaceMember.vue b/frontend/src/views/SettingWorkspaceMember.vue
index 578afd11b5..cf347da8c1 100644
--- a/frontend/src/views/SettingWorkspaceMember.vue
+++ b/frontend/src/views/SettingWorkspaceMember.vue
@@ -1,14 +1,16 @@
<template>
- <div class="w-full flex justify-center">
+ <div v-if="allowInvite" class="w-full flex justify-center mb-6">
<MemberInvite />
</div>
- <div class="mt-6">
+ <div>
<p class="text-xl font-bold leading-7 text-main">Current Members</p>
<MemberTable class="mt-2" />
</div>
</template>
<script lang="ts">
+import { computed } from "vue";
+import { useStore } from "vuex";
import MemberInvite from "../components/MemberInvite.vue";
import MemberTable from "../components/MemberTable.vue";
@@ -16,6 +18,23 @@ export default {
name: "SettingWorkspaceMember",
components: { MemberInvite, MemberTable },
props: {},
- setup(props, ctx) {},
+ setup(props, ctx) {
+ const store = useStore();
+ const currentUser = computed(() => store.getters["auth/currentUser"]());
+
+ const allowInvite = computed(() => {
+ const myRoleMapping = store.getters[
+ "roleMapping/roleMappingByPrincipalId"
+ ](currentUser.value.id);
+ if (myRoleMapping.role != "OWNER") {
+ return false;
+ }
+ return true;
+ });
+
+ return {
+ allowInvite,
+ };
+ },
};
</script>