Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Use a new User type which is decoupled from the underlying API model
Tianzhou Chen6e8d0386bcd4
diff --git a/frontend/src/components/ProfileDropdown.vue b/frontend/src/components/ProfileDropdown.vueindex c9d8c31b5d..790d809327 100644--- a/frontend/src/components/ProfileDropdown.vue+++ b/frontend/src/components/ProfileDropdown.vue@@ -9,17 +9,14 @@aria-label="User menu"aria-haspopup="true">- <BBAvatar :username="currentUser.attributes.name"> </BBAvatar>+ <BBAvatar :username="currentUser.name"> </BBAvatar></button><BBContextMenuref="menu"class="z-10 origin-top-left absolute right-0 mt-2 w-36 rounded-md shadow-lg"><div v-if="isDevOrDemo">- <div- v-if="currentUser.attributes.email != '[email protected]'"- class="py-1"- >+ <div v-if="currentUser.email != '[email protected]'" class="py-1"><a@click.prevent="switchToOwner"class="cursor-pointer block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900"@@ -28,10 +25,7 @@Switch to Owner</a></div>- <div- v-if="currentUser.attributes.email != '[email protected]'"- class="py-1"- >+ <div v-if="currentUser.email != '[email protected]'" class="py-1"><a@click.prevent="switchToDBA"class="cursor-pointer block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900"@@ -40,10 +34,7 @@Switch to DBA</a></div>- <div- v-if="currentUser.attributes.email != '[email protected]'"- class="py-1"- >+ <div v-if="currentUser.email != '[email protected]'" class="py-1"><a@click.prevent="switchToDeveloper"class="cursor-pointer block px-4 py-2 text-sm leading-5 text-gray-700 hover:bg-gray-100 hover:text-gray-900 focus:outline-none focus:bg-gray-100 focus:text-gray-900"@@ -122,11 +113,8 @@ export default {const switchToOwner = () => {store.dispatch("auth/login", {- type: "loginInfo",- attributes: {- username: "[email protected]",- password: "1024",- },+ username: "[email protected]",+ password: "1024",}).then(() => {// Do a full page reload to avoid stale UI state.@@ -137,11 +125,8 @@ export default {const switchToDBA = () => {store.dispatch("auth/login", {- type: "loginInfo",- attributes: {- username: "[email protected]",- password: "aaa",- },+ username: "[email protected]",+ password: "aaa",}).then(() => {// Do a full page reload to avoid stale UI state.@@ -152,11 +137,8 @@ export default {const switchToDeveloper = () => {store.dispatch("auth/login", {- type: "loginInfo",- attributes: {- username: "[email protected]",- password: "aaa",- },+ username: "[email protected]",+ password: "aaa",}).then(() => {// Do a full page reload to avoid stale UI state.diff --git a/frontend/src/plugins/task/template.ts b/frontend/src/plugins/task/template.tsindex 329fb34830..0aa7b1f890 100644--- a/frontend/src/plugins/task/template.ts+++ b/frontend/src/plugins/task/template.ts@@ -25,7 +25,7 @@ const allTaskTemplateList: TaskTemplate[] = [creatorId: ctx.currentUser.id,creator: {id: ctx.currentUser.id,- name: ctx.currentUser.attributes.name,+ name: ctx.currentUser.name,},payload: {},};@@ -49,7 +49,7 @@ const allTaskTemplateList: TaskTemplate[] = [creatorId: ctx.currentUser.id,creator: {id: ctx.currentUser.id,- name: ctx.currentUser.attributes.name,+ name: ctx.currentUser.name,},payload: {},};@@ -117,7 +117,7 @@ const allTaskTemplateList: TaskTemplate[] = [creatorId: ctx.currentUser.id,creator: {id: ctx.currentUser.id,- name: ctx.currentUser.attributes.name,+ name: ctx.currentUser.name,},payload: {},};diff --git a/frontend/src/store/modules/auth.ts b/frontend/src/store/modules/auth.tsindex ef450b7b64..7ade9f1a54 100644--- a/frontend/src/store/modules/auth.ts+++ b/frontend/src/store/modules/auth.ts@@ -1,5 +1,18 @@import axios from "axios";-import { User, AuthState, LoginInfo, SignupInfo } from "../../types";+import {+ User,+ AuthState,+ LoginInfo,+ SignupInfo,+ ResourceObject,+} from "../../types";++function convert(user: ResourceObject): User {+ return {+ id: user.id,+ ...(user.attributes as Omit<User, "id">),+ };+}const state: () => AuthState = () => ({currentUser: null,@@ -20,11 +33,13 @@ const getters = {const actions = {async login({ commit }: any, loginInfo: LoginInfo) {- const loggedInUser = (- await axios.post("/api/auth/login", {- data: loginInfo,- })- ).data.data;+ const loggedInUser = convert(+ (+ await axios.post("/api/auth/login", {+ data: { type: "loginInfo", attributes: loginInfo },+ })+ ).data.data+ );localStorage.setItem("bb.auth.user", JSON.stringify(loggedInUser));commit("setCurrentUser", loggedInUser);@@ -32,11 +47,13 @@ const actions = {},async signup({ commit }: any, signupInfo: SignupInfo) {- const newUser = (- await axios.post("/api/auth/signup", {- data: signupInfo,- })- ).data.data;+ const newUser = convert(+ (+ await axios.post("/api/auth/signup", {+ data: { type: "signupInfo", attributes: signupInfo },+ })+ ).data.data+ );localStorage.setItem("bb.auth.user", JSON.stringify(newUser));commit("setCurrentUser", newUser);@@ -44,7 +61,8 @@ const actions = {},async fetchCurrentUser({ commit }: any) {- const currentUser = (await axios.get("/api/user/1")).data.data;+ const currentUser = convert((await axios.get("/api/user/1")).data.data);+localStorage.setItem("bb.auth.user", JSON.stringify(currentUser));commit("setCurrentUser", currentUser);return currentUser;diff --git a/frontend/src/store/modules/principal.ts b/frontend/src/store/modules/principal.tsindex b0ae87902a..c2ca324977 100644--- a/frontend/src/store/modules/principal.ts+++ b/frontend/src/store/modules/principal.ts@@ -29,7 +29,7 @@ const actions = {const principalList = userList.map((user) => {return {id: user.id,- name: user.attributes.name,+ name: user.name,};});commit("setPrincipalList", principalList);diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex bf501a7528..f245ff023e 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -35,10 +35,9 @@ export type CommandRegisterId = string;// Persistent State Models// User-export type User = ResourceObject & {- attributes: {- name: string;- };+export type User = {+ id: UserId;+ name: string;};export type NewUser = Omit<User, "id">;@@ -236,25 +235,15 @@ export type Repository = ResourceObject & {};export type RepositoryNew = Omit<Repository, "id">;// Auth-export type LoginInfo = Omit<- ResourceObject & {- attributes: {- username: string;- password: string;- };- },- "id"->;--export type SignupInfo = Omit<- ResourceObject & {- attributes: {- username: string;- password: string;- };- },- "id"->;+export type LoginInfo = {+ username: string;+ password: string;+};++export type SignupInfo = {+ username: string;+ password: string;+};// UI State Modelsexport type RouterSlug = {diff --git a/frontend/src/views/TaskActivityPanel.vue b/frontend/src/views/TaskActivityPanel.vueindex 830043fe19..f673193f2a 100644--- a/frontend/src/views/TaskActivityPanel.vue+++ b/frontend/src/views/TaskActivityPanel.vue@@ -225,7 +225,7 @@<div class="flex"><div class="flex-shrink-0"><div class="relative">- <BBAvatar :username="currentUser.attributes.name"> </BBAvatar>+ <BBAvatar :username="currentUser.name"> </BBAvatar><spanclass="absolute -bottom-0.5 -right-1 bg-white rounded-tl px-0.5 py-px">@@ -413,7 +413,7 @@ export default {containerId: props.task.id,creator: {id: currentUser.id,- name: currentUser.attributes.name,+ name: currentUser.name,},payload: {comment: newComment.value,diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vueindex e45100d3e6..11d151dabf 100644--- a/frontend/src/views/TaskDetail.vue+++ b/frontend/src/views/TaskDetail.vue@@ -397,7 +397,7 @@ export default {...taskPatch,producer: {id: currentUser.id,- name: currentUser.attributes.name,+ name: currentUser.name,},},})diff --git a/frontend/src/views/auth/Signin.vue b/frontend/src/views/auth/Signin.vueindex 227f10f0ad..0e96e91091 100644--- a/frontend/src/views/auth/Signin.vue+++ b/frontend/src/views/auth/Signin.vue@@ -150,11 +150,8 @@ export default {const trySignin = () => {const loginInfo: LoginInfo = {- type: "loginInfo",- attributes: {- username: state.email,- password: state.password,- },+ username: state.email,+ password: state.password,};store.dispatch("auth/login", loginInfo)diff --git a/frontend/src/views/auth/Signup.vue b/frontend/src/views/auth/Signup.vueindex b43a79e124..b51c9684d7 100644--- a/frontend/src/views/auth/Signup.vue+++ b/frontend/src/views/auth/Signup.vue@@ -145,11 +145,8 @@ export default {const trySignup = () => {const signupInfo: SignupInfo = {- type: "signupInfo",- attributes: {- username: state.email,- password: state.password,- },+ username: state.email,+ password: state.password,};store.dispatch("auth/signup", signupInfo)