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

#136 Adding Multiple Admin Roles #146

Open
wants to merge 21 commits into
base: main
Choose a base branch
from
Open

#136 Adding Multiple Admin Roles #146

wants to merge 21 commits into from

Conversation

DavidOB1
Copy link
Contributor

@DavidOB1 DavidOB1 commented Feb 18, 2025

Closes #136

  • Change data model to replace isAdmin boolean field with role field to handle multiple admin types
  • Change backend logic to compare user's role rather than just checking isAdmin field
  • Change front end logic to allow assigning different roles to users

jolinhuang224 and others added 6 commits February 21, 2025 01:13
spacing changes, updated headers, added first & last name areas [placeholders for now, need to update database]
layout, name, and interactivity update
Copy link
Contributor

@arath7 arath7 left a comment

Choose a reason for hiding this comment

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

hi guys, code and logic itself looks great and i tested locally! just left a few comments about thoughts I had + error handling i'd like your thoughts on. let's discuss those, resolve conflicts with main branch, and fix some of the lint warnings and this code should be good to go

const user = req.user as IUser;
if (user?.isAdmin) {
export const isSuperAdmin: RequestHandler = (req, res, next) => {
const user = req.user as IUser | undefined;
Copy link
Contributor

Choose a reason for hiding this comment

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

would there ever be an instance where a user is undefined? just trying to think of when that would be the case otherwise I think we might not need the undefined field or we'd need to do some better error handling to default an undefined user to a basic user to not run into any other general issues

Copy link
Contributor Author

@DavidOB1 DavidOB1 Feb 25, 2025

Choose a reason for hiding this comment

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

I think there's maybe a few edge cases (user is logged out and tries to go straight to admin page, session timeout, user is deleted while session is active) but ultimately the main idea of making it potentially undefined is so that we can use the .? selector on the next line, since that would otherwise cause a server-side error if it were actually undefined.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We talked about this and we're gonna make a landing page yuh

return next();
}

next(new HttpError(403, "Admin access only"));
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought: would it make sense to specify what type of admin access is needed here? Could help with error handling in the future. This goes for line 30 and 40 asw.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO

);

router.post(
"/battery",
isAdmin,
isStudyManager,
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn't a super admin also be able to do all of these things? How are we also accounting for super admin functionality in these endpoints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, the naming is kimnda confusing but we account for this in the actual middleware implementation

throw new HttpError(404);
}

// TODO this needa be figured out lol
Copy link
Contributor

Choose a reason for hiding this comment

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

commenting to add visibility that we need to tackle this

Copy link
Contributor Author

Choose a reason for hiding this comment

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

User admin can't demote super admin
Nobody can demote themselves (including super admin)


const router = useRouter();
const authStore = useAuthStore();
const batteryEditingStore = useBatteryEditingStore();

if (!authStore.currentUser?.isAdmin) {
// TODO: Should all admins be able to access this page?
Copy link
Contributor

Choose a reason for hiding this comment

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

not the task manager admin

Copy link
Contributor

Choose a reason for hiding this comment

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

but, you bring up a good point about maybe having a general admin page for all admins, something we should think about for an additional ticket

Copy link
Contributor Author

@DavidOB1 DavidOB1 Feb 25, 2025

Choose a reason for hiding this comment

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

Shouldn't this page be the one only study manager/super admin can access? It's the admin page regarding the existing studies and batteries. Regardless yea I think we should abstract the functionality here and make it easily customizable which roles can access what

}
};

// TODO: Should all admins be able to access this page?
Copy link
Contributor

Choose a reason for hiding this comment

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

commenting for visibility so we don't forget ab this question. rn, i'm thinking no: only super admin and user admin

@DavidOB1
Copy link
Contributor Author

TODO: We still gotta do super admin page after this ticket

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.

Backend: creating a user management admin
4 participants