Skip to content

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

refactor: simplify the usage of getPrincipalFromIncludedList (#504)

Danny Xuda8e1cd5d7f6
diff --git a/frontend/src/store/modules/activity.ts b/frontend/src/store/modules/activity.ts
index 8f47e8f2cb..97a01fe603 100644
--- a/frontend/src/store/modules/activity.ts
+++ b/frontend/src/store/modules/activity.ts
@@ -6,10 +6,8 @@ import {
ActivityPatch,
ActivityState,
IssueId,
- Principal,
PrincipalId,
ProjectId,
- ResourceIdentifier,
ResourceObject,
} from "../../types";
import { getPrincipalFromIncludedList } from "./principal";
@@ -22,15 +20,16 @@ function convert(
const payload = activity.attributes.payload
? JSON.parse((activity.attributes.payload as string) || "{}")
: {};
- const creatorId = (activity.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (activity.relationships!.updater.data as ResourceIdentifier)
- .id;
-
return {
...(activity.attributes as Omit<Activity, "id" | "creator" | "updater">),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ activity.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ activity.relationships!.updater.data,
+ includedList
+ ),
id: parseInt(activity.id),
payload,
};
diff --git a/frontend/src/store/modules/anomaly.ts b/frontend/src/store/modules/anomaly.ts
index d3ab24d97f..551b5ee37b 100644
--- a/frontend/src/store/modules/anomaly.ts
+++ b/frontend/src/store/modules/anomaly.ts
@@ -1,10 +1,4 @@
-import {
- Anomaly,
- AnomalyState,
- Principal,
- ResourceIdentifier,
- ResourceObject,
-} from "../../types";
+import { Anomaly, AnomalyState, ResourceObject } from "../../types";
import { getPrincipalFromIncludedList } from "./principal";
function convert(
@@ -12,17 +6,19 @@ function convert(
includedList: ResourceObject[],
rootGetters: any
): Anomaly {
- const creatorId = (anomaly.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (anomaly.relationships!.updater.data as ResourceIdentifier)
- .id;
return {
...(anomaly.attributes as Omit<
Anomaly,
"id" | "payload" | "creator" | "updater"
>),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ anomaly.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ anomaly.relationships!.updater.data,
+ includedList
+ ),
id: parseInt(anomaly.id),
payload: JSON.parse((anomaly.attributes.payload as string) || "{}"),
};
diff --git a/frontend/src/store/modules/backup.ts b/frontend/src/store/modules/backup.ts
index 6cb34969de..bcf9bd8a7d 100644
--- a/frontend/src/store/modules/backup.ts
+++ b/frontend/src/store/modules/backup.ts
@@ -7,8 +7,6 @@ import {
BackupSettingUpsert,
BackupState,
DatabaseId,
- Principal,
- ResourceIdentifier,
ResourceObject,
unknown,
} from "../../types";
@@ -19,15 +17,17 @@ function convert(
includedList: ResourceObject[],
rootGetters: any
): Backup {
- const creatorId = (backup.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (backup.relationships!.updater.data as ResourceIdentifier)
- .id;
return {
...(backup.attributes as Omit<Backup, "id" | "creator" | "updater">),
id: parseInt(backup.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ backup.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ backup.relationships!.updater.data,
+ includedList
+ ),
};
}
@@ -36,28 +36,20 @@ function convertBackupSetting(
includedList: ResourceObject[],
rootGetters: any
): BackupSetting {
- let creator = null;
- let updater = null;
- if (backupSetting.relationships!.creator.data != null) {
- const creatorId = (
- backupSetting.relationships!.creator.data as ResourceIdentifier
- ).id;
- creator = getPrincipalFromIncludedList(creatorId, includedList);
- }
- if (backupSetting.relationships!.creator.data != null) {
- const updaterId = (
- backupSetting.relationships!.updater.data as ResourceIdentifier
- ).id;
- updater = getPrincipalFromIncludedList(updaterId, includedList);
- }
return {
...(backupSetting.attributes as Omit<
BackupSetting,
"id" | "creator" | "updater"
>),
id: parseInt(backupSetting.id),
- creator: creator as Principal,
- updater: updater as Principal,
+ creator: getPrincipalFromIncludedList(
+ backupSetting.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ backupSetting.relationships!.updater.data,
+ includedList
+ ),
};
}
diff --git a/frontend/src/store/modules/bookmark.ts b/frontend/src/store/modules/bookmark.ts
index 03396449a7..9260e2c178 100644
--- a/frontend/src/store/modules/bookmark.ts
+++ b/frontend/src/store/modules/bookmark.ts
@@ -4,8 +4,6 @@ import {
Bookmark,
BookmarkCreate,
BookmarkState,
- Principal,
- ResourceIdentifier,
ResourceObject,
unknown,
} from "../../types";
@@ -16,15 +14,17 @@ function convert(
includedList: ResourceObject[],
rootGetters: any
): Bookmark {
- const creatorId = (bookmark.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (bookmark.relationships!.updater.data as ResourceIdentifier)
- .id;
return {
...(bookmark.attributes as Omit<Bookmark, "id" | "creator" | "updater">),
id: parseInt(bookmark.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ bookmark.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ bookmark.relationships!.updater.data,
+ includedList
+ ),
};
}
diff --git a/frontend/src/store/modules/dataSource.ts b/frontend/src/store/modules/dataSource.ts
index 68f0fe4858..6eff9967f7 100644
--- a/frontend/src/store/modules/dataSource.ts
+++ b/frontend/src/store/modules/dataSource.ts
@@ -6,7 +6,6 @@ import {
DataSourceMember,
DataSourceMemberCreate,
DataSourceState,
- Principal,
PrincipalId,
ResourceObject,
ResourceIdentifier,
@@ -40,12 +39,6 @@ function convert(
};
}
);
- const creatorId = (
- dataSource.relationships!.creator.data as ResourceIdentifier
- ).id;
- const updaterId = (
- dataSource.relationships!.updater.data as ResourceIdentifier
- ).id;
let instance: Instance = unknown("INSTANCE") as Instance;
for (const item of includedList || []) {
@@ -69,8 +62,14 @@ function convert(
"id" | "instanceId" | "database" | "memberList" | "creator" | "updater"
>),
id: parseInt(dataSource.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ dataSource.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ dataSource.relationships!.updater.data,
+ includedList
+ ),
instance,
database,
memberList,
diff --git a/frontend/src/store/modules/database.ts b/frontend/src/store/modules/database.ts
index 0be6b5b407..5ee5e5871d 100644
--- a/frontend/src/store/modules/database.ts
+++ b/frontend/src/store/modules/database.ts
@@ -13,7 +13,6 @@ import {
EnvironmentId,
Instance,
InstanceId,
- Principal,
PrincipalId,
Project,
ProjectId,
@@ -95,11 +94,6 @@ function convert(
// nothing to catch
}
- const creatorId = (database.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (database.relationships!.updater.data as ResourceIdentifier)
- .id;
-
// Only able to assign an empty data source list / anomaly list, otherwise would cause circular dependency.
// This should be fine as e.g. we shouldn't access data source via dataSource.database.dataSourceList
const databaseWPartial = {
@@ -116,8 +110,14 @@ function convert(
| "updater"
>),
id: parseInt(database.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ database.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ database.relationships!.updater.data,
+ includedList
+ ),
instance,
project,
labels,
diff --git a/frontend/src/store/modules/deployment.ts b/frontend/src/store/modules/deployment.ts
index 97983615fe..7fd142e334 100644
--- a/frontend/src/store/modules/deployment.ts
+++ b/frontend/src/store/modules/deployment.ts
@@ -8,8 +8,6 @@ import {
empty,
unknown,
UNKNOWN_ID,
- Principal,
- ResourceIdentifier,
DeploymentConfigPatch,
} from "../../types";
import { getPrincipalFromIncludedList } from "./principal";
@@ -39,20 +37,20 @@ function convert(
// nothing
}
- const creatorId = (
- deployment.relationships!.creator.data as ResourceIdentifier
- ).id;
- const updaterId = (
- deployment.relationships!.updater.data as ResourceIdentifier
- ).id;
return {
...(deployment.attributes as Omit<
DeploymentConfig,
"id" | "schedule" | "creator" | "updater"
>),
id: parseInt(deployment.id, 10),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ deployment.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ deployment.relationships!.updater.data,
+ includedList
+ ),
schedule,
};
}
diff --git a/frontend/src/store/modules/environment.ts b/frontend/src/store/modules/environment.ts
index c5881d2d3d..288f119a9f 100644
--- a/frontend/src/store/modules/environment.ts
+++ b/frontend/src/store/modules/environment.ts
@@ -7,8 +7,6 @@ import {
EnvironmentId,
EnvironmentPatch,
EnvironmentState,
- Principal,
- ResourceIdentifier,
ResourceObject,
RowStatus,
unknown,
@@ -20,20 +18,20 @@ function convert(
includedList: ResourceObject[],
rootGetters: any
): Environment {
- const creatorId = (
- environment.relationships!.creator.data as ResourceIdentifier
- ).id;
- const updaterId = (
- environment.relationships!.updater.data as ResourceIdentifier
- ).id;
return {
...(environment.attributes as Omit<
Environment,
"id" | "creator" | "updater"
>),
id: parseInt(environment.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ environment.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ environment.relationships!.updater.data,
+ includedList
+ ),
};
}
diff --git a/frontend/src/store/modules/instance.ts b/frontend/src/store/modules/instance.ts
index 7661a5a236..1cafce5f85 100644
--- a/frontend/src/store/modules/instance.ts
+++ b/frontend/src/store/modules/instance.ts
@@ -14,7 +14,6 @@ import {
INSTANCE_OPERATION_TIMEOUT,
MigrationHistory,
MigrationHistoryId,
- Principal,
ResourceIdentifier,
ResourceObject,
RowStatus,
@@ -44,18 +43,20 @@ function convert(
anomalyList.push(anomaly);
}
- const creatorId = (instance.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (instance.relationships!.updater.data as ResourceIdentifier)
- .id;
const instancePartial = {
...(instance.attributes as Omit<
Instance,
"id" | "environment" | "anomalyList" | "creator" | "updater"
>),
id: parseInt(instance.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ instance.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ instance.relationships!.updater.data,
+ includedList
+ ),
environment,
anomalyList: [],
};
diff --git a/frontend/src/store/modules/issue.ts b/frontend/src/store/modules/issue.ts
index b2531d85eb..59303fed1d 100644
--- a/frontend/src/store/modules/issue.ts
+++ b/frontend/src/store/modules/issue.ts
@@ -10,7 +10,6 @@ import {
IssueStatus,
IssueStatusPatch,
Pipeline,
- Principal,
PrincipalId,
Project,
ProjectId,
@@ -51,12 +50,6 @@ function convert(
pipeline = rootGetters["pipeline/convert"](item, includedList);
}
}
- const creatorId = (issue.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (issue.relationships!.updater.data as ResourceIdentifier)
- .id;
- const assigneeId = (issue.relationships!.assignee.data as ResourceIdentifier)
- .id;
return {
...(issue.attributes as Omit<
@@ -64,12 +57,18 @@ function convert(
"id" | "project" | "creator" | "updater" | "assignee"
>),
id: parseInt(issue.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ issue.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ issue.relationships!.updater.data,
+ includedList
+ ),
assignee: getPrincipalFromIncludedList(
- assigneeId,
+ issue.relationships!.assignee.data,
includedList
- ) as Principal,
+ ),
project,
pipeline,
};
diff --git a/frontend/src/store/modules/issueSubscriber.ts b/frontend/src/store/modules/issueSubscriber.ts
index 389026ede4..03c5f72550 100644
--- a/frontend/src/store/modules/issueSubscriber.ts
+++ b/frontend/src/store/modules/issueSubscriber.ts
@@ -3,9 +3,7 @@ import {
PrincipalId,
IssueSubscriber,
IssueSubscriberState,
- ResourceIdentifier,
ResourceObject,
- Principal,
IssueId,
} from "../../types";
import { getPrincipalFromIncludedList } from "./principal";
@@ -15,15 +13,12 @@ function convert(
includedList: ResourceObject[],
rootGetters: any
): IssueSubscriber {
- const subscriberId = (
- issueSubscriber.relationships!.subscriber.data as ResourceIdentifier
- ).id;
return {
issueId: issueSubscriber.attributes.issueId as IssueId,
subscriber: getPrincipalFromIncludedList(
- subscriberId,
+ issueSubscriber.relationships!.subscriber.data,
includedList
- ) as Principal,
+ ),
};
}
diff --git a/frontend/src/store/modules/label.ts b/frontend/src/store/modules/label.ts
index 3b2744c6ac..89c451a1f4 100644
--- a/frontend/src/store/modules/label.ts
+++ b/frontend/src/store/modules/label.ts
@@ -6,10 +6,7 @@ import {
LabelId,
LabelPatch,
LabelValueType,
- Principal,
- ResourceIdentifier,
} from "../../types";
-import { getPrincipalFromIncludedList } from "./principal";
function convert(
label: ResourceObject,
diff --git a/frontend/src/store/modules/member.ts b/frontend/src/store/modules/member.ts
index d5198d6975..5c7eda2269 100644
--- a/frontend/src/store/modules/member.ts
+++ b/frontend/src/store/modules/member.ts
@@ -10,8 +10,6 @@ import {
unknown,
empty,
EMPTY_ID,
- Principal,
- ResourceIdentifier,
RoleType,
} from "../../types";
import { getPrincipalFromIncludedList } from "./principal";
@@ -21,17 +19,10 @@ function convert(
includedList: ResourceObject[],
rootGetters: any
): Member {
- const creatorId = (member.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (member.relationships!.updater.data as ResourceIdentifier)
- .id;
- const principalId = (
- member.relationships!.principal.data as ResourceIdentifier
- ).id;
const principal = getPrincipalFromIncludedList(
- principalId,
+ member.relationships!.principal.data,
includedList
- ) as Principal;
+ );
principal.role = member.attributes.role as RoleType;
return {
@@ -40,8 +31,14 @@ function convert(
"id" | "principal" | "creator" | "updater"
>),
id: parseInt(member.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ member.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ member.relationships!.updater.data,
+ includedList
+ ),
principal: principal,
};
}
diff --git a/frontend/src/store/modules/pipeline.ts b/frontend/src/store/modules/pipeline.ts
index 03dd0cb8eb..bc121fa769 100644
--- a/frontend/src/store/modules/pipeline.ts
+++ b/frontend/src/store/modules/pipeline.ts
@@ -1,7 +1,6 @@
import {
ResourceIdentifier,
ResourceObject,
- Principal,
Pipeline,
PipelineState,
Stage,
@@ -32,10 +31,6 @@ function convert(
}
}
}
- const creatorId = (pipeline.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (pipeline.relationships!.updater.data as ResourceIdentifier)
- .id;
const result: Pipeline = {
...(pipeline.attributes as Omit<
@@ -43,8 +38,14 @@ function convert(
"id" | "stageList" | "creator" | "updater"
>),
id: parseInt(pipeline.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ pipeline.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ pipeline.relationships!.updater.data,
+ includedList
+ ),
stageList,
};
diff --git a/frontend/src/store/modules/policy.ts b/frontend/src/store/modules/policy.ts
index e6048da358..bc4a9d14b5 100644
--- a/frontend/src/store/modules/policy.ts
+++ b/frontend/src/store/modules/policy.ts
@@ -3,7 +3,6 @@ import {
Environment,
EnvironmentId,
PolicyState,
- Principal,
ResourceIdentifier,
ResourceObject,
unknown,
@@ -31,10 +30,6 @@ function convert(
environment = rootGetters["environment/convert"](item, includedList);
}
}
- const creatorId = (policy.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (policy.relationships!.updater.data as ResourceIdentifier)
- .id;
return {
...(policy.attributes as Omit<
@@ -42,8 +37,14 @@ function convert(
"id" | "environment" | "payload" | "creator" | "updater"
>),
id: parseInt(policy.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ policy.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ policy.relationships!.updater.data,
+ includedList
+ ),
environment,
payload: JSON.parse((policy.attributes.payload as string) || "{}"),
};
diff --git a/frontend/src/store/modules/principal.ts b/frontend/src/store/modules/principal.ts
index 35fac56556..a365e53b46 100644
--- a/frontend/src/store/modules/principal.ts
+++ b/frontend/src/store/modules/principal.ts
@@ -10,6 +10,7 @@ import {
empty,
EMPTY_ID,
PrincipalType,
+ ResourceIdentifier,
RoleType,
} from "../../types";
import { randomString } from "../../utils";
@@ -29,18 +30,24 @@ function convert(principal: ResourceObject): Principal {
}
export function getPrincipalFromIncludedList(
- id: string,
+ data:
+ | ResourceIdentifier<ResourceObject>
+ | ResourceIdentifier<ResourceObject>[]
+ | undefined,
includedList: ResourceObject[]
-): Principal | null {
+): Principal {
+ if (data == null) {
+ return empty("PRINCIPAL") as Principal;
+ }
for (const item of includedList || []) {
if (item.type != "principal") {
continue;
}
- if (item.id == id) {
+ if (item.id == (data as ResourceIdentifier).id) {
return convert(item);
}
}
- return null;
+ return empty("PRINCIPAL") as Principal;
}
const state: () => PrincipalState = () => ({
diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.ts
index 242de63361..47d3a187c8 100644
--- a/frontend/src/store/modules/project.ts
+++ b/frontend/src/store/modules/project.ts
@@ -3,7 +3,6 @@ import {
empty,
EMPTY_ID,
MemberId,
- Principal,
PrincipalId,
Project,
ProjectCreate,
@@ -29,10 +28,6 @@ function convert(
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.memberList
const projectWithoutMemberList: Project = {
@@ -40,8 +35,14 @@ function convert(
rowStatus: attrs.rowStatus,
name: attrs.name,
key: attrs.key,
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ project.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ project.relationships!.updater.data,
+ includedList
+ ),
createdTs: attrs.createdTs,
updatedTs: attrs.updatedTs,
memberList: [],
@@ -80,16 +81,6 @@ function convertMember(
includedList: ResourceObject[],
rootGetters: any
): ProjectMember {
- 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"
@@ -98,15 +89,21 @@ function convertMember(
return {
id: parseInt(projectMember.id),
project: unknown("PROJECT") as Project,
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ projectMember.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ projectMember.relationships!.updater.data,
+ includedList
+ ),
createdTs: attrs.createdTs,
updatedTs: attrs.updatedTs,
role: attrs.role,
principal: getPrincipalFromIncludedList(
- principalId,
+ projectMember.relationships!.principal.data,
includedList
- ) as Principal,
+ ),
};
}
diff --git a/frontend/src/store/modules/projectWebhook.ts b/frontend/src/store/modules/projectWebhook.ts
index 8b386afd2d..ed664dd84a 100644
--- a/frontend/src/store/modules/projectWebhook.ts
+++ b/frontend/src/store/modules/projectWebhook.ts
@@ -1,6 +1,5 @@
import axios from "axios";
import {
- Principal,
ProjectId,
ProjectWebhook,
ProjectWebhookCreate,
@@ -8,7 +7,6 @@ import {
ProjectWebhookPatch,
ProjectWebhookState,
ProjectWebhookTestResult,
- ResourceIdentifier,
ResourceObject,
unknown,
} from "../../types";
@@ -19,20 +17,20 @@ function convert(
includedList: ResourceObject[],
rootGetters: any
): ProjectWebhook {
- const creatorId = (
- projectWebhook.relationships!.creator.data as ResourceIdentifier
- ).id;
- const updaterId = (
- projectWebhook.relationships!.updater.data as ResourceIdentifier
- ).id;
return {
...(projectWebhook.attributes as Omit<
ProjectWebhook,
"id" | "creator" | "updater"
>),
id: parseInt(projectWebhook.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ projectWebhook.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ projectWebhook.relationships!.updater.data,
+ includedList
+ ),
};
}
diff --git a/frontend/src/store/modules/repository.ts b/frontend/src/store/modules/repository.ts
index 7fb7e854b0..e4aff1d007 100644
--- a/frontend/src/store/modules/repository.ts
+++ b/frontend/src/store/modules/repository.ts
@@ -1,6 +1,5 @@
import axios from "axios";
import {
- Principal,
Project,
ProjectId,
Repository,
@@ -38,12 +37,6 @@ function convert(
project = rootGetters["project/convert"](item, includedList);
}
}
- const creatorId = (
- repository.relationships!.creator.data as ResourceIdentifier
- ).id;
- const updaterId = (
- repository.relationships!.updater.data as ResourceIdentifier
- ).id;
return {
...(repository.attributes as Omit<
@@ -51,8 +44,14 @@ function convert(
"id" | "vcs" | "project" | "creator" | "updater"
>),
id: parseInt(repository.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ repository.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ repository.relationships!.updater.data,
+ includedList
+ ),
vcs,
project,
};
diff --git a/frontend/src/store/modules/setting.ts b/frontend/src/store/modules/setting.ts
index fbb7babd4e..7a75120ac3 100644
--- a/frontend/src/store/modules/setting.ts
+++ b/frontend/src/store/modules/setting.ts
@@ -1,10 +1,5 @@
import axios from "axios";
-import {
- Principal,
- ResourceIdentifier,
- ResourceObject,
- SettingState,
-} from "../../types";
+import { ResourceObject, SettingState } from "../../types";
import { Setting, SettingName } from "../../types/setting";
import { getPrincipalFromIncludedList } from "./principal";
@@ -13,15 +8,17 @@ function convert(
includedList: ResourceObject[],
rootGetters: any
): Setting {
- const creatorId = (setting.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (setting.relationships!.updater.data as ResourceIdentifier)
- .id;
return {
...(setting.attributes as Omit<Setting, "id" | "creator" | "updater">),
id: parseInt(setting.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ setting.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ setting.relationships!.updater.data,
+ includedList
+ ),
};
}
diff --git a/frontend/src/store/modules/sqlEditor.ts b/frontend/src/store/modules/sqlEditor.ts
index e3c714ba8a..447dd2c4bd 100644
--- a/frontend/src/store/modules/sqlEditor.ts
+++ b/frontend/src/store/modules/sqlEditor.ts
@@ -12,8 +12,6 @@ import {
ProjectId,
QueryHistory,
SavedQuery,
- Principal,
- ResourceIdentifier,
ResourceObject,
} from "../../types";
import * as types from "../mutation-types";
@@ -24,20 +22,19 @@ function convertSavedQuery(
savedQuery: ResourceObject,
includedList: ResourceObject[]
): SavedQuery {
- const creatorId = (
- savedQuery.relationships!.creator.data as ResourceIdentifier
- ).id;
- const updaterId = (
- savedQuery.relationships!.updater.data as ResourceIdentifier
- ).id;
-
return {
...(savedQuery.attributes as Omit<
SavedQuery,
"id" | "creator" | "updater"
>),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ savedQuery.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ savedQuery.relationships!.updater.data,
+ includedList
+ ),
id: parseInt(savedQuery.id),
};
}
diff --git a/frontend/src/store/modules/stage.ts b/frontend/src/store/modules/stage.ts
index 9ba9c087c7..f0939cb4e7 100644
--- a/frontend/src/store/modules/stage.ts
+++ b/frontend/src/store/modules/stage.ts
@@ -7,7 +7,6 @@ import {
unknown,
PipelineId,
Pipeline,
- Principal,
Environment,
} from "../../types";
import { getPrincipalFromIncludedList } from "./principal";
@@ -54,19 +53,20 @@ function convertPartial(
}
}
- const creatorId = (stage.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (stage.relationships!.updater.data as ResourceIdentifier)
- .id;
-
const result: Omit<Stage, "pipeline"> = {
...(stage.attributes as Omit<
Stage,
"id" | "database" | "taskList" | "creator" | "updater"
>),
id: parseInt(stage.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ stage.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ stage.relationships!.updater.data,
+ includedList
+ ),
environment,
taskList,
};
diff --git a/frontend/src/store/modules/table.ts b/frontend/src/store/modules/table.ts
index eb1a2a1798..ec33a9060a 100644
--- a/frontend/src/store/modules/table.ts
+++ b/frontend/src/store/modules/table.ts
@@ -2,7 +2,6 @@ import axios from "axios";
import {
Database,
DatabaseId,
- Principal,
ResourceIdentifier,
ResourceObject,
Table,
@@ -26,18 +25,21 @@ function convert(
break;
}
}
- const creatorId = (table.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (table.relationships!.updater.data as ResourceIdentifier)
- .id;
+
return {
...(table.attributes as Omit<
Table,
"id" | "database" | "creator" | "updater"
>),
id: parseInt(table.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ table.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ table.relationships!.updater.data,
+ includedList
+ ),
database,
};
}
diff --git a/frontend/src/store/modules/task.ts b/frontend/src/store/modules/task.ts
index bfa9ad06ba..2081f82a84 100644
--- a/frontend/src/store/modules/task.ts
+++ b/frontend/src/store/modules/task.ts
@@ -5,7 +5,6 @@ import {
IssueId,
Pipeline,
PipelineId,
- Principal,
ResourceIdentifier,
ResourceObject,
Stage,
@@ -35,18 +34,20 @@ function convertTaskRun(
? JSON.parse((taskRun.attributes.payload as string) || "{}")
: {};
- const creatorId = (taskRun.relationships!.creator.data as ResourceIdentifier)
- .id;
- const updaterId = (taskRun.relationships!.updater.data as ResourceIdentifier)
- .id;
return {
...(taskRun.attributes as Omit<
TaskRun,
"id" | "result" | "payload" | "creator" | "updater"
>),
id: parseInt(taskRun.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ taskRun.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ taskRun.relationships!.updater.data,
+ includedList
+ ),
result,
payload,
};
@@ -65,20 +66,20 @@ function convertTaskCheckRun(
? JSON.parse((taskCheckRun.attributes.payload as string) || "{}")
: {};
- const creatorId = (
- taskCheckRun.relationships!.creator.data as ResourceIdentifier
- ).id;
- const updaterId = (
- taskCheckRun.relationships!.updater.data as ResourceIdentifier
- ).id;
return {
...(taskCheckRun.attributes as Omit<
TaskCheckRun,
"id" | "result" | "payload" | "creator" | "updater"
>),
id: parseInt(taskCheckRun.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ taskCheckRun.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ taskCheckRun.relationships!.updater.data,
+ includedList
+ ),
result,
payload,
};
@@ -89,8 +90,6 @@ function convertPartial(
includedList: ResourceObject[],
rootGetters: any
): Omit<Task, "pipeline" | "stage"> {
- const creatorId = (task.relationships!.creator.data as ResourceIdentifier).id;
- const updaterId = (task.relationships!.updater.data as ResourceIdentifier).id;
const payload = task.attributes.payload
? JSON.parse((task.attributes.payload as string) || "{}")
: {};
@@ -172,8 +171,14 @@ function convertPartial(
| "stage"
>),
id: parseInt(task.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ task.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ task.relationships!.updater.data,
+ includedList
+ ),
payload,
instance,
database,
diff --git a/frontend/src/store/modules/vcs.ts b/frontend/src/store/modules/vcs.ts
index 943d64d5fa..573838b813 100644
--- a/frontend/src/store/modules/vcs.ts
+++ b/frontend/src/store/modules/vcs.ts
@@ -4,8 +4,6 @@ import {
VCS,
VCSCreate,
VCSState,
- Principal,
- ResourceIdentifier,
ResourceObject,
unknown,
VCSPatch,
@@ -15,13 +13,17 @@ import {
import { getPrincipalFromIncludedList } from "./principal";
function convert(vcs: ResourceObject, includedList: ResourceObject[]): VCS {
- const creatorId = (vcs.relationships!.creator.data as ResourceIdentifier).id;
- const updaterId = (vcs.relationships!.updater.data as ResourceIdentifier).id;
return {
...(vcs.attributes as Omit<VCS, "id" | "creator" | "updater">),
id: parseInt(vcs.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ vcs.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ vcs.relationships!.updater.data,
+ includedList
+ ),
};
}
diff --git a/frontend/src/store/modules/view.ts b/frontend/src/store/modules/view.ts
index 7a7c3f1edf..ab98051dab 100644
--- a/frontend/src/store/modules/view.ts
+++ b/frontend/src/store/modules/view.ts
@@ -2,7 +2,6 @@ import axios from "axios";
import {
Database,
DatabaseId,
- Principal,
ResourceIdentifier,
ResourceObject,
unknown,
@@ -26,16 +25,21 @@ function convert(
break;
}
}
- const creatorId = (view.relationships!.creator.data as ResourceIdentifier).id;
- const updaterId = (view.relationships!.updater.data as ResourceIdentifier).id;
+
return {
...(view.attributes as Omit<
View,
"id" | "database" | "creator" | "updater"
>),
id: parseInt(view.id),
- creator: getPrincipalFromIncludedList(creatorId, includedList) as Principal,
- updater: getPrincipalFromIncludedList(updaterId, includedList) as Principal,
+ creator: getPrincipalFromIncludedList(
+ view.relationships!.creator.data,
+ includedList
+ ),
+ updater: getPrincipalFromIncludedList(
+ view.relationships!.updater.data,
+ includedList
+ ),
database,
};
}