redirect_back "/", :notice => t("issues.create.successful_report")
end
else
- redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id, :reported_user_id => @issue.reported_user_id), :notice => t("issues.create.provide_details")
+ redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id), :notice => t("issues.create.provide_details")
end
end
redirect_back "/", :notice => notice
end
else
- redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id, :reported_user_id => @issue.reported_user_id), :notice => t("issues.update.provide_details")
+ redirect_to new_issue_path(:reportable_type => @issue.reportable_type, :reportable_id => @issue.reportable_id), :notice => t("issues.update.provide_details")
end
end
end
def create_new_issue_params
- params.permit(:reportable_id, :reportable_type, :reported_user_id)
+ params.permit(:reportable_id, :reportable_type)
end
def issue_params
- params[:issue].permit(:reportable_id, :reportable_type, :reported_user_id)
+ params[:issue].permit(:reportable_id, :reportable_type)
end
def report_params
validates :reportable_id, :uniqueness => { :scope => [:reportable_type] }
validates :reported_user_id, :presence => true
+ before_validation :set_reported_user
+
# Check if more statuses are needed
enum :status => %w[open ignored resolved]
enum :type => %w[administrator moderator]
transitions :from => :ignored, :to => :open
end
end
+
+ private
+
+ def set_reported_user
+ self.reported_user = case reportable.class.name
+ when "User"
+ reportable
+ when "Note"
+ reportable.author
+ else
+ reportable.user
+ end
+ end
end
<a class="geolink" href="<%= root_path %>"><span class="icon close"></span></a>
<%= t('browse.changeset.title', :id => @changeset.id) %>
<% if @user and @user.id != @changeset.user.id %>
- <%= link_to new_issue_url(reportable_id: @changeset.id, reportable_type: @changeset.class.name, reported_user_id: @changeset.user.id,referer: request.fullpath), :title => t('browse.changeset.report') do %>
+ <%= link_to new_issue_url(reportable_id: @changeset.id, reportable_type: @changeset.class.name, referer: request.fullpath), :title => t('browse.changeset.report') do %>
⚐
<% end %>
<% end %>
<a class="geolink" href="<%= root_path %>"><span class="icon close"></span></a>
<%= t "browse.note.#{@note.status}_title", :note_name => @note.id %>
<% if @user && @note.author && @user.id != @note.author.id %>
- <%= link_to new_issue_url(reportable_id: @note.id, reportable_type: @note.class.name, reported_user_id: @note.author.id,referer: request.fullpath), :title => t('browse.note.report') do %>
+ <%= link_to new_issue_url(reportable_id: @note.id, reportable_type: @note.class.name, referer: request.fullpath), :title => t('browse.note.report') do %>
⚐
<% end %>
<% end %>
<%= user_thumbnail diary_comment.user %>
<p class="deemphasize comment-heading" id="comment<%= diary_comment.id %>"><%= raw(t('diary_entry.diary_comment.comment_from', :link_user => (link_to h(diary_comment.user.display_name), :controller => 'user', :action => 'view', :display_name => diary_comment.user.display_name), :comment_created_at => link_to(l(diary_comment.created_at, :format => :friendly), :anchor => "comment#{diary_comment.id}"))) %>
<% if @user and diary_comment.user.id != @user.id %>
- <%= link_to new_issue_url(reportable_id: diary_comment.id, reportable_type: diary_comment.class.name, reported_user_id: diary_comment.user.id, referer: request.fullpath), :title => t('diary_entry.diary_comment.report') do %>
+ <%= link_to new_issue_url(reportable_id: diary_comment.id, reportable_type: diary_comment.class.name, referer: request.fullpath), :title => t('diary_entry.diary_comment.report') do %>
⚐
<% end %>
<% end %>
<h2><%= link_to h(diary_entry.title), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id %></h2>
<% if @user and diary_entry.user.id != @user.id %>
- <%= link_to new_issue_url(reportable_id: diary_entry.id, reportable_type: diary_entry.class.name, reported_user_id: diary_entry.user.id,referer: request.fullpath), :title => t('diary_entry.diary_entry.report') do %>
+ <%= 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 %>
⚐
<% end %>
<% end %>
<div class='form-row'>
<%= f.hidden_field :reportable_id %>
<%= f.hidden_field :reportable_type %>
- <%= f.hidden_field :reported_user_id %>
</div>
<div class='form-row' style='width:600px'>
<% if @user and @this_user.id != @user.id %>
<div class="report-button">
- <%= link_to new_issue_url(reportable_id: @this_user.id, reportable_type: @this_user.class.name, reported_user_id: @this_user.id,referer: request.fullpath), :title => t('user.view.report') do%>
+ <%= link_to new_issue_url(reportable_id: @this_user.id, reportable_type: @this_user.class.name, referer: request.fullpath), :title => t('user.view.report') do%>
⚐
<% end %>
</div>
require "test_helper"
class IssueTest < ActiveSupport::TestCase
- # test "the truth" do
- # assert true
- # end
+ def test_reported_user
+ note = create(:note_comment, :author => create(:user)).note
+ user = create(:user)
+ create(:language, :code => "en")
+ diary_entry = create(:diary_entry)
+ issue = Issue.new
+
+ issue.reportable = user
+ issue.save!
+ assert_equal issue.reported_user, user
+
+ # FIXME: doesn't handle anonymous notes
+ issue.reportable = note
+ issue.save!
+ assert_equal issue.reported_user, note.author
+
+ issue.reportable = diary_entry
+ issue.save!
+ assert_equal issue.reported_user, diary_entry.user
+ end
end