Skip to content

Commit ae221f6

Browse files
committed
Migrate settings controllers to strong parameters
1 parent 980f8cc commit ae221f6

File tree

5 files changed

+77
-10
lines changed

5 files changed

+77
-10
lines changed

app/controllers/sites/settings_controller.rb

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ class Sites::SettingsController < Sites::BaseController
22
provider_required
33

44
before_action :find_settings
5-
before_action :find_service, :only => [:edit, :policies, :accessrules]
65

76
layout 'provider'
87
activate_menu :audience, :finance, :credit_card_policies
@@ -11,22 +10,22 @@ def show
1110
redirect_to :action => :edit
1211
end
1312

14-
def edit
15-
end
16-
17-
def accessrules
18-
end
13+
def edit; end
1914

2015
def update
21-
if @settings.update(params[:settings])
16+
if @settings.update(settings_params)
2217
redirect_to edit_admin_site_settings_path, success: t('.success')
2318
else
24-
render :accessrules
19+
redirect_to edit_admin_site_settings_path, danger: t('.error')
2520
end
2621
end
2722

2823
private
2924

25+
def settings_params
26+
params.require(:settings).permit(:cc_terms_path, :cc_privacy_path, :cc_refunds_path)
27+
end
28+
3029
def find_settings
3130
@settings = current_account.settings
3231
end

app/models/settings.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ class Settings < ApplicationRecord
44

55
audited allow_mass_assignment: true
66

7-
attr_protected :account_id, :tenant_id, :product, :audit_ids, :sso_key
8-
97
validates :product, inclusion: { in: %w[connect enterprise].freeze }
108
validates :change_account_plan_permission, :change_service_plan_permission, inclusion: { in: %w[request none credit_card request_credit_card direct].freeze }
119
validates :bg_colour, :link_colour, :text_colour, :menu_bg_colour, :link_label, :link_url, :menu_link_colour, :token_api,

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,6 +1244,7 @@ en:
12441244
settings:
12451245
update:
12461246
success: Settings updated
1247+
error: Settings could not be updated
12471248
spam_protections:
12481249
edit:
12491250
selector_label: Protection against bots on the developer portal
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# frozen_string_literal: true
2+
3+
require 'test_helper'
4+
5+
class Sites::SettingsControllerTest < ActionDispatch::IntegrationTest
6+
7+
test 'show emails tab if not master account' do
8+
provider = FactoryBot.create(:provider_account)
9+
10+
login_provider provider
11+
12+
get edit_admin_site_emails_path
13+
14+
assert_response :success
15+
end
16+
17+
test 'do not show emails tab if master account' do
18+
ThreeScale.config.stubs(onpremises: true, tenant_mode: 'master')
19+
20+
member = FactoryBot.create(:simple_admin, account: master_account)
21+
member.activate!
22+
23+
login! master_account, user: member
24+
25+
get edit_admin_site_emails_path
26+
27+
assert_response :forbidden
28+
end
29+
30+
end

test/integration/sites/settings_controller_test.rb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,43 @@ class Sites::SettingsControllerTest < ActionDispatch::IntegrationTest
2727
assert_response :forbidden
2828
end
2929

30+
test 'update credit card policies paths successfully' do
31+
provider = FactoryBot.create(:provider_account)
32+
login_provider provider
33+
34+
put admin_site_settings_path, params: {
35+
settings: {
36+
cc_terms_path: '/terms',
37+
cc_privacy_path: '/privacy',
38+
cc_refunds_path: '/refunds'
39+
}
40+
}
41+
42+
assert_redirected_to edit_admin_site_settings_path
43+
assert_equal 'Settings updated', flash[:success]
44+
45+
provider.settings.reload
46+
assert_equal '/terms', provider.settings.cc_terms_path
47+
assert_equal '/privacy', provider.settings.cc_privacy_path
48+
assert_equal '/refunds', provider.settings.cc_refunds_path
49+
end
50+
51+
test 'update with empty values clears settings' do
52+
provider = FactoryBot.create(:provider_account)
53+
provider.settings.update(cc_terms_path: '/terms', cc_privacy_path: '/privacy')
54+
login_provider provider
55+
56+
put admin_site_settings_path, params: {
57+
settings: {
58+
cc_terms_path: '',
59+
cc_privacy_path: ''
60+
}
61+
}
62+
63+
assert_redirected_to edit_admin_site_settings_path
64+
65+
provider.settings.reload
66+
assert_equal '', provider.settings.cc_terms_path
67+
assert_equal '', provider.settings.cc_privacy_path
68+
end
3069
end

0 commit comments

Comments
 (0)