-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[TR#400] Add blazer generator #97
Open
reedrolemodel
wants to merge
10
commits into
master
Choose a base branch
from
add_blazer_generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
032c998
WIP: add Blazer generator
timirwin 3bdf119
Update per code review
timirwin b0f20ff
Fix tests
timirwin cad3e3b
Fix File.exists? issue
timirwin 8273e2f
Update to use latest Blazer gem defaults
timirwin 97b8332
Copy methods into Reports::DashboardsController
timirwin 4185467
Update README, add db constraints, and manifest change
timirwin 4a0024e
Require authorization/authentication to use queries run
timirwin 1a5b846
Remove project specific styling, fix Turbo issue
timirwin 1fdcd2e
Move Blazer generator to rolemodel:blazer
timirwin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
## What you get | ||
|
||
* [Blazer](./blazer) | ||
* [CSS](./css) | ||
* [Github](./github) | ||
* [Heroku](./heroku) | ||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Blazer Generator | ||
|
||
Depends on the blazer generator | ||
Depends on [RSpec Generator](../testing/rspec) | ||
Depends on slim | ||
Works best with Optics | ||
* If not using with Optics, update blazer.css to use your own tokens. | ||
|
||
## What you get | ||
|
||
Installs [blazer](https://github.com/ankane/blazer) with customization for enabling non-admin users to run Dashboard-type reports (SQL queries with variables) at /reports/dashboards. Prevents SQL-injection vulnerability present in base gem which assumes super-admin access only. | ||
|
||
### Controllers | ||
* Adds Reports::DashboardController | ||
* Add Reports::QueriesController | ||
|
||
### Views | ||
* Reports list and show | ||
|
||
### Tests | ||
* Report system test |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
Description: | ||
installs and configures Blazer | ||
|
||
Example: | ||
rails generate rolemodel:blazer |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
require_relative '../../../bundler_helpers' | ||
|
||
module Rolemodel | ||
class BlazerGenerator < Rails::Generators::Base | ||
include Rolemodel::BundlerHelpers | ||
source_root File.expand_path('templates', __dir__) | ||
|
||
def install_blazer | ||
gem 'sprockets-rails' unless File.readlines('Gemfile').grep(/sprockets/).any? | ||
gem 'blazer' | ||
run_bundle | ||
|
||
generate 'blazer:install' | ||
end | ||
|
||
def update_migration | ||
filename = Dir.glob('db/migrate/*_install_blazer.rb').first | ||
inject_into_file filename, ', foreign_key: { to_table: :users }', after: 't.references :creator' | ||
end | ||
|
||
def add_routes | ||
return if File.readlines('config/routes.rb').grep(/blazer/).any? | ||
|
||
# add routes for the report controllers | ||
route_info = " namespace :reports do\n" | ||
route_info += " resources :dashboards, only: %i[index show]\n" | ||
route_info += " resources :queries, only: [] do\n" | ||
route_info += " post :run, on: :collection\n" | ||
route_info += " # post :cancel, on: :collection\n" | ||
route_info += " end\n" | ||
route_info += " end\n" | ||
route route_info | ||
|
||
# add routes for the Blazer engine | ||
route_info = " # authenticate :user, ->(u) { Admin::ReportPolicy.new(u, :report).manage? } do\n" | ||
route_info += " mount Blazer::Engine => '/admin/reports', as: :blazer\n" | ||
route_info += " # end\n" | ||
route route_info | ||
end | ||
|
||
def add_extensions | ||
copy_file 'config/initializers/blazer.rb' | ||
copy_file 'lib/blazer_extensions/data_source.rb' | ||
end | ||
|
||
def add_controllers | ||
directory 'app/controllers/reports' | ||
end | ||
|
||
def add_views | ||
directory 'app/views/reports' | ||
end | ||
|
||
def add_styles | ||
copy_file 'app/assets/stylesheets/blazer.css' | ||
copy_file 'app/assets/stylesheets/selectize.css' | ||
append_to_file 'app/assets/config/manifest.js', "\n//= link blazer.css" | ||
end | ||
|
||
def add_tests | ||
copy_file 'spec/factories/blazer_queries.rb' | ||
copy_file 'spec/system/reporting_spec.rb' | ||
end | ||
|
||
def add_rake_task | ||
copy_file 'lib/tasks/reports.rake' | ||
end | ||
end | ||
end |
82 changes: 82 additions & 0 deletions
82
lib/generators/rolemodel/blazer/templates/app/assets/stylesheets/blazer.css
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
*= require ./selectize | ||
*= require_self | ||
*= require blazer/daterangepicker | ||
*/ | ||
|
||
/* These styles map Blazer's html structure into our look and feel. */ | ||
|
||
.results-container { /* Copied from .table__wrapper */ | ||
overflow: auto; | ||
} | ||
|
||
.text-muted { | ||
color: var(--rm-color-disabled); | ||
} | ||
|
||
.chart-container { /* Copied from .card */ | ||
position: relative; | ||
border: 1px solid var(--rm-color-contrast-medium); | ||
border-radius: var(--rm-radius); | ||
padding: var(--rm-space-large); | ||
width: 100%; | ||
background: var(--rm-color-white); | ||
margin-bottom: var(--rm-space-medium); | ||
} | ||
|
||
.btn-success { /* Copied from .btn--rm-primary */ | ||
background: var(--rm-color-primary-minus-four); | ||
color: var(--rm-color-white); | ||
&:hover { | ||
opacity: 0.7; | ||
} | ||
&:visited { | ||
color: var(--rm-color-white); | ||
} | ||
} | ||
|
||
.form-inline { | ||
display: flex; | ||
align-items: center; | ||
} | ||
|
||
.form-inline label { | ||
margin-bottom: 0; | ||
} | ||
|
||
.selectize-control { | ||
margin-right: var(--rm-space-medium); | ||
} | ||
|
||
/* date range picker */ | ||
body .daterangepicker .drp-buttons .btn { | ||
font-size: var(--rm-text-small); | ||
padding: inherit; | ||
margin-top: var(--rm-space-x-small); | ||
margin-bottom: var(--rm-space-x-small); | ||
} | ||
|
||
body .daterangepicker .drp-buttons .btn.cancelBtn { | ||
box-shadow: var(--rm-border-all) var(--rm-border-color); | ||
background: var(--rm-color-white); | ||
color: var(--rm-color-neutral-minus-max); | ||
} | ||
|
||
body .daterangepicker .drp-buttons .btn.applyBtn { | ||
background: var(--rm-color-primary-minus-four); | ||
color: var(--rm-color-white); | ||
} | ||
|
||
body .daterangepicker td.in-range { | ||
background: var(--rm-color-primary-plus-four); | ||
} | ||
|
||
body .daterangepicker td.active, body .daterangepicker td.active:hover { | ||
background: var(--rm-color-primary-minus-four); | ||
color: var(--rm-color-white); | ||
} | ||
|
||
body .daterangepicker .ranges li.active { | ||
background: var(--rm-color-primary-minus-four); | ||
color: var(--rm-color-white); | ||
} |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we be copying
blazer_dashboards.rb
too?