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

Fix Super Admin User Login issue #1802

Open
4 tasks
Tracked by #1737
JackHaeg opened this issue Oct 22, 2024 · 7 comments
Open
4 tasks
Tracked by #1737

Fix Super Admin User Login issue #1802

JackHaeg opened this issue Oct 22, 2024 · 7 comments
Assignees
Labels
Bug feature: Login p-feature: User Permissions Feature includes how user access levels / user permissions will be implemented in the product role: Back End size: 2pt Can be done in 7-12 hours time-sensitive should be solved as soon as possible

Comments

@JackHaeg
Copy link
Member

JackHaeg commented Oct 22, 2024

Overview

After implementing the Super Admin User feature in #1747, we identified a bug where the Super Admin User ([email protected]) is unable to log in to VRMS. This issue tracks the fix for this bug.

Past Research

Bug summary from Jack Haeger_2024-10-17

Trillium merged the Super User PR, rebuilt Dev, and edited the DB to make [email protected] a super user.

The good news is that almost everything is working as expected (the user screen is grayed out and no other admin users can edit this user).

The bad news is that we cannot log in with this user to dev.vrms.io:

  • When we go to log in with that user ([email protected]) we are unable to log in and we receive the error message “We don’t recognize your email address. Please, create an account.”
  • I can confirm that this account already existed due to the fact that 1) the account shows up in dev.VRMS.io, and 2) the account’s email inbox received VRMS magic links to log in to the dev.vrms.io website on September 16, so it clearly existed and was logging in appropriately.
  • Also, this email address logs in as expected on PROD.
    Screenshot 2024-10-17 at 3 24 47 PM (1)

Nikhil's research_2024-10-22

The checkAuth Method has authOrigin Set to LOG_IN
image (3)

It fetches SIGN_IN
image (4)

Which is exposed by this route
image (5)

That router works in this way
and it checks for a method called verifyUser.isAdminByEmai
image (6)

And voila
image (7)

if (role === 'admin' || user.managedProjects.length > 0)
It is allowing either "admin"
or someone who has managedProjects.length>0

Now if we look at the super user
Neither are they "admin" and their "managedProjects" empty
So they are not able to log in
image (8)

But when you see Trillium's profile, Jack Haeger told me that when converting Trillium to super-user, he was still able to log in because the managedProjects list is not empty!
image (9)

Action Items

  • Implement Nikhil's proposed fix below:
change user.middleware.js to
const { User } = require('../models');
function checkDuplicateEmail(req, res, next) {
  User.findOne({ email: req.body.email }).then((user) => {
    if (user) {
      return res.sendStatus(400);
    }
    next();
  });
}
function isAdminByEmail(req, res, next) {
  User.findOne({ email: req.body.email }).then((user) => {
    if (!user) {
      return res.sendStatus(400);
    } else {
      const role = user.accessLevel;
      if (role === 'admin' || role ==='superadmin' ||  user.managedProjects.length > 0) {
        next();
      } else {
        next(res.sendStatus(401));
      }
    }
  });
}
const verifyUser = {
  checkDuplicateEmail,
  isAdminByEmail,
};
module.exports = verifyUser;
  • Test if fix is successful by logging into Dev with [email protected]
    • If fix worked, the "Success" message will be displayed and a VRMS Login link will be sent to the inbox of [email protected]
    • If fix fails, the error message will be displayed under the email name: "We don't recognize your email address. Please, create an account."
"Success" Screenshot

Screenshot 2024-10-22 at 1 34 16 PM

Error message screenshot

Screenshot 2024-10-17 at 3 24 47 PM (1)

Resources/Instructions

