mirror of
https://github.com/balzack/databag.git
synced 2025-02-12 03:29:16 +00:00
testing account deletion
This commit is contained in:
parent
5609704760
commit
3642d0f232
@ -23,11 +23,6 @@ func GetAccountAsset(w http.ResponseWriter, r *http.Request) {
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func RemoveAccount(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
}
|
||||
|
||||
func RemoveAccountApp(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json; charset=UTF-8")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
|
88
net/server/internal/api_removeAccount.go
Normal file
88
net/server/internal/api_removeAccount.go
Normal file
@ -0,0 +1,88 @@
|
||||
package databag
|
||||
|
||||
import (
|
||||
"os"
|
||||
"gorm.io/gorm"
|
||||
"net/http"
|
||||
"databag/internal/store"
|
||||
)
|
||||
|
||||
func RemoveAccount(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
account, err := AccountLogin(r)
|
||||
if err != nil {
|
||||
ErrResponse(w, http.StatusUnauthorized, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Tag{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.TagSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Asset{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Topic{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.TopicSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.ChannelSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Channel{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Article{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.ArticleSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.CardSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Card{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Group{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.GroupData{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Group{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.App{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.AccountToken{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Delete(&store.AccountDetail{}, account.AccountDetailID).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Delete(account).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
ErrResponse(w, http.StatusInternalServerError, err)
|
||||
return
|
||||
}
|
||||
|
||||
// delete asset files
|
||||
path := getStrConfigValue(CONFIG_ASSETPATH, ".") + "/" + account.Guid
|
||||
if err = os.RemoveAll(path); err != nil {
|
||||
ErrMsg(err)
|
||||
}
|
||||
|
||||
WriteResponse(w, nil)
|
||||
}
|
||||
|
@ -36,58 +36,58 @@ func RemoveNodeAccount(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
err := store.DB.Transaction(func(tx *gorm.DB) error {
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.Tag{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Tag{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.TagSlot{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.TagSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.Asset{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Asset{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.Topic{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Topic{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.TopicSlot{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.TopicSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.ChannelSlot{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.ChannelSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.Channel{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Channel{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.Article{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Article{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.ArticleSlot{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.ArticleSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.CardSlot{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.CardSlot{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.Card{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Card{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.Group{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Group{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.GroupData{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.GroupData{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.Group{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.Group{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.App{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.App{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.AccountDetail{}).Error; res != nil {
|
||||
if res := tx.Where("account_id = ?", account.ID).Delete(&store.AccountToken{}).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.Account{}).Error; res != nil {
|
||||
if res := tx.Delete(&store.AccountDetail{}, account.AccountDetailID).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
if res := tx.Where("account_id = ?", accountId).Delete(&store.AccountToken{}).Error; res != nil {
|
||||
if res := tx.Delete(account).Error; res != nil {
|
||||
return res
|
||||
}
|
||||
return nil
|
||||
|
@ -119,4 +119,10 @@ func TestAccountConfig(t *testing.T) {
|
||||
assert.Equal(t, 1, len(profiles))
|
||||
assert.Equal(t, set.A.Guid, profiles[0].Guid);
|
||||
|
||||
PrintMsg(set.A.Guid)
|
||||
|
||||
// delete account
|
||||
params = &TestApiParams{ query: "/account/profile", authorization: "newguy:ssap" }
|
||||
assert.NoError(t, TestApiRequest(RemoveAccount, params, nil))
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user