parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

feat: Add option to change log levels of username already exists message

Open coratgerl opened this issue 2 weeks ago โ€ข 7 comments

Pull Request

Issue

Fixes: https://github.com/parse-community/parse-server/issues/9329

  • [x] Add tests
  • [ ] Add changes to documentation (guides, repository pages, code comments)
  • [ ] Add security check
  • [ ] Add new Parse Error codes to Parse JS SDK

Summary by CodeRabbit

  • New Features

    • Added a new log-level setting signupUsernameTaken to control how sign-up failures for an already-existing username are logged (default: 'error'); documentation updated.
  • Tests

    • Added tests that verify logging behavior for duplicate-username signups under different log-level configurations (e.g., 'warn' and 'silent').

โœ๏ธ Tip: You can customize this high-level summary in your review settings.

coratgerl avatar Dec 06 '25 08:12 coratgerl

๐Ÿš€ Thanks for opening this pull request!

๐Ÿ“ Walkthrough

Walkthrough

Adds a new log-level option signupUsernameTaken (env PARSE_SERVER_LOG_LEVELS_SIGNUP_USERNAME_TAKEN, default 'info') to LogLevels, updates error-handling middleware to honor it for Parse.Error.USERNAME_TAKEN, adds docs/types/definitions entries, and adds tests validating 'warn' and 'silent' behaviors.

Changes

Cohort / File(s) Summary
Tests
spec/ParseUser.spec.js
Adds two tests that attempt duplicate-username signups and assert logger calls for signupUsernameTaken when configured as 'warn' and 'silent', and verify the signup still throws USERNAME_TAKEN.
Options definitions & docs
src/Options/Definitions.js, src/Options/docs.js, src/Options/index.js
Introduces signupUsernameTaken in exported LogLevels with env PARSE_SERVER_LOG_LEVELS_SIGNUP_USERNAME_TAKEN, help text, and default 'info'; adds corresponding documentation and index typing/comment.
Middleware
src/middlewares.js
In handleParseErrors, reads req.config?.logLevels?.signupUsernameTaken (default 'info') and logs Parse.Error.USERNAME_TAKEN using that level; treats 'silent' as no-op and falls back to log.error if the configured level method is missing.
Type declarations
types/Options/index.d.ts
Adds signupUsernameTaken?: string to the LogLevels interface.

Estimated code review effort

๐ŸŽฏ 3 (Moderate) | โฑ๏ธ ~20โ€“30 minutes

  • Pay attention to:
    • src/middlewares.js โ€” correct default ('info'), handling of 'silent', and fallback when the logger method for the configured level is absent.
    • Consistency of env var name, help text, and default across Definitions.js, docs.js, index.js, and types/Options/index.d.ts.
    • spec/ParseUser.spec.js โ€” ensure logger spies/assertions match the intended call counts and that the test still asserts the USERNAME_TAKEN error is raised.

Pre-merge checks and finishing touches

โŒ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage โš ๏ธ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check โ“ Inconclusive The description includes the required issue link (#9329) and indicates tests were added, but does not describe the implementation approach or changes made. Add an 'Approach' section describing how the signupUsernameTaken log level option was implemented and integrated into the codebase.
โœ… Passed checks (3 passed)
Check name Status Explanation
Title check โœ… Passed The title accurately summarizes the main change: adding an option to control log levels for username-taken signup failures.
Linked Issues check โœ… Passed The PR successfully implements the requested feature: adds a signupUsernameTaken log level option (defaulting to 'info') that controls logging behavior for duplicate username signup attempts, with tests validating 'warn' and 'silent' configurations.
Out of Scope Changes check โœ… Passed All changes directly support the core objective of issue #9329: adding configuration and logging for username-taken events. No unrelated modifications detected.
โœจ Finishing touches
  • [ ] ๐Ÿ“ Generate docstrings
๐Ÿงช Generate unit tests (beta)
  • [ ] Create PR with unit tests
  • [ ] Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

โค๏ธ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Dec 06 '25 08:12 coderabbitai[bot]

:white_check_mark: Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
:white_check_mark: Open Source Security 0 0 0 0 0 issues

:computer: Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

parseplatformorg avatar Dec 06 '25 08:12 parseplatformorg

Codecov Report

:white_check_mark: All modified and coverable lines are covered by tests. :white_check_mark: Project coverage is 92.58%. Comparing base (6b9f896) to head (0422864). :warning: Report is 4 commits behind head on alpha.

Additional details and impacted files
@@           Coverage Diff           @@
##            alpha    #9962   +/-   ##
=======================================
  Coverage   92.58%   92.58%           
=======================================
  Files         191      191           
  Lines       15544    15549    +5     
  Branches      177      177           
=======================================
+ Hits        14391    14396    +5     
  Misses       1141     1141           
  Partials       12       12           

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Dec 06 '25 08:12 codecov[bot]

I think we can also the default level for this to info. It's not really an error or warning.

mtrezza avatar Dec 07 '25 20:12 mtrezza

LogEvents is still all over the code

Do you mean this object ? image

This is because in the issue you mentionned this kind of object: image

Do you want I delete the object and pass directly the option ?

coratgerl avatar Dec 08 '25 17:12 coratgerl

I see where you got this from. May have been a typo. logLevels does the same for Cloud Function and trigger events:

logLevels: {
  env: 'PARSE_SERVER_LOG_LEVELS',
  help: '(Optional) Overrides the log levels used internally by Parse Server to log events.',
  action: parsers.objectParser,
  type: 'LogLevels',
  default: {},
},

Let's add there, unless you can think of a reason not to? They are grouped by prefix, cloudFunction..., trigger..., so maybe add a prefix like signup... since this is a sign-up event and name it signupUsernameTaken, which is the same wording as ParseError.USERNAME_TAKEN = 202, so we have a nice mapping.

mtrezza avatar Dec 08 '25 20:12 mtrezza

Yes, I fixed the option file image

coratgerl avatar Dec 11 '25 10:12 coratgerl

Before merging, let me check if Parse Server 9 release can be done before that.

mtrezza avatar Dec 11 '25 10:12 mtrezza