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 = {
|
||||
report: {
|
||||
post_id: this.model.id,
|
||||
post_type: $(evt.currentTarget).data("type"),
|
||||
item_id: this.model.id,
|
||||
item_type: $(evt.currentTarget).data("type"),
|
||||
text: msg
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -37,6 +37,6 @@ class ReportController < ApplicationController
|
|||
|
||||
private
|
||||
def report_params
|
||||
params.require(:report).permit(:post_id, :post_type, :text)
|
||||
params.require(:report).permit(:item_id, :item_type, :text)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
class Report < ActiveRecord::Base
|
||||
validates :user_id, presence: true
|
||||
validates :post_id, presence: true
|
||||
validates :post_type, presence: true
|
||||
validates :item_id, presence: true
|
||||
validates :item_type, presence: true
|
||||
validates :text, presence: true
|
||||
|
||||
validate :entry_does_not_exist, :on => :create
|
||||
|
|
@ -13,22 +13,22 @@ class Report < ActiveRecord::Base
|
|||
after_commit :send_report_notification, :on => :create
|
||||
|
||||
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.'
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_reported_item
|
||||
if post_type == 'post'
|
||||
if item_type == 'post'
|
||||
delete_post
|
||||
elsif post_type == 'comment'
|
||||
elsif item_type == 'comment'
|
||||
delete_comment
|
||||
end
|
||||
mark_as_reviewed
|
||||
end
|
||||
|
||||
def delete_post
|
||||
if post = Post.where(id: post_id).first
|
||||
if post = Post.where(id: item_id).first
|
||||
if post.author.local?
|
||||
post.author.owner.retract(post)
|
||||
else
|
||||
|
|
@ -38,7 +38,7 @@ class Report < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def delete_comment
|
||||
if comment = Comment.where(id: post_id).first
|
||||
if comment = Comment.where(id: item_id).first
|
||||
if comment.author.local?
|
||||
comment.author.owner.retract(comment)
|
||||
elsif comment.parent.author.local?
|
||||
|
|
@ -50,10 +50,10 @@ class Report < ActiveRecord::Base
|
|||
end
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
|
|
|||
|
|
@ -6,16 +6,17 @@
|
|||
= t('report.title')
|
||||
%div#reports
|
||||
- @reports.each do |r|
|
||||
- username = User.find_by_id(r.user_id).username
|
||||
%div.content
|
||||
%span
|
||||
= report_content(r.post_id, r.post_type)
|
||||
= report_content(r.item_id, r.item_type)
|
||||
%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
|
||||
= t('report.reason_label', text: r.text)
|
||||
%div.options
|
||||
%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
|
||||
= 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
|
||||
|
|
|
|||
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.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20140308154022) do
|
||||
ActiveRecord::Schema.define(:version => 20140422135040) do
|
||||
|
||||
create_table "account_deletions", :force => true do |t|
|
||||
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"
|
||||
|
||||
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|
|
||||
t.integer "author_id", :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"
|
||||
|
||||
create_table "reports", :force => true do |t|
|
||||
t.integer "post_id", :null => false
|
||||
t.string "post_type", :null => false
|
||||
t.string "user_id"
|
||||
t.integer "item_id", :null => false
|
||||
t.string "item_type", :null => false
|
||||
t.integer "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 "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|
|
||||
t.integer "person_id"
|
||||
|
|
|
|||
|
|
@ -33,21 +33,21 @@ describe ReportController do
|
|||
describe '#create' do
|
||||
let(:comment_hash) {
|
||||
{:text =>"facebook, is that you?",
|
||||
:post_id =>"#{@post.id}"}
|
||||
:item_id =>"#{@post.id}"}
|
||||
}
|
||||
|
||||
context 'report offensive post' 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
|
||||
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
|
||||
context 'report offensive comment' 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
|
||||
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
|
||||
|
|
@ -57,14 +57,14 @@ describe ReportController do
|
|||
it 'is behind redirect_unless_admin' do
|
||||
put :update, :id => @message.id, :type => 'post'
|
||||
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
|
||||
context 'mark comment report as user' do
|
||||
it 'is behind redirect_unless_admin' do
|
||||
put :update, :id => @comment.id, :type => 'comment'
|
||||
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
|
||||
|
||||
|
|
@ -75,7 +75,7 @@ describe ReportController do
|
|||
it 'succeeds' do
|
||||
put :update, :id => @message.id, :type => 'post'
|
||||
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
|
||||
context 'mark comment report as admin' do
|
||||
|
|
@ -85,7 +85,7 @@ describe ReportController do
|
|||
it 'succeeds' do
|
||||
put :update, :id => @comment.id, :type => 'comment'
|
||||
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
|
||||
|
|
@ -95,14 +95,14 @@ describe ReportController do
|
|||
it 'is behind redirect_unless_admin' do
|
||||
delete :destroy, :id => @message.id, :type => 'post'
|
||||
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
|
||||
context 'destroy comment as user' do
|
||||
it 'is behind redirect_unless_admin' do
|
||||
delete :destroy, :id => @comment.id, :type => 'comment'
|
||||
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
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ describe ReportController do
|
|||
it 'succeeds' do
|
||||
delete :destroy, :id => @message.id, :type => 'post'
|
||||
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
|
||||
context 'destroy comment as admin' do
|
||||
|
|
@ -123,7 +123,7 @@ describe ReportController do
|
|||
it 'succeeds' do
|
||||
delete :destroy, :id => @comment.id, :type => 'comment'
|
||||
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
|
||||
|
|
|
|||
|
|
@ -6,30 +6,30 @@ require 'spec_helper'
|
|||
|
||||
describe Report 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
|
||||
@bob_post = @user.post(:status_message, :text => "hello", :to => @user.aspects.first.id)
|
||||
@bob_comment = @user.comment!(@bob_post, "welcome")
|
||||
|
||||
@valid_post_report = {
|
||||
:post_id => @bob_post.id,
|
||||
:post_type => 'post',
|
||||
:item_id => @bob_post.id,
|
||||
:item_type => 'post',
|
||||
:text => 'offensive content'
|
||||
}
|
||||
@valid_comment_report = {
|
||||
:post_id => @bob_comment.id,
|
||||
:post_type => 'comment',
|
||||
:item_id => @bob_comment.id,
|
||||
:item_type => 'comment',
|
||||
:text => 'offensive content'
|
||||
}
|
||||
end
|
||||
|
||||
describe '#validation' 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
|
||||
|
||||
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
|
||||
|
||||
it 'validates that entry does not exist' do
|
||||
|
|
|
|||
Loading…
Reference in a new issue