Member Search: Order by certified at

This commit is contained in:
Noah Petherbridge 2024-08-23 23:09:27 -07:00
parent 81719218e2
commit 36e48f6ce0
4 changed files with 26 additions and 9 deletions

View File

@ -23,6 +23,7 @@ func Search() http.HandlerFunc {
var sortWhitelist = []string{
"last_login_at desc",
"created_at desc",
"certified_at desc",
"username",
"username desc",
"lower(name)",
@ -126,6 +127,11 @@ func Search() http.HandlerFunc {
sort = "last_login_at desc"
}
// Real name for certified_at
if sort == "certified_at desc" {
sort = "certification_photos.updated_at desc"
}
// Default
if isCertified == "" {
isCertified = "true"

View File

@ -193,12 +193,20 @@ func Profile() http.HandlerFunc {
var photoCount = models.CountPublicPhotos(currentUser.ID)
// Member Since date.
var memberSinceDate = currentUser.CreatedAt
if currentUser.Certified {
if dt, err := currentUser.CertifiedSince(); err == nil {
memberSinceDate = dt
}
}
var resp = Response{
OK: true,
ProfileFields: []ProfileField{
{
Name: "Member Since",
Value: fmt.Sprintf("%s ago", utility.FormatDurationCoarse(time.Since(currentUser.CreatedAt))),
Name: "Certified since",
Value: fmt.Sprintf("%s ago", utility.FormatDurationCoarse(time.Since(memberSinceDate))),
},
{
Name: "📸 Gallery",

View File

@ -430,27 +430,27 @@ func SearchUsers(user *User, search *UserSearch, pager *Pagination) ([]*User, er
// Non-admin user only ever sees active accounts.
if user.IsAdmin && len(statuses) > 0 {
wheres = append(wheres, "status IN ?")
wheres = append(wheres, "users.status IN ?")
placeholders = append(placeholders, statuses)
} else {
wheres = append(wheres, "status = ?")
wheres = append(wheres, "users.status = ?")
placeholders = append(placeholders, UserStatusActive)
}
// Certified filter (including if Shy Accounts are asked for)
if search.Certified {
wheres = append(wheres, "certified = ?")
wheres = append(wheres, "users.certified = ?")
placeholders = append(placeholders, search.Certified)
}
// Expressly Not Certified filtering
if search.NotCertified {
wheres = append(wheres, "certified = ?")
wheres = append(wheres, "users.certified = ?")
placeholders = append(placeholders, false)
}
if search.IsAdmin {
wheres = append(wheres, "is_admin = true")
wheres = append(wheres, "users.is_admin = true")
}
if search.ShyAccounts {
@ -516,7 +516,9 @@ func SearchUsers(user *User, search *UserSearch, pager *Pagination) ([]*User, er
placeholders = append(placeholders, date)
}
query = (&User{}).Preload()
query = (&User{}).Preload().Joins(
"JOIN certification_photos ON (certification_photos.user_id = users.id)",
)
if joins != "" {
query = query.Joins(joins)
}

View File

@ -305,6 +305,7 @@
<select id="sort" name="sort">
<option value="last_login_at desc"{{if eq .Sort "last_login_at desc"}} selected{{end}}>Last login</option>
<option value="created_at desc"{{if eq .Sort "created_at desc"}} selected{{end}}>Signup date</option>
<option value="certified_at desc"{{if eq .Sort "certification_photos.updated_at desc"}} selected{{end}}>Certified date</option>
<option value="username"{{if eq .Sort "username"}} selected{{end}}>Username (a-z)</option>
<option value="username desc"{{if eq .Sort "username desc"}} selected{{end}}>Username (z-a)</option>
<option value="lower(name)"{{if eq .Sort "lower(name)"}} selected{{end}}>Name (a-z)</option>
@ -452,7 +453,7 @@
</div>
{{end}}
{{if eq $Root.Sort "created_at desc"}}
{{if or (eq $Root.Sort "created_at desc") (eq $Root.Sort "certification_photos.updated_at desc")}}
<div>
<small>
Member since: