From 9de0f762e26660ae2c3c5bbff83468fd12253293 Mon Sep 17 00:00:00 2001 From: Victor Costa Date: Thu, 23 Oct 2014 10:22:10 -0300 Subject: [PATCH] proposals_discussion: display an error when trying to create a proposal without a topic --- controllers/myprofile/proposals_discussion_plugin_myprofile_controller.rb | 14 +++++++++++--- test/functional/proposals_discussion_plugin_myprofile_controller_test.rb | 7 ++++++- views/proposals_discussion_plugin_myprofile/select_topic.html.erb | 39 +++++++++++++++++++++++++++++++++++++++ views/select_topic.html.erb | 37 ------------------------------------- 4 files changed, 56 insertions(+), 41 deletions(-) create mode 100644 views/proposals_discussion_plugin_myprofile/select_topic.html.erb delete mode 100644 views/select_topic.html.erb diff --git a/controllers/myprofile/proposals_discussion_plugin_myprofile_controller.rb b/controllers/myprofile/proposals_discussion_plugin_myprofile_controller.rb index 9aaf14a..f02a4a5 100644 --- a/controllers/myprofile/proposals_discussion_plugin_myprofile_controller.rb +++ b/controllers/myprofile/proposals_discussion_plugin_myprofile_controller.rb @@ -1,14 +1,18 @@ class ProposalsDiscussionPluginMyprofileController < MyProfileController before_filter :check_edit_permission_to_proposal, :only => :publish_proposal + before_filter :set_discussion, :only => [:select_topic, :new_proposal] def select_topic - @discussion = profile.articles.find(params[:parent_id]) - render :file => 'select_topic' end def new_proposal - redirect_to :controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Proposal", :parent_id => params[:discussion][:topic] + if params[:discussion].blank? || params[:discussion][:topic].blank? + session[:notice] = _('Please select a topic') + render :file => 'proposals_discussion_plugin_myprofile/select_topic' + else + redirect_to :controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Proposal", :parent_id => params[:discussion][:topic] + end end def publish_proposal @@ -27,4 +31,8 @@ class ProposalsDiscussionPluginMyprofileController < MyProfileController render_access_denied unless @proposal.allow_edit?(user) end + def set_discussion + @discussion = profile.articles.find(params[:parent_id]) + end + end diff --git a/test/functional/proposals_discussion_plugin_myprofile_controller_test.rb b/test/functional/proposals_discussion_plugin_myprofile_controller_test.rb index 2ea908d..d4ef2ee 100644 --- a/test/functional/proposals_discussion_plugin_myprofile_controller_test.rb +++ b/test/functional/proposals_discussion_plugin_myprofile_controller_test.rb @@ -24,7 +24,7 @@ class ProposalsDiscussionPluginMyprofileControllerTest < ActionController::TestC end should 'new_proposal redirect to cms controller' do - get :new_proposal, :profile => profile.identifier, :discussion => {:topic => topic.id} + get :new_proposal, :profile => profile.identifier, :discussion => {:topic => topic.id}, :parent_id => discussion.id assert_redirected_to :controller => 'cms', :action => 'new', :type => "ProposalsDiscussionPlugin::Proposal", :parent_id => topic.id end @@ -41,4 +41,9 @@ class ProposalsDiscussionPluginMyprofileControllerTest < ActionController::TestC assert !proposal.reload.published end + should 'new_proposal without a topic redirect to back' do + get :new_proposal, :profile => profile.identifier, :parent_id => discussion.id + assert_template 'select_topic' + end + end diff --git a/views/proposals_discussion_plugin_myprofile/select_topic.html.erb b/views/proposals_discussion_plugin_myprofile/select_topic.html.erb new file mode 100644 index 0000000..8eeee03 --- /dev/null +++ b/views/proposals_discussion_plugin_myprofile/select_topic.html.erb @@ -0,0 +1,39 @@ + + +
+

<%= @discussion.title %>

+ <%= form_for :discussion, :url => {:controller => 'proposals_discussion_plugin_myprofile', :action => 'new_proposal'} do %> + +

<%= _('Select topic') %>

+
+ + <% @discussion.topics.each do |topic| %> +

+ <%= radio_button_tag('discussion[topic]', topic.id) %> + <%= topic.title %> +

+
+ <%= topic.body %> +
+ <% end %> + +
+
+ + <%= hidden_field_tag :parent_id, @discussion.id %> + +
+ <%= submit_button(:next, _('Next')) %> + <%= button :cancel, _('Cancel'), @discussion.view_url %> +
+ <% end %> +
diff --git a/views/select_topic.html.erb b/views/select_topic.html.erb deleted file mode 100644 index 7f28c6a..0000000 --- a/views/select_topic.html.erb +++ /dev/null @@ -1,37 +0,0 @@ - - -
-

<%= @discussion.title %>

- <%= form_for :discussion, :url => {:controller => 'proposals_discussion_plugin_myprofile', :action => 'new_proposal'} do %> - -

<%= _('Select topic') %>

-
- - <% @discussion.topics.each do |topic| %> -

- <%= radio_button_tag('discussion[topic]', topic.id) %> - <%= topic.title %> -

-
- <%= topic.body %> -
- <% end %> - -
-
- -
- <%= submit_button(:next, _('Next')) %> - <%= button :cancel, _('Cancel'), @discussion.view_url %> -
- <% end %> -
-- libgit2 0.21.2