diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb
index 3ee21a3..0387b4f 100644
--- a/app/controllers/my_profile/profile_editor_controller.rb
+++ b/app/controllers/my_profile/profile_editor_controller.rb
@@ -3,6 +3,9 @@ class ProfileEditorController < MyProfileController
protect 'edit_profile', :profile, :except => [:destroy_profile]
protect 'destroy_profile', :profile, :only => [:destroy_profile]
+ before_filter :access_welcome_page, :only => [:welcome_page]
+ helper_method :has_welcome_page
+
def index
@pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)}
end
@@ -78,4 +81,31 @@ class ProfileEditorController < MyProfileController
end
end
end
+
+ def welcome_page
+ @welcome_page = profile.welcome_page || TinyMceArticle.new(:name => 'Welcome Page', :profile => profile)
+ if request.post?
+ begin
+ @welcome_page.update_attributes!(params[:welcome_page])
+ profile.welcome_page = @welcome_page
+ profile.save!
+ session[:notice] = _('Welcome page saved successfully.')
+ redirect_to :action => 'index'
+ rescue Exception => exception
+ session[:notice] = _('Welcome page could not be saved.')
+ end
+ end
+ end
+
+ private
+
+ def has_welcome_page
+ profile.person? && profile.is_template
+ end
+
+ def access_welcome_page
+ unless has_welcome_page
+ render_access_denied
+ end
+ end
end
diff --git a/app/views/profile_editor/index.html.erb b/app/views/profile_editor/index.html.erb
index 0e9ba73..226fee2 100644
--- a/app/views/profile_editor/index.html.erb
+++ b/app/views/profile_editor/index.html.erb
@@ -68,6 +68,8 @@
<%= control_panel_button(_('Manage SPAM'), 'manage-spam', :controller => 'spam', :action => 'index') %>
+ <%= control_panel_button(_('Edit Welcome Page'), 'welcome', :action => 'welcome_page') if has_welcome_page %>
+
<% @plugins.dispatch(:control_panel_buttons).each do |button| %>
<%= control_panel_button(button[:title], button[:icon], button[:url]) %>
<% end %>
diff --git a/app/views/profile_editor/welcome_page.html.erb b/app/views/profile_editor/welcome_page.html.erb
new file mode 100644
index 0000000..2a5aef7
--- /dev/null
+++ b/app/views/profile_editor/welcome_page.html.erb
@@ -0,0 +1,19 @@
+
<%= _('Edit welcome page') %>
+
+<% labelled_form_for :welcome_page, @welcome_page do |f| %>
+ <%= f.check_box(:published) %>
+
+ <%= _('Your welcome page will only be displayed if this options is selected.') %>
+
+
+ <%= f.text_area(:body, :cols => 40, :style => 'width: 100%', :class => 'mceEditor') %>
+
+ <%= _('This page will be displayed to the user after his signup with this template.') %>
+
+
+ <% button_bar do%>
+ <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %>
+ <% end %>
+<% end %>
+
+<%= render :file => 'shared/tiny_mce' %>
diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb
index 854dcea..7488477 100644
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -876,6 +876,55 @@ class ProfileEditorControllerTest < ActionController::TestCase
end
end
+ should 'have welcome_page only for person template' do
+ organization = fast_create(Organization, :is_template => false)
+ @controller.stubs(:profile).returns(organization)
+ assert !@controller.send(:has_welcome_page)
+
+ organization = fast_create(Organization, :is_template => true)
+ @controller.stubs(:profile).returns(organization)
+ assert !@controller.send(:has_welcome_page)
+
+ person = fast_create(Person, :is_template => false)
+ @controller.stubs(:profile).returns(person)
+ assert !@controller.send(:has_welcome_page)
+
+ person = fast_create(Person, :is_template => true)
+ @controller.stubs(:profile).returns(person)
+ assert @controller.send(:has_welcome_page)
+ end
+
+ should 'display welcome_page button only if profile has_welcome_page' do
+ @controller.stubs(:has_welcome_page).returns(true)
+ get :index, :profile => fast_create(Profile).identifier
+ assert_tag :tag => 'a', :content => 'Edit Welcome Page'
+
+ @controller.stubs(:has_welcome_page).returns(false)
+ get :index, :profile => fast_create(Profile).identifier
+ assert_no_tag :tag => 'a', :content => 'Edit Welcome Page'
+ end
+
+ should 'not be able to access welcome_page if profile does not has_welcome_page' do
+ @controller.stubs(:has_welcome_page).returns(false)
+ get :welcome_page, :profile => fast_create(Profile).identifier
+ assert_response :forbidden
+ end
+
+ should 'update welcome page and redirect to index' do
+ welcome_page = fast_create(TinyMceArticle, :body => 'Initial welcome page')
+ person_template = create_user('person_template').person
+ person_template.is_template = true
+ person_template.welcome_page = welcome_page
+ person_template.save!
+ new_content = 'New welcome page'
+
+ post :welcome_page, :profile => person_template.identifier, :welcome_page => {:body => new_content}
+ assert_redirected_to :action => 'index'
+
+ welcome_page.reload
+ assert_equal new_content, welcome_page.body
+ end
+
should 'display plugins buttons on the control panel' do
class TestControlPanelButtons1 < Noosfero::Plugin
--
libgit2 0.21.2