Show countries of everyone, without checking show_country.
This commit is contained in:
parent
09523369b7
commit
24933cc08f
|
@ -22,13 +22,12 @@ func GetUser(c *gin.Context, db *sql.DB) {
|
||||||
|
|
||||||
mode := genmode(c.Query("m"))
|
mode := genmode(c.Query("m"))
|
||||||
|
|
||||||
var display bool
|
|
||||||
err := db.QueryRow(fmt.Sprintf(
|
err := db.QueryRow(fmt.Sprintf(
|
||||||
`SELECT
|
`SELECT
|
||||||
users.id, users.username,
|
users.id, users.username,
|
||||||
users_stats.playcount_%s, users_stats.ranked_score_%s, users_stats.total_score_%s,
|
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,
|
leaderboard_%s.position, users_stats.pp_%s, users_stats.avg_accuracy_%s,
|
||||||
users_stats.country, users_stats.show_country
|
users_stats.country
|
||||||
FROM users
|
FROM users
|
||||||
LEFT JOIN users_stats ON users_stats.id = users.id
|
LEFT JOIN users_stats ON users_stats.id = users.id
|
||||||
INNER JOIN leaderboard_%s ON leaderboard_%s.user = 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.UserID, &user.Username,
|
||||||
&user.Playcount, &user.RankedScore, &user.TotalScore,
|
&user.Playcount, &user.RankedScore, &user.TotalScore,
|
||||||
&user.Rank, &user.PP, &user.Accuracy,
|
&user.Rank, &user.PP, &user.Accuracy,
|
||||||
&user.Country, &display,
|
&user.Country,
|
||||||
)
|
)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
c.JSON(200, defaultResponse)
|
c.JSON(200, defaultResponse)
|
||||||
|
@ -48,9 +47,6 @@ func GetUser(c *gin.Context, db *sql.DB) {
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !display {
|
|
||||||
user.Country = "XX"
|
|
||||||
}
|
|
||||||
user.Level = ocl.GetLevelPrecise(user.TotalScore)
|
user.Level = ocl.GetLevelPrecise(user.TotalScore)
|
||||||
|
|
||||||
c.JSON(200, []osuapi.User{user})
|
c.JSON(200, []osuapi.User{user})
|
||||||
|
|
|
@ -40,12 +40,12 @@ func FriendsGET(md common.MethodData) common.CodeMessager {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Yes.
|
// Yes.
|
||||||
myFriendsQuery := `
|
const myFriendsQuery = `
|
||||||
SELECT
|
SELECT
|
||||||
users.id, users.username, users.register_datetime, users.privileges, users.latest_activity,
|
users.id, users.username, users.register_datetime, users.privileges, users.latest_activity,
|
||||||
|
|
||||||
users_stats.username_aka,
|
users_stats.username_aka,
|
||||||
users_stats.country, users_stats.show_country
|
users_stats.country
|
||||||
FROM users_relationships
|
FROM users_relationships
|
||||||
LEFT JOIN users
|
LEFT JOIN users
|
||||||
ON users_relationships.user2 = users.id
|
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) {
|
func friendPuts(md common.MethodData, row *sql.Rows) (user friendData) {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
var showcountry bool
|
err = row.Scan(&user.ID, &user.Username, &user.RegisteredOn, &user.Privileges, &user.LatestActivity, &user.UsernameAKA, &user.Country)
|
||||||
err = row.Scan(&user.ID, &user.Username, &user.RegisteredOn, &user.Privileges, &user.LatestActivity, &user.UsernameAKA, &user.Country, &showcountry)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
md.Err(err)
|
md.Err(err)
|
||||||
return
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ const lbUserQuery = `
|
||||||
SELECT
|
SELECT
|
||||||
users.id, users.username, users.register_datetime, users.privileges, users.latest_activity,
|
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.play_style, users_stats.favourite_mode,
|
||||||
|
|
||||||
users_stats.ranked_score_%[1]s, users_stats.total_score_%[1]s, users_stats.playcount_%[1]s,
|
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
|
var resp leaderboardResponse
|
||||||
for rows.Next() {
|
for rows.Next() {
|
||||||
var (
|
var u leaderboardUser
|
||||||
u leaderboardUser
|
|
||||||
showCountry bool
|
|
||||||
)
|
|
||||||
err := rows.Scan(
|
err := rows.Scan(
|
||||||
&u.ID, &u.Username, &u.RegisteredOn, &u.Privileges, &u.LatestActivity,
|
&u.ID, &u.Username, &u.RegisteredOn, &u.Privileges, &u.LatestActivity,
|
||||||
|
|
||||||
&u.UsernameAKA, &u.Country, &showCountry,
|
&u.UsernameAKA, &u.Country, &u.PlayStyle, &u.FavouriteMode,
|
||||||
&u.PlayStyle, &u.FavouriteMode,
|
|
||||||
|
|
||||||
&u.ChosenMode.RankedScore, &u.ChosenMode.TotalScore, &u.ChosenMode.PlayCount,
|
&u.ChosenMode.RankedScore, &u.ChosenMode.TotalScore, &u.ChosenMode.PlayCount,
|
||||||
&u.ChosenMode.ReplaysWatched, &u.ChosenMode.TotalHits,
|
&u.ChosenMode.ReplaysWatched, &u.ChosenMode.TotalHits,
|
||||||
|
@ -63,9 +59,6 @@ func LeaderboardGET(md common.MethodData) common.CodeMessager {
|
||||||
md.Err(err)
|
md.Err(err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if !showCountry {
|
|
||||||
u.Country = "XX"
|
|
||||||
}
|
|
||||||
resp.Users = append(resp.Users, u)
|
resp.Users = append(resp.Users, u)
|
||||||
}
|
}
|
||||||
resp.Code = 200
|
resp.Code = 200
|
||||||
|
|
|
@ -44,7 +44,7 @@ func UserManageSetAllowedPOST(md common.MethodData) common.CodeMessager {
|
||||||
query := `
|
query := `
|
||||||
SELECT users.id, users.username, register_datetime, privileges,
|
SELECT users.id, users.username, register_datetime, privileges,
|
||||||
latest_activity, users_stats.username_aka,
|
latest_activity, users_stats.username_aka,
|
||||||
users_stats.country, users_stats.show_country
|
users_stats.country
|
||||||
FROM users
|
FROM users
|
||||||
LEFT JOIN users_stats
|
LEFT JOIN users_stats
|
||||||
ON users.id=users_stats.id
|
ON users.id=users_stats.id
|
||||||
|
|
|
@ -30,7 +30,7 @@ func UsersGET(md common.MethodData) common.CodeMessager {
|
||||||
query := `
|
query := `
|
||||||
SELECT users.id, users.username, register_datetime, privileges,
|
SELECT users.id, users.username, register_datetime, privileges,
|
||||||
latest_activity, users_stats.username_aka,
|
latest_activity, users_stats.username_aka,
|
||||||
users_stats.country, users_stats.show_country
|
users_stats.country
|
||||||
FROM users
|
FROM users
|
||||||
LEFT JOIN users_stats
|
LEFT JOIN users_stats
|
||||||
ON users.id=users_stats.id
|
ON users.id=users_stats.id
|
||||||
|
@ -48,10 +48,9 @@ func userPuts(md common.MethodData, row *sql.Row) common.CodeMessager {
|
||||||
var err error
|
var err error
|
||||||
var user userPutsUserData
|
var user userPutsUserData
|
||||||
|
|
||||||
var showCountry bool
|
|
||||||
err = row.Scan(
|
err = row.Scan(
|
||||||
&user.ID, &user.Username, &user.RegisteredOn, &user.Privileges, &user.LatestActivity,
|
&user.ID, &user.Username, &user.RegisteredOn, &user.Privileges, &user.LatestActivity,
|
||||||
&user.UsernameAKA, &user.Country, &showCountry,
|
&user.UsernameAKA, &user.Country,
|
||||||
)
|
)
|
||||||
switch {
|
switch {
|
||||||
case err == sql.ErrNoRows:
|
case err == sql.ErrNoRows:
|
||||||
|
@ -61,8 +60,6 @@ func userPuts(md common.MethodData, row *sql.Row) common.CodeMessager {
|
||||||
return Err500
|
return Err500
|
||||||
}
|
}
|
||||||
|
|
||||||
user.Country = genCountry(md, user.ID, showCountry, user.Country)
|
|
||||||
|
|
||||||
user.Code = 200
|
user.Code = 200
|
||||||
return user
|
return user
|
||||||
}
|
}
|
||||||
|
@ -81,15 +78,6 @@ func badgesToArray(badges string) []int {
|
||||||
return end
|
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)
|
// UserSelfGET is a shortcut for /users/id/self. (/users/self)
|
||||||
func UserSelfGET(md common.MethodData) common.CodeMessager {
|
func UserSelfGET(md common.MethodData) common.CodeMessager {
|
||||||
md.C.Request.URL.RawQuery = "id=self&" + md.C.Request.URL.RawQuery
|
md.C.Request.URL.RawQuery = "id=self&" + md.C.Request.URL.RawQuery
|
||||||
|
@ -150,7 +138,7 @@ func UserFullGET(md common.MethodData) common.CodeMessager {
|
||||||
SELECT
|
SELECT
|
||||||
users.id, users.username, users.register_datetime, users.privileges, users.latest_activity,
|
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.play_style, users_stats.favourite_mode,
|
||||||
|
|
||||||
users_stats.ranked_score_std, users_stats.total_score_std, users_stats.playcount_std,
|
users_stats.ranked_score_std, users_stats.total_score_std, users_stats.playcount_std,
|
||||||
|
@ -188,12 +176,11 @@ LIMIT 1
|
||||||
var (
|
var (
|
||||||
badges string
|
badges string
|
||||||
country string
|
country string
|
||||||
showCountry bool
|
|
||||||
)
|
)
|
||||||
err := md.DB.QueryRow(query, param).Scan(
|
err := md.DB.QueryRow(query, param).Scan(
|
||||||
&r.ID, &r.Username, &r.RegisteredOn, &r.Privileges, &r.LatestActivity,
|
&r.ID, &r.Username, &r.RegisteredOn, &r.Privileges, &r.LatestActivity,
|
||||||
|
|
||||||
&r.UsernameAKA, &badges, &country, &showCountry,
|
&r.UsernameAKA, &badges, &country,
|
||||||
&r.PlayStyle, &r.FavouriteMode,
|
&r.PlayStyle, &r.FavouriteMode,
|
||||||
|
|
||||||
&r.STD.RankedScore, &r.STD.TotalScore, &r.STD.PlayCount,
|
&r.STD.RankedScore, &r.STD.TotalScore, &r.STD.PlayCount,
|
||||||
|
@ -220,7 +207,6 @@ LIMIT 1
|
||||||
return Err500
|
return Err500
|
||||||
}
|
}
|
||||||
|
|
||||||
r.Country = genCountry(md, r.ID, showCountry, country)
|
|
||||||
r.Badges = badgesToArray(badges)
|
r.Badges = badgesToArray(badges)
|
||||||
|
|
||||||
for _, m := range []*modeData{&r.STD, &r.Taiko, &r.CTB, &r.Mania} {
|
for _, m := range []*modeData{&r.STD, &r.Taiko, &r.CTB, &r.Mania} {
|
||||||
|
|
Loading…
Reference in New Issue
Block a user