add basic user revert functionality

This commit is contained in:
r888888888
2016-09-28 04:56:12 -07:00
parent 859efe026c
commit 5b48d272f2
8 changed files with 121 additions and 2 deletions

View File

@@ -0,0 +1,28 @@
# reverts all changes made by a user
class UserRevert
THRESHOLD = 1_000
class TooManyChangesError < RuntimeError ; end
attr_reader :user_id
def initialize(user_id)
@user_id = user_id
end
def process
validate!
revert_post_changes
end
def validate!
if PostVersion.where(updater_id: user_id).count > THRESHOLD
raise TooManyChangesError.new("This user has too many changes to be reverted")
end
end
def revert_post_changes
PostVersion.where(updater_id: user_id).find_each do |x|
x.undo!
end
end
end