Contact System - FreeUKGen/MyopicVicar GitHub Wiki

Contact System

Part of Communication-and-Engagement.

Model: app/models/contact.rb ยท Controller: app/controllers/contacts_controller.rb

The general "Contact Us" form โ€” public, no login required (skip_before_action :require_login). Used for data problems on a specific record, general questions, volunteering enquiries, website problems, etc., and (FreeCEN only) gazetteer place enquiries.

How it works

flowchart TD
    A[Public visitor submits Contact form] --> B{contact_name field filled in?}
    B -- "yes: bot hit the honeypot" --> Z[Silently dropped - spam trap]
    B -- "no: real submission" --> C[Set previous_page_url, session_data]
    C --> D{Valid?<br/>name, email_address, body present<br/>FreeCEN: selected_county required for<br/>Data/Volunteering Question}
    D -- no --> E["flash: 'There was a problem with<br/>your submission please review'"]
    E --> F{contact_type == 'Data Problem'?}
    F -- yes --> G[Redirect back to previous_page_url]
    F -- no --> H[Re-render new form with errors]
    D -- yes --> I[Save Contact]
    I --> J["flash: 'Thank you for contacting us!'"]
    J --> K[communicate_initial_contact]
    K --> L[acknowledge_communication:<br/>email the submitter]
    K --> M[contact_action_communication]
    M --> N[action_recipient_userid:<br/>role looked up from contact_type,<br/>e.g. Data Problem to county coordinator,<br/>Volunteering Question to volunteer_coordinator]
    N --> O{Coordinator found?}
    O -- no --> P[obtain_manager fallback:<br/>contacts_coordinator to REGManager to<br/>any system_administrator]
    O -- yes --> Q[UserMailer.contact_action_request<br/>to coordinator + cc copies]
    P --> Q
    J --> R[Redirect to search results]

    Q --> S[Coordinator opens the contact: #show]
    S --> T[reply_contact / forward_contact]
    T --> U[MessagesController#create<br/>dispatched by submit button label]
    U --> V[New Message saved<br/>nature: 'contact', source_contact_id set]
    V --> W[UserMailer delivers the reply/forward]
    S --> X[archive / restore / keep / unkeep]
    X --> Y[Cascades to every reply Message<br/>up to 12 levels deep - see Communication-and-Engagement known issues]
    S --> AA[convert_to_issue]
    AA --> AB[Octokit creates a GitHub issue;<br/>github_issue_url stored, further<br/>in-app editing disabled]
Loading

Key fields

  • Content: body, name, email_address, contact_type (drives routing โ€” see below), contact_name (spam honeypot, must stay blank)
  • Record context (when contacting about a specific search result): record_id, entry_id, line_id, county
  • FreeCEN-specific: selected_county, routed_syndicate_code, plus a cluster of census fields (census_year, piece, folio, page, etc.)
  • GitHub sync: github_issue_url, github_comment_url, github_number
  • Workflow state: archived, keep, identifier (a sequential-ish int: Time.now.to_i - Time.gm(2015).to_i, not a real timestamp)
  • Diagnostics: session_data (Hash โ€” a deliberately-curated subset of session keys, see safe_session_data in the controller), screenshot/screenshots (CarrierWave)

Routing logic

Contact#role_from_contact โ†’ action_recipient_userid: contact_type maps to a coordinator role (e.g. 'Data Problem' โ†’ looked up via the record's county coordinator, 'Volunteering Question' โ†’ volunteer_coordinator, 'Website Problem' โ†’ website_coordinator). FreeCEN has extra routing paths for gazetteer-originated "Data Question" / "Volunteering Question" contacts, resolved by chapman code โ†’ county/syndicate coordinator, with a hardcoded fallback userid (Freecen::CONTACT_FALLBACK_COORDINATOR_USERID) if no coordinator is found. If nobody at all is found, it falls all the way back to obtain_manager (contacts_coordinator โ†’ REGManager โ†’ any system_administrator).

GitHub integration

convert_to_issue (controller) / github_issue (model) files the contact as a GitHub issue via Octokit, gated on Rails.application.config.github_issues_access_token being configured. Once converted, the contact can no longer be edited in-app (edit redirects with a notice to edit on GitHub instead).

Routes

resources :contacts plus custom routes for list variants (list_by_type, list_by_name, list_by_date, list_by_most_recent, list_by_identifier, list_archived, select_by_identifier), report_error (pre-fills a Data Problem contact from a search result), reply_contact/forward_contact/send_forward_contact, contact_reply_messages, archive/restore/keep/unkeep/force_destroy, convert_to_issue.

โš ๏ธ **GitHub.com Fallback** โš ๏ธ