Skip to content

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

Invite members

Tianzhou Chen1dd76b868c41
diff --git a/frontend/src/assets/css/tailwind.css b/frontend/src/assets/css/tailwind.css
index 5c3afaac3c..e26a096168 100644
--- a/frontend/src/assets/css/tailwind.css
+++ b/frontend/src/assets/css/tailwind.css
@@ -71,7 +71,7 @@
}
.btn-icon {
- @apply select-none rounded-full text-control bg-transparent hover:text-control-hover disabled:opacity-50 disabled:cursor-not-allowed focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1;
+ @apply cursor-pointer select-none rounded-full text-control bg-transparent hover:text-control-hover disabled:opacity-50 disabled:cursor-not-allowed focus:ring-control focus:outline-none focus-visible:ring-2 focus:ring-offset-1;
}
.btn-icon-primary {
@@ -102,6 +102,22 @@
@apply text-main focus:ring-control focus:border-control sm:text-sm border-control-border shadow-sm;
}
+.radio-set {
+ @apply h-9 flex flex-row items-center space-x-2;
+}
+
+.radio {
+ @apply flex items-center;
+}
+
+.radio .btn {
+ @apply focus:ring-control h-4 w-4 text-control border-control-border select-none;
+}
+
+.radio .label {
+ @apply ml-2 block text-sm font-medium text-gray-700 select-none;
+}
+
.outline-title {
@apply text-control-light w-full group items-center text-xs leading-5 font-semibold focus:outline-none select-none capitalize tracking-wider;
}
diff --git a/frontend/src/components/MemberInvite.vue b/frontend/src/components/MemberInvite.vue
new file mode 100644
index 0000000000..23bce02cea
--- /dev/null
+++ b/frontend/src/components/MemberInvite.vue
@@ -0,0 +1,271 @@
+<template>
+ <div class="space-y-6">
+ <div class="space-y-2">
+ <div class="space-y-1">
+ <p id="invite_members_helper" class="sr-only">Add by email address</p>
+ <div
+ class="flex flex-col space-y-2 sm:flex-row sm:space-x-4 sm:space-y-0"
+ >
+ <div class="flex-grow">
+ <input
+ type="email"
+ name="invite_members"
+ id="invite_members"
+ class="textfield w-full lowercase"
+ placeholder="[email protected]"
+ v-model="state.inviteEmail"
+ ref="inviteEmailTextField"
+ aria-describedby="invite_members_helper"
+ />
+ </div>
+ <fieldset>
+ <div class="radio-set">
+ <div class="radio">
+ <input
+ name="invite_role"
+ type="radio"
+ class="btn"
+ value="OWNER"
+ v-model="state.inviteRole"
+ />
+ <label class="label"> Owner </label>
+ </div>
+ <div class="radio">
+ <input
+ name="invite_role"
+ type="radio"
+ class="btn"
+ value="DBA"
+ v-model="state.inviteRole"
+ />
+ <label class="label"> DBA </label>
+ </div>
+ <div class="radio">
+ <input
+ name="invite_role"
+ type="radio"
+ class="btn"
+ value="DEVELOPER"
+ v-model="state.inviteRole"
+ />
+ <label class="label"> Developer </label>
+ </div>
+ </div>
+ </fieldset>
+
+ <span class="flex justify-end">
+ <button
+ type="button"
+ class="btn-normal"
+ :disabled="!isValidEmail(state.inviteEmail)"
+ @click.prevent="addInvite"
+ >
+ <!-- Heroicon name: solid/plus -->
+ <svg
+ class="-ml-2 mr-1 h-5 w-5 text-gray-400"
+ xmlns="http://www.w3.org/2000/svg"
+ viewBox="0 0 20 20"
+ fill="currentColor"
+ aria-hidden="true"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M10 5a1 1 0 011 1v3h3a1 1 0 110 2h-3v3a1 1 0 11-2 0v-3H6a1 1 0 110-2h3V6a1 1 0 011-1z"
+ clip-rule="evenodd"
+ />
+ </svg>
+ <span>Add</span>
+ </button>
+ </span>
+ </div>
+ </div>
+
+ <div class="border-b border-gray-200 py-1">
+ <ul class="divide-y divide-gray-200">
+ <li
+ v-for="(invite, index) in state.inviteList"
+ :key="index"
+ class="py-4 flex"
+ >
+ <div
+ class="w-full flex flex-col space-y-2 sm:flex-row sm:justify-between sm:space-y-0"
+ >
+ <div class="flex items-center justify-between">
+ <div class="flex items-center space-x-2">
+ <BBAvatar :username="invite.email" />
+ <span class="text-sm text-gray-500">{{ invite.email }}</span>
+ </div>
+
+ <button
+ class="btn-icon"
+ type="button"
+ @click.prevent="deleteInvite(invite)"
+ >
+ <svg
+ class="btn-icon sm:hidden w-4 h-4"
+ fill="currentColor"
+ viewBox="0 0 20 20"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
+ clip-rule="evenodd"
+ ></path>
+ </svg>
+ </button>
+ </div>
+
+ <div class="flex flex-row items-center space-x-2">
+ <fieldset>
+ <div class="radio-set">
+ <div class="radio">
+ <input
+ type="radio"
+ class="btn"
+ value="OWNER"
+ v-model="invite.role"
+ />
+ <label class="label"> Owner </label>
+ </div>
+ <div class="radio">
+ <input
+ type="radio"
+ class="btn"
+ value="DBA"
+ v-model="invite.role"
+ />
+ <label class="label"> DBA </label>
+ </div>
+ <div class="radio">
+ <input
+ type="radio"
+ class="btn"
+ value="DEVELOPER"
+ v-model="invite.role"
+ />
+ <label class="label"> Developer </label>
+ </div>
+ </div>
+ </fieldset>
+
+ <button
+ class="btn-icon"
+ type="button"
+ @click.prevent="deleteInvite(invite)"
+ >
+ <svg
+ class="btn-icon hidden sm:block w-4 h-4"
+ fill="currentColor"
+ viewBox="0 0 20 20"
+ xmlns="http://www.w3.org/2000/svg"
+ >
+ <path
+ fill-rule="evenodd"
+ d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
+ clip-rule="evenodd"
+ ></path>
+ </svg>
+ </button>
+ </div>
+ </div>
+ </li>
+ </ul>
+ </div>
+ </div>
+
+ <div class="flex justify-end">
+ <button
+ type="button"
+ class="btn-primary"
+ :disabled="state.inviteList.length == 0"
+ @click.prevent="sendInvite"
+ >
+ Invite
+ </button>
+ </div>
+ </div>
+</template>
+
+<script lang="ts">
+import { computed, onMounted, onUnmounted, reactive, ref, Ref } from "vue";
+import { useStore } from "vuex";
+import cloneDeep from "lodash-es/cloneDeep";
+import { RoleType, RoleMappingNew } from "../types";
+import { isValidEmail } from "../utils";
+
+interface LocalState {
+ inviteList: RoleMappingNew[];
+ inviteEmail: Ref<string>;
+ inviteRole: Ref<RoleType>;
+}
+
+export default {
+ name: "MemberInvite",
+ props: {},
+ setup(props, ctx) {
+ const store = useStore();
+ const state = reactive<LocalState>({
+ inviteList: [],
+ inviteEmail: ref(""),
+ inviteRole: ref("OWNER"),
+ });
+ const inviteEmailTextField = ref();
+
+ const currentUser = computed(() => store.getters["auth/currentUser"]());
+
+ const keyboardHandler = (e: KeyboardEvent) => {
+ if (e.code == "Enter") {
+ if (inviteEmailTextField.value === document.activeElement) {
+ addInvite();
+ }
+ }
+ };
+
+ onMounted(() => {
+ document.addEventListener("keydown", keyboardHandler);
+ });
+
+ onUnmounted(() => {
+ document.removeEventListener("keydown", keyboardHandler);
+ });
+
+ const addInvite = () => {
+ if (isValidEmail(state.inviteEmail)) {
+ state.inviteList.push(
+ cloneDeep({
+ email: state.inviteEmail,
+ role: state.inviteRole,
+ updaterId: currentUser.value.id,
+ })
+ );
+ state.inviteEmail = "";
+ }
+ };
+
+ const deleteInvite = (invite: RoleMappingNew) => {
+ const i = state.inviteList.indexOf(invite);
+ if (i > -1) {
+ state.inviteList.splice(i, 1);
+ }
+ };
+
+ const sendInvite = () => {
+ console.log(state.inviteList);
+ for (const invite of state.inviteList) {
+ store.dispatch("roleMapping/createdRoleMapping", invite);
+ }
+ state.inviteList = [];
+ };
+
+ return {
+ state,
+ inviteEmailTextField,
+ addInvite,
+ deleteInvite,
+ sendInvite,
+ isValidEmail,
+ };
+ },
+};
+</script>
diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.js
index b4dd683e0c..aa994dbcc1 100644
--- a/frontend/src/miragejs/routes/index.js
+++ b/frontend/src/miragejs/routes/index.js
@@ -55,6 +55,23 @@ export default function routes() {
});
});
+ this.post("/roleMapping", function (schema, request) {
+ const ts = Date.now();
+ const attrs = {
+ ...this.normalizedRequestAttrs("role-mapping"),
+ workspaceId: WORKSPACE_ID,
+ };
+ const newRoleMapping = {
+ ...attrs,
+ createdTs: ts,
+ lastUpdatedTs: ts,
+ role: attrs.role,
+ updaterId: attrs.updaterId,
+ workspaceId: WORKSPACE_ID,
+ };
+ return schema.roleMappings.create(newRoleMapping);
+ });
+
// Task
this.get("/task", function (schema, request) {
const {
diff --git a/frontend/src/store/modules/roleMapping.ts b/frontend/src/store/modules/roleMapping.ts
index 7cb5829816..318a8d6d33 100644
--- a/frontend/src/store/modules/roleMapping.ts
+++ b/frontend/src/store/modules/roleMapping.ts
@@ -1,5 +1,10 @@
import axios from "axios";
-import { RoleMapping, RoleMappingState, ResourceObject } from "../../types";
+import {
+ RoleMapping,
+ RoleMappingNew,
+ RoleMappingState,
+ ResourceObject,
+} from "../../types";
function convert(roleMapping: ResourceObject, rootGetters: any): RoleMapping {
const principal = rootGetters["principal/principalById"](
@@ -40,12 +45,37 @@ const actions = {
commit("setRoleMappingList", roleMappingList);
return roleMappingList;
},
+
+ async createdRoleMapping(
+ { commit, rootGetters }: any,
+ newRoleMapping: RoleMappingNew
+ ) {
+ const createdRoleMapping = convert(
+ (
+ await axios.post(`/api/roleMapping`, {
+ data: {
+ type: "roleMapping",
+ attributes: newRoleMapping,
+ },
+ })
+ ).data.data,
+ rootGetters
+ );
+
+ commit("appendRoleMapping", createdRoleMapping);
+
+ return createdRoleMapping;
+ },
};
const mutations = {
setRoleMappingList(state: RoleMappingState, roleMappingList: RoleMapping[]) {
state.roleMappingList = roleMappingList;
},
+
+ appendRoleMapping(state: RoleMappingState, newRoleMapping: RoleMapping) {
+ state.roleMappingList.push(newRoleMapping);
+ },
};
export default {
diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.ts
index 0e06457f3a..3524400414 100644
--- a/frontend/src/types/bytebase.ts
+++ b/frontend/src/types/bytebase.ts
@@ -57,6 +57,12 @@ export type RoleMapping = {
updater: Principal;
};
+export type RoleMappingNew = {
+ email: string;
+ role: RoleType;
+ updaterId: PrincipalId;
+};
+
// Bookmark
export type Bookmark = {
id: BookmarkId;
diff --git a/frontend/src/utils/util.ts b/frontend/src/utils/util.ts
index d9cd11bc48..b2a3e697a5 100644
--- a/frontend/src/utils/util.ts
+++ b/frontend/src/utils/util.ts
@@ -46,3 +46,10 @@ export function sizeToFit(el: HTMLTextAreaElement) {
// Extra 2px is to prevent jiggling upon entering the text
el.style.height = `${el.scrollHeight + 2}px`;
}
+
+export function isValidEmail(email: string) {
+ // Rather than using esoteric regex complying RFC 822/2822, we just use a naive but readable version
+ // which should work most of the time.
+ var re = /\S+@\S+\.\S+/;
+ return re.test(email);
+}
diff --git a/frontend/src/views/SettingWorkspaceMember.vue b/frontend/src/views/SettingWorkspaceMember.vue
index 66bd2bbd12..39455f8db1 100644
--- a/frontend/src/views/SettingWorkspaceMember.vue
+++ b/frontend/src/views/SettingWorkspaceMember.vue
@@ -1,10 +1,15 @@
<template>
- <h1>Member</h1>
+ <div class="mx-4 flex justify-center">
+ <MemberInvite />
+ </div>
</template>
<script lang="ts">
+import MemberInvite from "../components/MemberInvite.vue";
+
export default {
name: "SettingWorkspaceMember",
+ components: { MemberInvite },
props: {},
setup(props, ctx) {},
};