Skip to content

feat(organizations): config-gated email verification policy {strict|off}#3919

Merged
PierreBrisorgueil merged 2 commits into
masterfrom
feat/email-verification-policy
Jun 28, 2026
Merged

feat(organizations): config-gated email verification policy {strict|off}#3919
PierreBrisorgueil merged 2 commits into
masterfrom
feat/email-verification-policy

Conversation

@PierreBrisorgueil

@PierreBrisorgueil PierreBrisorgueil commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Make email verification a config-gated policy instead of a hardcoded conditional.

config.organizations.emailVerification = { mode: 'strict' } (default). strict = current behavior (unverified users get no org/membership when the mailer is configured); off = auto-provision regardless (same path as the mailer-not-configured fallback). Gates both the org-provisioning service branch and the domain-search controller.

Zero data-model change (derives from the existing server-set fields); emailVerified stays server-only (no mass-assignment surface). Default behavior is byte-identical to today. Unit tests cover both modes.

Closes #3916

Summary by CodeRabbit

  • New Features

    • Added a configurable email-verification policy for organization signup and domain search.
    • Default behavior is now stricter for unverified email addresses when email delivery is available, with an optional setting to allow access without verification.
  • Bug Fixes

    • Improved handling of unverified users during organization search and provisioning so behavior now follows the selected verification mode.

Add config.organizations.emailVerification.mode ('strict' default) and gate
the existing email-verification checks in handleSignupOrganization and the
domain search controller. 'strict' preserves current behavior; 'off' always
auto-provisions / searches (same path as a mailer-not-configured env).

emailVerified stays server-only (no input-surface change); zero data-model
change. Adds unit tests for both modes.
Copilot AI review requested due to automatic review settings June 28, 2026 11:43
@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@PierreBrisorgueil, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 20 minutes and 37 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: a3e2b525-172b-4b58-8bd1-71de5b6c8aec

📥 Commits

Reviewing files that changed from the base of the PR and between ad7de96 and a7714c2.

📒 Files selected for processing (3)
  • modules/organizations/controllers/organizations.controller.js
  • modules/organizations/services/organizations.service.js
  • modules/organizations/tests/organizations.emailVerification.policy.unit.tests.js

Walkthrough

Adds a config.organizations.emailVerification.mode setting (strict or off, defaulting to strict) that gates the existing email-verification checks in handleSignupOrganization and the search controller. Previously these checks were unconditional. A new unit test file covers both modes across both code paths.

Changes

Email Verification Config-Gated Policy

Layer / File(s) Summary
Config default and gating logic
modules/organizations/config/organizations.development.config.js, modules/organizations/services/organizations.service.js, modules/organizations/controllers/organizations.controller.js
Adds emailVerification: { mode: 'strict' } to the org config. handleSignupOrganization computes emailVerificationStrict from that config and gates the early-return on it. The search controller reads the same config value before blocking unverified users from domain search.
Unit tests for strict and off modes
modules/organizations/tests/organizations.emailVerification.policy.unit.tests.js
New test file mocks config, mailer, repositories, and services; asserts strict mode blocks unverified signup org provisioning and search, and off mode allows both even when the mailer is configured.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

Possibly related PRs

  • pierreb-devkit/Node#3234: Modifies the same search handler and handleSignupOrganization provisioning logic where this PR adds the config-mode gate.
  • pierreb-devkit/Node#3680: Overlaps directly in handleSignupOrganization provisioning flow in organizations.service.js.
  • pierreb-devkit/Node#3765: Calls handleSignupOrganization after setting emailVerified = true, directly interacting with this PR's new mode gate.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the new config-gated email-verification policy and its strict/off modes.
Description check ✅ Passed The description covers the change, rationale, related issue, and behavior well enough for the template.
Linked Issues check ✅ Passed The code adds config-gated strict/off behavior for org provisioning and search, matching the requirements in #3916.
Out of Scope Changes check ✅ Passed No clear out-of-scope changes appear; the edits stay within email-verification policy and tests for organizations.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/email-verification-policy

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.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR makes organizations’ email-verification gating configurable via config.organizations.emailVerification.mode, so deployments can choose between enforcing verification (strict, default) vs. auto-provisioning/searching even for unverified users (off) when the mailer is configured.

