Module: UserRateLimits
- Extended by:
- ActiveSupport::Concern
- Included in:
- User
- Defined in:
- /var/apps/qpixel/app/models/concerns/user_rate_limits.rb
Instance Method Summary collapse
-
#comment_rate_limited?(post) ⇒ Boolean
Has the user reached comment limit for a given post?.
-
#max_comments_per_day(post) ⇒ Integer
Gets the max number of comments the user can make on a given post.
-
#max_comments_per_day_on_own_posts ⇒ Integer
Gets the max number of comments the user can make per day on their own posts or answers to them.
-
#max_comments_per_day_on_posts_of_others ⇒ Integer
Gets the max number of comments the user can make per day on posts made by other users.
-
#max_votes_per_day ⇒ Integer
Gets the max number of votes the user can make per day.
-
#recent_comments_count(post) ⇒ Integer
Number of comments by the user based on whether they own a given post.
-
#recent_comments_on_own_posts_count ⇒ Integer
Number of comments by the user on own posts or answers to them in the last 24 hours.
-
#recent_comments_on_posts_of_others_count ⇒ Integer
Number of comments by the user on posts made by other users in the last 24 hours.
-
#recent_votes_count ⇒ Integer
Number of votes by the user on posts of others in the last 24 hours.
Instance Method Details
#comment_rate_limited?(post) ⇒ Boolean
Has the user reached comment limit for a given post?
63 64 65 |
# File '/var/apps/qpixel/app/models/concerns/user_rate_limits.rb', line 63 def comment_rate_limited?(post) recent_comments_count(post) >= max_comments_per_day(post) end |
#max_comments_per_day(post) ⇒ Integer
Gets the max number of comments the user can make on a given post
19 20 21 |
# File '/var/apps/qpixel/app/models/concerns/user_rate_limits.rb', line 19 def max_comments_per_day(post) owns_post_or_parent?(post) ? max_comments_per_day_on_own_posts : max_comments_per_day_on_posts_of_others end |
#max_comments_per_day_on_own_posts ⇒ Integer
Gets the max number of comments the user can make per day on their own posts or answers to them
12 13 14 |
# File '/var/apps/qpixel/app/models/concerns/user_rate_limits.rb', line 12 def max_comments_per_day_on_own_posts SiteSetting[new? ? 'RL_NewUserCommentsOwnPosts' : 'RL_CommentsOwnPosts'] || 0 end |
#max_comments_per_day_on_posts_of_others ⇒ Integer
Gets the max number of comments the user can make per day on posts made by other users
6 7 8 |
# File '/var/apps/qpixel/app/models/concerns/user_rate_limits.rb', line 6 def max_comments_per_day_on_posts_of_others SiteSetting[new? ? 'RL_NewUserComments' : 'RL_Comments'] || 0 end |
#max_votes_per_day ⇒ Integer
Gets the max number of votes the user can make per day
25 26 27 |
# File '/var/apps/qpixel/app/models/concerns/user_rate_limits.rb', line 25 def max_votes_per_day SiteSetting[new? ? 'RL_NewUserVotes' : 'RL_Votes'] || 0 end |
#recent_comments_count(post) ⇒ Integer
Number of comments by the user based on whether they own a given post
32 33 34 |
# File '/var/apps/qpixel/app/models/concerns/user_rate_limits.rb', line 32 def recent_comments_count(post) owns_post_or_parent?(post) ? recent_comments_on_own_posts_count : recent_comments_on_posts_of_others_count end |
#recent_comments_on_own_posts_count ⇒ Integer
Number of comments by the user on own posts or answers to them in the last 24 hours
38 39 40 41 42 43 |
# File '/var/apps/qpixel/app/models/concerns/user_rate_limits.rb', line 38 def recent_comments_on_own_posts_count Comment.recent.by(self) .where(post: Post.parent_by(self)) .or(Comment.recent.by(self).where(post: Post.by(self))) .count end |
#recent_comments_on_posts_of_others_count ⇒ Integer
Number of comments by the user on posts made by other users in the last 24 hours
47 48 49 50 51 52 |
# File '/var/apps/qpixel/app/models/concerns/user_rate_limits.rb', line 47 def recent_comments_on_posts_of_others_count Comment.recent.by(self) .where.not(post: Post.parent_by(self)) .where.not(post: Post.by(self)) .count end |