Diff
Added: trunk/app/controllers/user_reports_controller.rb (0 => 2662)
--- trunk/app/controllers/user_reports_controller.rb (rev 0)
+++ trunk/app/controllers/user_reports_controller.rb 2011-08-02 14:48:52 UTC (rev 2662)
@@ -0,0 +1,43 @@
+# myExperiment: app/controllers/user_reports_controller.rb
+#
+# Copyright (c) 2011 University of Manchester and the University of Southampton.
+# See license.txt for details.
+
+class UserReportsController < ApplicationController
+
+ before_filter :find_object
+
+ def create
+ UserReport.create(:user => current_user, :subject => @object)
+ render(:text => '[ reported ]')
+ end
+
+ private
+
+ def find_object
+
+ # ensure that user is logged in and that params[:user_id] matches
+ return error if (current_user == 0 || (current_user.id.to_s != params[:user_id]))
+
+ # ensure that the object type is valid
+ return error unless ["Comment", "Message"].include?(params[:subject_type])
+
+ object = Object.const_get(params[:subject_type]).find(params[:subject_id])
+
+ # ensure that the object exists
+ return error if object.nil?
+
+ # ensure that the object is visible to the user
+ return error unless Authorization.check(:action ="" 'read', :object => object, :user => current_user)
+
+ @object = object
+
+ true
+ end
+
+ def error
+ render(:text => '400 Bad Request', :status => "400 Bad Request")
+ false
+ end
+end
+
Modified: trunk/app/views/comments/_comment.rhtml (2661 => 2662)
--- trunk/app/views/comments/_comment.rhtml 2011-08-02 12:41:07 UTC (rev 2661)
+++ trunk/app/views/comments/_comment.rhtml 2011-08-02 14:48:52 UTC (rev 2662)
@@ -16,6 +16,7 @@
</tr>
<tr>
<td style="text-align: right; padding-right: 1em;">
+ <%= render(:partial => 'contributions/user_report', :locals => { :subject => comment, :user => current_user }) -%>
<% if Authorization.check(:action ="" 'destroy', :object => comment, :user => current_user) %>
<small>
[
Modified: trunk/app/views/messages/show.rhtml (2661 => 2662)
--- trunk/app/views/messages/show.rhtml 2011-08-02 12:41:07 UTC (rev 2661)
+++ trunk/app/views/messages/show.rhtml 2011-08-02 14:48:52 UTC (rev 2662)
@@ -59,6 +59,10 @@
<p class="none_text">No message body</p>
<% end %>
</div>
+
+ <div style="margin: 6px; text-align: right">
+ <%= render(:partial => 'contributions/user_report', :locals => { :subject => @message, :user => current_user }) -%>
+ </div>
</div>
<%= render :partial => "contributions/alternative_formats" %>
Modified: trunk/config/base_schema.xml (2661 => 2662)
--- trunk/config/base_schema.xml 2011-08-02 12:41:07 UTC (rev 2661)
+++ trunk/config/base_schema.xml 2011-08-02 14:48:52 UTC (rev 2662)
@@ -59,7 +59,21 @@
<column type="datetime" name="updated_at"/>
</table>
-
+
+ <table name="user_reports">
+
+ <column type="integer" name="user_id"/>
+ <column type="string" name="subject_type"/>
+ <column type="integer" name="subject_id"/>
+ <column type="text" name="content"/>
+ <column type="text" name="report"/>
+ <column type="datetime" name="created_at"/>
+
+ <belongs-to target="users"/>
+ <belongs-to target="subject" polymorphic="true"/>
+
+ </table>
+
<table name="previews">
<column type="integer" name="image_blob_id"/>
Modified: trunk/config/routes.rb (2661 => 2662)
--- trunk/config/routes.rb 2011-08-02 12:41:07 UTC (rev 2661)
+++ trunk/config/routes.rb 2011-08-02 14:48:52 UTC (rev 2662)
@@ -227,6 +227,9 @@
# user's history
user.resource :userhistory, :controller => :userhistory
+
+ # user's reports of inappropriate content
+ user.resources :reports, :controller => :user_reports
end
map.resources :groups,