mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-11-25 19:37:41 +08:00
fix(share): remove share when user delete (#1493)
This commit is contained in:
@@ -60,3 +60,7 @@ func DeleteSharingById(id string) error {
|
|||||||
s := model.SharingDB{ID: id}
|
s := model.SharingDB{ID: id}
|
||||||
return errors.WithStack(db.Where(s).Delete(&s).Error)
|
return errors.WithStack(db.Where(s).Delete(&s).Error)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteSharingsByCreatorId(creatorId uint) error {
|
||||||
|
return errors.WithStack(db.Where("creator_id = ?", creatorId).Delete(&model.SharingDB{}).Error)
|
||||||
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ func (s *Sharing) Valid() bool {
|
|||||||
if len(s.Files) == 0 {
|
if len(s.Files) == 0 {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if !s.Creator.CanShare() {
|
if s.Creator == nil || !s.Creator.CanShare() {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if s.Expires != nil && !s.Expires.IsZero() && s.Expires.Before(time.Now()) {
|
if s.Expires != nil && !s.Expires.IsZero() && s.Expires.Before(time.Now()) {
|
||||||
|
|||||||
@@ -137,3 +137,7 @@ func DeleteSharing(sid string) error {
|
|||||||
sharingCache.Del(sid)
|
sharingCache.Del(sid)
|
||||||
return db.DeleteSharingById(sid)
|
return db.DeleteSharingById(sid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DeleteSharingsByCreatorId(creatorId uint) error {
|
||||||
|
return db.DeleteSharingsByCreatorId(creatorId)
|
||||||
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
"github.com/OpenListTeam/OpenList/v4/internal/model"
|
||||||
"github.com/OpenListTeam/OpenList/v4/pkg/singleflight"
|
"github.com/OpenListTeam/OpenList/v4/pkg/singleflight"
|
||||||
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
"github.com/OpenListTeam/OpenList/v4/pkg/utils"
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
var userG singleflight.Group[*model.User]
|
var userG singleflight.Group[*model.User]
|
||||||
@@ -78,6 +79,9 @@ func DeleteUserById(id uint) error {
|
|||||||
return errs.DeleteAdminOrGuest
|
return errs.DeleteAdminOrGuest
|
||||||
}
|
}
|
||||||
Cache.DeleteUser(old.Username)
|
Cache.DeleteUser(old.Username)
|
||||||
|
if err := DeleteSharingsByCreatorId(id); err != nil {
|
||||||
|
return errors.WithMessage(err, "failed to delete user's sharings")
|
||||||
|
}
|
||||||
return db.DeleteUserById(id)
|
return db.DeleteUserById(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user