diff --git a/pkg/controller/account/search.go b/pkg/controller/account/search.go index c592c87..9a83d9f 100644 --- a/pkg/controller/account/search.go +++ b/pkg/controller/account/search.go @@ -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" diff --git a/pkg/controller/api/barertc/barertc_webhooks.go b/pkg/controller/api/barertc/barertc_webhooks.go index 84d5e61..a356e6f 100644 --- a/pkg/controller/api/barertc/barertc_webhooks.go +++ b/pkg/controller/api/barertc/barertc_webhooks.go @@ -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", diff --git a/pkg/models/user.go b/pkg/models/user.go index 8d911a2..c5f53bc 100644 --- a/pkg/models/user.go +++ b/pkg/models/user.go @@ -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) } diff --git a/web/templates/account/search.html b/web/templates/account/search.html index 110b35b..bbd9d22 100644 --- a/web/templates/account/search.html +++ b/web/templates/account/search.html @@ -305,6 +305,7 @@