Skip to content

Commit e9fc272

Browse files
committed
remove acts_as_paranoid, use .trash! , .recover! and .with_deleted as needed
makes upgrading to rails 4 possible
1 parent a71a159 commit e9fc272

21 files changed

Lines changed: 77 additions & 36 deletions

Gemfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ gem 'simple_handlebars_rails', path: 'vendor/gems/simple_handlebars_rails'
1515

1616
gem 'redcarpet', require: false
1717
gem 'activerecord-postgres-hstore'
18-
gem 'acts_as_paranoid'
1918
gem 'active_attr' # until we get ActiveModel::Model with Rails 4
2019
gem 'airbrake', '3.1.2', require: false # errbit is broken with 3.1.3 for now
2120
gem 'clockwork', require: false

Gemfile.lock

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,6 @@ GEM
120120
activesupport (3.2.12)
121121
i18n (~> 0.6)
122122
multi_json (~> 1.0)
123-
acts_as_paranoid (0.4.1)
124-
activerecord (~> 3.2)
125123
airbrake (3.1.2)
126124
activesupport
127125
builder
@@ -448,7 +446,6 @@ DEPENDENCIES
448446
active_attr
449447
active_model_serializers!
450448
activerecord-postgres-hstore
451-
acts_as_paranoid
452449
airbrake (= 3.1.2)
453450
barber (= 0.3.0)
454451
better_errors

app/controllers/invites_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def destroy
3333

3434
invite = Invite.where(invited_by_id: current_user.id, email: params[:email]).first
3535
raise Discourse::InvalidParameters.new(:email) if invite.blank?
36-
invite.destroy
36+
invite.trash!
3737

3838
render nothing: true
3939
end

app/controllers/posts_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def destroy
128128
def recover
129129
post = find_post_from_params
130130
guardian.ensure_can_recover_post!(post)
131-
post.recover
131+
post.recover!
132132
render nothing: true
133133
end
134134

app/controllers/topics_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def unmute
100100
def destroy
101101
topic = Topic.where(id: params[:id]).first
102102
guardian.ensure_can_delete!(topic)
103-
topic.destroy
103+
topic.trash!
104104
render nothing: true
105105
end
106106

app/models/invite.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
require_dependency 'trashable'
2+
13
class Invite < ActiveRecord::Base
4+
include Trashable
25

36
belongs_to :user
47
belongs_to :topic
@@ -9,8 +12,6 @@ class Invite < ActiveRecord::Base
912
validates_presence_of :email
1013
validates_presence_of :invited_by_id
1114

12-
acts_as_paranoid
13-
1415
before_create do
1516
self.invite_key ||= SecureRandom.hex
1617
end

app/models/post.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,19 @@
33
require_dependency 'rate_limiter'
44
require_dependency 'post_revisor'
55
require_dependency 'enum'
6+
require_dependency 'trashable'
67

78
require 'archetype'
89
require 'digest/sha1'
910

1011
class Post < ActiveRecord::Base
1112
include RateLimiter::OnCreateRecord
13+
include Trashable
1214

1315
versioned if: :raw_changed?
1416

1517
rate_limit
16-
acts_as_paranoid
1718

18-
after_recover :update_flagged_posts_count
1919

2020
belongs_to :user
2121
belongs_to :topic, counter_cache: :posts_count
@@ -52,6 +52,11 @@ def self.types
5252
@types ||= Enum.new(:regular, :moderator_action)
5353
end
5454

55+
def recover!
56+
super
57+
update_flagged_posts_count
58+
end
59+
5560
def raw_quality
5661
sentinel = TextSentinel.body_sentinel(raw)
5762
errors.add(:raw, I18n.t(:is_invalid)) unless sentinel.valid?

app/models/post_action.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
require_dependency 'rate_limiter'
22
require_dependency 'system_message'
3+
require_dependency 'trashable'
34

45
class PostAction < ActiveRecord::Base
56
class AlreadyActed < StandardError; end
67

78
include RateLimiter::OnCreateRecord
9+
include Trashable
810

911
attr_accessible :post_action_type_id, :post_id, :user_id, :post, :user, :post_action_type, :message, :related_post_id
1012

1113
belongs_to :post
1214
belongs_to :user
1315
belongs_to :post_action_type
1416

15-
acts_as_paranoid
16-
1717
rate_limit :post_action_rate_limiter
1818

1919
validate :message_quality
@@ -114,8 +114,7 @@ def self.act(user, post, post_action_type_id, message = nil)
114114

115115
def self.remove_act(user, post, post_action_type_id)
116116
if action = where(post_id: post.id, user_id: user.id, post_action_type_id: post_action_type_id).first
117-
action.destroy
118-
action.deleted_at = Time.zone.now
117+
action.trash!
119118
action.run_callbacks(:save)
120119
end
121120
end

app/models/topic.rb

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
require_dependency 'rate_limiter'
55
require_dependency 'text_sentinel'
66
require_dependency 'text_cleaner'
7+
require_dependency 'trashable'
78

89
class Topic < ActiveRecord::Base
910
include ActionView::Helpers
1011
include RateLimiter::OnCreateRecord
12+
include Trashable
1113

1214
def self.max_sort_order
1315
2**31 - 1
@@ -18,9 +20,17 @@ def self.featured_users_count
1820
end
1921

2022
versioned if: :new_version_required?
21-
acts_as_paranoid
22-
after_recover :update_flagged_posts_count
23-
after_destroy :update_flagged_posts_count
23+
24+
25+
def trash!
26+
super
27+
update_flagged_posts_count
28+
end
29+
30+
def recover!
31+
super
32+
update_flagged_posts_count
33+
end
2434

2535
rate_limit :default_rate_limiter
2636
rate_limit :limit_topics_per_day

app/models/user.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,11 @@ def delete_all_posts!(guardian)
442442

443443
posts.order("post_number desc").each do |p|
444444
if p.post_number == 1
445-
p.topic.destroy
445+
p.topic.trash!
446446
# TODO: But the post is not destroyed. Why?
447447
else
448448
# TODO: This should be using the PostDestroyer!
449-
p.destroy
449+
p.trash!
450450
end
451451
end
452452
end

0 commit comments

Comments
 (0)