]> git.openstreetmap.org Git - rails.git/commitdiff
Allow reporting of anonymous notes
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 28 Feb 2018 06:26:40 +0000 (14:26 +0800)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 28 Feb 2018 06:26:40 +0000 (14:26 +0800)
app/controllers/issues_controller.rb
app/models/issue.rb
app/views/browse/note.html.erb
app/views/issues/index.html.erb
app/views/issues/show.html.erb
db/migrate/20160822153055_create_issues_and_reports.rb
db/structure.sql
test/system/issues_test.rb
test/system/report_anonymous_note_test.rb [new file with mode: 0644]

index e79a03203dfba0a32d7cc4f07b9cb1c783e2c386..dc04606f7b9044233a73a5ea04d140c2b2114db8 100644 (file)
@@ -50,7 +50,7 @@ class IssuesController < ApplicationController
     @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
 
index 83923f242bfc09ec0ba2bd94f97d0bbe9368e279..9eb6aac4c73455dcf3901307535dabc956e26da7 100644 (file)
@@ -5,7 +5,7 @@
 #  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
@@ -36,7 +36,6 @@ class Issue < ActiveRecord::Base
   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
index f292ccd197ac7e3ce4a7261d4c45b26bea115bbd..723f9d1977e777fdd7fc225ee9d4ed5d1fad00fa 100644 (file)
@@ -3,7 +3,7 @@
 <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 %>
         &nbsp;&#9872;
     <% end %>
index 4b7a2de507ee7f47fef10cc68e571f0023ce6bce..0edf364ec84d9efca84334858de7b777145a69e1 100644 (file)
@@ -38,7 +38,7 @@
         <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 %>
index b69203c4382d98e7b13188940b2a37c4a9cbdcdc..732fd2ef2a114c9ac50e1378772e196e99aa313e 100644 (file)
     <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>
index 4361c95285aa8bb2ed5687d8c41651c79111264d..ce2374c3118c3e95ce26d792d930943b8420f71b 100644 (file)
@@ -3,7 +3,7 @@ class CreateIssuesAndReports < ActiveRecord::Migration[5.0]
     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
index c7613fca4051b77182f1ba7dd2f60593435b36f5..eac2acaaf6a5fcca1c66e9132490f3ab0fe7cf0d 100644 (file)
@@ -726,7 +726,7 @@ CREATE TABLE issues (
     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,
index efe5236346e9f85a29bba19a7a4b39a6c9ca3919..f11b05a2d50fad0a2ccd07d6a17482419a40124a 100644 (file)
@@ -1,6 +1,8 @@
 require "application_system_test_case"
 
 class IssuesTest < ApplicationSystemTestCase
+  include IssuesHelper
+
   def test_view_issues_normal_user
     sign_in_as(create(:user))
 
@@ -23,6 +25,18 @@ class IssuesTest < ApplicationSystemTestCase
     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)
diff --git a/test/system/report_anonymous_note_test.rb b/test/system/report_anonymous_note_test.rb
new file mode 100644 (file)
index 0000000..a5a15d3
--- /dev/null
@@ -0,0 +1,30 @@
+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