Commit 16d3aa02ce8da795784929e9c5153a86d3b768c6

Authored by Victor Costa
1 parent 498b0dad

New config to define an exclusion pattern for profile identifier

app/models/profile.rb
... ... @@ -318,7 +318,9 @@ class Profile < ActiveRecord::Base
318 318 end
319 319  
320 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 324 return true if environment.nil?
323 325  
324 326 profiles = environment.profiles.where(:identifier => identifier)
... ...
config/noosfero.yml.dist
... ... @@ -10,6 +10,7 @@ development:
10 10 exception_recipients: [admin@example.com]
11 11 max_upload_size: 5MB
12 12 hours_until_user_activation_check: 72
  13 + exclude_profile_identifier_pattern: index(\..*)?|home(\..*)?
13 14  
14 15 test:
15 16  
... ...
test/unit/profile_test.rb
... ... @@ -1613,6 +1613,16 @@ class ProfileTest < ActiveSupport::TestCase
1613 1613 assert_equal false, Profile.is_available?('identifier-test', Environment.default)
1614 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 1626 should 'not have long descriptions' do
1617 1627 long_description = 'a' * 600
1618 1628 profile = Profile.new
... ...