fix: confirm overwrite for ID verified fields#80
Conversation
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughA new two-step confirmation flow for ID verification is added to the CRM cog. When verifying an already-verified contact, users receive a confirmation prompt before overwriting existing verification data. The Changes
Sequence DiagramsequenceDiagram
participant User
participant CRM Cog
participant Espo API
participant Confirmation View
User->>CRM Cog: Request to verify contact ID
CRM Cog->>Espo API: GET existing verification data
Espo API-->>CRM Cog: Return current verifier/date
alt Conflict detected & overwrite not allowed
CRM Cog->>CRM Cog: Audit denial
CRM Cog->>Confirmation View: Show overwrite confirmation
Confirmation View->>User: Display Overwrite/Cancel buttons
alt User clicks Overwrite
User->>CRM Cog: Confirm overwrite
CRM Cog->>Espo API: PUT with allow_overwrite=True
Espo API-->>CRM Cog: Updated
CRM Cog-->>User: Show success embed
else User clicks Cancel
User->>Confirmation View: Cancel
Confirmation View-->>User: Hide UI
end
else No conflict or overwrite allowed
CRM Cog->>Espo API: PUT verified_by/verified_at
Espo API-->>CRM Cog: Updated
CRM Cog-->>User: Show success embed
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
tests/unit/test_crm_mark_id_verified.py (1)
169-201: Add a partial-existing-values overwrite test case.Please add coverage where only one existing field is non-blank (e.g.,
cIdVerifiedByset,cIdVerifiedAtblank) and values differ, so the overwrite prompt behavior is pinned for that edge case too.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@tests/unit/test_crm_mark_id_verified.py` around lines 169 - 201, Add a new async unit test mirroring test_mark_id_verified_single_contact_prompts_for_overwrite_if_already_verified that uses crm_cog._search_contacts_for_mark_id_verification to return the contact and sets crm_cog.espo_api.request.return_value to have ID_VERIFIED_BY_FIELD populated and ID_VERIFIED_AT_FIELD blank (or vice versa) with differing values from the inputs; call crm_cog.mark_id_verified.callback with the conflicting inputs and assert crm_cog.espo_api.request was called with "GET" and the contact id, then assert mock_interaction.followup.send was invoked with a message containing "already ID verified" and that kwargs["view"].__class__ is MarkIdVerifiedOverwriteConfirmationView to confirm the overwrite prompt appears for the partial-existing-values edge case.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@apps/discord_bot/src/five08/discord_bot/cogs/crm.py`:
- Around line 2452-2459: The overwrite-protection currently only triggers when
both existing_verified_by and existing_verified_at are non-empty; change the
logic in the CRM cog (where needs_confirmation is computed) to require
confirmation if either existing_verified_by or existing_verified_at is present
and the corresponding normalized value differs (i.e., check per-field: if
existing_verified_by is truthy and existing_verified_by !=
normalized_verified_by OR if existing_verified_at is truthy and
existing_verified_at != normalized_verified_at). Update the needs_confirmation
boolean to reflect this per-field conflict check so single-field conflicts
prompt confirmation.
---
Nitpick comments:
In `@tests/unit/test_crm_mark_id_verified.py`:
- Around line 169-201: Add a new async unit test mirroring
test_mark_id_verified_single_contact_prompts_for_overwrite_if_already_verified
that uses crm_cog._search_contacts_for_mark_id_verification to return the
contact and sets crm_cog.espo_api.request.return_value to have
ID_VERIFIED_BY_FIELD populated and ID_VERIFIED_AT_FIELD blank (or vice versa)
with differing values from the inputs; call crm_cog.mark_id_verified.callback
with the conflicting inputs and assert crm_cog.espo_api.request was called with
"GET" and the contact id, then assert mock_interaction.followup.send was invoked
with a message containing "already ID verified" and that
kwargs["view"].__class__ is MarkIdVerifiedOverwriteConfirmationView to confirm
the overwrite prompt appears for the partial-existing-values edge case.
* fix: confirm ID verification overwrite before update * fix: require overwrite confirmation for single field conflicts
* Require id_type for mark-id-verified (#76) * feat: require id_type for mark-id-verified * docs: move slash command docs to linked command reference * docs: add consolidated Discord bot documentation file * docs: remove obsolete kimai slash commands * Handle optional id_type for mark-id-verified compatibility * Add job rerun endpoint and CLI tooling (#81) * add rerun endpoint and jobsctl CLI * Fix rerun payload validation and stabilize jobsctl tests * fix: confirm overwrite for ID verified fields (#80) * fix: confirm ID verification overwrite before update * fix: require overwrite confirmation for single field conflicts * feat(worker): add jobsctl recent jobs query --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
Description
Added an explicit confirmation flow to mark-id-verified so non-blank cIdVerifiedBy and cIdVerifiedAt values are not overwritten accidentally.
Introduced MarkIdVerifiedOverwriteConfirmationView and updated _mark_id_verified_for_contact to read current verification fields, block direct overwrite when mismatched non-empty values exist, and persist only after explicit confirmation.
Single-contact and selection-based flows now share this guard through the same persistence path.
Updated unit tests in test_crm_mark_id_verified.py to validate GET-before-PUT behavior and the overwrite prompt flow.
Related Issue
How Has This Been Tested?
Summary by CodeRabbit
Release Notes
New Features
Tests