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

Admin feature fixes, new admin privilege manager #448

Merged
merged 43 commits into from
May 7, 2024

Conversation

qiandrewj
Copy link
Contributor

Summary

This PR works on the Admin page feature, fixing old bugs and adding the ability to manage admin users by net-id.

PR Type

  • πŸ• Feature
  • πŸ› Bug Fix
  • πŸ“ Documentation Update
  • 🎨 Style
  • πŸ§‘β€πŸ’» Code Refactor
  • πŸ”₯ Performance Improvements
  • βœ… Test
  • πŸ€– Build
  • πŸ” CI
  • πŸ“¦ Chore (Release)
  • ⏩ Revert

Mobile + Desktop Screenshots & Recordings

Screenshot 2024-05-05 195112
Screenshot 2024-05-05 195151

QA - Test Plan

  • Tested all endpoints through rendering on front-end.
  • Tested admin management modal by removing Jacqueline's admin privilege. She was then unable to access admin features. After re-adding her as an admin user, she then had access to the admin site.

Breaking Changes & Notes

  • Moved stats rendering (counting reviews, writing to CSV file) to backend. Split up endpoints in order to improve performance.
  • Minor styling changes to whole Admin page.
  • Updated old class components to functional components.
  • Developed admin privilege interface.

Added to documentation?

  • πŸ“œ README.md
  • πŸ““ notion
  • πŸ“• Method specifications
  • πŸ™… no documentation needed

…ending/reported - length feature implemented too
@qiandrewj qiandrewj requested a review from a team as a code owner May 6, 2024 00:16
@qiandrewj qiandrewj changed the title Andrew/admin fixes Admin feature fixes, new admin privilege manager May 6, 2024
Copy link
Contributor

@jacquelinecai jacquelinecai left a comment

Choose a reason for hiding this comment

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

Great job with the admin page, Andrew! This interface will better support our internal processes as we manage admins and parse through reviews. I've left a couple comments related to the testing I did, but you are progressing really well with this task!

if (response.status === 200) {
setAdmins(result)
} else {
console.log('Error at getAdmins')
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally shouldn't be printing to console in the frontend

* @param _netId the user's net id
*/

function addAdminByNetId(_netId: string) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great work with this new feature! It'll help us better manage admin access semester-to-semester. I've left a couple comments with things I noticed while testing.

Currently, adding the admin by netid doesn't automatically update the frontend - perhaps use useEffect()? I think the remove function also doesn't automatically update.

Also, it'd be nice to attach the admin's full name before the netid (should just be a quick query to the name in the database)

I'm not sure if this is feasible, but restricting who can manage the admins would be great (maybe just permissions for TPM). Along with this, making sure that the admin manager shouldn't be able to remove themselves or add duplicates of other members on the team will help prevent "lockouts" and access issues.

<AdminUser
user={admin}
token={token}
removeHandler={removeAdmin}
Copy link
Contributor

Choose a reason for hiding this comment

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

For the admin manager, perhaps don't show the remove handle so that they don't accidentally remove themselves

<h2>Diagnostic information</h2>
<div className = {styles.stats}>
<button className={styles.downloadButton} onClick={downloadCSVFile}>
Download ApprovedReviewCount by Class
Copy link
Contributor

Choose a reason for hiding this comment

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

I would make this a link (like this) to make it clearer that a file can be downloaded from this text.

Comment on lines +180 to +185
/**
* Gets CSV text string of all reviews that are approved, sorted by class.
*
* @param {Auth} auth: Object that represents the authentication of a request being passed in.
* @returns CSV text if operation was successful, null otherwise
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

Love all the detailed documentation you added in this file!

Comment on lines +134 to +155
/*
* If there is an attempt to grant admin privilege to someone not in the database,
* a new user will be created with the given netid and added to the database.
*/

export const createNewAdminUser = async (id: string) => {

const admin: InsertStudentType = {
_id: shortid.generate(),
firstName: '',
lastName: '',
netId: id,
affiliation: '',
token: '',
privilege: 'admin',
};

const newAdmin = new Students(admin);
const res = await newAdmin.save();

return res
}
Copy link
Contributor

Choose a reason for hiding this comment

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

There should probably be some "security measure" here so that we don't accidentally add a random member as admin. I'm wondering if there's a way to cross-check with like a CUReviews roster automatically.

removePendingReview,
updateAllProfessorsDb,
resetAllProfessorsDb,
initAllDb,
addNewSemDb,
verifyTokenAdmin,
reportReview,
getAdminUsers,
removeAdmin,
addOrUpdateAdmin,
} from './admin.controller';

export const adminRouter = express.Router();
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would make it easier on the backend if all these routers were prepended by /admin. Like for getting reviews, that seems like it could belong to the display reviews page, but adding the admin route would help clarify that (and differentiate it from the user-facing reviews).

Copy link
Collaborator

@wizhaaa wizhaaa left a comment

Choose a reason for hiding this comment

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

Awesome work Andrew!!! Glad we managed to get a lot of the major functionality of the Admin page working so far.

For other issues, we will move other issues to another PR through in the future though!

Note: discussed most issues in person and worked through updating code

@dti-github-bot
Copy link
Member

dti-github-bot commented May 7, 2024

[diff-counting] Significant lines: 1150. This diff might be too big! Developer leads are invited to review the code.

@qiandrewj qiandrewj merged commit d03e687 into master May 7, 2024
4 checks passed
@qiandrewj qiandrewj deleted the andrew/admin-fixes branch May 7, 2024 17:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants