mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 06:04:11 +08:00
clean up first day user definition and object model
This commit is contained in:
parent
9834d11503
commit
5aa1272f05
|
@ -88,7 +88,7 @@ class Post < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def limit_posts_per_day
|
||||
if user.created_at > 1.day.ago && post_number > 1
|
||||
if user.first_day_user? && post_number > 1
|
||||
RateLimiter.new(user, "first-day-replies-per-day", SiteSetting.max_replies_in_first_day, 1.day.to_i)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -250,7 +250,7 @@ class Topic < ActiveRecord::Base
|
|||
# Additional rate limits on topics: per day and private messages per day
|
||||
def limit_topics_per_day
|
||||
apply_per_day_rate_limit_for("topics", :max_topics_per_day)
|
||||
limit_first_day_topics_per_day if user.added_a_day_ago?
|
||||
limit_first_day_topics_per_day if user.first_day_user?
|
||||
end
|
||||
|
||||
def limit_private_messages_per_day
|
||||
|
|
|
@ -311,6 +311,12 @@ class User < ActiveRecord::Base
|
|||
self.password_hash == hash_password(password, salt)
|
||||
end
|
||||
|
||||
def first_day_user?
|
||||
!staff? &&
|
||||
trust_level < TrustLevel[2] &&
|
||||
created_at >= 24.hours.ago
|
||||
end
|
||||
|
||||
def new_user?
|
||||
(created_at >= 24.hours.ago || trust_level == TrustLevel[0]) &&
|
||||
trust_level < TrustLevel[2] &&
|
||||
|
@ -562,10 +568,6 @@ class User < ActiveRecord::Base
|
|||
uploaded_avatar.present?
|
||||
end
|
||||
|
||||
def added_a_day_ago?
|
||||
created_at > 1.day.ago
|
||||
end
|
||||
|
||||
def generate_api_key(created_by)
|
||||
if api_key.present?
|
||||
api_key.regenerate!(created_by)
|
||||
|
|
|
@ -722,21 +722,17 @@ describe User do
|
|||
|
||||
end
|
||||
|
||||
describe "#added_a_day_ago?" do
|
||||
context "when user is more than a day old" do
|
||||
subject(:user) { Fabricate(:user, created_at: Date.today - 2.days) }
|
||||
describe "#first_day_user?" do
|
||||
|
||||
it "returns false" do
|
||||
expect(user).to_not be_added_a_day_ago
|
||||
end
|
||||
def test_user?(opts={})
|
||||
Fabricate.build(:user, {created_at: Time.now}.merge(opts)).first_day_user?
|
||||
end
|
||||
|
||||
context "is less than a day old" do
|
||||
subject(:user) { Fabricate(:user) }
|
||||
|
||||
it "returns true" do
|
||||
expect(user).to be_added_a_day_ago
|
||||
end
|
||||
it "works" do
|
||||
expect(test_user?).to eq(true)
|
||||
expect(test_user?(moderator: true)).to eq(false)
|
||||
expect(test_user?(trust_level: TrustLevel[2])).to eq(false)
|
||||
expect(test_user?(created_at: 2.days.ago)).to eq(false)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user