Changes:

  • Add a config-gated “email verification policy” check to signup org provisioning (handleSignupOrganization).
  • Add the same config gate to the organizations domain-search controller (search).
  • Add unit tests covering both strict and off policy modes, and document the config in the organizations development config.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
modules/organizations/tests/organizations.emailVerification.policy.unit.tests.js Adds unit coverage for the two newly gated surfaces across strict vs off modes.
modules/organizations/services/organizations.service.js Replaces the hardcoded mailer+unverified branch with a config-driven strict/off policy gate.
modules/organizations/controllers/organizations.controller.js Gates domain-search blocking for unverified users behind the same strict/off policy.
modules/organizations/config/organizations.development.config.js Documents and sets the default emailVerification.mode to strict in dev config.

Comment thread modules/organizations/services/organizations.service.js Outdated
Comment thread modules/organizations/controllers/organizations.controller.js Outdated
@codecov

codecov Bot commented Jun 28, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.66%. Comparing base (7a26112) to head (a7714c2).
⚠️ Report is 7 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3919   +/-   ##
=======================================
  Coverage   92.66%   92.66%           
=======================================
  Files         169      169           
  Lines        5535     5537    +2     
  Branches     1778     1780    +2     
=======================================
+ Hits         5129     5131    +2     
  Misses        326      326           
  Partials       80       80           
Flag Coverage Δ
integration 61.11% <50.00%> (-0.01%) ⬇️
unit 74.24% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2689a4d...a7714c2. Read the comment docs.

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

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@modules/organizations/controllers/organizations.controller.js`:
- Around line 185-191: The async `search` function in
`organizations.controller.js` is missing the required JSDoc header. Add a
one-line description plus `@param` entries for `req` and `res`, and include an
`@returns` tag documenting the resolved value for the async handler so it
matches the project’s JSDoc requirements.

In `@modules/organizations/services/organizations.service.js`:
- Around line 136-147: Add the missing JSDoc header for
handleSignupOrganization: include a one-line description, an `@param` entry for
user, and an `@returns` entry that documents the resolved value since this async
function returns a promise. Place the JSDoc immediately above
handleSignupOrganization so it matches the modified function and follows the
project’s documentation guideline.
- Around line 143-147: The email verification gate in organizations provisioning
is treating unknown orgConfig.emailVerification.mode values as non-strict, which
can bypass verification; update OrganizationsService’s strict-mode check to
normalize the mode value and fail closed so unrecognized values still behave as
strict. Apply the same normalization logic in the corresponding controller path
as well, using the existing emailVerificationStrict / emailVerification.mode
handling so both entry points enforce the same default-strict behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 1289b193-0c9e-4af9-accd-993e354cd09c

📥 Commits

Reviewing files that changed from the base of the PR and between 2689a4d and ad7de96.

📒 Files selected for processing (4)
  • modules/organizations/config/organizations.development.config.js
  • modules/organizations/controllers/organizations.controller.js
  • modules/organizations/services/organizations.service.js
  • modules/organizations/tests/organizations.emailVerification.policy.unit.tests.js

Comment thread modules/organizations/controllers/organizations.controller.js Outdated
Comment thread modules/organizations/services/organizations.service.js Outdated
Comment thread modules/organizations/services/organizations.service.js Outdated
…view)

Adversarial review (Copilot + CodeRabbit, security): the gate treated any
non-'strict' value as 'off', so a typo or wrong casing silently bypassed
verification (fail open). Bypass now requires the explicit permissive 'off'
value; default / typo / casing all keep the strict gate. Adds a fail-closed
unit test. Gate logic aligned in both the service and the controller.

Claude-Session: https://claude.ai/code/session_011zXXYka6vU5utEGoT4frME
@PierreBrisorgueil PierreBrisorgueil merged commit 2cc9781 into master Jun 28, 2026
8 checks passed
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.

🔧 config.organizations.emailVerification {strict|off} — gate the hardcoded mailer branch

2 participants