Changed and renamed database columns
* changed user_id type to integer * renamed post_id to item_id * renamed post_type to item_type
This commit is contained in:
parent
8ae89a443b
commit
218845d5b4
10 changed files with 71 additions and 52 deletions
|
|
@ -89,8 +89,8 @@ app.views.Base = Backbone.View.extend({
|
||||||
}
|
}
|
||||||
var data = {
|
var data = {
|
||||||
report: {
|
report: {
|
||||||
post_id: this.model.id,
|
item_id: this.model.id,
|
||||||
post_type: $(evt.currentTarget).data("type"),
|
item_type: $(evt.currentTarget).data("type"),
|
||||||
text: msg
|
text: msg
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,6 @@ class ReportController < ApplicationController
|
||||||
|
|
||||||
private
|
private
|
||||||
def report_params
|
def report_params
|
||||||
params.require(:report).permit(:post_id, :post_type, :text)
|
params.require(:report).permit(:item_id, :item_type, :text)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
class Report < ActiveRecord::Base
|
class Report < ActiveRecord::Base
|
||||||
validates :user_id, presence: true
|
validates :user_id, presence: true
|
||||||
validates :post_id, presence: true
|
validates :item_id, presence: true
|
||||||
validates :post_type, presence: true
|
validates :item_type, presence: true
|
||||||
validates :text, presence: true
|
validates :text, presence: true
|
||||||
|
|
||||||
validate :entry_does_not_exist, :on => :create
|
validate :entry_does_not_exist, :on => :create
|
||||||
|
|
@ -13,22 +13,22 @@ class Report < ActiveRecord::Base
|
||||||
after_commit :send_report_notification, :on => :create
|
after_commit :send_report_notification, :on => :create
|
||||||
|
|
||||||
def entry_does_not_exist
|
def entry_does_not_exist
|
||||||
if Report.where(post_id: post_id, post_type: post_type).exists?(user_id: user_id)
|
if Report.where(item_id: item_id, item_type: item_type).exists?(user_id: user_id)
|
||||||
errors[:base] << 'You cannot report the same post twice.'
|
errors[:base] << 'You cannot report the same post twice.'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def destroy_reported_item
|
def destroy_reported_item
|
||||||
if post_type == 'post'
|
if item_type == 'post'
|
||||||
delete_post
|
delete_post
|
||||||
elsif post_type == 'comment'
|
elsif item_type == 'comment'
|
||||||
delete_comment
|
delete_comment
|
||||||
end
|
end
|
||||||
mark_as_reviewed
|
mark_as_reviewed
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_post
|
def delete_post
|
||||||
if post = Post.where(id: post_id).first
|
if post = Post.where(id: item_id).first
|
||||||
if post.author.local?
|
if post.author.local?
|
||||||
post.author.owner.retract(post)
|
post.author.owner.retract(post)
|
||||||
else
|
else
|
||||||
|
|
@ -38,7 +38,7 @@ class Report < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete_comment
|
def delete_comment
|
||||||
if comment = Comment.where(id: post_id).first
|
if comment = Comment.where(id: item_id).first
|
||||||
if comment.author.local?
|
if comment.author.local?
|
||||||
comment.author.owner.retract(comment)
|
comment.author.owner.retract(comment)
|
||||||
elsif comment.parent.author.local?
|
elsif comment.parent.author.local?
|
||||||
|
|
@ -50,10 +50,10 @@ class Report < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
|
|
||||||
def mark_as_reviewed
|
def mark_as_reviewed
|
||||||
Report.where(post_id: post_id, post_type: post_type).update_all(reviewed: true)
|
Report.where(item_id: item_id, item_type: item_type).update_all(reviewed: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
def send_report_notification
|
def send_report_notification
|
||||||
Workers::Mail::ReportWorker.perform_async(self.post_type, self.post_id)
|
Workers::Mail::ReportWorker.perform_async(self.item_type, self.item_id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,16 +6,17 @@
|
||||||
= t('report.title')
|
= t('report.title')
|
||||||
%div#reports
|
%div#reports
|
||||||
- @reports.each do |r|
|
- @reports.each do |r|
|
||||||
|
- username = User.find_by_id(r.user_id).username
|
||||||
%div.content
|
%div.content
|
||||||
%span
|
%span
|
||||||
= report_content(r.post_id, r.post_type)
|
= report_content(r.item_id, r.item_type)
|
||||||
%span
|
%span
|
||||||
= raw t('report.reported_label', person: link_to(r.user_id, user_profile_path(r.user_id)))
|
= raw t('report.reported_label', person: link_to(username, user_profile_path(username)))
|
||||||
%span
|
%span
|
||||||
= t('report.reason_label', text: r.text)
|
= t('report.reason_label', text: r.text)
|
||||||
%div.options
|
%div.options
|
||||||
%span
|
%span
|
||||||
= link_to t('report.review_link'), report_path(r.id, :type => r.post_type), method: :put
|
= link_to t('report.review_link'), report_path(r.id, :type => r.item_type), method: :put
|
||||||
%span
|
%span
|
||||||
= link_to t('report.delete_link'), report_path(r.id, :type => r.post_type), method: :delete
|
= link_to t('report.delete_link'), report_path(r.id, :type => r.item_type), method: :delete
|
||||||
%div.clear
|
%div.clear
|
||||||
|
|
|
||||||
11
db/migrate/20140422134050_rename_post_columns_to_item.rb
Normal file
11
db/migrate/20140422134050_rename_post_columns_to_item.rb
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
class RenamePostColumnsToItem < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
rename_column :reports, :post_id, :item_id
|
||||||
|
rename_column :reports, :post_type, :item_type
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
rename_column :reports, :item_id, :post_id
|
||||||
|
rename_column :reports, :item_type, :post_type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
class ChangeUserIdTypeToInteger < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
change_column :reports, :user_id, :integer
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
change_column :reports, :user_id, :string
|
||||||
|
end
|
||||||
|
end
|
||||||
9
db/migrate/20140422135040_drop_table_post_reports.rb
Normal file
9
db/migrate/20140422135040_drop_table_post_reports.rb
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
class DropTablePostReports < ActiveRecord::Migration
|
||||||
|
def up
|
||||||
|
drop_table :post_reports
|
||||||
|
end
|
||||||
|
|
||||||
|
def down
|
||||||
|
raise ActiveRecord::IrreversibleMigration
|
||||||
|
end
|
||||||
|
end
|
||||||
21
db/schema.rb
21
db/schema.rb
|
|
@ -11,7 +11,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended to check this file into your version control system.
|
# It's strongly recommended to check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(:version => 20140308154022) do
|
ActiveRecord::Schema.define(:version => 20140422135040) do
|
||||||
|
|
||||||
create_table "account_deletions", :force => true do |t|
|
create_table "account_deletions", :force => true do |t|
|
||||||
t.string "diaspora_handle"
|
t.string "diaspora_handle"
|
||||||
|
|
@ -316,17 +316,6 @@ ActiveRecord::Schema.define(:version => 20140308154022) do
|
||||||
|
|
||||||
add_index "polls", ["status_message_id"], :name => "index_polls_on_status_message_id"
|
add_index "polls", ["status_message_id"], :name => "index_polls_on_status_message_id"
|
||||||
|
|
||||||
create_table "post_reports", :force => true do |t|
|
|
||||||
t.integer "post_id", :null => false
|
|
||||||
t.string "user_id"
|
|
||||||
t.boolean "reviewed", :default => false
|
|
||||||
t.text "text"
|
|
||||||
t.datetime "created_at", :null => false
|
|
||||||
t.datetime "updated_at", :null => false
|
|
||||||
end
|
|
||||||
|
|
||||||
add_index "post_reports", ["post_id"], :name => "index_post_reports_on_post_id"
|
|
||||||
|
|
||||||
create_table "posts", :force => true do |t|
|
create_table "posts", :force => true do |t|
|
||||||
t.integer "author_id", :null => false
|
t.integer "author_id", :null => false
|
||||||
t.boolean "public", :default => false, :null => false
|
t.boolean "public", :default => false, :null => false
|
||||||
|
|
@ -411,16 +400,16 @@ ActiveRecord::Schema.define(:version => 20140308154022) do
|
||||||
add_index "rails_admin_histories", ["item", "table", "month", "year"], :name => "index_rails_admin_histories"
|
add_index "rails_admin_histories", ["item", "table", "month", "year"], :name => "index_rails_admin_histories"
|
||||||
|
|
||||||
create_table "reports", :force => true do |t|
|
create_table "reports", :force => true do |t|
|
||||||
t.integer "post_id", :null => false
|
t.integer "item_id", :null => false
|
||||||
t.string "post_type", :null => false
|
t.string "item_type", :null => false
|
||||||
t.string "user_id"
|
t.integer "user_id"
|
||||||
t.boolean "reviewed", :default => false
|
t.boolean "reviewed", :default => false
|
||||||
t.text "text"
|
t.text "text"
|
||||||
t.datetime "created_at", :null => false
|
t.datetime "created_at", :null => false
|
||||||
t.datetime "updated_at", :null => false
|
t.datetime "updated_at", :null => false
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "reports", ["post_id"], :name => "index_post_reports_on_post_id"
|
add_index "reports", ["item_id"], :name => "index_post_reports_on_post_id"
|
||||||
|
|
||||||
create_table "roles", :force => true do |t|
|
create_table "roles", :force => true do |t|
|
||||||
t.integer "person_id"
|
t.integer "person_id"
|
||||||
|
|
|
||||||
|
|
@ -33,21 +33,21 @@ describe ReportController do
|
||||||
describe '#create' do
|
describe '#create' do
|
||||||
let(:comment_hash) {
|
let(:comment_hash) {
|
||||||
{:text =>"facebook, is that you?",
|
{:text =>"facebook, is that you?",
|
||||||
:post_id =>"#{@post.id}"}
|
:item_id =>"#{@post.id}"}
|
||||||
}
|
}
|
||||||
|
|
||||||
context 'report offensive post' do
|
context 'report offensive post' do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
put :create, :report => { :post_id => @message.id, :post_type => 'post', :text => 'offensive content' }
|
put :create, :report => { :item_id => @message.id, :item_type => 'post', :text => 'offensive content' }
|
||||||
response.status.should == 200
|
response.status.should == 200
|
||||||
Report.exists?(:post_id => @message.id, :post_type => 'post').should be_true
|
Report.exists?(:item_id => @message.id, :item_type => 'post').should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context 'report offensive comment' do
|
context 'report offensive comment' do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
put :create, :report => { :post_id => @comment.id, :post_type => 'comment', :text => 'offensive content' }
|
put :create, :report => { :item_id => @comment.id, :item_type => 'comment', :text => 'offensive content' }
|
||||||
response.status.should == 200
|
response.status.should == 200
|
||||||
Report.exists?(:post_id => @comment.id, :post_type => 'comment').should be_true
|
Report.exists?(:item_id => @comment.id, :item_type => 'comment').should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -57,14 +57,14 @@ describe ReportController do
|
||||||
it 'is behind redirect_unless_admin' do
|
it 'is behind redirect_unless_admin' do
|
||||||
put :update, :id => @message.id, :type => 'post'
|
put :update, :id => @message.id, :type => 'post'
|
||||||
response.should redirect_to stream_path
|
response.should redirect_to stream_path
|
||||||
Report.where(:reviewed => false, :post_id => @message.id, :post_type => 'post').should be_true
|
Report.where(:reviewed => false, :item_id => @message.id, :item_type => 'post').should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context 'mark comment report as user' do
|
context 'mark comment report as user' do
|
||||||
it 'is behind redirect_unless_admin' do
|
it 'is behind redirect_unless_admin' do
|
||||||
put :update, :id => @comment.id, :type => 'comment'
|
put :update, :id => @comment.id, :type => 'comment'
|
||||||
response.should redirect_to stream_path
|
response.should redirect_to stream_path
|
||||||
Report.where(:reviewed => false, :post_id => @comment.id, :post_type => 'comment').should be_true
|
Report.where(:reviewed => false, :item_id => @comment.id, :item_type => 'comment').should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -75,7 +75,7 @@ describe ReportController do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
put :update, :id => @message.id, :type => 'post'
|
put :update, :id => @message.id, :type => 'post'
|
||||||
response.status.should == 302
|
response.status.should == 302
|
||||||
Report.where(:reviewed => true, :post_id => @message.id, :post_type => 'post').should be_true
|
Report.where(:reviewed => true, :item_id => @message.id, :item_type => 'post').should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context 'mark comment report as admin' do
|
context 'mark comment report as admin' do
|
||||||
|
|
@ -85,7 +85,7 @@ describe ReportController do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
put :update, :id => @comment.id, :type => 'comment'
|
put :update, :id => @comment.id, :type => 'comment'
|
||||||
response.status.should == 302
|
response.status.should == 302
|
||||||
Report.where(:reviewed => true, :post_id => @comment.id, :post_type => 'comment').should be_true
|
Report.where(:reviewed => true, :item_id => @comment.id, :item_type => 'comment').should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
@ -95,14 +95,14 @@ describe ReportController do
|
||||||
it 'is behind redirect_unless_admin' do
|
it 'is behind redirect_unless_admin' do
|
||||||
delete :destroy, :id => @message.id, :type => 'post'
|
delete :destroy, :id => @message.id, :type => 'post'
|
||||||
response.should redirect_to stream_path
|
response.should redirect_to stream_path
|
||||||
Report.where(:reviewed => false, :post_id => @message.id, :post_type => 'post').should be_true
|
Report.where(:reviewed => false, :item_id => @message.id, :item_type => 'post').should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context 'destroy comment as user' do
|
context 'destroy comment as user' do
|
||||||
it 'is behind redirect_unless_admin' do
|
it 'is behind redirect_unless_admin' do
|
||||||
delete :destroy, :id => @comment.id, :type => 'comment'
|
delete :destroy, :id => @comment.id, :type => 'comment'
|
||||||
response.should redirect_to stream_path
|
response.should redirect_to stream_path
|
||||||
Report.where(:reviewed => false, :post_id => @comment.id, :post_type => 'comment').should be_true
|
Report.where(:reviewed => false, :item_id => @comment.id, :item_type => 'comment').should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -113,7 +113,7 @@ describe ReportController do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
delete :destroy, :id => @message.id, :type => 'post'
|
delete :destroy, :id => @message.id, :type => 'post'
|
||||||
response.status.should == 302
|
response.status.should == 302
|
||||||
Report.where(:reviewed => true, :post_id => @message.id, :post_type => 'post').should be_true
|
Report.where(:reviewed => true, :item_id => @message.id, :item_type => 'post').should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
context 'destroy comment as admin' do
|
context 'destroy comment as admin' do
|
||||||
|
|
@ -123,7 +123,7 @@ describe ReportController do
|
||||||
it 'succeeds' do
|
it 'succeeds' do
|
||||||
delete :destroy, :id => @comment.id, :type => 'comment'
|
delete :destroy, :id => @comment.id, :type => 'comment'
|
||||||
response.status.should == 302
|
response.status.should == 302
|
||||||
Report.where(:reviewed => true, :post_id => @comment.id, :post_type => 'comment').should be_true
|
Report.where(:reviewed => true, :item_id => @comment.id, :item_type => 'comment').should be_true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
||||||
|
|
@ -6,30 +6,30 @@ require 'spec_helper'
|
||||||
|
|
||||||
describe Report do
|
describe Report do
|
||||||
before do
|
before do
|
||||||
#:report => { :post_id => @message.id, :post_type => 'post', :text => 'offensive content' }
|
#:report => { :item_id => @message.id, :item_type => 'post', :text => 'offensive content' }
|
||||||
@user = bob
|
@user = bob
|
||||||
@bob_post = @user.post(:status_message, :text => "hello", :to => @user.aspects.first.id)
|
@bob_post = @user.post(:status_message, :text => "hello", :to => @user.aspects.first.id)
|
||||||
@bob_comment = @user.comment!(@bob_post, "welcome")
|
@bob_comment = @user.comment!(@bob_post, "welcome")
|
||||||
|
|
||||||
@valid_post_report = {
|
@valid_post_report = {
|
||||||
:post_id => @bob_post.id,
|
:item_id => @bob_post.id,
|
||||||
:post_type => 'post',
|
:item_type => 'post',
|
||||||
:text => 'offensive content'
|
:text => 'offensive content'
|
||||||
}
|
}
|
||||||
@valid_comment_report = {
|
@valid_comment_report = {
|
||||||
:post_id => @bob_comment.id,
|
:item_id => @bob_comment.id,
|
||||||
:post_type => 'comment',
|
:item_type => 'comment',
|
||||||
:text => 'offensive content'
|
:text => 'offensive content'
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
describe '#validation' do
|
describe '#validation' do
|
||||||
it 'validates that post ID is required' do
|
it 'validates that post ID is required' do
|
||||||
@user.reports.build(:post_type => 'post', :text => 'blub').should_not be_valid
|
@user.reports.build(:item_type => 'post', :text => 'blub').should_not be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates that post type is required' do
|
it 'validates that post type is required' do
|
||||||
@user.reports.build(:post_id => 666, :text => 'blub').should_not be_valid
|
@user.reports.build(:item_id => 666, :text => 'blub').should_not be_valid
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'validates that entry does not exist' do
|
it 'validates that entry does not exist' do
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue