Fix linter and type issues, made a small fix for secret rotation platform events

This commit is contained in:
carlosmonastyrski
2025-03-06 09:10:13 -03:00
parent cd5b6da541
commit 30bcf1f204
9 changed files with 91 additions and 34 deletions
@@ -39,6 +39,7 @@ import {
secretRotationPreSetFn secretRotationPreSetFn
} from "./secret-rotation-queue-fn"; } from "./secret-rotation-queue-fn";
import { TSecretRotationData, TSecretRotationDbFn, TSecretRotationEncData } from "./secret-rotation-queue-types"; import { TSecretRotationData, TSecretRotationDbFn, TSecretRotationEncData } from "./secret-rotation-queue-types";
import { ActorType } from "@app/services/auth/auth-type";
export type TSecretRotationQueueFactory = ReturnType<typeof secretRotationQueueFactory>; export type TSecretRotationQueueFactory = ReturnType<typeof secretRotationQueueFactory>;
@@ -332,6 +333,7 @@ export const secretRotationQueueFactory = ({
await secretVersionV2BridgeDAL.insertMany( await secretVersionV2BridgeDAL.insertMany(
updatedSecrets.map(({ id, updatedAt, createdAt, ...el }) => ({ updatedSecrets.map(({ id, updatedAt, createdAt, ...el }) => ({
...el, ...el,
actorType: ActorType.PLATFORM,
secretId: id secretId: id
})), })),
tx tx
@@ -34,6 +34,7 @@ import { TSnapshotFolderDALFactory } from "./snapshot-folder-dal";
import { TSnapshotSecretDALFactory } from "./snapshot-secret-dal"; import { TSnapshotSecretDALFactory } from "./snapshot-secret-dal";
import { TSnapshotSecretV2DALFactory } from "./snapshot-secret-v2-dal"; import { TSnapshotSecretV2DALFactory } from "./snapshot-secret-v2-dal";
import { getFullFolderPath } from "./snapshot-service-fns"; import { getFullFolderPath } from "./snapshot-service-fns";
import { ActorType } from "@app/services/auth/auth-type";
type TSecretSnapshotServiceFactoryDep = { type TSecretSnapshotServiceFactoryDep = {
snapshotDAL: TSnapshotDALFactory; snapshotDAL: TSnapshotDALFactory;
@@ -414,8 +415,18 @@ export const secretSnapshotServiceFactory = ({
})), })),
tx tx
); );
const userActorId = actor === ActorType.USER ? actorId : undefined;
const identityActorId = actor !== ActorType.USER ? actorId : undefined;
const actorType = actor || ActorType.PLATFORM;
const secretVersions = await secretVersionV2BridgeDAL.insertMany( const secretVersions = await secretVersionV2BridgeDAL.insertMany(
secrets.map(({ id, updatedAt, createdAt, ...el }) => ({ ...el, secretId: id })), secrets.map(({ id, updatedAt, createdAt, ...el }) => ({
...el,
secretId: id,
userActorId,
identityActorId,
actorType
})),
tx tx
); );
await secretVersionV2TagBridgeDAL.insertMany( await secretVersionV2TagBridgeDAL.insertMany(
@@ -114,8 +114,8 @@ export const secretRawSchema = z.object({
updatedAt: z.date(), updatedAt: z.date(),
actor: z actor: z
.object({ .object({
actorId: z.string().nullable(), actorId: z.string().nullable().optional(),
actorType: z.string().nullable(), actorType: z.string().nullable().optional(),
name: z.string().nullable().optional() name: z.string().nullable().optional()
}) })
.optional() .optional()
@@ -94,6 +94,7 @@ export const fnSecretBulkInsert = async ({
const userActorId = actor && actor.type === ActorType.USER ? actor.actorId : undefined; const userActorId = actor && actor.type === ActorType.USER ? actor.actorId : undefined;
const identityActorId = actor && actor.type !== ActorType.USER ? actor.actorId : undefined; const identityActorId = actor && actor.type !== ActorType.USER ? actor.actorId : undefined;
const actorType = actor?.type || ActorType.PLATFORM;
const newSecrets = await secretDAL.insertMany( const newSecrets = await secretDAL.insertMany(
sanitizedInputSecrets.map((el) => ({ ...el, folderId })), sanitizedInputSecrets.map((el) => ({ ...el, folderId })),
@@ -113,7 +114,7 @@ export const fnSecretBulkInsert = async ({
folderId, folderId,
userActorId, userActorId,
identityActorId, identityActorId,
actorType: actor?.type, actorType,
secretId: newSecretGroupedByKeyName[el.key][0].id secretId: newSecretGroupedByKeyName[el.key][0].id
})), })),
tx tx
@@ -170,6 +171,7 @@ export const fnSecretBulkUpdate = async ({
}: TFnSecretBulkUpdate) => { }: TFnSecretBulkUpdate) => {
const userActorId = actor && actor?.type === ActorType.USER ? actor?.actorId : undefined; const userActorId = actor && actor?.type === ActorType.USER ? actor?.actorId : undefined;
const identityActorId = actor && actor?.type !== ActorType.USER ? actor?.actorId : undefined; const identityActorId = actor && actor?.type !== ActorType.USER ? actor?.actorId : undefined;
const actorType = actor?.type || ActorType.PLATFORM;
const sanitizedInputSecrets = inputSecrets.map( const sanitizedInputSecrets = inputSecrets.map(
({ ({
@@ -231,7 +233,7 @@ export const fnSecretBulkUpdate = async ({
secretId, secretId,
userActorId, userActorId,
identityActorId, identityActorId,
actorType: actor?.type actorType
}) })
), ),
tx tx
+18 -1
View File
@@ -525,6 +525,7 @@ export const fnSecretBulkInsert = async ({
secretVersionDAL, secretVersionDAL,
secretTagDAL, secretTagDAL,
secretVersionTagDAL, secretVersionTagDAL,
actor,
tx tx
}: TFnSecretBulkInsert) => { }: TFnSecretBulkInsert) => {
const sanitizedInputSecrets = inputSecrets.map( const sanitizedInputSecrets = inputSecrets.map(
@@ -579,9 +580,17 @@ export const fnSecretBulkInsert = async ({
[`${TableName.Secret}Id` as const]: newSecretGroupByBlindIndex[secretBlindIndex as string][0].id [`${TableName.Secret}Id` as const]: newSecretGroupByBlindIndex[secretBlindIndex as string][0].id
})) }))
); );
const userActorId = actor && actor?.type === ActorType.USER ? actor?.actorId : undefined;
const identityActorId = actor && actor?.type !== ActorType.USER ? actor?.actorId : undefined;
const actorType = actor?.type || ActorType.PLATFORM;
const secretVersions = await secretVersionDAL.insertMany( const secretVersions = await secretVersionDAL.insertMany(
sanitizedInputSecrets.map((el) => ({ sanitizedInputSecrets.map((el) => ({
...el, ...el,
userActorId,
identityActorId,
actorType,
secretId: newSecretGroupByBlindIndex[el.secretBlindIndex as string][0].id secretId: newSecretGroupByBlindIndex[el.secretBlindIndex as string][0].id
})), })),
tx tx
@@ -614,7 +623,8 @@ export const fnSecretBulkUpdate = async ({
secretDAL, secretDAL,
secretVersionDAL, secretVersionDAL,
secretTagDAL, secretTagDAL,
secretVersionTagDAL secretVersionTagDAL,
actor
}: TFnSecretBulkUpdate) => { }: TFnSecretBulkUpdate) => {
const sanitizedInputSecrets = inputSecrets.map( const sanitizedInputSecrets = inputSecrets.map(
({ ({
@@ -664,10 +674,17 @@ export const fnSecretBulkUpdate = async ({
}) })
); );
const userActorId = actor && actor?.type === ActorType.USER ? actor?.actorId : undefined;
const identityActorId = actor && actor?.type !== ActorType.USER ? actor?.actorId : undefined;
const actorType = actor?.type || ActorType.PLATFORM;
const newSecrets = await secretDAL.bulkUpdate(sanitizedInputSecrets, tx); const newSecrets = await secretDAL.bulkUpdate(sanitizedInputSecrets, tx);
const secretVersions = await secretVersionDAL.insertMany( const secretVersions = await secretVersionDAL.insertMany(
newSecrets.map(({ id, createdAt, updatedAt, ...el }) => ({ newSecrets.map(({ id, createdAt, updatedAt, ...el }) => ({
...el, ...el,
userActorId,
identityActorId,
actorType,
secretId: id secretId: id
})), })),
tx tx
+2 -2
View File
@@ -324,7 +324,7 @@ export type TFnSecretBulkInsert = {
secretVersionTagDAL: Pick<TSecretVersionTagDALFactory, "insertMany">; secretVersionTagDAL: Pick<TSecretVersionTagDALFactory, "insertMany">;
actor?: { actor?: {
type?: string; type?: string;
actorId: string; actorId?: string;
}; };
}; };
@@ -342,7 +342,7 @@ export type TFnSecretBulkUpdate = {
tx?: Knex; tx?: Knex;
actor?: { actor?: {
type?: string; type?: string;
actorId: string; actorId?: string;
}; };
}; };
+4 -4
View File
@@ -102,10 +102,10 @@ export type SecretVersions = {
createdAt: string; createdAt: string;
updatedAt: string; updatedAt: string;
actor?: { actor?: {
actorId?: string, actorId?: string | null;
actorType: string, actorType?: string | null;
name?: string name?: string | null;
}; } | null;
}; };
// dto // dto
@@ -48,12 +48,11 @@ import {
useWorkspace useWorkspace
} from "@app/context"; } from "@app/context";
import { usePopUp, useToggle } from "@app/hooks"; import { usePopUp, useToggle } from "@app/hooks";
import { useGetSecretVersion } from "@app/hooks/api"; import { useGetSecretVersion, useGetWorkspaceUsers } from "@app/hooks/api";
import { useGetSecretAccessList } from "@app/hooks/api/secrets/queries"; import { useGetSecretAccessList } from "@app/hooks/api/secrets/queries";
import { SecretV3RawSanitized, WsTag } from "@app/hooks/api/types"; import { SecretV3RawSanitized, WsTag } from "@app/hooks/api/types";
import { ProjectType } from "@app/hooks/api/workspace/types"; import { ProjectType } from "@app/hooks/api/workspace/types";
import { ActorType } from "@app/hooks/api/auditLogs/enums"; import { ActorType } from "@app/hooks/api/auditLogs/enums";
import { useGetWorkspaceUsers } from "@app/hooks/api";
import { CreateReminderForm } from "./CreateReminderForm"; import { CreateReminderForm } from "./CreateReminderForm";
import { formSchema, SecretActionType, TFormSchema } from "./SecretListView.utils"; import { formSchema, SecretActionType, TFormSchema } from "./SecretListView.utils";
@@ -199,9 +198,16 @@ export const SecretDetailSidebar = ({
await onSaveSecret(secret, { ...secret, ...data }, () => reset()); await onSaveSecret(secret, { ...secret, ...data }, () => reset());
}; };
const handleReminderSubmit = async (reminderRepeatDays: number | null | undefined, reminderNote: string | null | undefined) => { const handleReminderSubmit = async (
await onSaveSecret(secret, { ...secret, reminderRepeatDays, reminderNote, isReminderEvent: true }, () => { }); reminderRepeatDays: number | null | undefined,
} reminderNote: string | null | undefined
) => {
await onSaveSecret(
secret,
{ ...secret, reminderRepeatDays, reminderNote, isReminderEvent: true },
() => {}
);
};
const [createReminderFormOpen, setCreateReminderFormOpen] = useToggle(false); const [createReminderFormOpen, setCreateReminderFormOpen] = useToggle(false);
@@ -217,14 +223,23 @@ export const SecretDetailSidebar = ({
default: default:
return faServer; return faServer;
} }
} };
const getModifiedByName = (userType: string, userName: string | undefined) => {
switch (userType) {
case ActorType.PLATFORM:
return "System-generated";
default:
return userName;
}
};
const getUserMembershipId = (actorId: string) => { const getUserMembershipId = (actorId: string) => {
return members.filter((member) => member.user?.id === actorId)?.[0].id || null; return members.filter((member) => member.user?.id === actorId)?.[0].id || null;
} };
const getLinkToModifyHistoryEntity = (actorId: string, actorType: string) => { const getLinkToModifyHistoryEntity = (actorId: string, actorType: string) => {
switch(actorType) { switch (actorType) {
case ActorType.USER: case ActorType.USER:
return `/${ProjectType.SecretManager}/${currentWorkspace.id}/members/${getUserMembershipId(actorId)}`; return `/${ProjectType.SecretManager}/${currentWorkspace.id}/members/${getUserMembershipId(actorId)}`;
case ActorType.IDENTITY: case ActorType.IDENTITY:
@@ -232,7 +247,7 @@ export const SecretDetailSidebar = ({
default: default:
return null; return null;
} }
} };
const onModifyHistoryClick = (actorId: string | undefined, actorType: string) => { const onModifyHistoryClick = (actorId: string | undefined, actorType: string) => {
if (actorId && actorType !== ActorType.PLATFORM) { if (actorId && actorType !== ActorType.PLATFORM) {
@@ -241,7 +256,7 @@ export const SecretDetailSidebar = ({
navigate({ to: redirectLink }); navigate({ to: redirectLink });
} }
} }
} };
return ( return (
<> <>
@@ -255,7 +270,7 @@ export const SecretDetailSidebar = ({
if (data) { if (data) {
setValue("reminderRepeatDays", data.days, { shouldDirty: false }); setValue("reminderRepeatDays", data.days, { shouldDirty: false });
setValue("reminderNote", data.note, { shouldDirty: false }); setValue("reminderNote", data.note, { shouldDirty: false });
handleReminderSubmit(data.days, data.note) handleReminderSubmit(data.days, data.note);
} }
}} }}
/> />
@@ -675,15 +690,23 @@ export const SecretDetailSidebar = ({
<div className="relative w-10"> <div className="relative w-10">
<div className="absolute bottom-0 left-3 top-0 mt-0.5 border-l border-mineshaft-400/60" /> <div className="absolute bottom-0 left-3 top-0 mt-0.5 border-l border-mineshaft-400/60" />
</div> </div>
<div className="flex flex-col w-full cursor-default"> <div className="flex w-full cursor-default flex-col">
{actor && ( {actor && (
<div className="flex flex-row"> <div className="flex flex-row">
<div className="flex flex-row w-fit text-sm"> <div className="flex w-fit flex-row text-sm">
Modified by: Modified by:
<Tooltip content={actor.name}> <Tooltip content={getModifiedByName(actor.actorType, actor.name)}>
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */} {/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
<div onClick={() => onModifyHistoryClick(actor.actorId, actor.actorType)} className="cursor-pointer"> <div
<FontAwesomeIcon icon={getModifiedByIcon(actor.actorType)} className="ml-2"/> onClick={() =>
onModifyHistoryClick(actor.actorId, actor.actorType)
}
className="cursor-pointer"
>
<FontAwesomeIcon
icon={getModifiedByIcon(actor.actorType)}
className="ml-2"
/>
</div> </div>
</Tooltip> </Tooltip>
</div> </div>
@@ -697,7 +720,7 @@ export const SecretDetailSidebar = ({
<div className="relative hidden cursor-pointer transition-all duration-200 group-[.show-value]:inline"> <div className="relative hidden cursor-pointer transition-all duration-200 group-[.show-value]:inline">
<button <button
type="button" type="button"
className="select-none" className="select-none text-left"
onClick={(e) => { onClick={(e) => {
navigator.clipboard.writeText(secretValue || ""); navigator.clipboard.writeText(secretValue || "");
const target = e.currentTarget; const target = e.currentTarget;
@@ -241,7 +241,9 @@ export const SecretListView = ({
let successMessage; let successMessage;
if (isReminderEvent) { if (isReminderEvent) {
successMessage = reminderRepeatDays ? "Successfully saved secret reminder" : "Successfully deleted secret reminder"; successMessage = reminderRepeatDays
? "Successfully saved secret reminder"
: "Successfully deleted secret reminder";
} else { } else {
successMessage = "Successfully saved secrets"; successMessage = "Successfully saved secrets";
} }