Fix private grants page
This commit is contained in:
parent
944dbb749b
commit
2d7f8c0d87
|
@ -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),
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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...,
|
||||
|
@ -234,12 +244,23 @@ type PrivateGranteeMap map[uint64]bool
|
|||
func MapPrivatePhotoGrantee(currentUser *User, users []*User) PrivateGranteeMap {
|
||||
var (
|
||||
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)
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user