Commit 16d3aa02ce8da795784929e9c5153a86d3b768c6
1 parent
498b0dad
Exists in
master
and in
26 other branches
New config to define an exclusion pattern for profile identifier
Showing
3 changed files
with
14 additions
and
1 deletions
Show diff stats
app/models/profile.rb
@@ -318,7 +318,9 @@ class Profile < ActiveRecord::Base | @@ -318,7 +318,9 @@ class Profile < ActiveRecord::Base | ||
318 | end | 318 | end |
319 | 319 | ||
320 | def self.is_available?(identifier, environment, profile_id=nil) | 320 | def self.is_available?(identifier, environment, profile_id=nil) |
321 | - return false unless identifier =~ IDENTIFIER_FORMAT && !RESERVED_IDENTIFIERS.include?(identifier) | 321 | + return false unless identifier =~ IDENTIFIER_FORMAT && |
322 | + !RESERVED_IDENTIFIERS.include?(identifier) && | ||
323 | + (NOOSFERO_CONF['exclude_profile_identifier_pattern'].blank? || identifier !~ /#{NOOSFERO_CONF['exclude_profile_identifier_pattern']}/) | ||
322 | return true if environment.nil? | 324 | return true if environment.nil? |
323 | 325 | ||
324 | profiles = environment.profiles.where(:identifier => identifier) | 326 | profiles = environment.profiles.where(:identifier => identifier) |
config/noosfero.yml.dist
@@ -10,6 +10,7 @@ development: | @@ -10,6 +10,7 @@ development: | ||
10 | exception_recipients: [admin@example.com] | 10 | exception_recipients: [admin@example.com] |
11 | max_upload_size: 5MB | 11 | max_upload_size: 5MB |
12 | hours_until_user_activation_check: 72 | 12 | hours_until_user_activation_check: 72 |
13 | + exclude_profile_identifier_pattern: index(\..*)?|home(\..*)? | ||
13 | 14 | ||
14 | test: | 15 | test: |
15 | 16 |
test/unit/profile_test.rb
@@ -1613,6 +1613,16 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1613,6 +1613,16 @@ class ProfileTest < ActiveSupport::TestCase | ||
1613 | assert_equal false, Profile.is_available?('identifier-test', Environment.default) | 1613 | assert_equal false, Profile.is_available?('identifier-test', Environment.default) |
1614 | end | 1614 | end |
1615 | 1615 | ||
1616 | + should 'not be available if identifier match with custom exclusion pattern' do | ||
1617 | + NOOSFERO_CONF.stubs(:[]).with('exclude_profile_identifier_pattern').returns('identifier.*') | ||
1618 | + assert_equal false, Profile.is_available?('identifier-test', Environment.default) | ||
1619 | + end | ||
1620 | + | ||
1621 | + should 'be available if identifier do not match with custom exclusion pattern' do | ||
1622 | + NOOSFERO_CONF.stubs(:[]).with('exclude_profile_identifier_pattern').returns('identifier.*') | ||
1623 | + assert_equal false, Profile.is_available?('test-identifier', Environment.default) | ||
1624 | + end | ||
1625 | + | ||
1616 | should 'not have long descriptions' do | 1626 | should 'not have long descriptions' do |
1617 | long_description = 'a' * 600 | 1627 | long_description = 'a' * 600 |
1618 | profile = Profile.new | 1628 | profile = Profile.new |