Skip to content

Commit

Permalink
feat: add redacted user information retrieval for leaderboard
Browse files Browse the repository at this point in the history
  • Loading branch information
taciturnaxolotl committed Nov 6, 2024
1 parent c6f3b6b commit 43bc4f2
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions models/compat/wakatime/v1/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,31 @@ func NewFromUser(user *models.User) *User {
avatarURL = fmt.Sprintf("%s%s/%s", cfg.Server.GetPublicUrl(), cfg.Server.BasePath, avatarURL)
}

return &User{
ID: user.ID,
DisplayName: user.ID,
Email: user.Email,
TimeZone: tz,
Username: user.ID,
CreatedAt: user.CreatedAt,
ModifiedAt: user.CreatedAt,
Photo: avatarURL,
}
}

func RedactedFromUser(user *models.User) *User {
cfg := config.Get()
tz, _ := time.Now().Zone()
if user.Location != "" {
tz = user.Location
}

avatarURL := user.AvatarURL(cfg.App.AvatarURLTemplate)

if !strings.HasPrefix(avatarURL, "http") {
avatarURL = fmt.Sprintf("%s%s/%s", cfg.Server.GetPublicUrl(), cfg.Server.BasePath, avatarURL)
}

return &User{
DisplayName: user.ID,
TimeZone: tz,
Expand Down
2 changes: 1 addition & 1 deletion routes/compat/wakatime/v1/leaders.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (h *LeadersHandler) buildViewModel(globalLeaderboard, languageLeaderboard m
}
}),
},
User: v1.NewFromUser(entry.User),
User: v1.RedactedFromUser(entry.User),
})
}

Expand Down

0 comments on commit 43bc4f2

Please sign in to comment.