Deactivating and invalidating sessions of guest users on guest disable (#13007)
Automatic Merge
Этот коммит содержится в:
коммит произвёл
mattermod
родитель
6a75d2fc68
Коммит
7031f51b41
39
app/user.go
39
app/user.go
@@ -943,28 +943,28 @@ func (a *App) UpdatePasswordAsUser(userId, currentPassword, newPassword string)
|
||||
return a.UpdatePasswordSendEmail(user, newPassword, T("api.user.update_password.menu"))
|
||||
}
|
||||
|
||||
func (a *App) userDeactivated(user *model.User) *model.AppError {
|
||||
if err := a.RevokeAllSessions(user.Id); err != nil {
|
||||
func (a *App) userDeactivated(userId string) *model.AppError {
|
||||
if err := a.RevokeAllSessions(userId); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
a.SetStatusOffline(user.Id, false)
|
||||
a.SetStatusOffline(userId, false)
|
||||
|
||||
if *a.Config().ServiceSettings.DisableBotsWhenOwnerIsDeactivated {
|
||||
a.disableUserBots(user.Id)
|
||||
a.disableUserBots(userId)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) invalidateUserChannelMembersCaches(user *model.User) *model.AppError {
|
||||
teamsForUser, err := a.GetTeamsForUser(user.Id)
|
||||
func (a *App) invalidateUserChannelMembersCaches(userId string) *model.AppError {
|
||||
teamsForUser, err := a.GetTeamsForUser(userId)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, team := range teamsForUser {
|
||||
channelsForUser, err := a.GetChannelsForUser(team.Id, user.Id, false)
|
||||
channelsForUser, err := a.GetChannelsForUser(team.Id, userId, false)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -992,12 +992,12 @@ func (a *App) UpdateActive(user *model.User, active bool) (*model.User, *model.A
|
||||
ruser := userUpdate.New
|
||||
|
||||
if !active {
|
||||
if err := a.userDeactivated(ruser); err != nil {
|
||||
if err := a.userDeactivated(ruser.Id); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
a.invalidateUserChannelMembersCaches(user)
|
||||
a.invalidateUserChannelMembersCaches(user.Id)
|
||||
a.InvalidateCacheForUser(user.Id)
|
||||
|
||||
a.sendUpdatedUserEvent(*ruser)
|
||||
@@ -1005,6 +1005,27 @@ func (a *App) UpdateActive(user *model.User, active bool) (*model.User, *model.A
|
||||
return ruser, nil
|
||||
}
|
||||
|
||||
func (a *App) DeactivateGuests() *model.AppError {
|
||||
userIds, err := a.Srv.Store.User().DeactivateGuests()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, userId := range userIds {
|
||||
if err := a.userDeactivated(userId); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
a.Srv.Store.Channel().ClearCaches()
|
||||
a.Srv.Store.User().ClearCaches()
|
||||
|
||||
message := model.NewWebSocketEvent(model.WEBSOCKET_EVENT_GUESTS_DEACTIVATED, "", "", "", nil)
|
||||
a.Publish(message)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *App) GetSanitizeOptions(asAdmin bool) map[string]bool {
|
||||
options := a.Config().GetSanitizeOptions()
|
||||
if asAdmin {
|
||||
|
||||
Ссылка в новой задаче
Block a user