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 | 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
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 | ... | ... |