Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Edit user default privileges for notes #80

Merged
merged 4 commits into from
May 7, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion api/src/api/notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,17 +105,21 @@ 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);
} else {
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,
Expand Down
6 changes: 2 additions & 4 deletions client/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ function App() {
<Route path={Routes.MEMBER_PAGE}>
<Switch>
<Route path={Routes.NOTE_PAGE}>
<Note user={user} />
{user && <Note user={user} />}
</Route>
<Route DEFAULT>
{user ? <Profile /> : <Redirect to={Routes.LOGIN_PAGE} />}
</Route>
</Switch>
</Route>
<Route path={Routes.NOTE_PAGE}>
<Note user={user} />
</Route>
<Route path={Routes.NOTE_PAGE}>{user && <Note user={user} />}</Route>
<Route path={Routes.NOTES}>
<Notes />
</Route>
Expand Down
26 changes: 16 additions & 10 deletions client/src/pages/Note.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import {
convertToRaw,
convertFromRaw,
} from 'draft-js';
import PropTypes from 'prop-types';
import {
Button,
Input,
Expand All @@ -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';
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -248,8 +251,8 @@ function Note({ user }) {
referencedMembers,
access: {
// remove duplicate of current user id's on existing notes
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is now outdated

editableBy: [...new Set([...editableBy, user._id])],
viewableBy: [...new Set([...viewableBy, user._id])],
editableBy,
viewableBy,
},
},
},
Expand Down Expand Up @@ -455,7 +458,10 @@ function Note({ user }) {
}

Note.propTypes = {
user: PropTypes.object,
user: PropTypes.shape({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this! I should've been more scrupulous with PropTypes

_id: PropTypes.string.isRequired,
firstName: PropTypes.string,
}).isRequired,
};

export default Note;