posts: add metatags for approving and banning posts.
* Allow approvers to approve a post by tagging it with status:active. * Allow approvers to ban a post by tagging it with status:banned. * Allow approvers to unban a post by tagging it with -status:banned.
This commit is contained in:
@@ -753,7 +753,7 @@ class Post < ApplicationRecord
|
|||||||
def filter_metatags(tags)
|
def filter_metatags(tags)
|
||||||
@pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent|-parent|-?locked):/i}
|
@pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent|-parent|-?locked):/i}
|
||||||
tags = apply_categorization_metatags(tags)
|
tags = apply_categorization_metatags(tags)
|
||||||
@post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav|-fav|child|-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|status|-status):/i}
|
||||||
apply_pre_metatags
|
apply_pre_metatags
|
||||||
return tags
|
return tags
|
||||||
end
|
end
|
||||||
@@ -803,6 +803,18 @@ class Post < ApplicationRecord
|
|||||||
when /^(up|down)vote:(.+)$/i
|
when /^(up|down)vote:(.+)$/i
|
||||||
vote!($1)
|
vote!($1)
|
||||||
|
|
||||||
|
when /^status:active$/i
|
||||||
|
raise User::PrivilegeError unless CurrentUser.is_approver?
|
||||||
|
approvals.create!(user: CurrentUser.user)
|
||||||
|
|
||||||
|
when /^status:banned$/i
|
||||||
|
raise User::PrivilegeError unless CurrentUser.is_approver?
|
||||||
|
ban!
|
||||||
|
|
||||||
|
when /^-status:banned$/i
|
||||||
|
raise User::PrivilegeError unless CurrentUser.is_approver?
|
||||||
|
unban!
|
||||||
|
|
||||||
when /^child:none$/i
|
when /^child:none$/i
|
||||||
children.each do |post|
|
children.each do |post|
|
||||||
post.update!(parent_id: nil)
|
post.update!(parent_id: nil)
|
||||||
|
|||||||
@@ -998,6 +998,64 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "for status:active" do
|
||||||
|
should "approve the post if the user has permission" do
|
||||||
|
as(create(:approver)) do
|
||||||
|
@post.update!(is_pending: true)
|
||||||
|
@post.update(tag_string: "aaa status:active")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal(false, @post.reload.is_pending?)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not approve the post if the user is doesn't have permission" do
|
||||||
|
assert_raises(User::PrivilegeError) do
|
||||||
|
@post.update!(is_pending: true)
|
||||||
|
@post.update(tag_string: "aaa status:active")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal(true, @post.reload.is_pending?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for status:banned" do
|
||||||
|
should "ban the post if the user has permission" do
|
||||||
|
as(create(:approver)) do
|
||||||
|
@post.update(tag_string: "aaa status:banned")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal(true, @post.reload.is_banned?)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not ban the post if the user doesn't have permission" do
|
||||||
|
assert_raises(User::PrivilegeError) do
|
||||||
|
@post.update(tag_string: "aaa status:banned")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal(false, @post.reload.is_banned?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "for -status:banned" do
|
||||||
|
should "unban the post if the user has permission" do
|
||||||
|
as(create(:approver)) do
|
||||||
|
@post.update!(is_banned: true)
|
||||||
|
@post.update(tag_string: "aaa -status:banned")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal(false, @post.reload.is_banned?)
|
||||||
|
end
|
||||||
|
|
||||||
|
should "not unban the post if the user doesn't have permission" do
|
||||||
|
assert_raises(User::PrivilegeError) do
|
||||||
|
@post.update!(is_banned: true)
|
||||||
|
@post.update(tag_string: "aaa status:banned")
|
||||||
|
end
|
||||||
|
|
||||||
|
assert_equal(true, @post.reload.is_banned?)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
context "for a source" do
|
context "for a source" do
|
||||||
should "set the source with source:foo_bar_baz" do
|
should "set the source with source:foo_bar_baz" do
|
||||||
@post.update(:tag_string => "source:foo_bar_baz")
|
@post.update(:tag_string => "source:foo_bar_baz")
|
||||||
|
|||||||
Reference in New Issue
Block a user