Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Add admin toggle to edit user page #338

Merged
merged 1 commit into from
Dec 10, 2017

Conversation

wacii
Copy link
Contributor

@wacii wacii commented Dec 1, 2017

This adds the ability to promote/demote users to/from admin status. Admins can't demote themselves. Although they're not prevented from trying, only told after the fact that they can't with an error message.

Could use some input on design/where exactly you want this feature. I'm real bad at design.

* Take Admin priveleges away from User
*/
export const demote = async function(req, res) {
if (req.params.userId === req.user._id)

This comment was marked as off-topic.

This comment was marked as off-topic.

@jspaine
Copy link
Contributor

jspaine commented Dec 3, 2017

I'm not great at design either, but maybe it could be a checkbox in with the rest of the form?

@wacii
Copy link
Contributor Author

wacii commented Dec 4, 2017

The toggle is now a checkbox. Remember thinking earlier that it would be better to have the toggle separate from the edit user form, but I can't remember why, so it must not have been a very good reason.

This PR is now dependent on #341. Something I had to fix to get this to work.

@jspaine
Copy link
Contributor

jspaine commented Dec 4, 2017

Cool, it looks a bit weird with the label above and nothing next to the checkbox though, you can add text next to the checkbox with options={"the text"}.

It also complains user.save is not a function because in user profile update, user can just be an object not a mongoose model.

@wacii
Copy link
Contributor Author

wacii commented Dec 4, 2017

Oh right. .lean() returns a plain javascript object. My mistake.

I removed the label and put text next to the checkbox.


export const promoteUser = userId => ({
[CALL_API]: {
endpoint: `admin/users/${userId}/promote`,

This comment was marked as off-topic.

This comment was marked as off-topic.

@wacii
Copy link
Contributor Author

wacii commented Dec 5, 2017

I finished cleaning up the old routes.

@@ -50,6 +51,17 @@ export const update = async function(req, res) {
if (sameEmail && sameEmail._id !== req.user._id)
throw new BadRequestError('Email address is taken')

// Update admin status

This comment was marked as off-topic.

This comment was marked as off-topic.

This comment was marked as off-topic.

// Update admin status
if (includes(req.user, ADMIN_ROLE)) {
const alreadyAdmin = includes(user.roles, ADMIN_ROLE)
if (user.isAdmin && !alreadyAdmin) {

This comment was marked as off-topic.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants