Skip to content

Explain and log failed manual API user identity approvals - #2986

Open
maricavor wants to merge 1 commit into
masterfrom
fix/api-user-approve-verification-errors
Open

maricavor wants to merge 1 commit into
masterfrom
fix/api-user-approve-verification-errors

Conversation

@maricavor

Copy link
Copy Markdown
Contributor

Problem

A registrar could not manually approve the identity verification of their machine-to-machine API user, and neither the registrar nor the logs showed why:

  • Any validation failure while saving the user (e.g. duplicate identity code at the registrar, legacy password shorter than 6 characters) raised ActiveRecord::RecordInvalid. That returned a 500, and the REPP log stored response: null.
  • A subject conflict returned only "Login subject is already used by another api user at this registrar", without saying which user.

The portal side, a missing approve_verification_payload that made every approval fail, is fixed in internetee/registrar_center2#287.

Changes

  • ApiUserApproveVerification
    • Rescues RecordInvalid and returns "Saving API user data failed: ". The transaction rolls back, so the user stays pending.
    • On a subject conflict, names the API user that already holds the identity. One verified person per registrar is still enforced.
    • Exposes failure_reason and failure_message.
    • Logs each failure with Rails.logger.warn: API user id, username, registrar, identity code, subject, reason and message.
  • POST /repp/v1/api_users/approve_verification/:id: on failure returns 400 with data: { verification_failed, reason, api_user: { id, username, identity_code, subject } }, so the REPP log record carries the details.
  • Admin → REPP log
    • New "Failed identity verifications only" filter.
    • Failed approval rows get an "Identity verification failed" label with the user, identity and error message. Time and acting user are in the existing columns.
  • New locale keys: subject_taken_by_user and update_failed (en and et).

Tests

  • Unit tests for the approve action: conflict naming, invalid data no longer raising, failure logging.
  • REPP integration tests: 400 response with reason, failure recorded in the REPP log.
  • ApiLog::ReppLog model tests.
  • Admin REPP log filter test.
  • Ran the affected suites (approve action, REPP api_users, ApiUser and ReppLog models, admin area): all pass.

🤖 Generated with Claude Code

- Rescue RecordInvalid in ApiUserApproveVerification so invalid user data
  returns a 400 with the validation messages instead of a 500.
- Name the API user that already holds the identity when the subject is
  taken at the registrar (one verified person per registrar stays enforced).
- Log every approval failure with user, registrar, identity code, subject
  and reason.
- Return verification_failed, reason and the user's identity in the REPP
  response, so the REPP log record carries them.
- Admin REPP log: filter for failed identity verifications and mark those
  rows with the user, identity and error message.

This branch has not been deployed

No deployments
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.

1 participant