Fix #3930: Can't remove children from a parent post through child: metatag.

Add `child:none` and `-child:123` edit metatags. Allow using ranges with
these metatags (e.g. `-child:1..10`, `child:1,3,5`).
This commit is contained in:
evazion
2018-09-29 19:05:09 -05:00
parent 929fd29c33
commit 2cc4e35cc9
2 changed files with 33 additions and 13 deletions

View File

@@ -791,7 +791,7 @@ class Post < ApplicationRecord
def filter_metatags(tags)
@pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent|-parent|-?locked):/i}
tags = apply_categorization_metatags(tags)
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav|-fav|child|-favgroup|favgroup|upvote|downvote):/i}
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav|-fav|child|-child|-favgroup|favgroup|upvote|downvote):/i}
apply_pre_metatags
return tags
end
@@ -841,10 +841,20 @@ class Post < ApplicationRecord
when /^(up|down)vote:(.+)$/i
vote!($1)
when /^child:none$/i
children.each do |post|
post.update!(parent_id: nil)
end
when /^-child:(.+)$/i
children.numeric_attribute_matches(:id, $1).each do |post|
post.update!(parent_id: nil)
end
when /^child:(.+)$/i
child = Post.find($1)
child.parent_id = id
child.save
Post.numeric_attribute_matches(:id, $1).where.not(id: id).limit(10).each do |post|
post.update!(parent_id: id)
end
when /^-favgroup:(\d+)$/i
favgroup = FavoriteGroup.where("id = ?", $1.to_i).for_creator(CurrentUser.user.id).first