mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-23 23:58:31 -05:00
FIX: badge grant count wasn't filtered to the current user in the user summary
This commit is contained in:
parent
61d61cd410
commit
0bf001ccd7
2 changed files with 15 additions and 9 deletions
|
@ -33,7 +33,7 @@ class UserBadgesController < ApplicationController
|
||||||
|
|
||||||
if params[:grouped]
|
if params[:grouped]
|
||||||
user_badges = user_badges.group(:badge_id)
|
user_badges = user_badges.group(:badge_id)
|
||||||
.select(UserBadge.attribute_names.map {|x| "MAX(#{x}) as #{x}" }, 'COUNT(*) as count')
|
.select(UserBadge.attribute_names.map {|x| "MAX(#{x}) AS #{x}" }, 'COUNT(*) AS "count"')
|
||||||
end
|
end
|
||||||
|
|
||||||
user_badges = user_badges.includes(badge: [:badge_grouping, :badge_type])
|
user_badges = user_badges.includes(badge: [:badge_grouping, :badge_type])
|
||||||
|
|
|
@ -662,19 +662,25 @@ class User < ActiveRecord::Base
|
||||||
|
|
||||||
def featured_user_badges(limit=3)
|
def featured_user_badges(limit=3)
|
||||||
user_badges
|
user_badges
|
||||||
|
.group(:badge_id)
|
||||||
|
.select(UserBadge.attribute_names.map { |x| "MAX(user_badges.#{x}) AS #{x}" },
|
||||||
|
'COUNT(*) AS "count"',
|
||||||
|
'MAX(badges.badge_type_id) AS badges_badge_type_id',
|
||||||
|
'MAX(badges.grant_count) AS badges_grant_count')
|
||||||
.joins(:badge)
|
.joins(:badge)
|
||||||
.order("CASE WHEN badges.id = (SELECT MAX(ub2.badge_id) FROM user_badges ub2
|
.order("CASE WHEN user_badges.badge_id = (
|
||||||
WHERE ub2.badge_id IN (#{Badge.trust_level_badge_ids.join(",")}) AND
|
SELECT MAX(ub2.badge_id)
|
||||||
ub2.user_id = #{self.id}) THEN 1 ELSE 0 END DESC")
|
FROM user_badges ub2
|
||||||
.order('badges.badge_type_id ASC, badges.grant_count ASC')
|
WHERE ub2.badge_id IN (#{Badge.trust_level_badge_ids.join(",")})
|
||||||
.includes(:user, :granted_by, badge: :badge_type)
|
AND ub2.user_id = #{self.id}
|
||||||
.where("user_badges.id in (select min(u2.id)
|
) THEN 1 ELSE 0 END DESC")
|
||||||
from user_badges u2 where u2.user_id = ? group by u2.badge_id)", id)
|
.order('badges_badge_type_id ASC, badges_grant_count ASC')
|
||||||
|
.includes(:user, :granted_by, { badge: :badge_type }, { post: :topic })
|
||||||
.limit(limit)
|
.limit(limit)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.count_by_signup_date(start_date, end_date, group_id=nil)
|
def self.count_by_signup_date(start_date, end_date, group_id=nil)
|
||||||
result = where('users.created_at >= ? and users.created_at <= ?', start_date, end_date)
|
result = where('users.created_at >= ? AND users.created_at <= ?', start_date, end_date)
|
||||||
|
|
||||||
if group_id
|
if group_id
|
||||||
result = result.joins("INNER JOIN group_users ON group_users.user_id = users.id")
|
result = result.joins("INNER JOIN group_users ON group_users.user_id = users.id")
|
||||||
|
|
Loading…
Reference in a new issue