Fix private grants page

face-detect
Noah Petherbridge 2023-09-01 22:41:33 -07:00
parent 944dbb749b
commit 2d7f8c0d87
3 changed files with 36 additions and 2 deletions

View File

@ -42,6 +42,8 @@ func Private() http.HandlerFunc {
return
}
log.Error("pager: %+v, len: %d", pager, len(users))
var vars = map[string]interface{}{
"IsGrantee": isGrantee,
"CountGrantee": models.CountPrivateGrantee(currentUser.ID),

View File

@ -28,6 +28,7 @@ func DeleteUser(user *models.User) error {
{"Comments", DeleteComments},
{"Subscriptions", DeleteSubscriptions},
{"Photos", DeleteUserPhotos},
{"Private Photo Grants", DeletePrivateGrants},
{"Certification Photo", DeleteCertification},
{"Who's Nearby Locations", DeleteUserLocation},
{"Comment Photos", DeleteUserCommentPhotos},
@ -170,6 +171,16 @@ func DeleteFriends(userID uint64) error {
return result.Error
}
// DeletePrivateGrants scrubs data for deleting a user.
func DeletePrivateGrants(userID uint64) error {
log.Error("DeleteUser: DeletePrivateGrants(%d)", userID)
result := models.DB.Where(
"source_user_id = ? OR target_user_id = ?",
userID, userID,
).Delete(&models.PrivatePhoto{})
return result.Error
}
// DeleteNotifications scrubs all notifications about a user.
func DeleteNotifications(userID uint64) error {
log.Error("DeleteUser: DeleteNotifications(%d)", userID)

View File

@ -197,6 +197,16 @@ func PaginatePrivatePhotoList(user *User, grantee bool, pager *Pagination) ([]*U
placeholders = append(placeholders, user.ID)
}
// Users that actually exist.
wheres = append(wheres, `
EXISTS (
SELECT 1
FROM users
WHERE users.id = private_photos.target_user_id
OR users.id = private_photos.source_user_id
)`,
)
query = DB.Where(
strings.Join(wheres, " AND "),
placeholders...,
@ -233,13 +243,24 @@ type PrivateGranteeMap map[uint64]bool
// MapShyAccounts looks up a set of user IDs in bulk and returns a PrivateGranteeMap suitable for templates.
func MapPrivatePhotoGrantee(currentUser *User, users []*User) PrivateGranteeMap {
var (
usermap = PrivateGranteeMap{}
usermap = PrivateGranteeMap{}
set = map[uint64]interface{}{}
distinct = []uint64{}
)
// Uniqueify users.
for _, user := range users {
if _, ok := set[user.ID]; ok {
continue
}
set[user.ID] = nil
distinct = append(distinct, user.ID)
}
var (
matched = []*PrivatePhoto{}
result = DB.Model(&PrivatePhoto{}).
Where("target_user_id = ?", currentUser.ID).
Where("target_user_id = ? AND source_user_id IN ?", currentUser.ID, distinct).
Find(&matched)
)