mirror of
https://github.com/thomiceli/opengist.git
synced 2025-01-03 16:22:40 +00:00
Delete gists when user is deleted (#108)
This commit is contained in:
parent
dd050bb6a0
commit
6c450c6f3b
1 changed files with 7 additions and 1 deletions
|
@ -39,7 +39,7 @@ func (user *User) BeforeDelete(tx *gorm.DB) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Decrement forks counter for all gists forked by this user
|
// Decrement forks counter for all gists forked by this user
|
||||||
return tx.Model(&Gist{}).
|
err = tx.Model(&Gist{}).
|
||||||
Omit("updated_at").
|
Omit("updated_at").
|
||||||
Where("id IN (?)", tx.
|
Where("id IN (?)", tx.
|
||||||
Select("forked_id").
|
Select("forked_id").
|
||||||
|
@ -48,6 +48,12 @@ func (user *User) BeforeDelete(tx *gorm.DB) error {
|
||||||
).
|
).
|
||||||
UpdateColumn("nb_forks", gorm.Expr("nb_forks - 1")).
|
UpdateColumn("nb_forks", gorm.Expr("nb_forks - 1")).
|
||||||
Error
|
Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delete all gists created by this user
|
||||||
|
return tx.Where("user_id = ?", user.ID).Delete(&Gist{}).Error
|
||||||
}
|
}
|
||||||
|
|
||||||
func UserExists(username string) (bool, error) {
|
func UserExists(username string) (bool, error) {
|
||||||
|
|
Loading…
Reference in a new issue