Commit c434a2af23163e2003f937a709ea22d764dcdaba
Committed by
Daniela Feitosa
1 parent
2e2cf49f
Exists in
master
and in
22 other branches
Adding link to edit inactive enterprise template to admin control panel
(ActionItem1934)
Showing
5 changed files
with
77 additions
and
7 deletions
Show diff stats
app/models/environment.rb
| @@ -673,13 +673,14 @@ class Environment < ActiveRecord::Base | @@ -673,13 +673,14 @@ class Environment < ActiveRecord::Base | ||
| 673 | def create_templates | 673 | def create_templates |
| 674 | pre = self.name.to_slug + '_' | 674 | pre = self.name.to_slug + '_' |
| 675 | ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :visible => false).id | 675 | ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => self, :visible => false).id |
| 676 | + inactive_enterprise_tmpl = Enterprise.create!(:name => 'Inactive Enterprise template', :identifier => pre + 'inactive_enterprise_template', :environment => self, :visible => false) | ||
| 676 | com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :visible => false).id | 677 | com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => self, :visible => false).id |
| 677 | pass = Digest::MD5.hexdigest rand.to_s | 678 | pass = Digest::MD5.hexdigest rand.to_s |
| 678 | user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person | 679 | user = User.create!(:login => (pre + 'person_template'), :email => (pre + 'template@template.noo'), :password => pass, :password_confirmation => pass, :environment => self).person |
| 679 | - user.visible = false | ||
| 680 | - user.save! | 680 | + user.update_attributes(:visible => false, :name => "Person template") |
| 681 | usr_id = user.id | 681 | usr_id = user.id |
| 682 | self.settings[:enterprise_template_id] = ent_id | 682 | self.settings[:enterprise_template_id] = ent_id |
| 683 | + self.inactive_enterprise_template = inactive_enterprise_tmpl | ||
| 683 | self.settings[:community_template_id] = com_id | 684 | self.settings[:community_template_id] = com_id |
| 684 | self.settings[:person_template_id] = usr_id | 685 | self.settings[:person_template_id] = usr_id |
| 685 | self.save! | 686 | self.save! |
| @@ -687,7 +688,7 @@ class Environment < ActiveRecord::Base | @@ -687,7 +688,7 @@ class Environment < ActiveRecord::Base | ||
| 687 | 688 | ||
| 688 | after_destroy :destroy_templates | 689 | after_destroy :destroy_templates |
| 689 | def destroy_templates | 690 | def destroy_templates |
| 690 | - [enterprise_template, community_template, person_template].compact.each do |template| | 691 | + [enterprise_template, inactive_enterprise_template, community_template, person_template].compact.each do |template| |
| 691 | template.destroy | 692 | template.destroy |
| 692 | end | 693 | end |
| 693 | end | 694 | end |
app/views/admin_panel/edit_templates.rhtml
| 1 | <h1><%= _('Edit Templates') %></h1> | 1 | <h1><%= _('Edit Templates') %></h1> |
| 2 | 2 | ||
| 3 | <ul> | 3 | <ul> |
| 4 | -<li><%= link_to _('Edit Person Template'), :controller => 'profile_editor', :profile => environment.person_template.identifier %></li> | ||
| 5 | -<li><%= link_to _('Edit Community Template'), :controller => 'profile_editor', :profile => environment.community_template.identifier %></li> | ||
| 6 | -<li><%= link_to __('Edit Enterprise Template'), :controller => 'profile_editor', :profile => environment.enterprise_template.identifier %></li> | 4 | +<% [[_('Edit Person Template'), environment.person_template], |
| 5 | + [_('Edit Community Template'), environment.community_template], | ||
| 6 | + [__('Edit Enterprise Template'), environment.enterprise_template], | ||
| 7 | + [__('Edit Inactive Enterprise Template'), environment.inactive_enterprise_template]].select{|i| i[1]}.each do |row| %> | ||
| 8 | +<li><%= link_to row[0], :controller => 'profile_editor', :profile => row[1].identifier %></li> | ||
| 9 | +<% end %> | ||
| 7 | </ul> | 10 | </ul> |
| @@ -0,0 +1,53 @@ | @@ -0,0 +1,53 @@ | ||
| 1 | +Feature: edit environment templates | ||
| 2 | + As an administrator | ||
| 3 | + I want edit templates | ||
| 4 | + | ||
| 5 | + Background: | ||
| 6 | + Given that the default environment have all profile templates | ||
| 7 | + | ||
| 8 | + Scenario: See links to edit all templates | ||
| 9 | + Given I am logged in as admin | ||
| 10 | + When I follow "Administration" | ||
| 11 | + And I follow "Edit Templates" | ||
| 12 | + Then I should see "Edit Person Template" link | ||
| 13 | + And I should see "Edit Community Template" link | ||
| 14 | + And I should see "Edit Enterprise Template" link | ||
| 15 | + And I should see "Edit Inactive Enterprise Template" link | ||
| 16 | + | ||
| 17 | + Scenario: Go to control panel of person template | ||
| 18 | + Given I am logged in as admin | ||
| 19 | + When I follow "Administration" | ||
| 20 | + And I follow "Edit Templates" | ||
| 21 | + And I follow "Edit Person Template" | ||
| 22 | + Then I should be on Person template's control panel | ||
| 23 | + | ||
| 24 | + Scenario: Go to control panel of enterprise template | ||
| 25 | + Given I am logged in as admin | ||
| 26 | + When I follow "Administration" | ||
| 27 | + And I follow "Edit Templates" | ||
| 28 | + And I follow "Edit Enterprise Template" | ||
| 29 | + Then I should be on Enterprise template's control panel | ||
| 30 | + | ||
| 31 | + Scenario: Go to control panel of inactive enterprise template | ||
| 32 | + Given I am logged in as admin | ||
| 33 | + When I follow "Administration" | ||
| 34 | + And I follow "Edit Templates" | ||
| 35 | + And I follow "Edit Inactive Enterprise Template" | ||
| 36 | + Then I should be on Inactive Enterprise template's control panel | ||
| 37 | + | ||
| 38 | + Scenario: Go to control panel of community template | ||
| 39 | + Given I am logged in as admin | ||
| 40 | + When I follow "Administration" | ||
| 41 | + And I follow "Edit Templates" | ||
| 42 | + And I follow "Edit Community Template" | ||
| 43 | + Then I should be on Community template's control panel | ||
| 44 | + | ||
| 45 | + Scenario: Not see link to edit an unexistent template | ||
| 46 | + Given that the default environment have no Inactive Enterprise template | ||
| 47 | + And I am logged in as admin | ||
| 48 | + When I follow "Administration" | ||
| 49 | + And I follow "Edit Templates" | ||
| 50 | + Then I should see "Edit Person Template" link | ||
| 51 | + And I should see "Edit Community Template" link | ||
| 52 | + And I should see "Edit Enterprise Template" link | ||
| 53 | + And I should not see "Edit Inactive Enterprise Template" link |
features/step_definitions/noosfero_steps.rb
| @@ -411,3 +411,13 @@ end | @@ -411,3 +411,13 @@ end | ||
| 411 | And /^I want to add "([^\"]*)" as cost$/ do |string| | 411 | And /^I want to add "([^\"]*)" as cost$/ do |string| |
| 412 | selenium.answer_on_next_prompt(string) | 412 | selenium.answer_on_next_prompt(string) |
| 413 | end | 413 | end |
| 414 | + | ||
| 415 | +Given /^that the default environment have (.+) templates?$/ do |option| | ||
| 416 | + env = Environment.default | ||
| 417 | + case option | ||
| 418 | + when 'all profile' | ||
| 419 | + env.create_templates | ||
| 420 | + when 'no Inactive Enterprise' | ||
| 421 | + env.inactive_enterprise_template && env.inactive_enterprise_template.destroy | ||
| 422 | + end | ||
| 423 | +end |
test/unit/environment_test.rb
| @@ -303,7 +303,7 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -303,7 +303,7 @@ class EnvironmentTest < Test::Unit::TestCase | ||
| 303 | 303 | ||
| 304 | should 'destroy templates' do | 304 | should 'destroy templates' do |
| 305 | env = fast_create(Environment) | 305 | env = fast_create(Environment) |
| 306 | - templates = [mock, mock, mock] | 306 | + templates = [mock, mock, mock, mock] |
| 307 | templates.each do |item| | 307 | templates.each do |item| |
| 308 | item.expects(:destroy) | 308 | item.expects(:destroy) |
| 309 | end | 309 | end |
| @@ -311,6 +311,7 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -311,6 +311,7 @@ class EnvironmentTest < Test::Unit::TestCase | ||
| 311 | env.stubs(:person_template).returns(templates[0]) | 311 | env.stubs(:person_template).returns(templates[0]) |
| 312 | env.stubs(:community_template).returns(templates[1]) | 312 | env.stubs(:community_template).returns(templates[1]) |
| 313 | env.stubs(:enterprise_template).returns(templates[2]) | 313 | env.stubs(:enterprise_template).returns(templates[2]) |
| 314 | + env.stubs(:inactive_enterprise_template).returns(templates[3]) | ||
| 314 | 315 | ||
| 315 | env.destroy | 316 | env.destroy |
| 316 | end | 317 | end |
| @@ -507,11 +508,13 @@ class EnvironmentTest < Test::Unit::TestCase | @@ -507,11 +508,13 @@ class EnvironmentTest < Test::Unit::TestCase | ||
| 507 | 508 | ||
| 508 | # the templates must be created | 509 | # the templates must be created |
| 509 | assert_kind_of Enterprise, e.enterprise_template | 510 | assert_kind_of Enterprise, e.enterprise_template |
| 511 | + assert_kind_of Enterprise, e.inactive_enterprise_template | ||
| 510 | assert_kind_of Community, e.community_template | 512 | assert_kind_of Community, e.community_template |
| 511 | assert_kind_of Person, e.person_template | 513 | assert_kind_of Person, e.person_template |
| 512 | 514 | ||
| 513 | # the templates must be private | 515 | # the templates must be private |
| 514 | assert !e.enterprise_template.visible? | 516 | assert !e.enterprise_template.visible? |
| 517 | + assert !e.inactive_enterprise_template.visible? | ||
| 515 | assert !e.community_template.visible? | 518 | assert !e.community_template.visible? |
| 516 | assert !e.person_template.visible? | 519 | assert !e.person_template.visible? |
| 517 | end | 520 | end |