From f3e3a9edf1689153c5ef185035c6d7c7520e1bbe Mon Sep 17 00:00:00 2001 From: Vladyslav Matsiiako Date: Mon, 26 Dec 2022 21:28:55 -0500 Subject: [PATCH] Added commenting functionality (#135) --- .../src/controllers/v1/secretController.ts | 4 + backend/src/helpers/secret.ts | 32 ++++++- backend/src/models/secret.ts | 20 +++++ frontend/components/basic/Toggle.tsx | 5 +- .../components/dashboard/CommentField.tsx | 16 ++++ frontend/components/dashboard/DropZone.tsx | 6 +- frontend/components/dashboard/SideBar.tsx | 18 ++-- .../utilities/secrets/getSecretsForProject.ts | 33 +++++-- .../components/utilities/secrets/pushKeys.ts | 14 +++ frontend/pages/dashboard/[id].tsx | 86 +++++++++++-------- 10 files changed, 172 insertions(+), 62 deletions(-) create mode 100644 frontend/components/dashboard/CommentField.tsx diff --git a/backend/src/controllers/v1/secretController.ts b/backend/src/controllers/v1/secretController.ts index bac9ea572..5d4b4da73 100644 --- a/backend/src/controllers/v1/secretController.ts +++ b/backend/src/controllers/v1/secretController.ts @@ -21,6 +21,10 @@ interface PushSecret { ivValue: string; tagValue: string; hashValue: string; + ciphertextComment: string; + ivComment: string; + tagComment: string; + hashComment: string; type: 'shared' | 'personal'; } diff --git a/backend/src/helpers/secret.ts b/backend/src/helpers/secret.ts index 4b3585c40..0e3d82749 100644 --- a/backend/src/helpers/secret.ts +++ b/backend/src/helpers/secret.ts @@ -25,6 +25,10 @@ interface PushSecret { ivValue: string; tagValue: string; hashValue: string; + ciphertextComment: string; + ivComment: string; + tagComment: string; + hashComment: string; type: 'shared' | 'personal'; } @@ -93,7 +97,8 @@ const pushSecrets = async ({ const toUpdate = oldSecrets .filter((s) => { if (`${s.type}-${s.secretKeyHash}` in newSecretsObj) { - if (s.secretValueHash !== newSecretsObj[`${s.type}-${s.secretKeyHash}`].hashValue) { + if (s.secretValueHash !== newSecretsObj[`${s.type}-${s.secretKeyHash}`].hashValue + || s.secretCommentHash !== newSecretsObj[`${s.type}-${s.secretKeyHash}`].hashComment) { // case: filter secrets where value changed return true; } @@ -113,14 +118,22 @@ const pushSecrets = async ({ ciphertextValue, ivValue, tagValue, - hashValue + hashValue, + ciphertextComment, + ivComment, + tagComment, + hashComment } = newSecretsObj[`${s.type}-${s.secretKeyHash}`]; const update: Update = { secretValueCiphertext: ciphertextValue, secretValueIV: ivValue, secretValueTag: tagValue, - secretValueHash: hashValue + secretValueHash: hashValue, + secretCommentCiphertext: ciphertextComment, + secretCommentIV: ivComment, + secretCommentTag: tagComment, + secretCommentHash: hashComment, } if (!s.version) { @@ -192,7 +205,11 @@ const pushSecrets = async ({ secretValueCiphertext: s.ciphertextValue, secretValueIV: s.ivValue, secretValueTag: s.tagValue, - secretValueHash: s.hashValue + secretValueHash: s.hashValue, + secretCommentCiphertext: s.ciphertextComment, + secretCommentIV: s.ivComment, + secretCommentTag: s.tagComment, + secretCommentHash: s.hashComment }; if (toAdd[idx].type === 'personal') { @@ -315,6 +332,13 @@ const reformatPullSecrets = ({ secrets }: { secrets: ISecret[] }) => { iv: s.secretValueIV, tag: s.secretValueTag, hash: s.secretValueHash + }, + secretComment: { + workspace: s.workspace, + ciphertext: s.secretCommentCiphertext, + iv: s.secretCommentIV, + tag: s.secretCommentTag, + hash: s.secretCommentHash } })); } catch (err) { diff --git a/backend/src/models/secret.ts b/backend/src/models/secret.ts index d34139ecb..d36e32b91 100644 --- a/backend/src/models/secret.ts +++ b/backend/src/models/secret.ts @@ -23,6 +23,10 @@ export interface ISecret { secretValueIV: string; secretValueTag: string; secretValueHash: string; + secretCommentCiphertext?: string; + secretCommentIV?: string; + secretCommentTag?: string; + secretCommentHash?: string; } const secretSchema = new Schema( @@ -82,6 +86,22 @@ const secretSchema = new Schema( secretValueHash: { type: String, required: true + }, + secretCommentCiphertext: { + type: String, + required: false + }, + secretCommentIV: { + type: String, // symmetric + required: false + }, + secretCommentTag: { + type: String, // symmetric + required: false + }, + secretCommentHash: { + type: String, + required: false } }, { diff --git a/frontend/components/basic/Toggle.tsx b/frontend/components/basic/Toggle.tsx index fa69e4419..70e32426e 100644 --- a/frontend/components/basic/Toggle.tsx +++ b/frontend/components/basic/Toggle.tsx @@ -7,6 +7,7 @@ interface OverrideProps { keyName: string; value: string; pos: number; + comment: string; } interface ToggleProps { @@ -17,6 +18,7 @@ interface ToggleProps { value: string; pos: number; id: string; + comment: string; deleteOverride: (id: string) => void; sharedToHide: string[]; setSharedToHide: (values: string[]) => void; @@ -46,6 +48,7 @@ export default function Toggle ({ value, pos, id, + comment, deleteOverride, sharedToHide, setSharedToHide @@ -55,7 +58,7 @@ export default function Toggle ({ checked={enabled} onChange={() => { if (enabled == false) { - addOverride({ id, keyName, value, pos }); + addOverride({ id, keyName, value, pos, comment }); setSharedToHide([ ...sharedToHide!, id diff --git a/frontend/components/dashboard/CommentField.tsx b/frontend/components/dashboard/CommentField.tsx new file mode 100644 index 000000000..35f524a69 --- /dev/null +++ b/frontend/components/dashboard/CommentField.tsx @@ -0,0 +1,16 @@ +/** + * This is the text field where people can add comments to particular secrets. + */ +const CommentField = ({ comment, modifyComment, position }: { comment: string; modifyComment: (value: string, posistion: number) => void; position: number;}) => { + return
+

Comments & notes

+