Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
Add AlterSchemaPrepForm for composing the alter schema task
天舟85bd1b2b600a
diff --git a/frontend/src/components/AlterSchemaPrepForm.vue b/frontend/src/components/AlterSchemaPrepForm.vuenew file mode 100644index 0000000000..7f1f7306a5--- /dev/null+++ b/frontend/src/components/AlterSchemaPrepForm.vue@@ -0,0 +1,202 @@+<template>+ <form class="mx-4 space-y-6 divide-y divide-block-border">+ <div class="grid gap-y-6 gap-x-4 grid-cols-2">+ <div class="col-span-2 col-start-1 w-64">+ <label for="project" class="textlabel">+ Project <span style="color: red">*</span>+ </label>+ <!-- Disable the selection if having preset project -->+ <ProjectSelect+ class="mt-1"+ id="project"+ name="project"+ :disabled="projectId != null"+ :selectedId="state.project.id"+ @select-project-id="+ (projectId) => {+ changeProjectId(projectId);+ }+ "+ />+ </div>++ <template v-if="state.singleEnvironment">+ <div class="col-span-2 col-start-1 w-64">+ <label for="environment" class="textlabel">+ Environment <span style="color: red">*</span>+ </label>+ <EnvironmentSelect+ class="mt-1 w-full"+ id="environment"+ name="environment"+ :selectedId="state.singleStageConfig.environmentId"+ @select-environment-id="+ (environmentId) => {+ state.singleStageConfig.environmentId = environmentId;+ }+ "+ />+ </div>+ <div class="col-span-2 col-start-1 w-64">+ <label for="database" class="textlabel">+ Database <span style="color: red">*</span>+ </label>+ <DatabaseSelect+ class="mt-1 w-full"+ id="database"+ name="database"+ :selectedId="state.singleStageConfig.databaseId"+ :environmentId="state.singleStageConfig.environmentId"+ :projectId="state.project.id"+ :mode="'USER'"+ @select-database-id="+ (databaseId) => {+ state.singleStageConfig.databaseId = databaseId;+ }+ "+ />+ </div>+ </template>+ </div>+ <!-- Create button group -->+ <div class="pt-4 flex justify-end">+ <button+ type="button"+ class="btn-normal py-2 px-4"+ @click.prevent="cancel"+ >+ Cancel+ </button>+ <button+ class="btn-primary ml-3 inline-flex justify-center py-2 px-4"+ :disabled="!allowNext"+ @click.prevent="goNext"+ >+ Next+ </button>+ </div>+ </form>+</template>++<script lang="ts">+import { computed, reactive, onMounted, onUnmounted, PropType } from "vue";+import { useStore } from "vuex";+import { useRouter } from "vue-router";+import ProjectSelect from "../components/ProjectSelect.vue";+import DatabaseSelect from "../components/DatabaseSelect.vue";+import EnvironmentSelect from "../components/EnvironmentSelect.vue";+import {+ DatabaseId,+ EnvironmentId,+ Project,+ ProjectId,+ unknown,+ UNKNOWN_ID,+} from "../types";++type StageConfig = {+ environmentId: EnvironmentId;+ databaseId: DatabaseId;+};++interface LocalState {+ project: Project;+ singleEnvironment: boolean;+ singleStageConfig: StageConfig;+ stageConfigList: StageConfig[];+}++export default {+ name: "AlterSchemaPrepForm",+ emits: ["dismiss"],+ props: {+ projectId: {+ type: String as PropType<ProjectId>,+ },+ },+ components: { ProjectSelect, DatabaseSelect, EnvironmentSelect },+ setup(props, { emit }) {+ const store = useStore();+ const router = useRouter();++ const keyboardHandler = (e: KeyboardEvent) => {+ if (e.code == "Escape") {+ cancel();+ }+ };++ onMounted(() => {+ document.addEventListener("keydown", keyboardHandler);+ });++ onUnmounted(() => {+ document.removeEventListener("keydown", keyboardHandler);+ });++ const state = reactive<LocalState>({+ project: props.projectId+ ? store.getters["project/projectById"](props.projectId)+ : (unknown("PROJECT") as Project),+ singleEnvironment: true,+ singleStageConfig: {+ environmentId: UNKNOWN_ID,+ databaseId: UNKNOWN_ID,+ },+ stageConfigList: [],+ });++ const allowNext = computed(() => {+ if (state.singleEnvironment) {+ return (+ state.project.id != UNKNOWN_ID &&+ state.singleStageConfig.environmentId != UNKNOWN_ID &&+ state.singleStageConfig.databaseId != UNKNOWN_ID+ );+ }+ return true;+ });++ const changeProjectId = (projectId: ProjectId) => {+ state.project = store.getters["project/projectById"](projectId);+ if (state.singleEnvironment) {+ } else {+ state.stageConfigList = [];+ }+ };++ const cancel = () => {+ emit("dismiss");+ };++ const goNext = () => {+ emit("dismiss");++ if (state.singleEnvironment) {+ const database = store.getters["database/databaseById"](+ state.singleStageConfig.databaseId+ );++ router.push({+ name: "workspace.task.detail",+ params: {+ taskSlug: "new",+ },+ query: {+ template: "bytebase.database.schema.update",+ name: `[${database.name}] Alter schema`,+ databaseList: database.id,+ },+ });+ }+ };++ return {+ state,+ allowNext,+ changeProjectId,+ cancel,+ goNext,+ };+ },+};+</script>diff --git a/frontend/src/components/QuickActionPanel.vue b/frontend/src/components/QuickActionPanel.vueindex ab3665fa65..9acdbef5a6 100644--- a/frontend/src/components/QuickActionPanel.vue+++ b/frontend/src/components/QuickActionPanel.vue@@ -170,10 +170,7 @@v-if="quickAction == 'quickaction.bytebase.database.schema.update'"class="flex flex-col items-center w-28">- <router-link- to="/task/new?template=bytebase.database.schema.update"- class="btn-icon-primary p-3"- >+ <button class="btn-icon-primary p-3" @click.prevent="alterSchema"><svgclass="w-6 h-6"fill="none"@@ -188,7 +185,7 @@d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z"></path></svg>- </router-link>+ </button><h3 class="mt-1 text-center text-base font-normal text-main">Alter Schema</h3>@@ -315,6 +312,16 @@><InstanceForm :create="true" @dismiss="state.showModal = false" /></template>+ <template+ v-else-if="+ state.quickActionType == 'quickaction.bytebase.database.schema.update'+ "+ >+ <AlterSchemaPrepForm+ :projectId="projectId"+ @dismiss="state.showModal = false"+ />+ </template><templatev-else-if="state.quickActionType == 'quickaction.bytebase.database.request'@@ -331,8 +338,10 @@ import { useRouter } from "vue-router";import { useStore } from "vuex";import ProjectNew from "../components/ProjectNew.vue";import InstanceForm from "../components/InstanceForm.vue";+import AlterSchemaPrepForm from "../components/AlterSchemaPrepForm.vue";import RequestDatabasePrepForm from "../components/RequestDatabasePrepForm.vue";-import { QuickActionType } from "../types";+import { ProjectId, QuickActionType } from "../types";+import { idFromSlug } from "../utils";// Quick action only applicable when DBA workflow feature is enabled.const DBA_WORKFLOW_APPLICABLE_QUICK_ACTION_LIST: QuickActionType[] = [@@ -351,6 +360,7 @@ export default {components: {ProjectNew,InstanceForm,+ AlterSchemaPrepForm,RequestDatabasePrepForm,},props: {@@ -379,6 +389,14 @@ export default {});});+ const projectId = computed((): ProjectId | undefined => {+ if (router.currentRoute.value.name == "workspace.project.detail") {+ const parts = router.currentRoute.value.path.split("/");+ return idFromSlug(parts[parts.length - 1]);+ }+ return undefined;+ });+const createProject = () => {state.modalTitle = "Create project";state.quickActionType = "quickaction.bytebase.project.create";@@ -391,6 +409,12 @@ export default {state.showModal = true;};+ const alterSchema = () => {+ state.modalTitle = "Alter schema";+ state.quickActionType = "quickaction.bytebase.database.schema.update";+ state.showModal = true;+ };+const requestDatabase = () => {state.modalTitle = "Request database";state.quickActionType = "quickaction.bytebase.database.request";@@ -408,8 +432,10 @@ export default {return {state,effectiveQuickActionList,+ projectId,createProject,createInstance,+ alterSchema,requestDatabase,createEnvironment,reorderEnvironment,diff --git a/frontend/src/miragejs/models/index.js b/frontend/src/miragejs/models/index.jsindex 4576e7c5fb..d173176981 100644--- a/frontend/src/miragejs/models/index.js+++ b/frontend/src/miragejs/models/index.js@@ -77,6 +77,8 @@ export default {project: belongsTo(),}),+ taskNew: Model,+taskPatch: Model,environment: Model.extend({diff --git a/frontend/src/miragejs/routes/task.js b/frontend/src/miragejs/routes/task.jsindex 51049d1f27..cff405c9be 100644--- a/frontend/src/miragejs/routes/task.js+++ b/frontend/src/miragejs/routes/task.js@@ -2,7 +2,7 @@ import { Response } from "miragejs";import isEqual from "lodash-es/isEqual";import { WORKSPACE_ID } from "./index";import { TaskBuiltinFieldId } from "../../plugins";-import { UNKNOWN_ID } from "../../types";+import { UNKNOWN_ID, DEFAULT_PROJECT_ID } from "../../types";export default function configureTask(route) {route.get("/task", function (schema, request) {@@ -39,12 +39,14 @@ export default function configureTask(route) {route.post("/task", function (schema, request) {const ts = Date.now();- const attrs = this.normalizedRequestAttrs("task");+ const attrs = this.normalizedRequestAttrs("task-new");+ const database = schema.databases.find(attrs.stageList[0].databaseId);const newTask = {...attrs,createdTs: ts,lastUpdatedTs: ts,status: "OPEN",+ projectId: database.projectId,workspaceId: WORKSPACE_ID,};const createdTask = schema.tasks.create(newTask);diff --git a/frontend/src/miragejs/seeds/index.ts b/frontend/src/miragejs/seeds/index.tsindex a0c8048dd0..91ea6279ec 100644--- a/frontend/src/miragejs/seeds/index.ts+++ b/frontend/src/miragejs/seeds/index.ts@@ -673,6 +673,7 @@ const fillTaskAndStageStatus = (name: environmentList[0].name,type,environmentId: environmentList[0].id,+ databaseId: databaseList[0].id,runnable: {auto: true,run: () => {},diff --git a/frontend/src/plugins/task/DatabaseCreateTemplate.ts b/frontend/src/plugins/task/DatabaseCreateTemplate.tsindex 54eaeb5e76..b83f046da1 100644--- a/frontend/src/plugins/task/DatabaseCreateTemplate.ts+++ b/frontend/src/plugins/task/DatabaseCreateTemplate.ts@@ -14,15 +14,8 @@ const template: TaskTemplate = {type: "bytebase.database.create",buildTask: (ctx: TemplateContext): TaskNew => {const payload: any = {};- if (ctx.environmentList.length > 0) {- // Set the last element as the default value.- // Normally the last environment is the prod env and is most commonly used.- payload[TaskBuiltinFieldId.ENVIRONMENT] =- ctx.environmentList[ctx.environmentList.length - 1].id;- }payload[TaskBuiltinFieldId.DATABASE] = "";return {- projectId: UNKNOWN_ID,name: "Request new db",type: "bytebase.database.create",description: "",@@ -32,6 +25,8 @@ const template: TaskTemplate = {name: "Create database",type: "bytebase.stage.database.create",status: "PENDING",+ databaseId:+ ctx.databaseList.length > 0 ? ctx.databaseList[0].id : UNKNOWN_ID,},],creatorId: ctx.currentUser.id,diff --git a/frontend/src/plugins/task/DatabaseGrantTemplate.ts b/frontend/src/plugins/task/DatabaseGrantTemplate.tsindex 3a9e1acdb7..a08fb014c7 100644--- a/frontend/src/plugins/task/DatabaseGrantTemplate.ts+++ b/frontend/src/plugins/task/DatabaseGrantTemplate.ts@@ -17,7 +17,6 @@ const template: TaskTemplate = {const payload: any = {};return {- projectId: UNKNOWN_ID,name: "Request database access",type: "bytebase.database.grant",description: "",@@ -27,6 +26,8 @@ const template: TaskTemplate = {name: "Request database access",type: "bytebase.stage.database.grant",status: "PENDING",+ databaseId:+ ctx.databaseList.length > 0 ? ctx.databaseList[0].id : UNKNOWN_ID,},],creatorId: ctx.currentUser.id,diff --git a/frontend/src/plugins/task/DatabaseSchemaUpdateTemplate.ts b/frontend/src/plugins/task/DatabaseSchemaUpdateTemplate.tsindex 70dbf609ca..41b30ffb96 100644--- a/frontend/src/plugins/task/DatabaseSchemaUpdateTemplate.ts+++ b/frontend/src/plugins/task/DatabaseSchemaUpdateTemplate.ts@@ -7,74 +7,33 @@ import {TaskContext,} from "../types";-import { TaskNew, UNKNOWN_ID } from "../../types";+import { Database, Stage, TaskNew, UNKNOWN_ID } from "../../types";const template: TaskTemplate = {type: "bytebase.database.schema.update",buildTask: (ctx: TemplateContext): TaskNew => {const payload: any = {};- if (ctx.environmentList.length > 0) {- // Set the last element as the default value.- // Normally the last environment is the prod env and is most commonly used.- payload[TaskBuiltinFieldId.ENVIRONMENT] =- ctx.environmentList[ctx.environmentList.length - 1].id;- }return {- projectId: UNKNOWN_ID,name: "Change db",type: "bytebase.database.schema.update",description: "",- stageList: [- {- id: "1",- name: "Update schema",- type: "bytebase.stage.schema.update",- status: "PENDING",- },- ],+ stageList: ctx.databaseList.map(+ (database: Database): Stage => {+ return {+ id: "1",+ name: `[${database.instance.environment.name}] ${database.name}`,+ type: "bytebase.stage.schema.update",+ status: "PENDING",+ databaseId: database.id,+ };+ }+ ),creatorId: ctx.currentUser.id,subscriberIdList: [],payload,};},- fieldList: [- {- category: "INPUT",- id: TaskBuiltinFieldId.PROJECT,- slug: "project",- name: "Project",- type: "Project",- required: true,- resolved: (ctx: TaskContext): boolean => {- const projectId = ctx.task.payload[TaskBuiltinFieldId.PROJECT];- return !isEmpty(projectId);- },- },- {- category: "INPUT",- id: TaskBuiltinFieldId.ENVIRONMENT,- slug: "env",- name: "Environment",- type: "Environment",- required: true,- resolved: (ctx: TaskContext): boolean => {- const environmentId = ctx.task.payload[TaskBuiltinFieldId.ENVIRONMENT];- return !isEmpty(environmentId);- },- },- {- category: "INPUT",- id: TaskBuiltinFieldId.DATABASE,- slug: "db",- name: "Database",- type: "Database",- required: true,- resolved: (ctx: TaskContext): boolean => {- const databaseId = ctx.task.payload[TaskBuiltinFieldId.DATABASE];- return !isEmpty(databaseId) || databaseId == UNKNOWN_ID;- },- },- ],+ fieldList: [],};export default template;diff --git a/frontend/src/plugins/task/DefaultTemplate.ts b/frontend/src/plugins/task/DefaultTemplate.tsindex b8d1bd82f6..7b1cca52d9 100644--- a/frontend/src/plugins/task/DefaultTemplate.ts+++ b/frontend/src/plugins/task/DefaultTemplate.ts@@ -11,7 +11,6 @@ const template: TaskTemplate = {type: "bytebase.general",buildTask: (ctx: TemplateContext): TaskNew => {return {- projectId: UNKNOWN_ID,name: "",type: "bytebase.general",description: "",@@ -21,6 +20,7 @@ const template: TaskTemplate = {name: "Request",type: "bytebase.stage.general",status: "PENDING",+ databaseId: UNKNOWN_ID,},],creatorId: ctx.currentUser.id,diff --git a/frontend/src/plugins/types.ts b/frontend/src/plugins/types.tsindex 81ed73d407..94367961b7 100644--- a/frontend/src/plugins/types.ts+++ b/frontend/src/plugins/types.ts@@ -6,6 +6,7 @@ import {Task,DatabaseId,UNKNOWN_ID,+ Database,} from "../types";// Task@@ -105,7 +106,7 @@ export type DatabaseFieldPayload = {// Templateexport type TemplateContext = {- environmentList: Environment[];+ databaseList: Database[];currentUser: Principal;};diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.tsindex 151db4d2b3..d66146b65e 100644--- a/frontend/src/router/index.ts+++ b/frontend/src/router/index.ts@@ -338,6 +338,11 @@ const routes: Array<RouteRecordRaw> = [return store.getters["project/projectById"](idFromSlug(slug)).name;},+ quickActionListByRole: new Map([+ ["OWNER", ["quickaction.bytebase.database.schema.update"]],+ ["DBA", ["quickaction.bytebase.database.schema.update"]],+ ["DEVELOPER", ["quickaction.bytebase.database.schema.update"]],+ ]),allowBookmark: true,},components: {diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.tsindex cd4423e102..911639ec84 100644--- a/frontend/src/store/modules/database.ts+++ b/frontend/src/store/modules/database.ts@@ -155,10 +155,6 @@ const getters = {return list;},- // If caller provides scoped search in any of accepted idParams, we search that first.- // If none is found, we then do an exhaustive search.- // We have to do this because we store the fetched database info differently based on- // how is requested.databaseById: (state: DatabaseState) => (databaseId: DatabaseId,instanceId?: InstanceIddiff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.tsindex bca32a11d3..20830e96e5 100644--- a/frontend/src/store/modules/task.ts+++ b/frontend/src/store/modules/task.ts@@ -110,7 +110,7 @@ const actions = {const data = (await axios.post(`/api/task?include=project`, {data: {- type: "task",+ type: "tasknew",attributes: newTask,},})diff --git a/frontend/src/types/bytebase.ts b/frontend/src/types/bytebase.tsindex 429f666e55..54905c4df4 100644--- a/frontend/src/types/bytebase.ts+++ b/frontend/src/types/bytebase.ts@@ -410,7 +410,7 @@ export type Stage = {type: StageType;status: StageStatus;environmentId?: EnvironmentId;- databaseId?: DatabaseId;+ databaseId: DatabaseId;runnable?: StageRunnable;};@@ -454,7 +454,6 @@ export type Task = {};export type TaskNew = {- projectId: ProjectId;name: string;type: TaskType;description: string;diff --git a/frontend/src/views/TaskDetail.vue b/frontend/src/views/TaskDetail.vueindex 1bb6d7890e..d1d20c7379 100644--- a/frontend/src/views/TaskDetail.vue+++ b/frontend/src/views/TaskDetail.vue@@ -205,6 +205,7 @@ import {StageProgressPatch,PrincipalId,TASK_STATUS_TRANSITION_LIST,+ Database,} from "../types";import {defaulTemplate,@@ -346,8 +347,16 @@ export default {watchEffect(refreshTemplate);const refreshState = () => {+ const databaseList: Database[] = [];++ if (router.currentRoute.value.query.databaseList) {+ for (const databaseId of (router.currentRoute.value.query+ .databaseList as string).split(","))+ databaseList.push(store.getters["database/databaseById"](databaseId));+ }+const newTask: TaskNew = newTaskTemplate.value.buildTask({- environmentList: environmentList.value,+ databaseList,currentUser: currentUser.value,});diff --git a/frontend/src/views/TaskSidebar.vue b/frontend/src/views/TaskSidebar.vueindex 09ce285f41..df55ee1596 100644--- a/frontend/src/views/TaskSidebar.vue+++ b/frontend/src/views/TaskSidebar.vue@@ -80,11 +80,10 @@class="w-full":disabled="!allowEdit":selectedId="fieldValue(field)"- :mode="'ENVIRONMENT'"- :environmentId="environmentId"+ :mode="'USER'"@select-database-id="(databaseId) => {- trySaveCustomField(field, databaseId);+ trySaveDatabaseId(field, databaseId);}"/>@@ -115,39 +114,71 @@</template></div><div- v-if="!$props.new"class="mt-6 border-t border-block-border pt-6 grid gap-y-6 gap-x-6 grid-cols-3">- <h2 class="textlabel flex items-center col-span-1 col-start-1">- Creator- </h2>- <ul class="col-span-2">- <li class="flex justify-start items-center space-x-2">- <div class="flex-shrink-0">- <BBAvatar :size="'small'" :username="task.creator.name" />- </div>- <router-link- :to="`/u/${task.creator.id}`"- class="text-sm font-medium text-main hover:underline"- >- {{ task.creator.name }}- </router-link>- </li>- </ul>+ <template v-if="database.id != UNKNOWN_ID">+ <h2 class="textlabel flex items-center col-span-1 col-start-1">+ Database<span v-if="$props.new" class="text-red-600">*</span>+ </h2>+ <router-link+ :to="`/db/${databaseSlug(database)}`"+ class="col-span-2 text-sm font-medium text-main hover:underline"+ >+ {{ database.name }}+ </router-link>- <h2 class="textlabel flex items-center col-span-1 col-start-1">- Updated- </h2>- <span class="textfield col-span-2">- {{ moment(task.lastUpdatedTs).format("LLL") }}</span- >+ <h2 class="textlabel flex items-center col-span-1 col-start-1">+ Environment+ </h2>+ <router-link+ :to="`/environment/${environmentSlug(environment)}`"+ class="col-span-2 text-sm font-medium text-main hover:underline"+ >+ {{ environmentName(environment) }}+ </router-link>- <h2 class="textlabel flex items-center col-span-1 col-start-1">- Created- </h2>- <span class="textfield col-span-2">- {{ moment(task.createdTs).format("LLL") }}</span- >+ <h2 class="textlabel flex items-center col-span-1 col-start-1">+ Project+ </h2>+ <router-link+ :to="`/project/${projectSlug(project)}`"+ class="col-span-2 text-sm font-medium text-main hover:underline"+ >+ {{ projectName(project) }}+ </router-link>+ </template>++ <template v-if="!$props.new">+ <h2 class="textlabel flex items-center col-span-1 col-start-1">+ Updated+ </h2>+ <span class="textfield col-span-2">+ {{ moment(task.lastUpdatedTs).format("LLL") }}</span+ >++ <h2 class="textlabel flex items-center col-span-1 col-start-1">+ Created+ </h2>+ <span class="textfield col-span-2">+ {{ moment(task.createdTs).format("LLL") }}</span+ >+ <h2 class="textlabel flex items-center col-span-1 col-start-1">+ Creator+ </h2>+ <ul class="col-span-2">+ <li class="flex justify-start items-center space-x-2">+ <div class="flex-shrink-0">+ <BBAvatar :size="'small'" :username="task.creator.name" />+ </div>+ <router-link+ :to="`/u/${task.creator.id}`"+ class="text-sm font-medium text-main hover:underline"+ >+ {{ task.creator.name }}+ </router-link>+ </li>+ </ul>+ </template></div><divv-if="!$props.new"@@ -209,13 +240,19 @@ import EnvironmentSelect from "../components/EnvironmentSelect.vue";import ProjectSelect from "../components/ProjectSelect.vue";import PrincipalSelect from "../components/PrincipalSelect.vue";import TaskStatusIcon from "../components/TaskStatusIcon.vue";+import { TaskField, DatabaseFieldPayload } from "../plugins";import {- TaskField,- TaskBuiltinFieldId,- DatabaseFieldPayload,-} from "../plugins";-import { DatabaseId, EnvironmentId, Principal, Task } from "../types";-import { isDBAOrOwner } from "../utils";+ Database,+ DatabaseId,+ Environment,+ EnvironmentId,+ Principal,+ Project,+ Task,+ TaskNew,+ UNKNOWN_ID,+} from "../types";+import { activeDatabaseId, isDBAOrOwner } from "../utils";interface LocalState {}@@ -229,7 +266,7 @@ export default {props: {task: {required: true,- type: Object as PropType<Task>,+ type: Object as PropType<Task | TaskNew>,},new: {required: true,@@ -261,12 +298,34 @@ export default {return props.task.payload[field.id];};- const environmentId = computed(() => {- return props.task.payload[TaskBuiltinFieldId.ENVIRONMENT];- });+ const database = computed(+ (): Database => {+ const databaseId = props.new+ ? props.task.stageList[0].databaseId+ : activeDatabaseId(props.task as Task);+ return store.getters["database/databaseById"](databaseId);+ }+ );++ const project = computed(+ (): Project => {+ // For new task, we derive the project from the 1st stage's database.+ // For existing task, we use task's project. We can't derive from the stage's database because+ // database may be transferred to a different project after creating the task.+ return props.new+ ? database.value.project+ : (props.task as Task).project;+ }+ );++ const environment = computed(+ (): Environment => {+ return database.value.instance.environment;+ }+ );const isCurrentUserSubscribed = computed((): boolean => {- for (const principal of props.task.subscriberList) {+ for (const principal of (props.task as Task).subscriberList) {if (currentUser.value.id == principal.id) {return true;}@@ -276,7 +335,7 @@ export default {const subscriberList = computed((): Principal[] => {const list: Principal[] = [];- props.task.subscriberList.forEach((principal: Principal) => {+ (props.task as Task).subscriberList.forEach((principal: Principal) => {// Put the current user at the front if in the list.if (currentUser.value.id == principal.id) {list.unshift(principal);@@ -294,8 +353,8 @@ export default {// being assigned to the task.return (props.new ||- (props.task.status == "OPEN" &&- (currentUser.value.id == props.task.assignee?.id ||+ ((props.task as Task).status == "OPEN" &&+ (currentUser.value.id == (props.task as Task).assignee?.id ||isDBAOrOwner(currentUser.value.role))));});@@ -346,11 +405,13 @@ export default {};const toggleSubscription = () => {- const list = cloneDeep(props.task.subscriberList);+ const list = cloneDeep((props.task as Task).subscriberList);if (isCurrentUserSubscribed.value) {- const index = props.task.subscriberList.findIndex((item: Principal) => {- return item.id == currentUser.value.id;- });+ const index = (props.task as Task).subscriberList.findIndex(+ (item: Principal) => {+ return item.id == currentUser.value.id;+ }+ );if (index >= 0) {list.splice(index, 1);}@@ -366,10 +427,13 @@ export default {};return {+ UNKNOWN_ID,state,allowEditAssignee,fieldValue,- environmentId,+ environment,+ database,+ project,isCurrentUserSubscribed,subscriberList,trySaveCustomField,