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

Review _user API mod #1264

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

Conversation

dbauszus-glx
Copy link
Member

@dbauszus-glx dbauszus-glx commented May 20, 2024

The _user API methods should each individually check whether the ACL is provided and user admin rights are required.

The admin view method was pushed into it's own mod file user/admin.js

The user/delete API will now allow for a logged in user to remove themselves.

@dbauszus-glx dbauszus-glx added Feature New feature requests or changes to the behaviour or look of existing application features. Code Issues related to the code structure and performance. Security Ticket relates to either the authentication process, security headers, and or encryption. labels May 20, 2024
@dbauszus-glx dbauszus-glx linked an issue May 20, 2024 that may be closed by this pull request
@dbauszus-glx dbauszus-glx self-assigned this May 31, 2024
Copy link
Contributor

@AlexanderGeere AlexanderGeere left a comment

Choose a reason for hiding this comment

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

Looks good to me

@RobAndrewHurst
Copy link
Contributor

I am happy for this to be reviewed. @simon-leech Do you still want to write some tests for this? Or should I try give it a crack?

@simon-leech
Copy link
Contributor

@RobAndrewHurst Happy for you to pick up the tests then I can review the PR and tests all in one go?

@RobAndrewHurst
Copy link
Contributor

Sure!

@RobAndrewHurst
Copy link
Contributor

@RobAndrewHurst Happy for you to pick up the tests then I can review the PR and tests all in one go?

The main problem with testing these modules is that we can't test them via the CLI. We would want to write a login_test similar to the test_view to the run on deployed instances. This will then fully test the ACL.

I don't see a point in mocking the ACL in the CLI.

Let me know what you think?

@AlexanderGeere @dbauszus-glx @simon-leech

@simon-leech
Copy link
Contributor

@RobAndrewHurst Happy for you to pick up the tests then I can review the PR and tests all in one go?

The main problem with testing these modules is that we can't test them via the CLI. We would want to write a login_test similar to the test_view to the run on deployed instances. This will then fully test the ACL.

I don't see a point in mocking the ACL in the CLI.

Let me know what you think?

@AlexanderGeere @dbauszus-glx @simon-leech

@RobAndrewHurst Happy for you to pick up the tests then I can review the PR and tests all in one go?

The main problem with testing these modules is that we can't test them via the CLI. We would want to write a login_test similar to the test_view to the run on deployed instances. This will then fully test the ACL.

I don't see a point in mocking the ACL in the CLI.

Let me know what you think?

@AlexanderGeere @dbauszus-glx @simon-leech

@RobAndrewHurst Agreed - sounds quite tricky to mock, maybe we can add a login_test view as a separate PR? Once this one is in?

@RobAndrewHurst
Copy link
Contributor

@RobAndrewHurst Agreed - sounds quite tricky to mock, maybe we can add a login_test view as a separate PR? Once this one is in?

Sounds good!

@dbauszus-glx dbauszus-glx marked this pull request as draft June 5, 2024 11:35
@dbauszus-glx
Copy link
Member Author

dbauszus-glx commented Jun 5, 2024

This is back into draft. There was a couple of issues especially in regards to the auth mod, token and session check.

The session check did not work when no session field is available in ACL. This was failing silently with the request authenticating.

The session and token check are now individual documented methods.

@dbauszus-glx dbauszus-glx linked an issue Jun 20, 2024 that may be closed by this pull request
@dbauszus-glx
Copy link
Member Author

The update method as called from the admin panel will now do the verification bits.

  let verification_by_admin = ''
  if (req.params.field === 'verified' && req.params.value === true) {

    verification_by_admin = `
      , password = password_reset
      , password_reset = NULL
      , failedattempts = 0
      , verificationtoken = NULL
      , approved = true
      , approved_by = '${req.params.user.email}|${ISODate}'
    `
  }

  // Get user to update from ACL.
  const rows = await acl(`
    UPDATE acl_schema.acl_table
    SET
      ${req.params.field} = $2
      ${verification_by_admin}
      ${approved_by}
    WHERE lower(email) = lower($1);`,
    [email, req.params.value])

  if (rows instanceof Error) {
    return res.status(500).send('Failed to access ACL.')
  }

The verification can be called directly by an admin.

http://localhost:3000/api/user/update?email=dennis@mail.com&field=verified&value=true

@dbauszus-glx dbauszus-glx marked this pull request as ready for review June 20, 2024 08:02
Copy link
Contributor

@RobAndrewHurst RobAndrewHurst left a comment

Choose a reason for hiding this comment

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

Can we force the users verification flag be set to false when they reset their passwords? So that when an admin user goes to reset their password via the verification flag they don't have to toggle it from true to false to true.

@dbauszus-glx
Copy link
Member Author

dbauszus-glx commented Jun 20, 2024

@RobAndrewHurst No, we cannot. Otherwise I could set your verification to false knowing your email address.

Anybody could... I can anyways being an administrator. But you get what I mean.

@RobAndrewHurst
Copy link
Contributor

We then need a way for Admin's to easily see who needs to be verified again

@dbauszus-glx
Copy link
Member Author

I added a column re_verification which is false if there user [record] has a verification token. If clicked on this the the verified true update query will be sent and the verified and approved columns will be toggled after successful update query.

@RobAndrewHurst
Copy link
Contributor

image

Resetting a users email (roberthurstsa@gmail.com) I don't see a green tick in the outstanding password reset column.

But after re-verifying the user through the admin panel, I then see a green tick for the user. Seems as if the logic needs to be reversed?

image
^^ This is after re-verifying the user.

@dbauszus-glx
Copy link
Member Author

Green tick means that the user is fully verified. Happy for you to reverse the logic.

@RobAndrewHurst
Copy link
Contributor

Green tick means that the user is fully verified. Happy for you to reverse the logic.

Ah ok! If you put it like that I am happy with it!

@RobAndrewHurst
Copy link
Contributor

image

Should we change the message returned from this to maybe "Your session has been terminated. Please login again."

@RobAndrewHurst
Copy link
Contributor

image
Maybe something like this.

@RobAndrewHurst RobAndrewHurst added the Bug A genuine bug. There must be some form of error exception to work with. label Jun 20, 2024
Copy link
Contributor

@RobAndrewHurst RobAndrewHurst left a comment

Choose a reason for hiding this comment

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

image

On vanilla email templates we don't see the host of the email that is being sent. In this case it should be localhost:300. I set the ALIAS in the .env and I don't see it coming through.

@dbauszus-glx
Copy link
Member Author

@RobAndrewHurst The issue with missing host should be resolved in last commit.

The register request get's short circuited in the api module since it doesn't have user auth by definition.

Hence the reqHost util is required in the register module itself.

Copy link
Contributor

@RobAndrewHurst RobAndrewHurst left a comment

Choose a reason for hiding this comment

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

I have run through the ACL process. Looks all good!

Copy link
Contributor

@simon-leech simon-leech left a comment

Choose a reason for hiding this comment

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

I'm happy with this too, seems to be working from my testing!

@simon-leech
Copy link
Contributor

It doesn't seem to want me to mark it as approved though idk why 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A genuine bug. There must be some form of error exception to work with. Code Issues related to the code structure and performance. Feature New feature requests or changes to the behaviour or look of existing application features. Security Ticket relates to either the authentication process, security headers, and or encryption.
Projects
None yet
4 participants