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(
|
params.require(:tag).permit(
|
||||||
:tag,
|
:tag,
|
||||||
:description,
|
:description,
|
||||||
|
:permit_by_new_users,
|
||||||
:privileged,
|
:privileged,
|
||||||
:inactive,
|
:inactive,
|
||||||
:hotness_mod,
|
:hotness_mod,
|
||||||
|
|
|
@ -404,6 +404,11 @@ class Story < ApplicationRecord
|
||||||
# stories can have inactive tags as long as they existed before
|
# stories can have inactive tags as long as they existed before
|
||||||
raise "#{u.username} cannot add inactive tag #{t.tag.tag}"
|
raise "#{u.username} cannot add inactive tag #{t.tag.tag}"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
if self.taggings.reject {|t| t.marked_for_destruction? || t.tag.is_media? }.empty?
|
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: /,/ }
|
uniqueness: true, format: { without: /,/ }
|
||||||
validates :description, length: { maximum: 100 }
|
validates :description, length: { maximum: 100 }
|
||||||
validates :hotness_mod, inclusion: { in: -10..10 }
|
validates :hotness_mod, inclusion: { in: -10..10 }
|
||||||
|
validates :permit_by_new_users, :privileged, inclusion: { in: [true, false] }
|
||||||
|
|
||||||
scope :active, -> { where(:inactive => false) }
|
scope :active, -> { where(:inactive => false) }
|
||||||
|
|
||||||
|
|
|
@ -461,6 +461,7 @@ class User < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def is_new?
|
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
|
Time.current - self.created_at <= NEW_USER_DAYS.days
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,11 @@
|
||||||
<%= f.text_field :description %>
|
<%= f.text_field :description %>
|
||||||
</div>
|
</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">
|
<div class="boxline">
|
||||||
<%= f.label :privileged, 'Privileged:' %>
|
<%= f.label :privileged, 'Privileged:' %>
|
||||||
<%= f.check_box :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.
|
# 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|
|
create_table "comments", id: :bigint, unsigned: true, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4", force: :cascade do |t|
|
||||||
t.datetime "created_at", null: false
|
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 "is_media", default: false
|
||||||
t.boolean "inactive", default: false
|
t.boolean "inactive", default: false
|
||||||
t.float "hotness_mod", default: 0.0
|
t.float "hotness_mod", default: 0.0
|
||||||
|
t.boolean "permit_by_new_users", default: true, null: false
|
||||||
t.index ["tag"], name: "tag", unique: true
|
t.index ["tag"], name: "tag", unique: true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue