@ -61,7 +61,7 @@ type writestore interface {
GetAccessToken ( userID int64 ) ( string , error )
GetAccessToken ( userID int64 ) ( string , error )
GetTemporaryAccessToken ( userID int64 , validSecs int ) ( string , error )
GetTemporaryAccessToken ( userID int64 , validSecs int ) ( string , error )
GetTemporaryOneTimeAccessToken ( userID int64 , validSecs int , oneTime bool ) ( string , error )
GetTemporaryOneTimeAccessToken ( userID int64 , validSecs int , oneTime bool ) ( string , error )
DeleteAccount ( userID int64 , posts bool ) error
DeleteAccount ( userID int64 ) error
ChangeSettings ( app * App , u * User , s * userSettings ) error
ChangeSettings ( app * App , u * User , s * userSettings ) error
ChangePassphrase ( userID int64 , sudo bool , curPass string , hashedPass [ ] byte ) error
ChangePassphrase ( userID int64 , sudo bool , curPass string , hashedPass [ ] byte ) error
@ -2079,9 +2079,8 @@ func (db *datastore) CollectionHasAttribute(id int64, attr string) bool {
return true
return true
}
}
// DeleteAccount will delete the entire account for userID, and if posts
// DeleteAccount will delete the entire account for userID
// is true, also all posts associated with the userID
func ( db * datastore ) DeleteAccount ( userID int64 ) error {
func ( db * datastore ) DeleteAccount ( userID int64 , posts bool ) error {
// Get all collections
// Get all collections
rows , err := db . Query ( "SELECT id, alias FROM collections WHERE owner_id = ?" , userID )
rows , err := db . Query ( "SELECT id, alias FROM collections WHERE owner_id = ?" , userID )
if err != nil {
if err != nil {
@ -2110,7 +2109,6 @@ func (db *datastore) DeleteAccount(userID int64, posts bool) error {
// Clean up all collection related information
// Clean up all collection related information
var res sql . Result
var res sql . Result
for _ , c := range colls {
for _ , c := range colls {
// TODO: user deleteCollection() func
// Delete tokens
// Delete tokens
res , err = t . Exec ( "DELETE FROM collectionattributes WHERE collection_id = ?" , c . ID )
res , err = t . Exec ( "DELETE FROM collectionattributes WHERE collection_id = ?" , c . ID )
if err != nil {
if err != nil {
@ -2151,18 +2149,15 @@ func (db *datastore) DeleteAccount(userID int64, posts bool) error {
rs , _ = res . RowsAffected ( )
rs , _ = res . RowsAffected ( )
log . Info ( "Deleted %d for %s from collectionkeys" , rs , c . Alias )
log . Info ( "Deleted %d for %s from collectionkeys" , rs , c . Alias )
// only remove collection in posts if not deleting the user posts
// Float all collection's posts
if ! posts {
res , err = t . Exec ( "UPDATE posts SET collection_id = NULL WHERE collection_id = ? AND owner_id = ?" , c . ID , userID )
// Float all collection's posts
if err != nil {
res , err = t . Exec ( "UPDATE posts SET collection_id = NULL WHERE collection_id = ? AND owner_id = ?" , c . ID , userID )
t . Rollback ( )
if err != nil {
log . Error ( "Unable to update collection %s for posts: %v" , c . Alias , err )
t . Rollback ( )
return err
log . Error ( "Unable to update collection %s for posts: %v" , err )
return err
}
rs , _ = res . RowsAffected ( )
log . Info ( "Removed %d posts from collection %s" , rs , c . Alias )
}
}
rs , _ = res . RowsAffected ( )
log . Info ( "Removed %d posts from collection %s" , rs , c . Alias )
// TODO: federate delete collection
// TODO: federate delete collection
@ -2198,18 +2193,16 @@ func (db *datastore) DeleteAccount(userID int64, posts bool) error {
log . Info ( "Deleted %d from accesstokens" , rs )
log . Info ( "Deleted %d from accesstokens" , rs )
// Delete posts
// Delete posts
if posts {
// TODO: should maybe get each row so we can federate a delete
// TODO: should maybe get each row so we can federate a delete
// if so needs to be outside of transaction like collections
// if so needs to be outside of transaction like collections
res , err = t . Exec ( "DELETE FROM posts WHERE owner_id = ?" , userID )
res , err = t . Exec ( "DELETE FROM posts WHERE owner_id = ?" , userID )
if err != nil {
if err != nil {
t . Rollback ( )
t . Rollback ( )
log . Error ( "Unable to delete posts: %v" , err )
log . Error ( "Unable to delete posts: %v" , err )
return err
return err
}
rs , _ = res . RowsAffected ( )
log . Info ( "Deleted %d from posts" , rs )
}
}
rs , _ = res . RowsAffected ( )
log . Info ( "Deleted %d from posts" , rs )
// Delete user attributes
// Delete user attributes
res , err = t . Exec ( "DELETE FROM userattributes WHERE user_id = ?" , userID )
res , err = t . Exec ( "DELETE FROM userattributes WHERE user_id = ?" , userID )