make some tags unavabile to new users
This commit is contained in:
parent
abb400978f
commit
9d5097ee70
|
@ -51,6 +51,7 @@ private
|
|||
params.require(:tag).permit(
|
||||
:tag,
|
||||
:description,
|
||||
:permit_by_new_users,
|
||||
:privileged,
|
||||
:inactive,
|
||||
:hotness_mod,
|
||||
|
|
|
@ -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?
|
||||
|
|
|
@ -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) }
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
<%= f.text_field :description %>
|
||||
</div>
|
||||
|
||||
<div class="boxline">
|
||||
<%= f.label :permit_by_new_users, 'Permit by new users:' %>
|
||||
<%= f.check_box :permit_by_new_users %>
|
||||
</div>
|
||||
|
||||
<div class="boxline">
|
||||
<%= f.label :privileged, 'Privileged:' %>
|
||||
<%= f.check_box :privileged %>
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class LimitNewUserTags < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :tags, :permit_by_new_users, :boolean, null: false, default: true
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(version: 2020_02_10_125425) do
|
||||
ActiveRecord::Schema.define(version: 2020_02_10_155624) do
|
||||
|
||||
create_table "comments", id: :bigint, unsigned: true, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
|
||||
t.datetime "created_at", null: false
|
||||
|
@ -256,6 +256,7 @@ ActiveRecord::Schema.define(version: 2020_02_10_125425) do
|
|||
t.boolean "is_media", default: false
|
||||
t.boolean "inactive", default: false
|
||||
t.float "hotness_mod", default: 0.0
|
||||
t.boolean "permit_by_new_users", default: true, null: false
|
||||
t.index ["tag"], name: "tag", unique: true
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue