From 8a5c98ff30faef1df4aed138ae053b08739e2750 Mon Sep 17 00:00:00 2001 From: MoisesMachado Date: Sat, 23 Aug 2008 23:12:59 +0000 Subject: [PATCH] ActionItem591: setted the templates and iterface to edit them --- app/controllers/admin/admin_panel_controller.rb | 3 +++ app/models/environment.rb | 34 +++++++++++++++++++++++++++++++--- app/views/admin_panel/edit_templates.rhtml | 7 +++++++ app/views/admin_panel/index.rhtml | 1 + lib/tasks/populate.rake | 6 ++++++ test/unit/environment_test.rb | 18 ++++++++++++++++++ 6 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 app/views/admin_panel/edit_templates.rhtml diff --git a/app/controllers/admin/admin_panel_controller.rb b/app/controllers/admin/admin_panel_controller.rb index 2cde1da..925b930 100644 --- a/app/controllers/admin/admin_panel_controller.rb +++ b/app/controllers/admin/admin_panel_controller.rb @@ -20,6 +20,9 @@ class AdminPanelController < AdminController end end + def edit_templates + end + protected def load_default_enviroment diff --git a/app/models/environment.rb b/app/models/environment.rb index 43d5a37..d5703b3 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -31,7 +31,7 @@ class Environment < ActiveRecord::Base 'disable_products_for_enterprises' => _('Disable products for enterprises'), } end - + # ################################################# # Relationships and applied behaviour # ################################################# @@ -90,7 +90,7 @@ class Environment < ActiveRecord::Base def settings self[:settings] ||= {} end - + # Enables a feature identified by its name def enable(feature) self.settings["#{feature}_enabled"] = true @@ -193,7 +193,7 @@ class Environment < ActiveRecord::Base self.settings['organization_approval_method'] = actual_value end - + # the description of the environment. Normally used in the homepage. def description self.settings[:description] @@ -263,4 +263,32 @@ class Environment < ActiveRecord::Base self[:theme] || 'default' end + def enterprise_template + Enterprise.find settings[:enterprise_template_id] + end + + def community_template + Community.find settings[:community_template_id] + end + + def person_template + Person.find settings[:person_template_id] + end + + after_create do |env| + pre = env.name.to_slug + '_' + ent_id = Enterprise.create!(:name => 'Enterprise template', :identifier => pre + 'enterprise_template', :environment => env, :public_profile => false).id + com_id = Community.create!(:name => 'Community template', :identifier => pre + 'community_template', :environment => env, :public_profile => false).id + pass = Digest::MD5.hexdigest rand.to_s + user = User.create!(:login => 'person_template', :email => 'template@template.noo', :password => pass, :password_confirmation => pass).person + user.environment = env + user.public_profile = false + user.save! + usr_id = user.id + env.settings[:enterprise_template_id] = ent_id + env.settings[:community_template_id] = com_id + env.settings[:person_template_id] = usr_id + env.save! + end + end diff --git a/app/views/admin_panel/edit_templates.rhtml b/app/views/admin_panel/edit_templates.rhtml new file mode 100644 index 0000000..9704ca5 --- /dev/null +++ b/app/views/admin_panel/edit_templates.rhtml @@ -0,0 +1,7 @@ +

<%= _('Edit Templates') %>

+ + diff --git a/app/views/admin_panel/index.rhtml b/app/views/admin_panel/index.rhtml index 154c393..e66e50a 100644 --- a/app/views/admin_panel/index.rhtml +++ b/app/views/admin_panel/index.rhtml @@ -10,4 +10,5 @@
  • <%= link_to _('Manage Categories'), :controller => 'categories'%>
  • <%= link_to _('Manage User roles'), :controller => 'role' %>
  • <%= link_to _('Manage Validators by region'), :controller => 'region_validators' %>
  • +
  • <%= link_to _('Edit Templates'), :action => 'edit_templates' %>
  • diff --git a/lib/tasks/populate.rake b/lib/tasks/populate.rake index d33b170..3745ace 100644 --- a/lib/tasks/populate.rake +++ b/lib/tasks/populate.rake @@ -30,6 +30,12 @@ def create_roles 'manage_environment_categories', 'manage_environment_roles', 'manage_environment_validators', + 'edit_profile', + 'destroy_profile', + 'manage_memberships', + 'post_content', + 'edit_profile_design', + 'manage_products', ]) Role.create!(:key => 'profile_admin', :name => N_('Profile Administrator'), :permissions => [ 'edit_profile', diff --git a/test/unit/environment_test.rb b/test/unit/environment_test.rb index 548b782..6c0f143 100644 --- a/test/unit/environment_test.rb +++ b/test/unit/environment_test.rb @@ -379,4 +379,22 @@ class EnvironmentTest < Test::Unit::TestCase assert_equal 'default', Environment.new.theme end + should 'create templates' do + e = Environment.create!(:name => 'test_env') + e.reload + + assert_kind_of Enterprise, e.enterprise_template + assert_kind_of Community, e.community_template + assert_kind_of Person, e.person_template + end + + should 'have private templates' do + e = Environment.create!(:name => 'test_env') + e.reload + + assert !e.enterprise_template.public? + assert !e.community_template.public? + assert !e.person_template.public? + end + end -- libgit2 0.21.2