Skip to content

Commit

Permalink
Shift API user name validations to config file for easier customization.
Browse files Browse the repository at this point in the history
  • Loading branch information
GUI committed Oct 23, 2017
1 parent a804e0c commit 1566eef
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
3 changes: 3 additions & 0 deletions config/default.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ web:
workers: 2
min_threads: 2
max_threads: 24
api_user:
first_name_exclude_regex: "(http|https|www|<|>|\\r|\\n)"
last_name_exclude_regex: "(http|https|www|<|>|\\r|\\n)"
admin:
initial_superusers: []
username_is_email: true
Expand Down
4 changes: 2 additions & 2 deletions src/api-umbrella/web-app/app/models/api_user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ class ApiUser
:uniqueness => true
validates :first_name,
:presence => { :message => "Provide your first name." },
:format => { :without => /(http|https|www|<|>|\r|\n)/i },
:format => { :without => proc { ::Regexp.new(ApiUmbrellaConfig[:web][:api_user][:first_name_exclude_regex], ::Regexp::IGNORECASE) } },
:length => { :maximum => 80 }
validates :last_name,
:presence => { :message => "Provide your last name." },
:format => { :without => /(http|https|www|<|>|\r|\n)/i },
:format => { :without => proc { ::Regexp.new(ApiUmbrellaConfig[:web][:api_user][:last_name_exclude_regex], ::Regexp::IGNORECASE) } },
:length => { :maximum => 80 }
validates :email,
:presence => { :message => "Provide your email address." },
Expand Down
2 changes: 2 additions & 0 deletions test/apis/v1/users/test_create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ def test_validates_first_name_format
"https:",
"www",
"www.",
"WwW.",
"<",
">",
"test\rtest",
Expand Down Expand Up @@ -329,6 +330,7 @@ def test_validates_last_name_format
"https:",
"www",
"www.",
"WwW.",
"<",
">",
"test\rtest",
Expand Down

0 comments on commit 1566eef

Please sign in to comment.