Skip to content

Commit 4d34092

Browse files
committed
Address rubocop and brakeman issues
1 parent 3fbdd5e commit 4d34092

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

app/controllers/better_together/pages_controller.rb

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def create
3030
authorize @page
3131

3232
if @page.save
33-
redirect_to @page, notice: 'Page was successfully created.'
33+
redirect_to safe_page_redirect_url, notice: 'Page was successfully created.'
3434
else
3535
render :new
3636
end
@@ -44,7 +44,7 @@ def update
4444
authorize @page
4545

4646
if @page.update(page_params)
47-
redirect_to @page, notice: 'Page was successfully updated.'
47+
redirect_to safe_page_redirect_url, notice: 'Page was successfully updated.'
4848
else
4949
render :edit
5050
end
@@ -58,6 +58,22 @@ def destroy
5858

5959
private
6060

61+
def page
62+
path = params[:path]
63+
id_param = path.present? ? path : params[:id]
64+
65+
@page ||= ::BetterTogether::Page.friendly.find(id_param)
66+
end
67+
68+
def safe_page_redirect_url
69+
if page
70+
url = url_for(page)
71+
return url if url.start_with?(root_url)
72+
end
73+
74+
root_url # Fallback to a safe URL if the original is not safe
75+
end
76+
6177
def set_page
6278
path = params[:path]
6379
id_param = path.present? ? path : params[:id]

spec/dummy/config/environments/production.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
config.active_support.report_deprecations = false
8383

8484
# Use default logging formatter so that PID and timestamp are not suppressed.
85-
config.log_formatter = ::Logger::Formatter.new
85+
config.log_formatter = Logger::Formatter.new
8686

8787
# Use a different logger for distributed setups.
8888
# require "syslog/logger"

spec/dummy/config/initializers/asset_sync.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@
44
AssetSync.configure do |config|
55
config.fog_provider = 'AWS'
66

7-
config.aws_access_key_id = ENV['AWS_ACCESS_KEY_ID']
8-
config.aws_secret_access_key = ENV['AWS_SECRET_ACCESS_KEY']
7+
config.aws_access_key_id = ENV.fetch('AWS_ACCESS_KEY_ID', nil)
8+
config.aws_secret_access_key = ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)
99

1010
config.aws_session_token = ENV['AWS_SESSION_TOKEN'] if ENV.key?('AWS_SESSION_TOKEN')
1111

1212
# Ensure that aws_iam_roles is set to false if not explicitly required
1313
config.aws_iam_roles = ENV['AWS_IAM_ROLES'] == 'true'
1414

15-
config.fog_directory = ENV['FOG_DIRECTORY']
16-
config.fog_region = ENV['FOG_REGION']
15+
config.fog_directory = ENV.fetch('FOG_DIRECTORY', nil)
16+
config.fog_region = ENV.fetch('FOG_REGION', nil)
1717

1818
# Additional configurations (commented out by default)
1919
# config.aws_reduced_redundancy = true
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# frozen_string_literal: true
22

33
Sidekiq.configure_server do |config|
4-
config.redis = { url: ENV['REDIS_URL'] }
4+
config.redis = { url: ENV.fetch('REDIS_URL', nil) }
55
end
66

77
Sidekiq.configure_client do |config|
8-
config.redis = { url: ENV['REDIS_URL'] }
8+
config.redis = { url: ENV.fetch('REDIS_URL', nil) }
99
end

0 commit comments

Comments
 (0)