From 043448c429c38ebc770573ac1f94e73c3c5078b7 Mon Sep 17 00:00:00 2001 From: Howl Date: Wed, 19 Oct 2016 17:10:36 +0200 Subject: [PATCH] Add search by privilege group name in users --- app/v1/user.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/v1/user.go b/app/v1/user.go index bd26e84..fef6644 100644 --- a/app/v1/user.go +++ b/app/v1/user.go @@ -22,7 +22,7 @@ type userData struct { Country string `json:"country"` } -const userFields = `users.id, users.username, register_datetime, privileges, +const userFields = `SELECT users.id, users.username, register_datetime, users.privileges, latest_activity, users_stats.username_aka, users_stats.country FROM users @@ -37,8 +37,7 @@ func UsersGET(md common.MethodData) common.CodeMessager { return userPutsMulti(md) } - query := ` -SELECT ` + userFields + ` + query := userFields + ` WHERE ` + whereClause + ` AND ` + md.User.OnlyUserPublic(true) + ` LIMIT 1` return userPutsSingle(md, md.DB.QueryRowx(query, param)) @@ -82,12 +81,18 @@ func userPutsMulti(md common.MethodData) common.CodeMessager { Where("users.privileges & ? > 0", md.Query("has_privileges")). Where("users_stats.country = ?", md.Query("country")). Where("users_stats.username_aka = ?", md.Query("name_aka")). + Where("privileges_groups.name = ?", md.Query("privilege_group")). In("users.id", q["ids"]...). In("users.username_safe", safeUsernameBulk(q["names"])...). In("users_stats.username_aka", q["names_aka"]...). In("users_stats.country", q["countries"]...) - query := "" + - "SELECT " + userFields + wh.ClauseSafe() + " AND " + md.User.OnlyUserPublic(true) + + + var extraJoin string + if md.Query("privilege_group") != "" { + extraJoin = " LEFT JOIN privileges_groups ON users.privileges & privileges_groups.privileges = privileges_groups.privileges " + } + + query := userFields + extraJoin + wh.ClauseSafe() + " AND " + md.User.OnlyUserPublic(true) + " " + common.Sort(md, common.SortConfiguration{ Allowed: []string{ "id",