Skip to content

Commit 48c5c8b

Browse files
not allow search based on prefs
1 parent 718535e commit 48c5c8b

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

internal/repository/user.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ func (r *userRepository) SearchByUsernameOrName(query string, limit int) ([]*mod
8383
var users []*models.User
8484

8585
err := r.db.Where("is_active = ?", true).
86+
Where("(preferences->>'privacy.allow_search')::boolean IS NOT FALSE").
8687
Where("LOWER(username) LIKE LOWER(?) OR LOWER(first_name) LIKE LOWER(?) OR LOWER(last_name) LIKE LOWER(?)",
8788
"%"+query+"%", "%"+query+"%", "%"+query+"%").
8889
Limit(limit).

internal/services/user.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,15 @@ func (s *UserService) SearchPublicUsers(query string, limit int) ([]models.Publi
168168
var profiles []models.PublicUserProfile
169169
for _, user := range users {
170170
if user.IsActive {
171+
userPrefs := user.Preferences
172+
if len(userPrefs) == 0 {
173+
userPrefs = models.DefaultUserPreferences()
174+
}
175+
176+
if !userPrefs.GetBool(models.PREF_ALLOW_SEARCH, true) {
177+
continue
178+
}
179+
171180
profiles = append(profiles, user.ToPublicProfile())
172181
}
173182
}

0 commit comments

Comments
 (0)