Skip to content

Build MVP for ID generation and admin badge management#290

Merged
stefan-burke merged 10 commits intomainfrom
terragon/mvp-id-generation-5n8tw7
Oct 12, 2025
Merged

Build MVP for ID generation and admin badge management#290
stefan-burke merged 10 commits intomainfrom
terragon/mvp-id-generation-5n8tw7

Conversation

@stefan-burke
Copy link
Copy Markdown
Member

@stefan-burke stefan-burke commented Oct 12, 2025

Summary

  • Introduces a minimal MVP for ID generation with admin badge batches and their IDs
  • Adds admin-only interfaces to create, view, and edit badge batches and individual badges
  • Generates unique 8-character IDs per badge, excluding ambiguous characters
  • Adds localization hooks for badges and shared navigation label updates
  • Adds search capability for badge batches (by badge ID) and corresponding admin flow

Changes

Core functionality

  • Implemented BadgeBatch and Badge models with associations
  • Badge generates a unique 8-character ID on creation (via CustomIdGenerator) and links to its batch
  • BadgeBatch exposes a helper (badge_count) to reflect how many badges it contains
  • Enhanced CustomIdGenerator with methods to generate random IDs and batches of IDs, ensuring uniqueness and exclusion of ambiguous characters
  • IDs are generated without ambiguous characters and respect the defined length
  • Added search capability for badge batches: BadgeBatchesController#search, route, and UI flow to locate a badge by ID

Backend / Controllers

  • Added BadgesController to manage individual badges (edit/update) and show batch context
  • Added BadgeBatchesController with index/show/new/create/edit/update/search
  • Batch creation flow: create a BadgeBatch, generate the requested number of Badge IDs, and seed them under the batch
  • Search flow: search endpoint redirects to a found badge or batch with appropriate flash messages

Persistence

  • Migrations added:
    • CreateBadgeBatches to store batch meta (note, timestamps)
    • CreateBadges with custom string primary key (8 chars), foreign key to badge_batch, and optional note
    • AddCountToBadgeBatches to store batch count
  • Badges table uses a non-incrementing string primary key (id) and stores batch_id and note

Routes

  • Exposed admin badge management under path /badges
    • resources :badge_batches, path: "badges", only: [:index, :show, :new, :create, :edit, :update] do
      collection do
      get :search, path: "search", as: :search
      end
      end
    • resources :badges, only: [:edit, :update]

UI / Views

  • Added admin-facing views for badge batches and individual badges:
    • app/views/badge_batches/index.html.erb
    • app/views/badge_batches/show.html.erb
    • app/views/badge_batches/new.html.erb
    • app/views/badge_batches/edit.html.erb
    • app/views/badges/edit.html.erb
  • Admin navigation updated to include Badges link
  • Locales added/updated for Badges (badges.en.yml) and shared navigation (shared.en.yml)

Locales

  • New config/locales/badges.en.yml with titles, fields, buttons, and messages
  • Updated config/locales/shared.en.yml to include a Badges label under navigation

Tests

  • Factories for badge_batch and badge
  • Model specs:
    • spec/models/badge_batch_spec.rb (associations, destruction of badges, badge_count, note field behavior)
    • spec/models/badge_spec.rb (association with batch, ID generation properties, note field)
  • Feature spec: spec/features/badges/badge_management_spec.rb updated to cover:
    • Admin access to badge management from the admin dashboard
    • Creating a new badge batch and validating batch creation message
    • Viewing batch details and contained badges
    • Viewing and editing individual badges within a batch
    • Ensuring badge count is shown on the batch list
    • Access control: regular users cannot access badge management
  • Request specs: badge_batches and badges endpoints to cover admin/authorization and CRUD flows

Test plan

  • Admin can access badge management from admin dashboard
  • Admin can create a new badge batch and verify batch creation message
  • Admin can view batch details and the number of badges
  • Admin can view and edit individual badges in a batch
  • Batch listing shows correct badge counts
  • Regular users are restricted from accessing badge management
  • Search flow for badges and batch navigation is validated

How to run locally

  • Set up and migrate the database:
    • bin/rails db:migrate
  • Run tests:
    • bundle exec rspec
  • Manual flow (admin):
    • Sign in as admin
    • Navigate to Admin -> Badges
    • Create a new batch (specify count and note), view batch, edit a badge note

Notes & potential follow-ups

  • Consider adding batch-level edit/delete capabilities and stronger validations on note fields
  • Potential UX tweaks for large batch generation (progress indicators, background job handling)
  • Add pagination for batches/badges if growth requires it

🌿 Generated by Terry


ℹ️ Tag @terragon-labs to ask questions and address PR feedback

📎 Task: https://www.terragonlabs.com/task/0df353f1-aa27-4fa7-b660-6517e8b3e532

stefan-burke and others added 4 commits October 12, 2025 13:15
- Introduce BadgeBatch and Badge models with associations
- Create migrations for badges and badge_batches tables
- Add BadgesController with actions for listing, showing, creating batches, and editing badges
- Implement views for badge batch index, show, new batch, and badge edit
- Add routes for badge batches and badges restricted to admin
- Add localization strings for badges
- Add admin navigation link to badges
- Include comprehensive model and feature specs for badges functionality

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
- Introduce BadgeBatch model with note and count attributes
- Add BadgeBatchesController to manage badge batches (index, show, new, create, edit, update)
- Implement batch creation generating multiple badges with unique IDs
- Add views for listing, showing, creating, and editing badge batches
- Add count column to badge_batches table and migrate schema
- Refactor badge ID generation to support batch generation
- Update routes to include badge batch actions
- Include comprehensive specs and feature tests for badge batches
- Remove deprecated badge batch related code from BadgesController
- Add localization strings for badge batch UI and messages

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
…scope conditions

Removed scope_conditions parameter from generate_random_id and generate_random_ids methods. Adjusted uniqueness check to no longer consider external scope conditions. Updated generate_custom_id to call generate_random_id without arguments. Corresponding spec tests cleaned up to reflect these changes.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
Add comprehensive request specs for BadgeBatches and Badges controllers covering authentication, authorization, CRUD operations, and edge cases.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
@stefan-burke stefan-burke changed the title Build MVP for ID generation: badge batches and IDs (admin) Build MVP for ID generation and admin badge management Oct 12, 2025
stefan-burke and others added 6 commits October 12, 2025 15:49
- Added feature specs for badge management UI navigation and display
- Simplified and consolidated badge batch request specs
- Streamlined badge request specs with combined update tests
- Removed redundant tests for missing badge batch and badge on edit/update
- Improved readability and maintainability of badge-related test files

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
Corrected multiple I18n key usages in badge batch management feature specs to align with the current localization keys, ensuring test accuracy for new and edit batch forms.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
- Implement search action in BadgeBatchesController to find badges by ID with flash messages and redirects.
- Add badge show action and view displaying badge and related batch details.
- Add search form to badge batches index page.
- Update routes to include badge_batches search route and badges show route.
- Add I18n translations for new UI elements and messages.
- Include specs for badge search and badge show features.

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
…essages

Co-authored-by: terragon-labs[bot] <terragon-labs[bot]@users.noreply.github.com>
@stefan-burke stefan-burke merged commit f824794 into main Oct 12, 2025
16 checks passed
@stefan-burke stefan-burke deleted the terragon/mvp-id-generation-5n8tw7 branch October 12, 2025 21:53
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