Commit 3599b17b353e25e0db6b75af8731a3d48e79a4de
1 parent
c054d8c6
Exists in
master
and in
29 other branches
Restricting template alternatives to those inside the current environment
ActionItem2608
Showing
6 changed files
with
27 additions
and
10 deletions
Show diff stats
app/helpers/application_helper.rb
@@ -1330,11 +1330,12 @@ module ApplicationHelper | @@ -1330,11 +1330,12 @@ module ApplicationHelper | ||
1330 | end | 1330 | end |
1331 | 1331 | ||
1332 | def template_options(klass, field_name) | 1332 | def template_options(klass, field_name) |
1333 | - return '' if klass.templates.count == 0 | ||
1334 | - return hidden_field_tag("#{field_name}[template_id]", klass.templates.first.id) if klass.templates.count == 1 | 1333 | + templates = klass.templates(environment.id) |
1334 | + return '' if templates.count == 0 | ||
1335 | + return hidden_field_tag("#{field_name}[template_id]", templates.first.id) if templates.count == 1 | ||
1335 | 1336 | ||
1336 | counter = 0 | 1337 | counter = 0 |
1337 | - radios = klass.templates.map do |template| | 1338 | + radios = templates.map do |template| |
1338 | counter += 1 | 1339 | counter += 1 |
1339 | content_tag('li', labelled_radio_button(link_to(template.name, template.url, :target => '_blank'), "#{field_name}[template_id]", template.id, counter==1)) | 1340 | content_tag('li', labelled_radio_button(link_to(template.name, template.url, :target => '_blank'), "#{field_name}[template_id]", template.id, counter==1)) |
1340 | end.join("\n") | 1341 | end.join("\n") |
app/models/profile.rb
@@ -68,7 +68,7 @@ class Profile < ActiveRecord::Base | @@ -68,7 +68,7 @@ class Profile < ActiveRecord::Base | ||
68 | #FIXME: these will work only if the subclass is already loaded | 68 | #FIXME: these will work only if the subclass is already loaded |
69 | named_scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | 69 | named_scope :enterprises, lambda { {:conditions => (Enterprise.send(:subclasses).map(&:name) << 'Enterprise').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } |
70 | named_scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } | 70 | named_scope :communities, lambda { {:conditions => (Community.send(:subclasses).map(&:name) << 'Community').map { |klass| "profiles.type = '#{klass}'"}.join(" OR ")} } |
71 | - named_scope :templates, :conditions => {:is_template => true} | 71 | + named_scope :templates, lambda { |environment_id| { :conditions => {:is_template => true, :environment_id => environment_id} } } |
72 | 72 | ||
73 | def members | 73 | def members |
74 | scopes = plugins.dispatch_scopes(:organization_members, self) | 74 | scopes = plugins.dispatch_scopes(:organization_members, self) |
app/views/templates/index.html.erb
@@ -2,9 +2,9 @@ | @@ -2,9 +2,9 @@ | ||
2 | 2 | ||
3 | <%= _('Manage the templates used on creation of profiles') %> | 3 | <%= _('Manage the templates used on creation of profiles') %> |
4 | 4 | ||
5 | -<% list_of_templates = [[_('Person') , Person.templates , 'person' ], | ||
6 | - [_('Community') , Community.templates , 'community' ], | ||
7 | - [_('Enterprise'), Enterprise.templates, 'enterprise']] %> | 5 | +<% list_of_templates = [[_('Person') , Person.templates(environment.id) , 'person' ], |
6 | + [_('Community') , Community.templates(environment.id) , 'community' ], | ||
7 | + [_('Enterprise'), Enterprise.templates(environment.id), 'enterprise']] %> | ||
8 | 8 | ||
9 | <% list_of_templates.each do |title, templates, kind|%> | 9 | <% list_of_templates.each do |title, templates, kind|%> |
10 | <div class='template-kind'> | 10 | <div class='template-kind'> |
test/functional/account_controller_test.rb
@@ -579,6 +579,21 @@ class AccountControllerTest < ActionController::TestCase | @@ -579,6 +579,21 @@ class AccountControllerTest < ActionController::TestCase | ||
579 | assert_equal 1, assigns(:user).person.boxes[0].blocks.size | 579 | assert_equal 1, assigns(:user).person.boxes[0].blocks.size |
580 | end | 580 | end |
581 | 581 | ||
582 | + should 'display only templates of the current environment' do | ||
583 | + env2 = fast_create(Environment) | ||
584 | + | ||
585 | + template1 = fast_create(Person, :name => 'template1', :environment_id => Environment.default.id, :is_template => true) | ||
586 | + template2 = fast_create(Person, :name => 'template2', :environment_id => Environment.default.id, :is_template => true) | ||
587 | + template3 = fast_create(Person, :name => 'template3', :environment_id => env2.id, :is_template => true) | ||
588 | + | ||
589 | + get :signup | ||
590 | + assert_select '#template-options' do |elements| | ||
591 | + assert_match /template1/, elements[0].to_s | ||
592 | + assert_match /template2/, elements[0].to_s | ||
593 | + assert_no_match /template3/, elements[0].to_s | ||
594 | + end | ||
595 | + end | ||
596 | + | ||
582 | should 'render person partial' do | 597 | should 'render person partial' do |
583 | Environment.any_instance.expects(:signup_person_fields).returns(['contact_phone']).at_least_once | 598 | Environment.any_instance.expects(:signup_person_fields).returns(['contact_phone']).at_least_once |
584 | get :signup | 599 | get :signup |
test/unit/application_helper_test.rb
@@ -243,6 +243,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase | @@ -243,6 +243,7 @@ class ApplicationHelperTest < ActiveSupport::TestCase | ||
243 | end | 243 | end |
244 | 244 | ||
245 | should 'not display templates options when there is no template' do | 245 | should 'not display templates options when there is no template' do |
246 | + self.stubs(:environment).returns(Environment.default) | ||
246 | [Person, Community, Enterprise].each do |klass| | 247 | [Person, Community, Enterprise].each do |klass| |
247 | assert_equal '', template_options(klass, 'profile_data') | 248 | assert_equal '', template_options(klass, 'profile_data') |
248 | end | 249 | end |
test/unit/profile_test.rb
@@ -1444,9 +1444,9 @@ class ProfileTest < ActiveSupport::TestCase | @@ -1444,9 +1444,9 @@ class ProfileTest < ActiveSupport::TestCase | ||
1444 | t2 = fast_create(Profile, :is_template => true) | 1444 | t2 = fast_create(Profile, :is_template => true) |
1445 | profile = fast_create(Profile) | 1445 | profile = fast_create(Profile) |
1446 | 1446 | ||
1447 | - assert_includes Profile.templates, t1 | ||
1448 | - assert_includes Profile.templates, t2 | ||
1449 | - assert_not_includes Profile.templates, profile | 1447 | + assert_includes Profile.templates(Environment.default.id), t1 |
1448 | + assert_includes Profile.templates(Environment.default.id), t2 | ||
1449 | + assert_not_includes Profile.templates(Environment.default.id), profile | ||
1450 | end | 1450 | end |
1451 | 1451 | ||
1452 | should 'provide URL to leave' do | 1452 | should 'provide URL to leave' do |