From 8b5aac7808c6694b97c7624c1662c78c137d9560 Mon Sep 17 00:00:00 2001 From: evazion Date: Sat, 22 Oct 2016 01:47:38 -0500 Subject: [PATCH] Add locked:{notes,status,rating} editing metatags (fix #1716). --- app/models/post.rb | 11 ++++++- test/unit/post_test.rb | 69 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) diff --git a/app/models/post.rb b/app/models/post.rb index 64f02929a..f2770a654 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -679,7 +679,7 @@ class Post < ActiveRecord::Base end def filter_metatags(tags) - @pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent|-parent|source):/i} + @pre_metatags, tags = tags.partition {|x| x =~ /\A(?:rating|parent|-parent|source|-?locked):/i} @post_metatags, tags = tags.partition {|x| x =~ /\A(?:-pool|pool|newpool|fav|-fav|child|-favgroup|favgroup):/i} apply_pre_metatags return tags @@ -773,6 +773,15 @@ class Post < ActiveRecord::Base when /^rating:([qse])/i self.rating = $1.downcase + + when /^(-?)locked:notes?$/i + assign_attributes({ is_note_locked: $1 != "-" }, as: CurrentUser.role) + + when /^(-?)locked:rating$/i + assign_attributes({ is_rating_locked: $1 != "-" }, as: CurrentUser.role) + + when /^(-?)locked:status$/i + assign_attributes({ is_status_locked: $1 != "-" }, as: CurrentUser.role) end end end diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 79ead2b17..6d1276b3e 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -731,6 +731,75 @@ class PostTest < ActiveSupport::TestCase assert_equal(14901720, @post.pixiv_id) end end + + context "of" do + setup do + @builder = FactoryGirl.build(:builder_user) + end + + context "locked:notes" do + context "by a member" do + should "not lock the notes" do + @post.update(:tag_string => "locked:notes") + assert_equal(false, @post.is_note_locked) + end + end + + context "by a builder" do + should "lock/unlock the notes" do + CurrentUser.scoped(@builder) do + @post.update(:tag_string => "locked:notes") + assert_equal(true, @post.is_note_locked) + + @post.update(:tag_string => "-locked:notes") + assert_equal(false, @post.is_note_locked) + end + end + end + end + + context "locked:rating" do + context "by a member" do + should "not lock the rating" do + @post.update(:tag_string => "locked:rating") + assert_equal(false, @post.is_rating_locked) + end + end + + context "by a builder" do + should "lock/unlock the rating" do + CurrentUser.scoped(@builder) do + @post.update(:tag_string => "locked:rating") + assert_equal(true, @post.is_rating_locked) + + @post.update(:tag_string => "-locked:rating") + assert_equal(false, @post.is_rating_locked) + end + end + end + end + + context "locked:status" do + context "by a member" do + should "not lock the status" do + @post.update(:tag_string => "locked:status") + assert_equal(false, @post.is_status_locked) + end + end + + context "by an admin" do + should "lock/unlock the status" do + CurrentUser.scoped(FactoryGirl.build(:admin_user)) do + @post.update(:tag_string => "locked:status") + assert_equal(true, @post.is_status_locked) + + @post.update(:tag_string => "-locked:status") + assert_equal(false, @post.is_status_locked) + end + end + end + end + end end context "tagged with a negated tag" do