File tree Expand file tree Collapse file tree 4 files changed +13
-1
lines changed Expand file tree Collapse file tree 4 files changed +13
-1
lines changed Original file line number Diff line number Diff line change @@ -60,3 +60,7 @@ func DeleteSharingById(id string) error {
6060 s := model.SharingDB {ID : id }
6161 return errors .WithStack (db .Where (s ).Delete (& s ).Error )
6262}
63+
64+ func DeleteSharingsByCreatorId (creatorId uint ) error {
65+ return errors .WithStack (db .Where ("creator_id = ?" , creatorId ).Delete (& model.SharingDB {}).Error )
66+ }
Original file line number Diff line number Diff line change @@ -33,7 +33,7 @@ func (s *Sharing) Valid() bool {
3333 if len (s .Files ) == 0 {
3434 return false
3535 }
36- if ! s .Creator .CanShare () {
36+ if s . Creator == nil || ! s .Creator .CanShare () {
3737 return false
3838 }
3939 if s .Expires != nil && ! s .Expires .IsZero () && s .Expires .Before (time .Now ()) {
Original file line number Diff line number Diff line change @@ -137,3 +137,7 @@ func DeleteSharing(sid string) error {
137137 sharingCache .Del (sid )
138138 return db .DeleteSharingById (sid )
139139}
140+
141+ func DeleteSharingsByCreatorId (creatorId uint ) error {
142+ return db .DeleteSharingsByCreatorId (creatorId )
143+ }
Original file line number Diff line number Diff line change 66 "github.com/OpenListTeam/OpenList/v4/internal/model"
77 "github.com/OpenListTeam/OpenList/v4/pkg/singleflight"
88 "github.com/OpenListTeam/OpenList/v4/pkg/utils"
9+ "github.com/pkg/errors"
910)
1011
1112var userG singleflight.Group [* model.User ]
@@ -78,6 +79,9 @@ func DeleteUserById(id uint) error {
7879 return errs .DeleteAdminOrGuest
7980 }
8081 Cache .DeleteUser (old .Username )
82+ if err := DeleteSharingsByCreatorId (id ); err != nil {
83+ return errors .WithMessage (err , "failed to delete user's sharings" )
84+ }
8185 return db .DeleteUserById (id )
8286}
8387
You can’t perform that action at this time.
0 commit comments