Database governance built for humans and agents — controlling changes and access across every major database.
Go cicddata-governancedata-maskingdata-securitydatabase-accessdatabase-governancedevopsdevsecopsflywaygitopsliquibasemongodbmysqloraclepostgresqlschema-migrationssecuritysql-clientsqlservertidb
feat(test): use relations for updator/creators because they're relations (#481)
Danny Xufca7a7226162
diff --git a/api/project.go b/api/project.goindex a3f5b7e811..1737db3a85 100644--- a/api/project.go+++ b/api/project.go@@ -69,10 +69,10 @@ type Project struct {// Standard fieldsRowStatus RowStatus `jsonapi:"attr,rowStatus"`CreatorID int- Creator *Principal `jsonapi:"attr,creator"`+ Creator *Principal `jsonapi:"relation,creator"`CreatedTs int64 `jsonapi:"attr,createdTs"`UpdaterID int- Updater *Principal `jsonapi:"attr,updater"`+ Updater *Principal `jsonapi:"relation,updater"`UpdatedTs int64 `jsonapi:"attr,updatedTs"`// Related fieldsdiff --git a/api/project_member.go b/api/project_member.goindex 2c8cfd2c98..63326799db 100644--- a/api/project_member.go+++ b/api/project_member.go@@ -13,10 +13,10 @@ type ProjectMember struct {// Standard fieldsCreatorID int- Creator *Principal `jsonapi:"attr,creator"`+ Creator *Principal `jsonapi:"relation,creator"`CreatedTs int64 `jsonapi:"attr,createdTs"`UpdaterID int- Updater *Principal `jsonapi:"attr,updater"`+ Updater *Principal `jsonapi:"relation,updater"`UpdatedTs int64 `jsonapi:"attr,updatedTs"`// Related fields@@ -26,7 +26,7 @@ type ProjectMember struct {// Domain specific fieldsRole string `jsonapi:"attr,role"`PrincipalID int- Principal *Principal `jsonapi:"attr,principal"`+ Principal *Principal `jsonapi:"relation,principal"`}// ProjectMemberCreate is the API message for creating a project member.diff --git a/frontend/src/store/modules/principal.ts b/frontend/src/store/modules/principal.tsindex 50e3a50dbc..35fac56556 100644--- a/frontend/src/store/modules/principal.ts+++ b/frontend/src/store/modules/principal.ts@@ -28,6 +28,21 @@ function convert(principal: ResourceObject): Principal {};}+export function getPrincipalFromIncludedList(+ id: string,+ includedList: ResourceObject[]+): Principal | null {+ for (const item of includedList || []) {+ if (item.type != "principal") {+ continue;+ }+ if (item.id == id) {+ return convert(item);+ }+ }+ return null;+}+const state: () => PrincipalState = () => ({principalList: [],});diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.tsindex 40f03fa1b6..242de63361 100644--- a/frontend/src/store/modules/project.ts+++ b/frontend/src/store/modules/project.ts@@ -18,13 +18,21 @@ import {RowStatus,unknown,} from "../../types";+import { getPrincipalFromIncludedList } from "./principal";function convert(project: ResourceObject,includedList: ResourceObject[],rootGetters: any): Project {- const attrs = project.attributes as Omit<Project, "id" | "memberList">;+ const attrs = project.attributes as Omit<+ Project,+ "id" | "memberList" | "creator" | "updater"+ >;+ const creatorId = (project.relationships!.creator.data as ResourceIdentifier)+ .id;+ const updaterId = (project.relationships!.creator.data as ResourceIdentifier)+ .id;// Only able to assign an empty member list, otherwise would cause circular dependency.// This should be fine as we shouldn't access member via member.project.memberListconst projectWithoutMemberList: Project = {@@ -32,8 +40,8 @@ function convert(rowStatus: attrs.rowStatus,name: attrs.name,key: attrs.key,- creator: attrs.creator,- updater: attrs.updater,+ creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,+ updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,createdTs: attrs.createdTs,updatedTs: attrs.updatedTs,memberList: [],@@ -72,24 +80,33 @@ function convertMember(includedList: ResourceObject[],rootGetters: any): ProjectMember {- const creator = projectMember.attributes.creator as Principal;- const updater = projectMember.attributes.updater as Principal;- const principal = projectMember.attributes.principal as Principal;+ const creatorId = (+ projectMember.relationships!.creator.data as ResourceIdentifier+ ).id;+ const updaterId = (+ projectMember.relationships!.updater.data as ResourceIdentifier+ ).id;+ const principalId = (+ projectMember.relationships!.principal.data as ResourceIdentifier+ ).id;const attrs = projectMember.attributes as Omit<ProjectMember,- "id" | "project" | "creator" | "updater" | "principal"+ "id" | "project">;return {id: parseInt(projectMember.id),project: unknown("PROJECT") as Project,- creator,- updater,+ creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,+ updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,createdTs: attrs.createdTs,updatedTs: attrs.updatedTs,role: attrs.role,- principal,+ principal: getPrincipalFromIncludedList(+ principalId,+ includedList+ ) as Principal,};}