bnb_blazer 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9dfd9dcc54ad8fc13934d9de74792a7c1be24d2449fb4c868490692302086341
|
4
|
+
data.tar.gz: ce3a925a2fc273a2d79873ba3c3c3e3f60581cad6cd8ec0f93a23711597ba833
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e73e24bd82ede29b8fe9b4e4e7b66d6ff15797d7704c8586ebb7acace5312ecbecf158372470790c95559d19267995e62cf3a1aa463a94e7a9d1021a9654f468
|
7
|
+
data.tar.gz: 608fcfcc41142cc28c697740f03eee11c3471b289e491db051527e13c5ca4310f253c875478c8d7fe15fbc6ebb77b7c5e19cb7c49d4956430772e7b0139d894c
|
@@ -0,0 +1,133 @@
|
|
1
|
+
Blazer::BaseController.class_eval do
|
2
|
+
# skip filters
|
3
|
+
filters = _process_action_callbacks.map(&:filter) - [:activate_authlogic]
|
4
|
+
skip_before_action(*filters, raise: false)
|
5
|
+
skip_after_action(*filters, raise: false)
|
6
|
+
skip_around_action(*filters, raise: false)
|
7
|
+
|
8
|
+
clear_helpers
|
9
|
+
|
10
|
+
protect_from_forgery with: :exception
|
11
|
+
|
12
|
+
if ENV["BLAZER_PASSWORD"]
|
13
|
+
http_basic_authenticate_with name: ENV["BLAZER_USERNAME"], password: ENV["BLAZER_PASSWORD"]
|
14
|
+
end
|
15
|
+
|
16
|
+
if Blazer.settings["before_action"]
|
17
|
+
raise Blazer::Error, "The docs for protecting Blazer with a custom before_action had an incorrect example from August 2017 to June 2018. The example method had a boolean return value. However, you must render or redirect if a user is unauthorized rather than return a falsy value. Double check that your before_action works correctly for unauthorized users (if it worked when added, there should be no issue). Then, change before_action to before_action_method in config/blazer.yml."
|
18
|
+
end
|
19
|
+
|
20
|
+
if Blazer.before_action
|
21
|
+
before_action Blazer.before_action.to_sym
|
22
|
+
end
|
23
|
+
|
24
|
+
if Blazer.override_csp
|
25
|
+
after_action do
|
26
|
+
response.headers['Content-Security-Policy'] = "default-src 'self' https: 'unsafe-inline' 'unsafe-eval' data:"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
layout "bnb_blazer/application"
|
31
|
+
append_view_path(["views/blazer", "views/bnb_blazer", "views/blazer"])
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def process_vars(statement, data_source)
|
36
|
+
(@bind_vars ||= []).concat(Blazer.extract_vars(statement)).uniq!
|
37
|
+
@bind_vars.each do |var|
|
38
|
+
params[var] ||= Blazer.data_sources[data_source].variable_defaults[var]
|
39
|
+
end
|
40
|
+
@success = @bind_vars.all? { |v| params[v] }
|
41
|
+
|
42
|
+
if @success
|
43
|
+
@bind_vars.each do |var|
|
44
|
+
value = params[var].presence
|
45
|
+
if value
|
46
|
+
if ["start_time", "end_time"].include?(var)
|
47
|
+
value = value.to_s.gsub(" ", "+") # fix for Quip bug
|
48
|
+
end
|
49
|
+
|
50
|
+
if var.end_with?("_at")
|
51
|
+
begin
|
52
|
+
value = Blazer.time_zone.parse(value)
|
53
|
+
rescue
|
54
|
+
# do nothing
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
if value =~ /\A\d+\z/
|
59
|
+
value = value.to_i
|
60
|
+
elsif value =~ /\A\d+\.\d+\z/
|
61
|
+
value = value.to_f
|
62
|
+
end
|
63
|
+
end
|
64
|
+
value = Blazer.transform_variable.call(var, value) if Blazer.transform_variable
|
65
|
+
statement.gsub!("{#{var}}", ActiveRecord::Base.connection.quote(value))
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def add_cohort_analysis_vars
|
71
|
+
@bind_vars << "cohort_period" unless @bind_vars.include?("cohort_period")
|
72
|
+
@smart_vars["cohort_period"] = ["day", "week", "month"]
|
73
|
+
params[:cohort_period] ||= "week"
|
74
|
+
end
|
75
|
+
|
76
|
+
def parse_smart_variables(var, data_source)
|
77
|
+
smart_var_data_source =
|
78
|
+
([data_source] + Array(data_source.settings["inherit_smart_settings"]).map { |ds| Blazer.data_sources[ds] }).find { |ds| ds.smart_variables[var] }
|
79
|
+
|
80
|
+
if smart_var_data_source
|
81
|
+
query = smart_var_data_source.smart_variables[var]
|
82
|
+
|
83
|
+
if query.is_a? Hash
|
84
|
+
smart_var = query.map { |k,v| [v, k] }
|
85
|
+
elsif query.is_a? Array
|
86
|
+
smart_var = query.map { |v| [v, v] }
|
87
|
+
elsif query
|
88
|
+
result = smart_var_data_source.run_statement(query)
|
89
|
+
smart_var = result.rows.map { |v| v.reverse }
|
90
|
+
error = result.error if result.error
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
[smart_var, error]
|
95
|
+
end
|
96
|
+
|
97
|
+
# don't pass to url helpers
|
98
|
+
#
|
99
|
+
# some are dangerous when passed as symbols
|
100
|
+
# root_url({host: "evilsite.com"})
|
101
|
+
#
|
102
|
+
# certain ones (like host) only affect *_url and not *_path
|
103
|
+
#
|
104
|
+
# when permitted parameters are passed in Rails 6,
|
105
|
+
# they appear to be added as GET parameters
|
106
|
+
# root_url(params.permit(:host))
|
107
|
+
UNPERMITTED_KEYS = [:controller, :action, :id, :host, :query, :dashboard, :query_id, :query_ids, :table_names, :authenticity_token, :utf8, :_method, :commit, :statement, :data_source, :name, :fork_query_id, :blazer, :run_id, :script_name, :original_script_name]
|
108
|
+
|
109
|
+
# remove unpermitted keys from both params and permitted keys for better sleep
|
110
|
+
def variable_params(resource)
|
111
|
+
permitted_keys = resource.variables - UNPERMITTED_KEYS.map(&:to_s)
|
112
|
+
params.except(*UNPERMITTED_KEYS).slice(*permitted_keys).permit!
|
113
|
+
end
|
114
|
+
helper_method :variable_params
|
115
|
+
|
116
|
+
def blazer_user
|
117
|
+
send(Blazer.user_method) if Blazer.user_method && respond_to?(Blazer.user_method, true)
|
118
|
+
end
|
119
|
+
helper_method :blazer_user
|
120
|
+
|
121
|
+
def render_errors(resource)
|
122
|
+
@errors = resource.errors
|
123
|
+
action = resource.persisted? ? :edit : :new
|
124
|
+
render action, status: :unprocessable_entity
|
125
|
+
end
|
126
|
+
|
127
|
+
# do not inherit from ApplicationController - #120
|
128
|
+
def default_url_options
|
129
|
+
{}
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
end
|
data/lib/bnb_blazer/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bnb_blazer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Joe
|
@@ -32,7 +32,7 @@ extensions: []
|
|
32
32
|
extra_rdoc_files: []
|
33
33
|
files:
|
34
34
|
- Rakefile
|
35
|
-
- app/controllers/
|
35
|
+
- app/overrides/controllers/blazer/base_controller_override.rb
|
36
36
|
- app/views/bnb_blazer/_variables.html.haml
|
37
37
|
- app/views/bnb_blazer/checks/_form.html.haml
|
38
38
|
- app/views/bnb_blazer/checks/edit.html.haml
|