mirror of
https://github.com/discourse/discourse.git
synced 2024-11-26 17:43:42 +08:00
d2f3c829db
* rename `User#password_required` to `User#password_required!` * emails with "i" @ something are a special case as well * get rid of `self.` and returns where possible * prefer "unless a" instead of "if !a" * `unread_notifications` without manually iterating * introduce `User#moderator?` * introduce `TrustLevel#valid_key?`, `TrustLevel#compare`, and `TrustLevel#level_key`
36 lines
894 B
Ruby
36 lines
894 B
Ruby
#
|
|
# Check whether a user is ready for a new trust level.
|
|
#
|
|
class Promotion
|
|
|
|
def initialize(user)
|
|
@user = user
|
|
end
|
|
|
|
# Review a user for a promotion. Delegates work to a review_#{trust_level} method.
|
|
# Returns true if the user was promoted, false otherwise.
|
|
def review
|
|
# nil users are never promoted
|
|
return false if @user.blank?
|
|
|
|
trust_key = TrustLevel.level_key(@user.trust_level)
|
|
|
|
review_method = :"review_#{trust_key.to_s}"
|
|
return send(review_method) if respond_to?(review_method)
|
|
|
|
false
|
|
end
|
|
|
|
def review_new
|
|
return false if @user.topics_entered < SiteSetting.basic_requires_topics_entered
|
|
return false if @user.posts_read_count < SiteSetting.basic_requires_read_posts
|
|
return false if (@user.time_read / 60) < SiteSetting.basic_requires_time_spent_mins
|
|
|
|
@user.trust_level = TrustLevel.Levels[:basic]
|
|
@user.save
|
|
|
|
true
|
|
end
|
|
|
|
end
|