@read_reports = @issue.read_reports
@unread_reports = @issue.unread_reports
@comments = @issue.comments
- @related_issues = @issue.reported_user.issues.where(:assigned_role => current_user.roles.map(&:role))
+ @related_issues = @issue.reported_user.issues.where(:assigned_role => current_user.roles.map(&:role)) if @issue.reported_user
@new_comment = IssueComment.new(:issue => @issue)
end
# id :integer not null, primary key
# reportable_type :string not null
# reportable_id :integer not null
-# reported_user_id :integer not null
+# reported_user_id :integer
# status :integer
# assigned_role :enum not null
# resolved_at :datetime
has_many :comments, :class_name => "IssueComment", :dependent => :destroy
validates :reportable_id, :uniqueness => { :scope => [:reportable_type] }
- validates :reported_user_id, :presence => true
ASSIGNED_ROLES = %w[administrator moderator].freeze
validates :assigned_role, :presence => true, :inclusion => ASSIGNED_ROLES
<h2>
<a class="geolink" href="<%= root_path %>"><span class="icon close"></span></a>
<%= t "browse.note.#{@note.status}_title", :note_name => @note.id %>
- <% if current_user && @note.author && current_user.id != @note.author.id %>
+ <% if current_user && current_user != @note.author %>
<%= link_to new_report_url(reportable_id: @note.id, reportable_type: @note.class.name), :title => t('browse.note.report') do %>
⚐
<% end %>
<td><%= l(issue.updated_at.to_datetime, :format => :friendly) %></td>
<td><% if issue.user_updated %> <%= issue.user_updated.display_name %> <% else %> - <% end %></td>
<td><%= link_to reportable_title(issue.reportable), issue %></td>
- <td><%= link_to issue.reported_user.display_name , :controller => :user, :action => :view, :display_name => issue.reported_user.display_name %></td>
+ <td><%= link_to issue.reported_user.display_name, :controller => :user, :action => :view, :display_name => issue.reported_user.display_name if issue.reported_user %></td>
<td><%= link_to t(".show_instance"), reportable_url(issue.reportable) %></td>
</tr>
<% end %>
<br/>
</div>
- <div class="related-block">
- <h3><%= t ".other_issues_against_this_user" %></h3>
- <div class="unread-reports">
- <% if @related_issues.count > 1 %>
- <% @related_issues.each do |issue| %>
- <% if issue.id != @issue.id %>
- <%= link_to reportable_title(issue.reportable), issue %> <br/>
+ <% if @issue.reported_user %>
+ <div class="related-block">
+ <h3><%= t ".other_issues_against_this_user" %></h3>
+ <div class="unread-reports">
+ <% if @related_issues.count > 1 %>
+ <% @related_issues.each do |issue| %>
+ <% if issue.id != @issue.id %>
+ <%= link_to reportable_title(issue.reportable), issue %> <br/>
+ <% end %>
<% end %>
+ <% else %>
+ <p><%= t ".no_other_issues" %></p>
<% end %>
- <% else %>
- <p><%= t ".no_other_issues" %></p>
- <% end %>
+ </div>
</div>
- </div>
+ <% end %>
</div>
<h3><%= t ".comments_on_this_issue" %></h3>
create_table :issues do |t|
t.string :reportable_type, :null => false
t.integer :reportable_id, :null => false
- t.integer :reported_user_id, :null => false
+ t.integer :reported_user_id
t.integer :status
t.column :assigned_role, :user_role_enum, :null => false
t.datetime :resolved_at
id integer NOT NULL,
reportable_type character varying NOT NULL,
reportable_id integer NOT NULL,
- reported_user_id integer NOT NULL,
+ reported_user_id integer,
status integer,
assigned_role user_role_enum NOT NULL,
resolved_at timestamp without time zone,
require "application_system_test_case"
class IssuesTest < ApplicationSystemTestCase
+ include IssuesHelper
+
def test_view_issues_normal_user
sign_in_as(create(:user))
assert page.has_content?(issues.first.reported_user.display_name)
end
+ def test_view_issues_with_no_reported_user
+ sign_in_as(create(:moderator_user))
+ anonymous_note = create(:note_with_comments)
+ issue = create(:issue, :reportable => anonymous_note)
+
+ visit issues_path
+ assert page.has_content?(reportable_title(anonymous_note))
+
+ visit issue_path(issue)
+ assert page.has_content?(reportable_title(anonymous_note))
+ end
+
def test_search_issues_by_user
good_user = create(:user)
bad_user = create(:user)
--- /dev/null
+require "application_system_test_case"
+
+class ReportAnonymousNoteTest < ApplicationSystemTestCase
+ def test_no_flag_when_not_logged_in
+ note = create(:note_with_comments)
+ visit browse_note_path(note)
+ assert page.has_content?(note.comments.first.body)
+
+ assert !page.has_content?("\u2690")
+ end
+
+ def test_can_report_anonymous_notes
+ note = create(:note_with_comments)
+ sign_in_as(create(:user))
+ visit browse_note_path(note)
+
+ click_on "\u2690"
+ assert page.has_content? "Report"
+ assert page.has_content? I18n.t("issues.new.disclaimer.intro")
+
+ choose I18n.t("reports.categories.Note.spam")
+ fill_in "report_details", :with => "This is spam"
+ click_on "Create Report"
+
+ assert page.has_content? "Your report has been registered sucessfully"
+
+ assert_equal 1, Issue.count
+ assert Issue.last.reportable == note
+ end
+end