diff --git a/app/peppy/user.go b/app/peppy/user.go index f793a5c..5d28e3c 100644 --- a/app/peppy/user.go +++ b/app/peppy/user.go @@ -22,13 +22,12 @@ func GetUser(c *gin.Context, db *sql.DB) { mode := genmode(c.Query("m")) - var display bool err := db.QueryRow(fmt.Sprintf( `SELECT users.id, users.username, users_stats.playcount_%s, users_stats.ranked_score_%s, users_stats.total_score_%s, leaderboard_%s.position, users_stats.pp_%s, users_stats.avg_accuracy_%s, - users_stats.country, users_stats.show_country + users_stats.country FROM users LEFT JOIN users_stats ON users_stats.id = users.id INNER JOIN leaderboard_%s ON leaderboard_%s.user = users.id @@ -39,7 +38,7 @@ func GetUser(c *gin.Context, db *sql.DB) { &user.UserID, &user.Username, &user.Playcount, &user.RankedScore, &user.TotalScore, &user.Rank, &user.PP, &user.Accuracy, - &user.Country, &display, + &user.Country, ) if err != nil { c.JSON(200, defaultResponse) @@ -48,9 +47,6 @@ func GetUser(c *gin.Context, db *sql.DB) { } return } - if !display { - user.Country = "XX" - } user.Level = ocl.GetLevelPrecise(user.TotalScore) c.JSON(200, []osuapi.User{user}) diff --git a/app/v1/friend.go b/app/v1/friend.go index 77ff1ea..e5d51d3 100644 --- a/app/v1/friend.go +++ b/app/v1/friend.go @@ -40,12 +40,12 @@ func FriendsGET(md common.MethodData) common.CodeMessager { } // Yes. - myFriendsQuery := ` + const myFriendsQuery = ` SELECT users.id, users.username, users.register_datetime, users.privileges, users.latest_activity, users_stats.username_aka, - users_stats.country, users_stats.show_country + users_stats.country FROM users_relationships LEFT JOIN users ON users_relationships.user2 = users.id @@ -86,18 +86,12 @@ ORDER BY users_relationships.id` func friendPuts(md common.MethodData, row *sql.Rows) (user friendData) { var err error - var showcountry bool - err = row.Scan(&user.ID, &user.Username, &user.RegisteredOn, &user.Privileges, &user.LatestActivity, &user.UsernameAKA, &user.Country, &showcountry) + err = row.Scan(&user.ID, &user.Username, &user.RegisteredOn, &user.Privileges, &user.LatestActivity, &user.UsernameAKA, &user.Country) if err != nil { md.Err(err) return } - // If the user wants to stay anonymous, don't show their country. - // This can be overriden if we have the ReadConfidential privilege and the user we are accessing is the token owner. - if !(showcountry || (md.User.Privileges.HasPrivilegeReadConfidential() && user.ID == md.ID())) { - user.Country = "XX" - } return } diff --git a/app/v1/leaderboard.go b/app/v1/leaderboard.go index c27ce50..a512eba 100644 --- a/app/v1/leaderboard.go +++ b/app/v1/leaderboard.go @@ -22,7 +22,7 @@ const lbUserQuery = ` SELECT users.id, users.username, users.register_datetime, users.privileges, users.latest_activity, - users_stats.username_aka, users_stats.country, users_stats.show_country, + users_stats.username_aka, users_stats.country, users_stats.play_style, users_stats.favourite_mode, users_stats.ranked_score_%[1]s, users_stats.total_score_%[1]s, users_stats.playcount_%[1]s, @@ -45,15 +45,11 @@ func LeaderboardGET(md common.MethodData) common.CodeMessager { } var resp leaderboardResponse for rows.Next() { - var ( - u leaderboardUser - showCountry bool - ) + var u leaderboardUser err := rows.Scan( &u.ID, &u.Username, &u.RegisteredOn, &u.Privileges, &u.LatestActivity, - &u.UsernameAKA, &u.Country, &showCountry, - &u.PlayStyle, &u.FavouriteMode, + &u.UsernameAKA, &u.Country, &u.PlayStyle, &u.FavouriteMode, &u.ChosenMode.RankedScore, &u.ChosenMode.TotalScore, &u.ChosenMode.PlayCount, &u.ChosenMode.ReplaysWatched, &u.ChosenMode.TotalHits, @@ -63,9 +59,6 @@ func LeaderboardGET(md common.MethodData) common.CodeMessager { md.Err(err) continue } - if !showCountry { - u.Country = "XX" - } resp.Users = append(resp.Users, u) } resp.Code = 200 diff --git a/app/v1/manage_user.go b/app/v1/manage_user.go index b751fab..99efacf 100644 --- a/app/v1/manage_user.go +++ b/app/v1/manage_user.go @@ -44,7 +44,7 @@ func UserManageSetAllowedPOST(md common.MethodData) common.CodeMessager { query := ` SELECT users.id, users.username, register_datetime, privileges, latest_activity, users_stats.username_aka, - users_stats.country, users_stats.show_country + users_stats.country FROM users LEFT JOIN users_stats ON users.id=users_stats.id diff --git a/app/v1/user.go b/app/v1/user.go index 4049b21..9105561 100644 --- a/app/v1/user.go +++ b/app/v1/user.go @@ -30,7 +30,7 @@ func UsersGET(md common.MethodData) common.CodeMessager { query := ` SELECT users.id, users.username, register_datetime, privileges, latest_activity, users_stats.username_aka, - users_stats.country, users_stats.show_country + users_stats.country FROM users LEFT JOIN users_stats ON users.id=users_stats.id @@ -48,10 +48,9 @@ func userPuts(md common.MethodData, row *sql.Row) common.CodeMessager { var err error var user userPutsUserData - var showCountry bool err = row.Scan( &user.ID, &user.Username, &user.RegisteredOn, &user.Privileges, &user.LatestActivity, - &user.UsernameAKA, &user.Country, &showCountry, + &user.UsernameAKA, &user.Country, ) switch { case err == sql.ErrNoRows: @@ -61,8 +60,6 @@ func userPuts(md common.MethodData, row *sql.Row) common.CodeMessager { return Err500 } - user.Country = genCountry(md, user.ID, showCountry, user.Country) - user.Code = 200 return user } @@ -81,15 +78,6 @@ func badgesToArray(badges string) []int { return end } -func genCountry(md common.MethodData, uid int, showCountry bool, country string) string { - // If the user wants to stay anonymous, don't show their country. - // This can be overriden if we have the ReadConfidential privilege and the user we are accessing is the token owner. - if showCountry || (md.User.Privileges.HasPrivilegeReadConfidential() && uid == md.ID()) { - return country - } - return "XX" -} - // UserSelfGET is a shortcut for /users/id/self. (/users/self) func UserSelfGET(md common.MethodData) common.CodeMessager { md.C.Request.URL.RawQuery = "id=self&" + md.C.Request.URL.RawQuery @@ -150,7 +138,7 @@ func UserFullGET(md common.MethodData) common.CodeMessager { SELECT users.id, users.username, users.register_datetime, users.privileges, users.latest_activity, - users_stats.username_aka, users_stats.badges_shown, users_stats.country, users_stats.show_country, + users_stats.username_aka, users_stats.badges_shown, users_stats.country, users_stats.play_style, users_stats.favourite_mode, users_stats.ranked_score_std, users_stats.total_score_std, users_stats.playcount_std, @@ -186,14 +174,13 @@ LIMIT 1 // Fuck. r := userFullResponse{} var ( - badges string - country string - showCountry bool + badges string + country string ) err := md.DB.QueryRow(query, param).Scan( &r.ID, &r.Username, &r.RegisteredOn, &r.Privileges, &r.LatestActivity, - &r.UsernameAKA, &badges, &country, &showCountry, + &r.UsernameAKA, &badges, &country, &r.PlayStyle, &r.FavouriteMode, &r.STD.RankedScore, &r.STD.TotalScore, &r.STD.PlayCount, @@ -220,7 +207,6 @@ LIMIT 1 return Err500 } - r.Country = genCountry(md, r.ID, showCountry, country) r.Badges = badgesToArray(badges) for _, m := range []*modeData{&r.STD, &r.Taiko, &r.CTB, &r.Mania} {