@github-project-automation github-project-automation bot moved this to New Issue Approval in P: VRMS: Project Board Oct 22, 2024
@JackHaeg JackHaeg added role: Back End feature: Login size: 2pt Can be done in 7-12 hours p-feature: User Permissions Feature includes how user access levels / user permissions will be implemented in the product labels Oct 22, 2024
@JackHaeg JackHaeg added Bug time-sensitive should be solved as soon as possible labels Oct 22, 2024
@JackHaeg JackHaeg moved this from New Issue Approval to In progress in P: VRMS: Project Board Oct 22, 2024
@JackHaeg JackHaeg assigned ntrehan and JackHaeg and unassigned JackHaeg Oct 22, 2024
@ntrehan
Copy link
Member

ntrehan commented Oct 23, 2024

@JackHaeg
The good news is that I was indeed able to sign in with the super user with the changes
So I was on the right track

But we have another big problem
image
The entire application runs as if the super user is a "USER"

This is happening because as I checked, a lot of parts of VRMS are only visible to users that have accessLevel = "ADMIN", for example user edit screen, event creation etc.

We have two options, I would like to know your opinions @trillium @jbubar @bkmorgan3

  1. Scan the entire code base and wherever anything is allowed for Admin, should also be allowed for superadmin
  2. Keep accessLevel of the superuser to be "admin", and add a totally separate boolean "isSuperAdmin" in the mongoDB users collection. That way the super user is both admin and super admin. This approach is much simpler and will need less refactoring

@JackHaeg
Copy link
Member Author

JackHaeg commented Oct 29, 2024

@trillium Please provide next steps for Nikhil as discussed on call (while considering delivery timeline of 2-3 weeks)

@trillium
Copy link
Member

trillium commented Nov 5, 2024

I'd prefer us to create an isAdmin() function that takes in the user's access level and returns whathe app currently expects eg:

function isAdmin(user) { 
    user.accessLevel('admin' || 'superadmin') {
        return true
    }
    return false
}

and then swap that function in where the comparisons are added for " === 'admin' " is requested in the app

@JackHaeg
Copy link
Member Author

@ntrehan Just checking in on this issue:

  • Does the feedback from @trillium make sense / do you have any additional questions?
  • Can you please provide an update on your progress on this issue?
    1. Progress: "What is the current status of your project? What have you completed and what is left to do?"
    2. Blockers: "Difficulties or errors encountered."
    3. Availability: "How much time will you have this week to work on this issue?"
    4. ETA: "When do you expect this issue to be completed?"
    5. Pictures or links* (if necessary): "Add any pictures or links that will help illustrate what you are working on."
      - remember to add links to the top of the issue if they are going to be needed again.

@trillium
Copy link
Member

trillium commented Nov 19, 2024

FYI - tested logging in on Dev with an account that includes symbols (+ and -), and was unable to log in. However, if your build is allowing emails with symbols to log in, you can ignore the following screenshots.

image image

@trillium
Copy link
Member

Hey all, I'd like us to use a different boolean check for admin status, let's do:

image

Checking if the access level string contains the word "admin" will return true for both admin and superadmin

@trillium
Copy link
Member

trillium commented Nov 21, 2024

// change user.middleware.js to

const { User } = require('../models');
function checkDuplicateEmail(req, res, next) {
  User.findOne({ email: req.body.email }).then((user) => {
    if (user) {
      return res.sendStatus(400);
    }
    next();
  });
}
function isAdminByEmail(req, res, next) {
  User.findOne({ email: req.body.email }).then((user) => {
    if (!user) {
      return res.sendStatus(400);
    } else {
      const role = user.accessLevel;
      if (role.includes('admin') ||  user.managedProjects.length > 0) { // changes added here with .includes()
        next();
      } else {
        next(res.sendStatus(401));
      }
    }
  });
}
const verifyUser = {
  checkDuplicateEmail,
  isAdminByEmail,
};
module.exports = verifyUser;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug feature: Login p-feature: User Permissions Feature includes how user access levels / user permissions will be implemented in the product role: Back End size: 2pt Can be done in 7-12 hours time-sensitive should be solved as soon as possible
Projects
Status: In progress
Development

No branches or pull requests

3 participants