From 5fbb8f4357fd759cadfa0191694d3bad49d86a90 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 22 Mar 2013 16:48:48 +1100 Subject: Move reporting actions to their own controller --- app/controllers/reports_controller.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 app/controllers/reports_controller.rb (limited to 'app/controllers/reports_controller.rb') diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb new file mode 100644 index 000000000..cf1ad19e7 --- /dev/null +++ b/app/controllers/reports_controller.rb @@ -0,0 +1,23 @@ +class ReportsController < ApplicationController + def report_request + info_request = InfoRequest.find_by_url_title!(params[:url_title]) + if !authenticated_user + flash[:notice] = _("You need to be logged in to report a request for administrator attention") + elsif info_request.attention_requested + flash[:notice] = _("This request has already been reported for administrator attention") + else + info_request.report!(params[:reason], params[:message], @user) + flash[:notice] = _("This request has been reported for administrator attention") + end + redirect_to request_url(info_request) + end + + def new_report_request + @info_request = InfoRequest.find_by_url_title!(params[:url_title]) + if authenticated?( + :web => _("To report this request"), + :email => _("Then you can report the request '{{title}}'", :title => @info_request.title), + :email_subject => _("Report an offensive or unsuitable request")) + end + end +end -- cgit v1.2.3 From 1e89b0ab2050238d3368fd0fbaeac66e35c80d1c Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 22 Mar 2013 17:02:23 +1100 Subject: Rename controller actions --- app/controllers/reports_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers/reports_controller.rb') diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index cf1ad19e7..070a91421 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -1,5 +1,5 @@ class ReportsController < ApplicationController - def report_request + def create info_request = InfoRequest.find_by_url_title!(params[:url_title]) if !authenticated_user flash[:notice] = _("You need to be logged in to report a request for administrator attention") @@ -12,7 +12,7 @@ class ReportsController < ApplicationController redirect_to request_url(info_request) end - def new_report_request + def new @info_request = InfoRequest.find_by_url_title!(params[:url_title]) if authenticated?( :web => _("To report this request"), -- cgit v1.2.3 From 2973621ba353cb48e251fda31631f7bfa4f57621 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 22 Mar 2013 17:15:08 +1100 Subject: Rename parameter used in routes and controller --- app/controllers/reports_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/controllers/reports_controller.rb') diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 070a91421..924eb0108 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -1,6 +1,6 @@ class ReportsController < ApplicationController def create - info_request = InfoRequest.find_by_url_title!(params[:url_title]) + info_request = InfoRequest.find_by_url_title!(params[:request_id]) if !authenticated_user flash[:notice] = _("You need to be logged in to report a request for administrator attention") elsif info_request.attention_requested @@ -13,7 +13,7 @@ class ReportsController < ApplicationController end def new - @info_request = InfoRequest.find_by_url_title!(params[:url_title]) + @info_request = InfoRequest.find_by_url_title!(params[:request_id]) if authenticated?( :web => _("To report this request"), :email => _("Then you can report the request '{{title}}'", :title => @info_request.title), -- cgit v1.2.3 From 8c5a1ba9ed8a3d30564a178926a2729b9e9931d7 Mon Sep 17 00:00:00 2001 From: Matthew Landauer Date: Fri, 22 Mar 2013 17:47:01 +1100 Subject: User needs to choose a reason --- app/controllers/reports_controller.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'app/controllers/reports_controller.rb') diff --git a/app/controllers/reports_controller.rb b/app/controllers/reports_controller.rb index 924eb0108..a1dd53125 100644 --- a/app/controllers/reports_controller.rb +++ b/app/controllers/reports_controller.rb @@ -1,15 +1,23 @@ class ReportsController < ApplicationController def create - info_request = InfoRequest.find_by_url_title!(params[:request_id]) + @info_request = InfoRequest.find_by_url_title!(params[:request_id]) + @reason = params[:reason] + @message = params[:message] + if @reason.empty? + flash[:error] = _("Please choose a reason") + render "new" + return + end + if !authenticated_user flash[:notice] = _("You need to be logged in to report a request for administrator attention") - elsif info_request.attention_requested + elsif @info_request.attention_requested flash[:notice] = _("This request has already been reported for administrator attention") else - info_request.report!(params[:reason], params[:message], @user) + @info_request.report!(@reason, @message, @user) flash[:notice] = _("This request has been reported for administrator attention") end - redirect_to request_url(info_request) + redirect_to request_url(@info_request) end def new -- cgit v1.2.3