delete user on telegram bot on delete

main
alex 2023-10-22 16:06:03 +02:00
parent 8cc63fc0ef
commit 7a15a9379c
3 changed files with 36 additions and 30 deletions

View File

@ -1,7 +1,6 @@
package notification
import (
"jannex/admin-dashboard-backend/modules/config"
"jannex/admin-dashboard-backend/modules/database"
"jannex/admin-dashboard-backend/modules/requestclient"
"jannex/admin-dashboard-backend/modules/structs"
@ -104,13 +103,11 @@ func AddNotification(c *fiber.Ctx, body structs.AddNotificationRequest) error {
})
}
if config.Cfg.TelegramBotManagerEnabled {
requestclient.TelegramBotManagerRequestClient(structs.TelegramBotManagerRequestBody{
UserIds: userIds,
Title: body.Title,
Type: body.Type,
})
}
requestclient.TelegramBotManagerRequestClient(structs.TelegramBotManagerRequestBody{
UserIds: userIds,
Title: body.Title,
Type: body.Type,
})
return c.SendStatus(fiber.StatusOK)
}

View File

@ -54,6 +54,10 @@ func InvexApiRequestClient(requestMethod string, url string) (statusCode int, bo
}
func TelegramBotManagerRequestClient(telegramBotManagerRequestBody structs.TelegramBotManagerRequestBody) {
if !config.Cfg.TelegramBotManagerEnabled {
return
}
a := fiber.AcquireAgent()
req := a.Request()
@ -83,3 +87,27 @@ func TelegramBotManagerRequestClient(telegramBotManagerRequestBody structs.Teleg
logger.AddSystemLog(rslogger.LogTypeError, "TelegramBotManagerRequestClient err: %s statusCode: %s", "failed to send notification", strconv.Itoa(code))
}
}
func TelegramBotManagerDeleteUserRequestClient(userId string) {
if !config.Cfg.TelegramBotManagerEnabled {
return
}
a := fiber.AcquireAgent()
req := a.Request()
req.Header.SetMethod(fiber.MethodDelete)
req.SetRequestURI(config.Cfg.TelegramBotManagerServerUrl + "/v1/verifycode/" + userId)
if err := a.Parse(); err != nil {
log.Error().Msgf("Failed to parse request, err: %s", err)
logger.AddSystemLog(rslogger.LogTypeError, "TelegramBotManagerRequestClient failed to parse request, err: %s", err.Error())
return
}
code, _, _ := a.Bytes()
if code != 200 {
logger.AddSystemLog(rslogger.LogTypeError, "TelegramBotManagerRequestClient err: %s statusCode: %s", "failed to send notification", strconv.Itoa(code))
}
}

View File

@ -5,6 +5,7 @@ import (
"jannex/admin-dashboard-backend/modules/cache"
"jannex/admin-dashboard-backend/modules/database"
"jannex/admin-dashboard-backend/modules/logger"
"jannex/admin-dashboard-backend/modules/requestclient"
"jannex/admin-dashboard-backend/modules/structs"
"jannex/admin-dashboard-backend/modules/systempermissions"
"jannex/admin-dashboard-backend/modules/utils"
@ -918,6 +919,8 @@ func AllUsersDeleteUser(conn *websocket.Conn, userId string) {
logger.AddSystemLog(rslogger.LogTypeInfo, "User %s has deleted the user %s",
conn.Locals("userId").(string), userId)
requestclient.TelegramBotManagerDeleteUserRequestClient(userId)
}
func AllUsersUserDeactivation(conn *websocket.Conn, userId string, deactivate bool) {
@ -944,28 +947,6 @@ func AllUsersUserDeactivation(conn *websocket.Conn, userId string, deactivate bo
conn.Locals("userId").(string), userId, strconv.FormatBool(deactivate))
}
/*
func ScannersUpdateScannerUsedByUserId(userId string, scannerId string) {
database.DB.Model(&structs.Scanner{}).Where("id = ?", scannerId).Updates(structs.Scanner{UsedByUserId: userId})
BroadcastMessage(structs.SendSocketMessage{
Cmd: utils.SentCmdUpdateScannerUsedBy,
Body: struct {
ScannerId string
UsedByUserId string
}{
ScannerId: scannerId,
UsedByUserId: userId,
},
})
if userId != "" {
logger.AddSystemLog(rslogger.LogTypeInfo, "Scanner %s is now used by user %s", scannerId, userId)
} else {
logger.AddSystemLog(rslogger.LogTypeInfo, "Scanner %s is not longer used", scannerId)
}
}*/
func GetUserApiKeys(userId string) []structs.UserApiKey {
var apiKeys []structs.UserApiKey