It's really a report that the user is creating, the issue is created indirectly. Similar
refactoring will be required for issue comments.
@related_issues = @issue.reported_user.issues.where(:issue_type => @user_role)
end
- def new
- if create_new_issue_params.present?
- @issue = Issue.find_or_initialize_by(create_new_issue_params)
- path = "issues.report_strings." + @issue.reportable.class.name.to_s
- @report_strings_yaml = t(path)
- end
- end
-
- def create
- @issue = Issue.find_by(:reportable_id => params[:reportable_id], :reportable_type => params[:reportable_type])
- # Check if Issue already exists
- unless @issue
- @issue = Issue.find_or_initialize_by(issue_params)
- @issue.updated_by = nil
-
- # Reassign to moderators if it is a moderator issue
- @issue.issue_type = "administrator"
- reassign_issue if @moderator_issues.include? @issue.reportable.class.name
- end
-
- # Check if details provided are sufficient
- if check_report_params
- @report = @issue.reports.build(report_params)
- details = report_details
- @report.reporter_user_id = current_user.id
- @report.details = details
- # Checking if instance has been updated since last report
- @last_report = @issue.reports.order(:updated_at => :desc).last
- if check_if_updated
- @issue.save! if @issue.reopen
- end
-
- if @issue.save!
- @issue.report_count = @issue.reports.count
- @issue.save!
-
- @admins_or_mods = UserRole.where(:role => @issue.issue_type)
- @admins_or_mods.each do |user|
- Notifier.new_issue_notification(@issue.id, User.find(user.user_id)).deliver_now
- end
-
- redirect_back :fallback_location => "/", :notice => t("issues.create.successful_report")
- end
- else
- redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id), :notice => t("issues.create.provide_details")
- end
- end
-
def update
@issue = Issue.find_by(issue_params)
# Check if details provided are sufficient
end
end
- def create_new_issue_params
- params.permit(:reportable_id, :reportable_type)
- end
-
def issue_params
params[:issue].permit(:reportable_id, :reportable_type)
end
--- /dev/null
+class ReportsController < ApplicationController
+ layout "site"
+
+ before_action :authorize_web
+ before_action :require_user
+
+ def new
+ if create_new_report_params.present?
+ @report = Report.new
+ @report.issue = Issue.find_or_initialize_by(create_new_report_params)
+ path = "issues.report_strings." + @report.issue.reportable.class.name.to_s
+ @report_strings_yaml = t(path)
+ end
+ end
+
+ def create
+ @report = current_user.reports.new(report_params)
+ @report.issue = Issue.find_or_initialize_by(:reportable_id => params[:report][:issue][:reportable_id], :reportable_type => params[:report][:issue][:reportable_type])
+
+ if @report.save
+ @report.issue.save
+ # FIXME: reopen issue if necessary
+ # FIXME: new issue notification (or via model observer)
+ redirect_to root_path, :notice => t("issues.create.successful_report")
+ else
+ redirect_to new_report_path(:reportable_type => @report.issue.reportable_type, :reportable_id => @report.issue.reportable_id), :notice => t("issues.create.provide_details")
+ end
+ end
+
+ private
+
+ def create_new_report_params
+ params.permit(:reportable_id, :reportable_type)
+ end
+
+ def report_params
+ params[:report].permit(:details)
+ end
+end
<h2><%= link_to h(diary_entry.title), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id %></h2>
- <% if current_user and diary_entry.user.id != current_user.id %>
- <%= link_to new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, referer: request.fullpath), :title => t('diary_entry.diary_entry.report') do %>
+ <% if current_user and diary_entry.user != current_user %>
+ <%= link_to new_report_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name), :title => t('diary_entry.diary_entry.report') do %>
⚐
<% end %>
<% end %>
<% content_for :heading do %>
- <h1>Report <%= reportable_url(@issue.reportable) %></h1>
+ <h1>Report <%= reportable_url(@report.issue.reportable) %></h1>
<% end %>
<div class="disclaimer">
</ul>
</div>
-<%= form_for(@issue) do |f| %>
+<%= form_for(@report) do |f| %>
<%= f.error_messages %>
<fieldset>
- <div class='form-row'>
- <%= f.hidden_field :reportable_id %>
- <%= f.hidden_field :reportable_type %>
- </div>
+ <%= f.fields_for @report.issue do |issue_form| %>
+ <%= issue_form.hidden_field :reportable_id %>
+ <%= issue_form.hidden_field :reportable_type %>
+ <% end %>
<div class='form-row' style='width:600px'>
<p><%= t('issues.new.select') %>:</p>
end
end
+ resources :reports
+
post "/comment" => "issues#comment"
# redactions