Fix #3965: Extraneous API attributes.
Remove the updater_id/updater_ip_addr virtual attributes from pools/notes. Juss pass them in as params to create_version instead.
This commit is contained in:
@@ -1,14 +1,11 @@
|
||||
class Note < ApplicationRecord
|
||||
class RevertError < Exception ; end
|
||||
|
||||
attribute :updater_id, :integer
|
||||
attribute :updater_ip_addr, :inet
|
||||
attr_accessor :html_id
|
||||
belongs_to :post
|
||||
belongs_to_creator
|
||||
belongs_to_updater
|
||||
has_many :versions, -> {order("note_versions.id ASC")}, :class_name => "NoteVersion", :dependent => :destroy
|
||||
validates_presence_of :post_id, :creator_id, :updater_id, :x, :y, :width, :height, :body
|
||||
validates_presence_of :post_id, :creator_id, :x, :y, :width, :height, :body
|
||||
validate :post_must_exist
|
||||
validate :note_within_image
|
||||
after_save :update_post
|
||||
@@ -115,15 +112,15 @@ class Note < ApplicationRecord
|
||||
end
|
||||
end
|
||||
|
||||
def create_version
|
||||
def create_version(updater: CurrentUser.user, updater_ip_addr: CurrentUser.ip_addr)
|
||||
return unless saved_change_to_versioned_attributes?
|
||||
|
||||
if merge_version?
|
||||
if merge_version?(updater.id)
|
||||
merge_version
|
||||
else
|
||||
Note.where(:id => id).update_all("version = coalesce(version, 0) + 1")
|
||||
reload
|
||||
create_new_version
|
||||
create_new_version(updater.id, updater_ip_addr)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -131,7 +128,7 @@ class Note < ApplicationRecord
|
||||
new_record? || saved_change_to_x? || saved_change_to_y? || saved_change_to_width? || saved_change_to_height? || saved_change_to_is_active? || saved_change_to_body?
|
||||
end
|
||||
|
||||
def create_new_version
|
||||
def create_new_version(updater_id, updater_ip_addr)
|
||||
versions.create(
|
||||
:updater_id => updater_id,
|
||||
:updater_ip_addr => updater_ip_addr,
|
||||
@@ -158,9 +155,9 @@ class Note < ApplicationRecord
|
||||
)
|
||||
end
|
||||
|
||||
def merge_version?
|
||||
def merge_version?(updater_id)
|
||||
prev = versions.last
|
||||
prev && prev.updater_id == CurrentUser.user.id && prev.updated_at > 1.hour.ago && !saved_change_to_is_active?
|
||||
prev && prev.updater_id == updater_id && prev.updated_at > 1.hour.ago && !saved_change_to_is_active?
|
||||
end
|
||||
|
||||
def revert_to(version)
|
||||
@@ -175,8 +172,6 @@ class Note < ApplicationRecord
|
||||
self.width = version.width
|
||||
self.height = version.height
|
||||
self.is_active = version.is_active
|
||||
self.updater_id = CurrentUser.id
|
||||
self.updater_ip_addr = CurrentUser.ip_addr
|
||||
end
|
||||
|
||||
def revert_to!(version)
|
||||
|
||||
Reference in New Issue
Block a user