Skip to content

Commit 1566eef

Browse files
committed
Shift API user name validations to config file for easier customization.
1 parent a804e0c commit 1566eef

File tree

3 files changed

+7
-2
lines changed

3 files changed

+7
-2
lines changed

config/default.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ web:
8080
workers: 2
8181
min_threads: 2
8282
max_threads: 24
83+
api_user:
84+
first_name_exclude_regex: "(http|https|www|<|>|\\r|\\n)"
85+
last_name_exclude_regex: "(http|https|www|<|>|\\r|\\n)"
8386
admin:
8487
initial_superusers: []
8588
username_is_email: true

src/api-umbrella/web-app/app/models/api_user.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ class ApiUser
5050
:uniqueness => true
5151
validates :first_name,
5252
:presence => { :message => "Provide your first name." },
53-
:format => { :without => /(http|https|www|<|>|\r|\n)/i },
53+
:format => { :without => proc { ::Regexp.new(ApiUmbrellaConfig[:web][:api_user][:first_name_exclude_regex], ::Regexp::IGNORECASE) } },
5454
:length => { :maximum => 80 }
5555
validates :last_name,
5656
:presence => { :message => "Provide your last name." },
57-
:format => { :without => /(http|https|www|<|>|\r|\n)/i },
57+
:format => { :without => proc { ::Regexp.new(ApiUmbrellaConfig[:web][:api_user][:last_name_exclude_regex], ::Regexp::IGNORECASE) } },
5858
:length => { :maximum => 80 }
5959
validates :email,
6060
:presence => { :message => "Provide your email address." },

test/apis/v1/users/test_create.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ def test_validates_first_name_format
282282
"https:",
283283
"www",
284284
"www.",
285+
"WwW.",
285286
"<",
286287
">",
287288
"test\rtest",
@@ -329,6 +330,7 @@ def test_validates_last_name_format
329330
"https:",
330331
"www",
331332
"www.",
333+
"WwW.",
332334
"<",
333335
">",
334336
"test\rtest",

0 commit comments

Comments
 (0)