Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
List/Update/Delete member
Tianzhou Chen3b6e10e93e59
diff --git a/frontend/src/components/MemberTable.vue b/frontend/src/components/MemberTable.vuenew file mode 100644index 0000000000..2baa8fd1e7--- /dev/null+++ b/frontend/src/components/MemberTable.vue@@ -0,0 +1,168 @@+<template>+ <BBTable+ :columnList="columnList"+ :sectionDataSource="dataSource"+ :showHeader="true"+ >+ <template v-slot:header>+ <BBTableHeaderCell+ :leftPadding="4"+ class="w-24 table-cell"+ :title="columnList[0].title"+ />+ <BBTableHeaderCell class="w-8 table-cell" :title="columnList[1].title" />+ <BBTableHeaderCell class="w-48 table-cell" :title="columnList[2].title" />+ <BBTableHeaderCell class="w-4 table-cell" :title="columnList[3].title" />+ </template>+ <template v-slot:body="{ rowData: roleMapping }">+ <BBTableCell :leftPadding="4" class="w-24 table-cell">+ <div class="flex flex-row items-center">+ <BBAvatar :size="'small'" :username="roleMapping.principal.name" />+ <span class="ml-2">{{ roleMapping.principal.name }}</span>+ </div>+ </BBTableCell>+ <BBTableCell class="w-8">+ <RoleSelect+ :selectedRole="roleMapping.role"+ @change-role="+ (role) => {+ changeRole(roleMapping.id, role);+ }+ "+ />+ </BBTableCell>+ <BBTableCell class="w-48 table-cell">+ <div class="flex flex-row items-center">+ {{ humanizeTs(roleMapping.lastUpdatedTs) }}+ <span class="ml-1">by {{ roleMapping.principal.name }}</span>+ </div>+ </BBTableCell>+ <BBTableCell>+ <button+ class="w-4 btn-icon"+ @click.prevent="deleteRole(roleMapping.id)"+ >+ <svg+ class="w-4 h-4"+ fill="none"+ stroke="currentColor"+ viewBox="0 0 24 24"+ xmlns="http://www.w3.org/2000/svg"+ >+ <path+ stroke-linecap="round"+ stroke-linejoin="round"+ stroke-width="2"+ d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"+ ></path>+ </svg>+ </button>+ </BBTableCell>+ </template>+ </BBTable>+</template>++<script lang="ts">+import { computed, reactive, watchEffect } from "vue";+import { useStore } from "vuex";+import { useRouter } from "vue-router";+import RoleSelect from "../components/RoleSelect.vue";+import { RoleMappingId, RoleType } from "../types";+import { BBTableColumn } from "../bbkit/types";++const columnList: BBTableColumn[] = [+ {+ title: "Account",+ },+ {+ title: "Role",+ },+ {+ title: "Granted Time",+ },+ {+ title: "",+ },+];++interface LocalState {}++export default {+ name: "MemberTable",+ components: { RoleSelect },+ props: {},+ setup(props, ctx) {+ const store = useStore();+ const router = useRouter();++ const currentUser = computed(() => store.getters["auth/currentUser"]());++ const state = reactive<LocalState>({});++ const prepareRoleMappingList = () => {+ store.dispatch("roleMapping/fetchRoleMappingList").catch((error) => {+ console.log(error);+ });+ };++ watchEffect(prepareRoleMappingList);++ const dataSource = computed(() => {+ const ownerList = [];+ const dbaList = [];+ const developerList = [];+ for (const roleMapping of store.getters[+ "roleMapping/roleMappingList"+ ]()) {+ if (roleMapping.role === "OWNER") {+ ownerList.push(roleMapping);+ } else if (roleMapping.role === "DBA") {+ dbaList.push(roleMapping);+ } else if (roleMapping.role === "DEVELOPER") {+ developerList.push(roleMapping);+ }+ }+ const dataSource = [];+ dataSource.push({+ title: "Owner",+ list: ownerList,+ });+ dataSource.push({+ title: "DBA",+ list: dbaList,+ });+ dataSource.push({+ title: "Developer",+ list: developerList,+ });+ return dataSource;+ });++ const changeRole = (id: RoleMappingId, role: RoleType) => {+ store+ .dispatch("roleMapping/patchRoleMapping", {+ id,+ role,+ updaterId: currentUser.value.id,+ })+ .catch((error) => {+ console.log(error);+ });+ };++ const deleteRole = (id: RoleMappingId) => {+ store.dispatch("roleMapping/deleteRoleMappingById", id).catch((error) => {+ console.log(error);+ });+ };++ return {+ state,+ columnList,+ dataSource,+ changeRole,+ deleteRole,+ };+ },+};+</script>diff --git a/frontend/src/components/RoleSelect.vue b/frontend/src/components/RoleSelect.vuenew file mode 100644index 0000000000..e7a76270a3--- /dev/null+++ b/frontend/src/components/RoleSelect.vue@@ -0,0 +1,31 @@+<template>+ <BBSelect+ :selectedItem="selectedRole"+ :itemList="['OWNER', 'DBA', 'DEVELOPER']"+ :placeholder="'Select role'"+ @select-item="(role) => $emit('change-role', role)"+ >+ <template v-slot:menuItem="{ item }">+ {{ item }}+ </template>+ </BBSelect>+</template>++<script lang="ts">+import { PropType } from "vue";+import { RoleType } from "../types";++export default {+ name: "RoleSelect",+ emits: ["change-role"],+ components: {},+ props: {+ selectedRole: {+ type: String as PropType<RoleType>,+ },+ },+ setup() {+ return {};+ },+};+</script>diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.jsindex aa994dbcc1..e18361e095 100644--- a/frontend/src/miragejs/routes/index.js+++ b/frontend/src/miragejs/routes/index.js@@ -49,13 +49,13 @@ export default function routes() {});// RoleMapping- this.get("/roleMapping", function (schema, request) {+ this.get("/rolemapping", function (schema, request) {return schema.roleMappings.where((roleMapping) => {return roleMapping.workspaceId == WORKSPACE_ID;});});- this.post("/roleMapping", function (schema, request) {+ this.post("/rolemapping", function (schema, request) {const ts = Date.now();const attrs = {...this.normalizedRequestAttrs("role-mapping"),@@ -72,6 +72,15 @@ export default function routes() {return schema.roleMappings.create(newRoleMapping);});+ this.patch("/rolemapping/:roleMappingId", function (schema, request) {+ const attrs = this.normalizedRequestAttrs("role-mapping");+ return schema.roleMappings.find(request.params.roleMappingId).update(attrs);+ });++ this.delete("/rolemapping/:roleMappingId", function (schema, request) {+ return schema.roleMappings.find(request.params.roleMappingId).destroy();+ });+// Taskthis.get("/task", function (schema, request) {const {diff --git a/frontend/src/store/modules/roleMapping.ts b/frontend/src/store/modules/roleMapping.tsindex 318a8d6d33..507300be39 100644--- a/frontend/src/store/modules/roleMapping.ts+++ b/frontend/src/store/modules/roleMapping.ts@@ -1,7 +1,9 @@import axios from "axios";import {RoleMapping,+ RoleMappingId,RoleMappingNew,+ RoleMappingPatch,RoleMappingState,ResourceObject,} from "../../types";@@ -13,6 +15,7 @@ function convert(roleMapping: ResourceObject, rootGetters: any): RoleMapping {const updater = rootGetters["principal/principalById"](roleMapping.attributes.updaterId);+return {id: roleMapping.id,principal,@@ -36,7 +39,7 @@ const getters = {const actions = {async fetchRoleMappingList({ commit, rootGetters }: any) {- const roleMappingList = (await axios.get(`/api/roleMapping`)).data.data.map(+ const roleMappingList = (await axios.get(`/api/rolemapping`)).data.data.map((roleMapping: ResourceObject) => {return convert(roleMapping, rootGetters);}@@ -52,7 +55,7 @@ const actions = {) {const createdRoleMapping = convert((- await axios.post(`/api/roleMapping`, {+ await axios.post(`/api/rolemapping`, {data: {type: "roleMapping",attributes: newRoleMapping,@@ -66,6 +69,41 @@ const actions = {return createdRoleMapping;},++ async patchRoleMapping(+ { commit, rootGetters }: any,+ roleMapping: RoleMappingPatch+ ) {+ const { id, ...attrs } = roleMapping;+ const updatedRoleMapping = convert(+ (+ await axios.patch(`/api/rolemapping/${roleMapping.id}`, {+ data: {+ type: "roleMapping",+ attributes: attrs,+ },+ })+ ).data.data,+ rootGetters+ );++ commit("replaceRoleMappingInList", updatedRoleMapping);++ return updatedRoleMapping;+ },++ async deleteRoleMappingById(+ { state, commit }: { state: RoleMappingState; commit: any },+ id: RoleMappingId+ ) {+ await axios.delete(`/api/rolemapping/${id}`);++ const newList = state.roleMappingList.filter((item: RoleMapping) => {+ return item.id != id;+ });++ commit("setRoleMappingList", newList);+ },};const mutations = {@@ -76,6 +114,18 @@ const mutations = {appendRoleMapping(state: RoleMappingState, newRoleMapping: RoleMapping) {state.roleMappingList.push(newRoleMapping);},++ replaceRoleMappingInList(+ state: RoleMappingState,+ updatedRoleMapping: RoleMapping+ ) {+ const i = state.roleMappingList.findIndex(+ (item: RoleMapping) => item.id == updatedRoleMapping.id+ );+ if (i != -1) {+ state.roleMappingList[i] = updatedRoleMapping;+ }+ },};export default {diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex 3524400414..1a4d28bb77 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -63,6 +63,11 @@ export type RoleMappingNew = {updaterId: PrincipalId;};+export type RoleMappingPatch = {+ id: RoleMappingId;+ role: RoleType;+};+// Bookmarkexport type Bookmark = {id: BookmarkId;diff --git a/frontend/src/views/SettingWorkspaceMember.vue b/frontend/src/views/SettingWorkspaceMember.vueindex 39455f8db1..409572fcec 100644--- a/frontend/src/views/SettingWorkspaceMember.vue+++ b/frontend/src/views/SettingWorkspaceMember.vue@@ -2,14 +2,19 @@<div class="mx-4 flex justify-center"><MemberInvite /></div>+ <div class="mt-6">+ <p class="ml-4 text-xl font-bold leading-7 text-main">Members</p>+ <MemberTable class="mt-2" />+ </div></template><script lang="ts">import MemberInvite from "../components/MemberInvite.vue";+import MemberTable from "../components/MemberTable.vue";export default {name: "SettingWorkspaceMember",- components: { MemberInvite },+ components: { MemberInvite, MemberTable },props: {},setup(props, ctx) {},};