Commit bde757c9677967d25968544af068b77f657cd6de
1 parent
55fbbbb6
Exists in
master
and in
29 other branches
[template-welcome-page] Person template welcome page edition
(ActionItem3075)
Showing
4 changed files
with
100 additions
and
0 deletions
Show diff stats
app/controllers/my_profile/profile_editor_controller.rb
... | ... | @@ -3,6 +3,9 @@ class ProfileEditorController < MyProfileController |
3 | 3 | protect 'edit_profile', :profile, :except => [:destroy_profile] |
4 | 4 | protect 'destroy_profile', :profile, :only => [:destroy_profile] |
5 | 5 | |
6 | + before_filter :access_welcome_page, :only => [:welcome_page] | |
7 | + helper_method :has_welcome_page | |
8 | + | |
6 | 9 | def index |
7 | 10 | @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)} |
8 | 11 | end |
... | ... | @@ -78,4 +81,31 @@ class ProfileEditorController < MyProfileController |
78 | 81 | end |
79 | 82 | end |
80 | 83 | end |
84 | + | |
85 | + def welcome_page | |
86 | + @welcome_page = profile.welcome_page || TinyMceArticle.new(:name => 'Welcome Page', :profile => profile) | |
87 | + if request.post? | |
88 | + begin | |
89 | + @welcome_page.update_attributes!(params[:welcome_page]) | |
90 | + profile.welcome_page = @welcome_page | |
91 | + profile.save! | |
92 | + session[:notice] = _('Welcome page saved successfully.') | |
93 | + redirect_to :action => 'index' | |
94 | + rescue Exception => exception | |
95 | + session[:notice] = _('Welcome page could not be saved.') | |
96 | + end | |
97 | + end | |
98 | + end | |
99 | + | |
100 | + private | |
101 | + | |
102 | + def has_welcome_page | |
103 | + profile.person? && profile.is_template | |
104 | + end | |
105 | + | |
106 | + def access_welcome_page | |
107 | + unless has_welcome_page | |
108 | + render_access_denied | |
109 | + end | |
110 | + end | |
81 | 111 | end | ... | ... |
app/views/profile_editor/index.html.erb
... | ... | @@ -68,6 +68,8 @@ |
68 | 68 | |
69 | 69 | <%= control_panel_button(_('Manage SPAM'), 'manage-spam', :controller => 'spam', :action => 'index') %> |
70 | 70 | |
71 | + <%= control_panel_button(_('Edit Welcome Page'), 'welcome', :action => 'welcome_page') if has_welcome_page %> | |
72 | + | |
71 | 73 | <% @plugins.dispatch(:control_panel_buttons).each do |button| %> |
72 | 74 | <%= control_panel_button(button[:title], button[:icon], button[:url]) %> |
73 | 75 | <% end %> | ... | ... |
... | ... | @@ -0,0 +1,19 @@ |
1 | +<h1><%= _('Edit welcome page') %></h1> | |
2 | + | |
3 | +<% labelled_form_for :welcome_page, @welcome_page do |f| %> | |
4 | + <%= f.check_box(:published) %> | |
5 | + <div class='explanation'> | |
6 | + <%= _('Your welcome page will only be displayed if this options is selected.') %> | |
7 | + </div> | |
8 | + | |
9 | + <%= f.text_area(:body, :cols => 40, :style => 'width: 100%', :class => 'mceEditor') %> | |
10 | + <div class='explanation'> | |
11 | + <%= _('This page will be displayed to the user after his signup with this template.') %> | |
12 | + </div> | |
13 | + | |
14 | + <% button_bar do%> | |
15 | + <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %> | |
16 | + <% end %> | |
17 | +<% end %> | |
18 | + | |
19 | +<%= render :file => 'shared/tiny_mce' %> | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -876,6 +876,55 @@ class ProfileEditorControllerTest < ActionController::TestCase |
876 | 876 | end |
877 | 877 | end |
878 | 878 | |
879 | + should 'have welcome_page only for person template' do | |
880 | + organization = fast_create(Organization, :is_template => false) | |
881 | + @controller.stubs(:profile).returns(organization) | |
882 | + assert !@controller.send(:has_welcome_page) | |
883 | + | |
884 | + organization = fast_create(Organization, :is_template => true) | |
885 | + @controller.stubs(:profile).returns(organization) | |
886 | + assert !@controller.send(:has_welcome_page) | |
887 | + | |
888 | + person = fast_create(Person, :is_template => false) | |
889 | + @controller.stubs(:profile).returns(person) | |
890 | + assert !@controller.send(:has_welcome_page) | |
891 | + | |
892 | + person = fast_create(Person, :is_template => true) | |
893 | + @controller.stubs(:profile).returns(person) | |
894 | + assert @controller.send(:has_welcome_page) | |
895 | + end | |
896 | + | |
897 | + should 'display welcome_page button only if profile has_welcome_page' do | |
898 | + @controller.stubs(:has_welcome_page).returns(true) | |
899 | + get :index, :profile => fast_create(Profile).identifier | |
900 | + assert_tag :tag => 'a', :content => 'Edit Welcome Page' | |
901 | + | |
902 | + @controller.stubs(:has_welcome_page).returns(false) | |
903 | + get :index, :profile => fast_create(Profile).identifier | |
904 | + assert_no_tag :tag => 'a', :content => 'Edit Welcome Page' | |
905 | + end | |
906 | + | |
907 | + should 'not be able to access welcome_page if profile does not has_welcome_page' do | |
908 | + @controller.stubs(:has_welcome_page).returns(false) | |
909 | + get :welcome_page, :profile => fast_create(Profile).identifier | |
910 | + assert_response :forbidden | |
911 | + end | |
912 | + | |
913 | + should 'update welcome page and redirect to index' do | |
914 | + welcome_page = fast_create(TinyMceArticle, :body => 'Initial welcome page') | |
915 | + person_template = create_user('person_template').person | |
916 | + person_template.is_template = true | |
917 | + person_template.welcome_page = welcome_page | |
918 | + person_template.save! | |
919 | + new_content = 'New welcome page' | |
920 | + | |
921 | + post :welcome_page, :profile => person_template.identifier, :welcome_page => {:body => new_content} | |
922 | + assert_redirected_to :action => 'index' | |
923 | + | |
924 | + welcome_page.reload | |
925 | + assert_equal new_content, welcome_page.body | |
926 | + end | |
927 | + | |
879 | 928 | should 'display plugins buttons on the control panel' do |
880 | 929 | |
881 | 930 | class TestControlPanelButtons1 < Noosfero::Plugin | ... | ... |