Skip to content

Conversation

@FionaLMcLaren
Copy link

@FionaLMcLaren FionaLMcLaren commented Feb 4, 2026

What Issue Does This PR Cover, If Any?

Resolves #572

What Changed? And Why Did It Change?

This PR adds the actions to revoke and regenerate tokens. It refactors the previous
"regenerate" code in the controller to be in a model. These actions are accessible to an admin user on their Admin Dashboard, when viewing a Beacon. This PR also does some cleanup on the views here, e.g.: removing the flashes for :api_key, as the information is already included in the success flash

How Has This Been Tested?

RSpec

Please Provide Screenshots

Beacon Configuration Admin View - Index Beacon Configuration Admin View - Index Beacon Configuration Admin View - Show Beacon Configuration Admin View - Show Beacon Configuration Admin View - Edit Beacon Configuration Admin View - Edit Beacon Configuration Admin View - Show, after regenerating token Beacon Configuration Admin View - Show, after regenerating token Beacon Configuration Admin View - Show, after revoking token Beacon Configuration Admin View - Show, after revoking token

seanmarcia and others added 8 commits February 3, 2026 12:08
…-api-keys

- Removed old beacon migration that conflicted with device migrations
- Updated BeaconsController to use Beacons::Creator service for API key generation
- Changed beacon relationships from direct provider/tags to many-to-many beacon_providers and beacon_topics
- Updated forms to use provider_ids and topic_ids multi-selects instead of single provider_id and tag_ids
- Updated show page to display API key (when just created) instead of token
- Updated index page to show region, language, provider count, and topic count
- Removed beacon_tag model and references as we now use beacon_topics
- Changed status from online/offline to active/revoked based on revoked_at timestamp
Topics use 'title' column, not 'name'. Updated controller and views to use Topic.active.order(:title)
- Update API key display messaging for admin context
- Add regenerate_key action in BeaconsController using KeyRegenerator service
- Add 'Regenerate API Key' button on show page with confirmation dialog
- Full API key still shown only after creation/regeneration via flash
- Clearer messaging that full key is displayed immediately after provisioning
- Added document_count method to Beacon model to count available topics
- Added file_count method to count actual attached document files
- Updated show page with 4 stat cards: Status, Available Topics, Document Files, and Configured Filters
- Logic respects beacon's language, providers (or region if no providers), and topic filters
Resolves #572

Adds actions to revoke and regenerate tokens. Refactors the previous
"regenerate" code in the controller to be in a model

TODO:
- Controller specs for beacons controller
- Route for revoking a Token
@FionaLMcLaren FionaLMcLaren changed the title Regenerate and Revoke Tokens on Beacon Configuration Admin View Beacon Configuration Admin View, with CRUD and Regenerate and Revoke Tokens Options Feb 4, 2026
@FionaLMcLaren FionaLMcLaren changed the title Beacon Configuration Admin View, with CRUD and Regenerate and Revoke Tokens Options Beacon Configuration Admin View, with CRUD and Regenerate and Revoke Tokens Actions Feb 4, 2026
context "when there is an error" do
allow(Beacon).to receive(:regenerate).raise_error

it "does not regenerate the API key for the requested beacon" do
Copy link
Author

Choose a reason for hiding this comment

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

These specs seem rather redundant, as the logic is already tested for in the model spec. I wasn't sure if to keep going with these tests for POST /revoke_key, or to keep it as testing that the redirects work? I used the code from our other request specs are reference

Copy link
Author

@FionaLMcLaren FionaLMcLaren Feb 4, 2026

Choose a reason for hiding this comment

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

The question here is: Do I bother with these specs, if we have the logic verified by the model spec; or do we want to test that revoking/regenerating a token works in these request specs?

Copy link
Author

Choose a reason for hiding this comment

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

Decided it was ok to get rid of redundant tests in request spec 👍

Copy link
Collaborator

@dmitrytrager dmitrytrager Feb 4, 2026

Choose a reason for hiding this comment

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

We can test individual methods within models (unit specs) and the whole flow with requests specs.
Since request spec is more about integration testing, please prefer requests specs over model specs if you need to choose

dependabot bot and others added 10 commits February 4, 2026 12:19
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
- Add libffi-dev package to Dockerfile.dev for Alpine Linux to support ffi gem (dependency).
Allows Bundler to resolve dependencies for Darwin
25.
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Sean Marcia <seanmarcia@github.com>
@devjona
Copy link
Collaborator

devjona commented Feb 4, 2026

Hey @FionaLMcLaren for a ticket with so many visual elements, it's really helpful to put some screenshots in the PR description, particularly for:

  • Creating a token
  • Regen
  • Revoke

Thanks! Solid work!

Copy link
Collaborator

@devjona devjona left a comment

Choose a reason for hiding this comment

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

Solid work! I left a few comments.

Copy link
Collaborator

@dmitrytrager dmitrytrager left a comment

Choose a reason for hiding this comment

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

have some comments, mostly about code validation and data integrity

@@ -0,0 +1,94 @@
class BeaconsController < ApplicationController
before_action :redirect_contributors
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggestion: add base beacons controller and move this before action there

flash[:notice] = "API key has been successfully revoked."
redirect_to @beacon

rescue => e
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can use rescue without begin/end

Copy link
Collaborator

Choose a reason for hiding this comment

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

For this case (since we control revoke process) could be better to return result from revoke method and just have simple condition here

The same comment for regeneration

Copy link
Author

Choose a reason for hiding this comment

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

Hey! Thank you for your review - it's been very helpful :) Do you have an idea how we should then use the result from the revoke method when we have an error? Cheers!

Copy link
Collaborator

Choose a reason for hiding this comment

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

You can catch error there and return false

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we can skip it, simple update rarely returns errors

# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[8.1].define(version: 2026_02_03_100004) do
ActiveRecord::Schema[8.1].define(version: 2026_02_03_100134) do
Copy link
Collaborator

Choose a reason for hiding this comment

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

Not sure why did schema change. Were there any migrations?

Copy link
Author

Choose a reason for hiding this comment

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

This happened because of a merge conflict resolution - What version number is expected here?

Copy link
Collaborator

Choose a reason for hiding this comment

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

What was the reason for conflict? Do we update version here in this branch?

@FionaLMcLaren FionaLMcLaren force-pushed the beacons-regenerate branch 2 times, most recently from 9931cda to a628a77 Compare February 4, 2026 15:05
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.

Admin Dashboard - Beacon Configuration

6 participants