From 97d281e14d27b9d75afcf61bd6812918fed10f47 Mon Sep 17 00:00:00 2001 From: Yousef Ahmed Date: Thu, 6 May 2021 23:53:13 -0500 Subject: [PATCH 1/3] Add memberID as editor when creating note by default --- api/src/api/notes.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/api/src/api/notes.js b/api/src/api/notes.js index c0b4f2c..313c4ea 100644 --- a/api/src/api/notes.js +++ b/api/src/api/notes.js @@ -105,10 +105,11 @@ router.post( '/', requireLead, errorWrap(async (req, res) => { + const memberID = req.user._id; const currentVersion = { date: Date.now(), action: Note.actions.CREATED, - memberID: req.user._id, + memberID, }; if (req.body.metaData.versionHistory) { req.body.metaData.versionHistory.push(currentVersion); @@ -116,6 +117,9 @@ router.post( req.body.metaData.versionHistory = [currentVersion]; } + // Automatically include the note creator as an editor + req.body.metaData.access.editableBy.push(memberID.toString()); + const note = await Note.create(req.body); res.status(200).json({ success: true, From df4418dcf43b538101a42330f552ee01c6ed80b0 Mon Sep 17 00:00:00 2001 From: Yousef Ahmed Date: Thu, 6 May 2021 23:53:37 -0500 Subject: [PATCH 2/3] Remove the current member from the dropdowns when creating a note --- client/src/App.js | 6 ++---- client/src/pages/Note.js | 27 +++++++++++++++++++-------- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/client/src/App.js b/client/src/App.js index a6b1710..c18140f 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -33,16 +33,14 @@ function App() { - + {user && } {user ? : } - - - + {user && } diff --git a/client/src/pages/Note.js b/client/src/pages/Note.js index fd11aff..42b7f3a 100644 --- a/client/src/pages/Note.js +++ b/client/src/pages/Note.js @@ -17,6 +17,7 @@ import { Message, } from 'semantic-ui-react'; import 'draft-js/dist/Draft.css'; +import PropTypes from 'prop-types'; import { useParams, Redirect } from 'react-router-dom'; import EditorToolbar from '../components/notes/EditorToolbar'; @@ -44,7 +45,7 @@ const NOTE_STATE = Object.freeze({ error: 'error', }); -function Note() { +const Note = ({ user }) => { // note state const [noteState, setNoteState] = useState(NOTE_STATE.loading); const [submitError, setSubmitError] = useState(false); @@ -115,12 +116,15 @@ function Note() { // get member data for dropdown reference const allMembers = await getMembers(); - // map allMembers into a dropdown-friendly interface - const cleanedMembers = (allMembers?.data?.result ?? []).map((m) => ({ - key: m._id, - text: `${m.firstName} ${m.lastName}`, - value: m._id, - })); + + // map allMembers into a dropdown-friendly interface and remove the current user from the list + const cleanedMembers = (allMembers?.data?.result ?? []) + .filter((m) => m._id !== user._id) + .map((m) => ({ + key: m._id, + text: `${m.firstName} ${m.lastName}`, + value: m._id, + })); setMembers(cleanedMembers); const resNoteLabels = await getNoteLabels(); @@ -344,6 +348,13 @@ function Note() { ); } -} +}; + +Note.propTypes = { + user: PropTypes.shape({ + _id: PropTypes.string.isRequired, + firstName: PropTypes.string, + }).isRequired, +}; export default Note; From 1bd20bb003ab729b28c6cb7969fce95c464b0a7f Mon Sep 17 00:00:00 2001 From: Yousef Ahmed Date: Fri, 7 May 2021 00:57:17 -0500 Subject: [PATCH 3/3] Remove outdated comment --- client/src/pages/Note.js | 1 - 1 file changed, 1 deletion(-) diff --git a/client/src/pages/Note.js b/client/src/pages/Note.js index 99eadda..ed60469 100644 --- a/client/src/pages/Note.js +++ b/client/src/pages/Note.js @@ -250,7 +250,6 @@ function Note({ user }) { labels: noteLabels, referencedMembers, access: { - // remove duplicate of current user id's on existing notes editableBy, viewableBy, },