Add optional permission hooks (can_create_blazer_queries?, can_access_blazer_query?)#520
Open
CesarOliveira wants to merge 3 commits intoankane:masterfrom
Open
Add optional permission hooks (can_create_blazer_queries?, can_access_blazer_query?)#520CesarOliveira wants to merge 3 commits intoankane:masterfrom
CesarOliveira wants to merge 3 commits intoankane:masterfrom
Conversation
Add two backwards-compatible permission methods that are delegated to the Blazer user object. These are only called if defined on the user class, preserving full backwards compatibility: - can_create_blazer_queries? — controls create/edit/delete access - can_access_blazer_query?(query) — controls per-query read access Controllers enforce these via before_actions. Views conditionally hide New/Edit/Delete/Fork buttons. The home page query listing is filtered through can_access_blazer_query?. Host applications implement the actual logic by defining these methods on their user model class. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The original permission-hooks commit wired authorize_blazer_create! to [:new, :create, :edit, :update, :destroy] on dashboards and checks, but only to [:new, :create] on queries. Consistent with the other controllers now, so users without can_create_blazer_queries? can't edit or delete queries either.
Adds can_access_blazer_dashboard?(dashboard) host-app hook plus the matching authorize_blazer_dashboard_access! before_action, wired on the dashboards controller (show/edit/update/destroy/refresh) and applied to the dashboard listing on the queries home action. Backwards-compatible: when the host app's blazer_user does not define the method, access is allowed (mirrors the query-side hook). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two optional, backwards-compatible permission hooks so host applications can gate Blazer actions on a per-user and per-query basis:
can_create_blazer_queries?— controls create/edit/update/destroy access across queries, dashboards, and checks.can_access_blazer_query?(query)— controls per-query read access (show, edit, update, destroy, refresh, and the home page listing).Both hooks delegate to the
blazer_userobject only when the method is defined, so existing Blazer installs (whoseblazer_userdoesn't implement these methods) behave exactly as they do today.Motivation
In a multi-tenant / multi-team Rails app we wanted to let non-admin users reach Blazer while restricting:
Today a host app has to monkey-patch Blazer controllers or duplicate Blazer behind an outer gate to do either. The hook surface here is small enough that it can live upstream without adding any new concept for existing users.
Behavior when the host app does nothing
If the host app's user class doesn't define either method, both hooks return
true— identical to today's unrestricted behavior.Where the hooks are wired in
QueriesControllershow/edit/update/destroy/refreshauthorize_blazer_query_access!→can_access_blazer_query?(@query)QueriesControllernew/create/edit/update/destroyauthorize_blazer_create!→can_create_blazer_queries?DashboardsControllernew/create/edit/update/destroyauthorize_blazer_create!ChecksControllernew/create/edit/update/destroyauthorize_blazer_create!select { can_access_blazer_query?(q) }queries#show/queries/_form/dashboards#show/dashboards/_form<% if can_create_blazer_queries? %>wraps New/Edit/Delete/Fork buttonsHost-app example
Backwards compatibility
respond_to?checks and default totruewhen the user class doesn't implement them.Happy to iterate on naming, placement, or behavior — feedback welcome.