Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Phase 1 of reworking the user display/update logic
Tianzhou Chena317ab374d32
diff --git a/frontend/src/components/ProvideContext.vue b/frontend/src/components/ProvideContext.vueindex 92f9a1d782..4904b86321 100644--- a/frontend/src/components/ProvideContext.vue+++ b/frontend/src/components/ProvideContext.vue@@ -10,6 +10,7 @@ export default {async setup() {const store = useStore();+ await store.dispatch("principal/fetchPrincipalList");await store.dispatch("environment/fetchEnvironmentList");},};diff --git a/frontend/src/miragejs/factories/task.js b/frontend/src/miragejs/factories/task.jsindex fd1c97d916..8d53f40fbb 100644--- a/frontend/src/miragejs/factories/task.js+++ b/frontend/src/miragejs/factories/task.js@@ -40,6 +40,12 @@ export default {},];},+ creatorId() {+ return "100";+ },+ assigneeId() {+ return "200";+ },creator() {return {id: "100",diff --git a/frontend/src/miragejs/routes/index.js b/frontend/src/miragejs/routes/index.jsindex 392c420d87..ce1637c9cd 100644--- a/frontend/src/miragejs/routes/index.js+++ b/frontend/src/miragejs/routes/index.js@@ -16,6 +16,8 @@ export default function routes() {// Userthis.get("/user/:id");+ this.get("/user");+// Auththis.post("/auth/login", function (schema, request) {const loginInfo = this.normalizedRequestAttrs("login-info");@@ -63,8 +65,8 @@ export default function routes() {return schema.tasks.where((task) => {return (task.workspaceId == WORKSPACE_ID &&- (task.creator.id == userId ||- task.assignee.id == userId ||+ (task.creatorId == userId ||+ task.assigneeId == userId ||task.subscriberIdList.includes(userId)));});diff --git a/frontend/src/miragejs/seeds/index.js b/frontend/src/miragejs/seeds/index.jsindex 7070a9f830..774252d198 100644--- a/frontend/src/miragejs/seeds/index.js+++ b/frontend/src/miragejs/seeds/index.js@@ -63,6 +63,8 @@ const workspacesSeeder = (server) => {let task = server.create("task", {type: "bytebase.general",name: "General Task",+ creatorId: ws1Dev1.id,+ assigneeId: ws1Owner.id,creator: {id: ws1Dev1.id,name: ws1Dev1.name,@@ -112,6 +114,8 @@ const workspacesSeeder = (server) => {task = server.create("task", {type: "bytebase.datasource.create",name: "Request data source for environment - " + environmentList1[1].name,+ creatorId: ws1Dev1.id,+ assigneeId: ws1Owner.id,creator: {id: ws1Dev1.id,name: ws1Dev1.name,@@ -165,6 +169,8 @@ const workspacesSeeder = (server) => {for (let i = 0; i < 5; i++) {task = server.create("task", {type: "bytebase.datasource.schema.update",+ creatorId: ws1Dev1.id,+ assigneeId: ws1Owner.id,creator: {id: ws1Dev1.id,name: ws1Dev1.name,@@ -208,6 +214,8 @@ const workspacesSeeder = (server) => {for (let i = 0; i < 15; i++) {task = server.create("task", {type: "bytebase.datasource.schema.update",+ creatorId: ws1Owner.id,+ assigneeId: ws1DBA.id,creator: {id: ws1Owner.id,name: ws1Owner.name,@@ -251,6 +259,8 @@ const workspacesSeeder = (server) => {for (let i = 0; i < 15; i++) {task = server.create("task", {type: "bytebase.datasource.schema.update",+ creatorId: ws1Dev2.id,+ assigneeId: ws1DBA.id,creator: {id: ws1Dev2.id,name: ws1Dev2.name,@@ -293,6 +303,8 @@ const workspacesSeeder = (server) => {task = server.create("task", {type: "bytebase.datasource.schema.update",+ creatorId: ws2Dev.id,+ assigneeId: ws2DBA.id,creator: {id: ws2Dev.id,name: ws2Dev.name,diff --git a/frontend/src/store/index.ts b/frontend/src/store/index.tsindex 9479077be8..8006163d31 100644--- a/frontend/src/store/index.ts+++ b/frontend/src/store/index.ts@@ -8,6 +8,7 @@ import project from "./modules/project";import environment from "./modules/environment";import instance from "./modules/instance";import dataSource from "./modules/dataSource";+import principal from "./modules/principal";import repository from "./modules/repository";import auth from "./modules/auth";import group from "./modules/group";@@ -32,6 +33,7 @@ export const store: Store<any> = createStore({environment,instance,dataSource,+ principal,repository,auth,group,diff --git a/frontend/src/store/modules/principal.ts b/frontend/src/store/modules/principal.tsnew file mode 100644index 0000000000..b0ae87902a--- /dev/null+++ b/frontend/src/store/modules/principal.ts@@ -0,0 +1,53 @@+import axios from "axios";+import { User, PrincipalId, Principal, PrincipalState } from "../../types";++const state: () => PrincipalState = () => ({+ principalList: [],+});++const getters = {+ principalList: (state: PrincipalState) => (): Principal[] => {+ return state.principalList;+ },++ principalById: (state: PrincipalState) => (+ principalId: PrincipalId+ ): Principal | undefined => {+ for (const principal of state.principalList) {+ if (principal.id == principalId) {+ return principal;+ }+ }+ return undefined;+ },+};++const actions = {+ async fetchPrincipalList({ commit }: any) {+ const userList: User[] = (await axios.get(`/api/user`)).data.data;++ const principalList = userList.map((user) => {+ return {+ id: user.id,+ name: user.attributes.name,+ };+ });+ commit("setPrincipalList", principalList);++ return userList;+ },+};++const mutations = {+ setPrincipalList(state: PrincipalState, principalList: Principal[]) {+ state.principalList = principalList;+ },+};++export default {+ namespaced: true,+ state,+ getters,+ actions,+ mutations,+};diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex 0a1d0facc9..c86696364b 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -6,6 +6,9 @@ import { TaskFieldId } from "../plugins";// Also good for readability.export type UserId = string;+// For now, Principal is equal to UserId, in the future it may contain other id such as application, bot etc.+export type PrincipalId = UserId;+export type StageId = string;export type TaskId = string;@@ -43,6 +46,12 @@ export type UserDisplay = {name: string;};+// Principal+export type Principal = {+ id: PrincipalId;+ name: string;+};+// Memberexport type RoleType = "OWNER" | "DBA" | "DEVELOPER";@@ -110,6 +119,8 @@ export type Task = ResourceObject & {type: TaskType;description: string;stageProgressList: StageProgress[];+ creatorId: PrincipalId;+ assigneeId: PrincipalId;creator: UserDisplay;assignee?: UserDisplay;subscriberIdList: Array<string>;@@ -123,6 +134,8 @@ export type TaskNew = Omit<ResourceObject, "id"> & {type: TaskType;description: string;stageProgressList: StageProgress[];+ creatorId: PrincipalId;+ assigneeId: PrincipalId;creator: UserDisplay;assignee?: UserDisplay;payload: TaskPayload;@@ -133,6 +146,7 @@ export type TaskPatch = {name?: string;status?: TaskStatus;description?: string;+ assigneeId?: PrincipalId;assignee?: UserDisplay;stageProgressList?: StageProgressPatch[];payload?: TaskPayload;@@ -170,6 +184,7 @@ export type Activity = ResourceObject & {// The object where this activity belongs// e.g if actionType is "bytebase.task.xxx", then this field refers to the corresponding task's id.containerId: TaskId;+ creatorId: PrincipalId;creator: UserDisplay;payload?: ActionPayloadType;};@@ -284,6 +299,10 @@ export interface MemberState {memberList: Member[];}+export interface PrincipalState {+ principalList: Principal[];+}+export interface BookmarkState {bookmarkListByUser: Map<UserId, Bookmark[]>;}diff --git a/frontend/src/views/Home.vue b/frontend/src/views/Home.vueindex 044533d643..87f0db2ac7 100644--- a/frontend/src/views/Home.vue+++ b/frontend/src/views/Home.vue@@ -70,8 +70,8 @@ export default {// "OPEN"if (task.attributes.status === "OPEN") {if (- task.attributes.creator.id === currentUser.id ||- task.attributes.assignee?.id === currentUser.id+ task.attributes.creatorId === currentUser.id ||+ task.attributes.assigneeId === currentUser.id) {state.attentionList.push(task);} else if (diff --git a/frontend/src/views/TaskActivityPanel.vue b/frontend/src/views/TaskActivityPanel.vueindex 6599680968..1ace0ceb4b 100644--- a/frontend/src/views/TaskActivityPanel.vue+++ b/frontend/src/views/TaskActivityPanel.vue@@ -105,7 +105,7 @@</div><divv-if="- currentUser.id == activity.attributes.creator.id &&+ currentUser.id == activity.attributes.creatorId &&activity.attributes.actionType =='bytebase.task.comment.create'"diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vueindex 8a65b295fb..a01307077d 100644--- a/frontend/src/views/TaskDetail.vue+++ b/frontend/src/views/TaskDetail.vue@@ -473,9 +473,9 @@ export default {const applicableStageTransitionList = () => {return STAGE_TRANSITION_LIST.filter((transition) => {const actionListForRole =- currentUser.id === state.task.attributes.creator.id+ currentUser.id === state.task.attributes.creatorId? CREATOR_APPLICABLE_STAGE_ACTION_LIST- : currentUser.id === state.task.attributes.assignee?.id+ : currentUser.id === state.task.attributes.assigneeId? ASSIGNEE_APPLICABLE_STAGE_ACTION_LIST: GUEST_APPLICABLE_STAGE_ACTION_LIST;const stage = activeStage(state.task as Task);