From c42bde719ecf2dd8757453bed18e082d14c1d3fa Mon Sep 17 00:00:00 2001 From: Julian Date: Sun, 6 Jan 2019 20:29:05 +0100 Subject: [PATCH] Only count users own actions for heatmap contributions (#5647) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Julian Tölle --- models/user_heatmap.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/models/user_heatmap.go b/models/user_heatmap.go index 0745a66058..3fdabbbf79 100644 --- a/models/user_heatmap.go +++ b/models/user_heatmap.go @@ -32,12 +32,22 @@ func GetUserHeatmapDataByUser(user *User) ([]*UserHeatmapData, error) { groupByName = groupBy } - err := x.Select(groupBy+" AS timestamp, count(user_id) as contributions"). + sess := x.Select(groupBy+" AS timestamp, count(user_id) as contributions"). Table("action"). Where("user_id = ?", user.ID). - And("created_unix > ?", (util.TimeStampNow() - 31536000)). - GroupBy(groupByName). + And("created_unix > ?", (util.TimeStampNow() - 31536000)) + + // * Heatmaps for individual users only include actions that the user themself + // did. + // * For organizations actions by all users that were made in owned + // repositories are counted. + if user.Type == UserTypeIndividual { + sess = sess.And("act_user_id = ?", user.ID) + } + + err := sess.GroupBy(groupByName). OrderBy("timestamp"). Find(&hdata) + return hdata, err }