freeCodeCamp / pantry-for-good

An open source food bank logistics and inventory management tool
Other
395 stars 189 forks source link

Add admin toggle to edit user page #338

Closed wacii closed 6 years ago

wacii commented 6 years ago

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.

jspaine commented 6 years ago

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

wacii commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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

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

wacii commented 6 years ago

I finished cleaning up the old routes.