- 修复「修改接入网关失败」的问题

- 完成「[功能请求]审计的历史会话建议添加“已阅”的功能」close #194
- 增加一键删除登录日志和历史会话的功能
This commit is contained in:
dushixiang
2021-11-12 20:07:15 +08:00
parent 09040c316e
commit f1432b6886
34 changed files with 801 additions and 234 deletions

View File

@ -2,6 +2,7 @@ package api
import (
"errors"
"next-terminal/server/constant"
"strconv"
"strings"
@ -29,6 +30,7 @@ func UserCreateEndpoint(c echo.Context) (err error) {
item.ID = utils.UUID()
item.Created = utils.NowJsonTime()
item.Status = constant.StatusEnabled
if err := userRepository.Create(&item); err != nil {
return err
@ -82,6 +84,21 @@ func UserUpdateEndpoint(c echo.Context) error {
return Success(c, nil)
}
func UserUpdateStatusEndpoint(c echo.Context) error {
id := c.Param("id")
status := c.QueryParam("status")
account, _ := GetCurrentAccount(c)
if account.ID == id {
return Fail(c, -1, "不能操作自身账户")
}
if err := userService.UpdateStatusById(id, status); err != nil {
return err
}
return Success(c, nil)
}
func UserDeleteEndpoint(c echo.Context) error {
ids := c.Param("id")
account, found := GetCurrentAccount(c)
@ -94,26 +111,10 @@ func UserDeleteEndpoint(c echo.Context) error {
if account.ID == userId {
return Fail(c, -1, "不允许删除自身账户")
}
user, err := userRepository.FindById(userId)
if err != nil {
// 下线该用户
if err := userService.LogoutById(userId); err != nil {
return err
}
// 将用户强制下线
loginLogs, err := loginLogRepository.FindAliveLoginLogsByUsername(user.Username)
if err != nil {
return err
}
for j := range loginLogs {
token := loginLogs[j].ID
cacheKey := userService.BuildCacheKeyByToken(token)
cache.GlobalCache.Delete(cacheKey)
if err := userService.Logout(token); err != nil {
log.WithError(err).WithField("id:", token).Error("Cache Deleted Error")
return Fail(c, 500, "强制下线错误")
}
}
// 删除用户
if err := userRepository.DeleteById(userId); err != nil {
return err