diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index f9682c30..0311e652 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -51,6 +51,7 @@ private params.require(:tag).permit( :tag, :description, + :permit_by_new_users, :privileged, :inactive, :hotness_mod, diff --git a/app/models/story.rb b/app/models/story.rb index 69b311ae..06dd7023 100644 --- a/app/models/story.rb +++ b/app/models/story.rb @@ -404,6 +404,11 @@ class Story < ApplicationRecord # stories can have inactive tags as long as they existed before raise "#{u.username} cannot add inactive tag #{t.tag.tag}" end + + if u.is_new? && !t.tag.permit_by_new_users? + errors.add(:base, "New users can't submit #{t.tag.tag} stories, please wait. " << + "If the tag is appropriate, leaving it off to skirt this restriction is a bad idea.") + end end if self.taggings.reject {|t| t.marked_for_destruction? || t.tag.is_media? }.empty? diff --git a/app/models/tag.rb b/app/models/tag.rb index 254905fe..8de9f1c2 100644 --- a/app/models/tag.rb +++ b/app/models/tag.rb @@ -17,6 +17,7 @@ class Tag < ApplicationRecord uniqueness: true, format: { without: /,/ } validates :description, length: { maximum: 100 } validates :hotness_mod, inclusion: { in: -10..10 } + validates :permit_by_new_users, :privileged, inclusion: { in: [true, false] } scope :active, -> { where(:inactive => false) } diff --git a/app/models/user.rb b/app/models/user.rb index 1b054425..d696aa7b 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -461,6 +461,7 @@ class User < ApplicationRecord end def is_new? + return true unless self.created_at # unsaved object; in signup flow or a test Time.current - self.created_at <= NEW_USER_DAYS.days end diff --git a/app/views/tags/_form.html.erb b/app/views/tags/_form.html.erb index 894771e6..c32e4a0e 100644 --- a/app/views/tags/_form.html.erb +++ b/app/views/tags/_form.html.erb @@ -9,6 +9,11 @@ <%= f.text_field :description %> +