Adding perm delete to cmd line

Этот коммит содержится в:
=Corey Hulen
2015-11-16 17:12:49 -08:00
родитель 03c6dcbd86
Коммит 6b2eabf610
25 изменённых файлов: 461 добавлений и 35 удалений

Просмотреть файл

@@ -87,7 +87,7 @@ func (s SqlAuditStore) Get(user_id string, limit int) StoreChannel {
return storeChannel
}
func (s SqlAuditStore) Delete(userId string) StoreChannel {
func (s SqlAuditStore) PermanentDeleteByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)

Просмотреть файл

@@ -45,7 +45,7 @@ func TestSqlAuditStore(t *testing.T) {
t.Fatal("Should have returned empty because user_id is missing")
}
if r2 := <-store.Audit().Delete(audit.UserId); r2.Err != nil {
if r2 := <-store.Audit().PermanentDeleteByUser(audit.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
}

Просмотреть файл

@@ -616,7 +616,7 @@ func (s SqlChannelStore) RemoveMember(channelId string, userId string) StoreChan
return storeChannel
}
func (s SqlChannelStore) DeleteMember(userId string) StoreChannel {
func (s SqlChannelStore) PermanentDeleteMembersByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

Просмотреть файл

@@ -428,7 +428,7 @@ func TestChannelDeleteMemberStore(t *testing.T) {
t.Fatal("should have saved 2 members")
}
Must(store.Channel().DeleteMember(o2.UserId))
Must(store.Channel().PermanentDeleteMembersByUser(o2.UserId))
count = (<-store.Channel().GetMemberCount(o1.ChannelId)).Data.(int64)
if count != 1 {

Просмотреть файл

@@ -333,7 +333,7 @@ func (as SqlOAuthStore) RemoveAuthData(code string) StoreChannel {
return storeChannel
}
func (as SqlOAuthStore) RemoveAuthDataByUserId(userId string) StoreChannel {
func (as SqlOAuthStore) PermanentDeleteAuthDataByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

Просмотреть файл

@@ -181,7 +181,7 @@ func TestOAuthStoreRemoveAuthData(t *testing.T) {
}
}
func TestOAuthStoreRemoveAuthDataByUserId(t *testing.T) {
func TestOAuthStoreRemoveAuthDataByUser(t *testing.T) {
Setup()
a1 := model.AuthData{}
@@ -190,7 +190,7 @@ func TestOAuthStoreRemoveAuthDataByUserId(t *testing.T) {
a1.Code = model.NewId()
Must(store.OAuth().SaveAuthData(&a1))
if err := (<-store.OAuth().RemoveAuthDataByUserId(a1.UserId)).Err; err != nil {
if err := (<-store.OAuth().PermanentDeleteAuthDataByUser(a1.UserId)).Err; err != nil {
t.Fatal(err)
}
}

Просмотреть файл

@@ -228,13 +228,13 @@ func (s SqlPostStore) Delete(postId string, time int64) StoreChannel {
return storeChannel
}
func (s SqlPostStore) PermanentDelete(userId string) StoreChannel {
func (s SqlPostStore) permanentDelete(postId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
_, err := s.GetMaster().Exec("Update Posts SET DeleteAt = :DeleteAt, UpdateAt = :UpdateAt WHERE Id = :Id OR ParentId = :ParentId OR RootId = :RootId", map[string]interface{}{"DeleteAt": time, "UpdateAt": time, "Id": postId, "ParentId": postId, "RootId": postId})
_, err := s.GetMaster().Exec("DELETE FROM Posts WHERE Id = :Id OR ParentId = :ParentId OR RootId = :RootId", map[string]interface{}{"Id": postId, "ParentId": postId, "RootId": postId})
if err != nil {
result.Err = model.NewAppError("SqlPostStore.Delete", "We couldn't delete the post", "id="+postId+", err="+err.Error())
}
@@ -246,6 +246,81 @@ func (s SqlPostStore) PermanentDelete(userId string) StoreChannel {
return storeChannel
}
func (s SqlPostStore) permanentDeleteAllCommentByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
_, err := s.GetMaster().Exec("DELETE FROM Posts WHERE UserId = :UserId AND RootId != ''", map[string]interface{}{"UserId": userId})
if err != nil {
result.Err = model.NewAppError("SqlPostStore.permanentDeleteAllCommentByUser", "We couldn't delete the comments for user", "userId="+userId+", err="+err.Error())
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (s SqlPostStore) PermanentDeleteByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
result := StoreResult{}
// First attempt to delete all the comments for a user
if r := <-s.permanentDeleteAllCommentByUser(userId); r.Err != nil {
result.Err = r.Err
storeChannel <- result
close(storeChannel)
return
}
// Now attempt to delete all the root posts for a user. This will also
// delete all the comments for each post.
found := true
count := 0
for found {
var ids []string
_, err := s.GetMaster().Select(&ids, "SELECT Id FROM Posts WHERE UserId = :UserId LIMIT 1000", map[string]interface{}{"UserId": userId})
if err != nil {
result.Err = model.NewAppError("SqlPostStore.PermanentDeleteByUser.select", "We couldn't select the posts to delete for the user", "userId="+userId+", err="+err.Error())
storeChannel <- result
close(storeChannel)
return
} else {
found = false
for _, id := range ids {
found = true
if r := <-s.permanentDelete(id); r.Err != nil {
result.Err = r.Err
storeChannel <- result
close(storeChannel)
return
}
}
}
// This is a fail safe, give up if more than 10K messages
count = count + 1
if count >= 10 {
result.Err = model.NewAppError("SqlPostStore.PermanentDeleteByUser.toolarge", "We couldn't select the posts to delete for the user (too many), please re-run", "userId="+userId)
storeChannel <- result
close(storeChannel)
return
}
}
storeChannel <- result
close(storeChannel)
}()
return storeChannel
}
func (s SqlPostStore) GetPosts(channelId string, offset int, limit int) StoreChannel {
storeChannel := make(StoreChannel)

Просмотреть файл

@@ -247,6 +247,76 @@ func TestPostStoreDelete2Level(t *testing.T) {
}
}
func TestPostStorePermDelete1Level(t *testing.T) {
Setup()
o1 := &model.Post{}
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
if r2 := <-store.Post().PermanentDeleteByUser(o2.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Post().Get(o1.Id)); r3.Err != nil {
t.Fatal("Deleted id shouldn't have failed")
}
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed")
}
}
func TestPostStorePermDelete1Level2(t *testing.T) {
Setup()
o1 := &model.Post{}
o1.ChannelId = model.NewId()
o1.UserId = model.NewId()
o1.Message = "a" + model.NewId() + "b"
o1 = (<-store.Post().Save(o1)).Data.(*model.Post)
o2 := &model.Post{}
o2.ChannelId = o1.ChannelId
o2.UserId = model.NewId()
o2.Message = "a" + model.NewId() + "b"
o2.ParentId = o1.Id
o2.RootId = o1.Id
o2 = (<-store.Post().Save(o2)).Data.(*model.Post)
o3 := &model.Post{}
o3.ChannelId = model.NewId()
o3.UserId = model.NewId()
o3.Message = "a" + model.NewId() + "b"
o3 = (<-store.Post().Save(o3)).Data.(*model.Post)
if r2 := <-store.Post().PermanentDeleteByUser(o1.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
if r3 := (<-store.Post().Get(o1.Id)); r3.Err == nil {
t.Fatal("Deleted id should have failed")
}
if r4 := (<-store.Post().Get(o2.Id)); r4.Err == nil {
t.Fatal("Deleted id should have failed")
}
if r5 := (<-store.Post().Get(o3.Id)); r5.Err != nil {
t.Fatal("Deleted id shouldn't have failed")
}
}
func TestPostStoreGetWithChildren(t *testing.T) {
Setup()

Просмотреть файл

@@ -240,7 +240,7 @@ func (s SqlPreferenceStore) GetAll(userId string) StoreChannel {
return storeChannel
}
func (s SqlPreferenceStore) Delete(userId string) StoreChannel {
func (s SqlPreferenceStore) PermanentDeleteByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

Просмотреть файл

@@ -228,7 +228,7 @@ func TestPreferenceDelete(t *testing.T) {
Must(store.Preference().Save(&preferences))
if result := <-store.Preference().Delete(userId); result.Err != nil {
if result := <-store.Preference().PermanentDeleteByUser(userId); result.Err != nil {
t.Fatal(result.Err)
}
}

Просмотреть файл

@@ -158,7 +158,7 @@ func (me SqlSessionStore) RemoveAllSessionsForTeam(teamId string) StoreChannel {
return storeChannel
}
func (me SqlSessionStore) RemoveAllSessionsForUser(userId string) StoreChannel {
func (me SqlSessionStore) PermanentDeleteSessionsByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

Просмотреть файл

@@ -119,7 +119,7 @@ func TestSessionRemoveByUser(t *testing.T) {
}
}
Must(store.Session().RemoveAllSessionsForUser(s1.UserId))
Must(store.Session().PermanentDeleteSessionsByUser(s1.UserId))
if rs2 := (<-store.Session().Get(s1.Id)); rs2.Err == nil {
t.Fatal("should have been removed")

Просмотреть файл

@@ -301,7 +301,7 @@ func (s SqlTeamStore) GetAllTeamListing() StoreChannel {
return storeChannel
}
func (s SqlTeamStore) Delete(teamId string) StoreChannel {
func (s SqlTeamStore) PermanentDelete(teamId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

Просмотреть файл

@@ -257,7 +257,7 @@ func TestDelete(t *testing.T) {
o2.Type = model.TEAM_OPEN
Must(store.Team().Save(&o2))
if r1 := <-store.Team().Delete(o1.Id); r1.Err != nil {
if r1 := <-store.Team().PermanentDelete(o1.Id); r1.Err != nil {
t.Fatal(r1.Err)
}
}

Просмотреть файл

@@ -555,7 +555,7 @@ func (us SqlUserStore) GetTotalActiveUsersCount() StoreChannel {
return storeChannel
}
func (us SqlUserStore) Delete(userId string) StoreChannel {
func (us SqlUserStore) PermanentDelete(userId string) StoreChannel {
storeChannel := make(StoreChannel)

Просмотреть файл

@@ -386,7 +386,7 @@ func TestUserStoreDelete(t *testing.T) {
u1.Email = model.NewId()
Must(store.User().Save(&u1))
if err := (<-store.User().Delete(u1.Id)).Err; err != nil {
if err := (<-store.User().PermanentDelete(u1.Id)).Err; err != nil {
t.Fatal(err)
}
}

Просмотреть файл

@@ -116,7 +116,7 @@ func (s SqlWebhookStore) DeleteIncoming(webhookId string, time int64) StoreChann
return storeChannel
}
func (s SqlWebhookStore) DeleteIncomingByUser(userId string) StoreChannel {
func (s SqlWebhookStore) PermanentDeleteIncomingByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {
@@ -312,7 +312,7 @@ func (s SqlWebhookStore) DeleteOutgoing(webhookId string, time int64) StoreChann
return storeChannel
}
func (s SqlWebhookStore) DeleteOutgoingByUser(userId string) StoreChannel {
func (s SqlWebhookStore) PermanentDeleteOutgoingByUser(userId string) StoreChannel {
storeChannel := make(StoreChannel)
go func() {

Просмотреть файл

@@ -121,7 +121,7 @@ func TestWebhookStoreDeleteIncomingByUser(t *testing.T) {
}
}
if r2 := <-store.Webhook().DeleteIncomingByUser(o1.UserId); r2.Err != nil {
if r2 := <-store.Webhook().PermanentDeleteIncomingByUser(o1.UserId); r2.Err != nil {
t.Fatal(r2.Err)
}
@@ -305,7 +305,7 @@ func TestWebhookStoreDeleteOutgoingByUser(t *testing.T) {
}
}
if r2 := <-store.Webhook().DeleteOutgoingByUser(o1.CreatorId); r2.Err != nil {
if r2 := <-store.Webhook().PermanentDeleteOutgoingByUser(o1.CreatorId); r2.Err != nil {
t.Fatal(r2.Err)
}

Просмотреть файл

@@ -52,7 +52,7 @@ type TeamStore interface {
GetAll() StoreChannel
GetAllTeamListing() StoreChannel
GetByInviteId(inviteId string) StoreChannel
Delete(teamId string) StoreChannel
PermanentDelete(teamId string) StoreChannel
}
type ChannelStore interface {
@@ -73,7 +73,7 @@ type ChannelStore interface {
GetMember(channelId string, userId string) StoreChannel
GetMemberCount(channelId string) StoreChannel
RemoveMember(channelId string, userId string) StoreChannel
DeleteMember(userId string) StoreChannel
PermanentDeleteMembersByUser(userId string) StoreChannel
GetExtraMembers(channelId string, limit int) StoreChannel
CheckPermissionsTo(teamId string, channelId string, userId string) StoreChannel
CheckOpenChannelPermissions(teamId string, channelId string) StoreChannel
@@ -88,6 +88,7 @@ type PostStore interface {
Update(post *model.Post, newMessage string, newHashtags string) StoreChannel
Get(id string) StoreChannel
Delete(postId string, time int64) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
GetPosts(channelId string, offset int, limit int) StoreChannel
GetPostsBefore(channelId string, postId string, numPosts int, offset int) StoreChannel
GetPostsAfter(channelId string, postId string, numPosts int, offset int) StoreChannel
@@ -120,7 +121,7 @@ type UserStore interface {
GetTotalUsersCount() StoreChannel
GetTotalActiveUsersCount() StoreChannel
GetSystemAdminProfiles() StoreChannel
Delete(userId string) StoreChannel
PermanentDelete(userId string) StoreChannel
}
type SessionStore interface {
@@ -129,7 +130,7 @@ type SessionStore interface {
GetSessions(userId string) StoreChannel
Remove(sessionIdOrToken string) StoreChannel
RemoveAllSessionsForTeam(teamId string) StoreChannel
RemoveAllSessionsForUser(teamId string) StoreChannel
PermanentDeleteSessionsByUser(teamId string) StoreChannel
UpdateLastActivityAt(sessionId string, time int64) StoreChannel
UpdateRoles(userId string, roles string) StoreChannel
}
@@ -137,7 +138,7 @@ type SessionStore interface {
type AuditStore interface {
Save(audit *model.Audit) StoreChannel
Get(user_id string, limit int) StoreChannel
Delete(userId string) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
}
type OAuthStore interface {
@@ -148,7 +149,7 @@ type OAuthStore interface {
SaveAuthData(authData *model.AuthData) StoreChannel
GetAuthData(code string) StoreChannel
RemoveAuthData(code string) StoreChannel
RemoveAuthDataByUserId(userId string) StoreChannel
PermanentDeleteAuthDataByUser(userId string) StoreChannel
SaveAccessData(accessData *model.AccessData) StoreChannel
GetAccessData(token string) StoreChannel
GetAccessDataByAuthCode(authCode string) StoreChannel
@@ -167,14 +168,14 @@ type WebhookStore interface {
GetIncomingByUser(userId string) StoreChannel
GetIncomingByChannel(channelId string) StoreChannel
DeleteIncoming(webhookId string, time int64) StoreChannel
DeleteIncomingByUser(userId string) StoreChannel
PermanentDeleteIncomingByUser(userId string) StoreChannel
SaveOutgoing(webhook *model.OutgoingWebhook) StoreChannel
GetOutgoing(id string) StoreChannel
GetOutgoingByCreator(userId string) StoreChannel
GetOutgoingByChannel(channelId string) StoreChannel
GetOutgoingByTeam(teamId string) StoreChannel
DeleteOutgoing(webhookId string, time int64) StoreChannel
DeleteOutgoingByUser(userId string) StoreChannel
PermanentDeleteOutgoingByUser(userId string) StoreChannel
UpdateOutgoing(hook *model.OutgoingWebhook) StoreChannel
}
@@ -183,5 +184,5 @@ type PreferenceStore interface {
Get(userId string, category string, name string) StoreChannel
GetCategory(userId string, category string) StoreChannel
GetAll(userId string) StoreChannel
Delete(userId string) StoreChannel
PermanentDeleteByUser(userId string) StoreChannel
}