Adding perm delete to cmd line
Этот коммит содержится в:
26
api/team.go
26
api/team.go
@@ -582,6 +582,32 @@ func updateTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte(oldTeam.ToJson()))
|
||||
}
|
||||
|
||||
func PermanentDeleteTeam(c *Context, team *model.Team) *model.AppError {
|
||||
l4g.Warn("Attempting to permanently delete team %v id=%v", team.Name, team.Id)
|
||||
|
||||
team.DeleteAt = model.GetMillis()
|
||||
if result := <-Srv.Store.Team().Update(team); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.User().GetForExport(team.Id); result.Err != nil {
|
||||
return result.Err
|
||||
} else {
|
||||
users := result.Data.([]*model.User)
|
||||
for _, user := range users {
|
||||
PermanentDeleteUser(c, user)
|
||||
}
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Team().PermanentDelete(team.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
l4g.Warn("Permanently deleted team %v id=%v", team.Name, team.Id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func getMyTeam(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if len(c.Session.TeamId) == 0 {
|
||||
|
||||
@@ -168,6 +168,43 @@ func TestGetAllTeams(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestTeamPermDelete(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
|
||||
|
||||
user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
|
||||
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
|
||||
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
|
||||
|
||||
Client.LoginByEmail(team.Name, user1.Email, "pwd")
|
||||
|
||||
channel1 := &model.Channel{DisplayName: "TestGetPosts", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
||||
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
|
||||
|
||||
post1 := &model.Post{ChannelId: channel1.Id, Message: "search for post1"}
|
||||
post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post)
|
||||
|
||||
post2 := &model.Post{ChannelId: channel1.Id, Message: "search for post2"}
|
||||
post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post)
|
||||
|
||||
post3 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag search for post3"}
|
||||
post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post)
|
||||
|
||||
post4 := &model.Post{ChannelId: channel1.Id, Message: "hashtag for post4"}
|
||||
post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post)
|
||||
|
||||
c := &Context{}
|
||||
c.RequestId = model.NewId()
|
||||
c.IpAddress = "test"
|
||||
|
||||
err := PermanentDeleteTeam(c, team)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
XXXXXX investigate and fix failing test
|
||||
|
||||
63
api/user.go
63
api/user.go
@@ -1196,6 +1196,14 @@ func updateActive(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
ruser := UpdateActive(c, user, active)
|
||||
|
||||
if c.Err == nil {
|
||||
w.Write([]byte(ruser.ToJson()))
|
||||
}
|
||||
}
|
||||
|
||||
func UpdateActive(c *Context, user *model.User, active bool) *model.User {
|
||||
if active {
|
||||
user.DeleteAt = 0
|
||||
} else {
|
||||
@@ -1204,7 +1212,7 @@ func updateActive(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
if result := <-Srv.Store.User().Update(user, true); result.Err != nil {
|
||||
c.Err = result.Err
|
||||
return
|
||||
return nil
|
||||
} else {
|
||||
c.LogAuditWithUserId(user.Id, fmt.Sprintf("active=%v", active))
|
||||
|
||||
@@ -1216,10 +1224,61 @@ func updateActive(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
options := utils.SanitizeOptions
|
||||
options["passwordupdate"] = false
|
||||
ruser.Sanitize(options)
|
||||
w.Write([]byte(ruser.ToJson()))
|
||||
return ruser
|
||||
}
|
||||
}
|
||||
|
||||
func PermanentDeleteUser(c *Context, user *model.User) *model.AppError {
|
||||
l4g.Warn("Attempting to permanently delete account %v id=%v", user.Email, user.Id)
|
||||
c.Path = "/user/permanent_delete"
|
||||
c.LogAuditWithUserId(user.Id, fmt.Sprintf("attempt"))
|
||||
if user.IsInRole(model.ROLE_SYSTEM_ADMIN) {
|
||||
l4g.Warn("You are deleting %v that is a system administrator. You may need to set another account as the system administrator using the command line tools.", user.Email)
|
||||
}
|
||||
|
||||
UpdateActive(c, user, false)
|
||||
|
||||
if result := <-Srv.Store.Session().PermanentDeleteSessionsByUser(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.OAuth().PermanentDeleteAuthDataByUser(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().PermanentDeleteIncomingByUser(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Webhook().PermanentDeleteOutgoingByUser(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Preference().PermanentDeleteByUser(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Channel().PermanentDeleteMembersByUser(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Post().PermanentDeleteByUser(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.User().PermanentDelete(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
if result := <-Srv.Store.Audit().PermanentDeleteByUser(user.Id); result.Err != nil {
|
||||
return result.Err
|
||||
}
|
||||
|
||||
l4g.Warn("Permanently deleted account %v id=%v", user.Email, user.Id)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func sendPasswordReset(c *Context, w http.ResponseWriter, r *http.Request) {
|
||||
props := model.MapFromJson(r.Body)
|
||||
|
||||
|
||||
@@ -767,6 +767,43 @@ func TestUserUpdateActive(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserPermDelete(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
team := &model.Team{DisplayName: "Name", Name: "z-z-" + model.NewId() + "a", Email: "test@nowhere.com", Type: model.TEAM_OPEN}
|
||||
team = Client.Must(Client.CreateTeam(team)).Data.(*model.Team)
|
||||
|
||||
user1 := &model.User{TeamId: team.Id, Email: model.NewId() + "corey@test.com", Nickname: "Corey Hulen", Password: "pwd"}
|
||||
user1 = Client.Must(Client.CreateUser(user1, "")).Data.(*model.User)
|
||||
store.Must(Srv.Store.User().VerifyEmail(user1.Id))
|
||||
|
||||
Client.LoginByEmail(team.Name, user1.Email, "pwd")
|
||||
|
||||
channel1 := &model.Channel{DisplayName: "TestGetPosts", Name: "a" + model.NewId() + "a", Type: model.CHANNEL_OPEN, TeamId: team.Id}
|
||||
channel1 = Client.Must(Client.CreateChannel(channel1)).Data.(*model.Channel)
|
||||
|
||||
post1 := &model.Post{ChannelId: channel1.Id, Message: "search for post1"}
|
||||
post1 = Client.Must(Client.CreatePost(post1)).Data.(*model.Post)
|
||||
|
||||
post2 := &model.Post{ChannelId: channel1.Id, Message: "search for post2"}
|
||||
post2 = Client.Must(Client.CreatePost(post2)).Data.(*model.Post)
|
||||
|
||||
post3 := &model.Post{ChannelId: channel1.Id, Message: "#hashtag search for post3"}
|
||||
post3 = Client.Must(Client.CreatePost(post3)).Data.(*model.Post)
|
||||
|
||||
post4 := &model.Post{ChannelId: channel1.Id, Message: "hashtag for post4"}
|
||||
post4 = Client.Must(Client.CreatePost(post4)).Data.(*model.Post)
|
||||
|
||||
c := &Context{}
|
||||
c.RequestId = model.NewId()
|
||||
c.IpAddress = "test"
|
||||
|
||||
err := PermanentDeleteUser(c, user1)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSendPasswordReset(t *testing.T) {
|
||||
Setup()
|
||||
|
||||
|
||||
Ссылка в новой задаче
Block a user