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, diff --git a/client/src/App.js b/client/src/App.js index 8056346..d6881c8 100644 --- a/client/src/App.js +++ b/client/src/App.js @@ -35,16 +35,14 @@ function App() { - + {user && } {user ? : } - - - + {user && } diff --git a/client/src/pages/Note.js b/client/src/pages/Note.js index 7989e11..ed60469 100644 --- a/client/src/pages/Note.js +++ b/client/src/pages/Note.js @@ -7,7 +7,6 @@ import { convertToRaw, convertFromRaw, } from 'draft-js'; -import PropTypes from 'prop-types'; import { Button, Input, @@ -18,6 +17,7 @@ import { Message, } from 'semantic-ui-react'; import 'draft-js/dist/Draft.css'; +import PropTypes from 'prop-types'; import { useHistory, useParams, Redirect } from 'react-router-dom'; import EditorToolbar from '../components/notes/EditorToolbar'; @@ -167,12 +167,15 @@ function Note({ user }) { // 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(); @@ -247,9 +250,8 @@ function Note({ user }) { labels: noteLabels, referencedMembers, access: { - // remove duplicate of current user id's on existing notes - editableBy: [...new Set([...editableBy, user._id])], - viewableBy: [...new Set([...viewableBy, user._id])], + editableBy, + viewableBy, }, }, }, @@ -455,7 +457,10 @@ function Note({ user }) { } Note.propTypes = { - user: PropTypes.object, + user: PropTypes.shape({ + _id: PropTypes.string.isRequired, + firstName: PropTypes.string, + }).isRequired, }; export default Note;