Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a791e0f678 | ||
|
|
c1bb2cf4ed | ||
|
|
0ad3e3dead | ||
|
|
aebc53174b | ||
|
|
88e5ffedad | ||
|
|
71a841fee0 | ||
|
|
3029e084ce |
No files matched your search
@@ -17,6 +17,9 @@ linters:
|
|||||||
- tagalign # не всегда имеет смысл
|
- tagalign # не всегда имеет смысл
|
||||||
- varnamelen # очень индивидуально (db)
|
- varnamelen # очень индивидуально (db)
|
||||||
- wsl # расставление пробелов очень индивидуально
|
- wsl # расставление пробелов очень индивидуально
|
||||||
|
- wsl_v5 # расставление пробелов очень индивидуально
|
||||||
|
- godoclint # ругается на // nolint, не удобно
|
||||||
|
- prealloc # слишком аггресивный, в большинстве случаев не требуется
|
||||||
settings:
|
settings:
|
||||||
cyclop:
|
cyclop:
|
||||||
max-complexity: 15 # по умолчанию 10 мало
|
max-complexity: 15 # по умолчанию 10 мало
|
||||||
@@ -53,6 +56,10 @@ linters:
|
|||||||
- linters:
|
- linters:
|
||||||
- wrapcheck
|
- wrapcheck
|
||||||
path: transaction # транзакции прозрачны
|
path: transaction # транзакции прозрачны
|
||||||
|
- linters:
|
||||||
|
- unqueryvet
|
||||||
|
- prealloc
|
||||||
|
path: ".*_test\\.go$"
|
||||||
paths:
|
paths:
|
||||||
- third_party$
|
- third_party$
|
||||||
- builtin$
|
- builtin$
|
||||||
|
|||||||
+19
-1
@@ -1,5 +1,23 @@
|
|||||||
|
### v6.8.1
|
||||||
|
* Обновлен isp-kit
|
||||||
|
### v6.8.0
|
||||||
|
* Изменен контракт методов. В запросах теперь массив идентификаторов пользователей и массив статусов сессий
|
||||||
|
* Обновлена версия go
|
||||||
|
### v6.7.0
|
||||||
|
* Обновлены методы `admin/log/all`, `admin/session/all` и `admin/user/get_users`: добавлена сортировка и поиск
|
||||||
|
* Добавлен воркер выставления статуса 'EXPIRED' для токенов сессий
|
||||||
|
* Добавлено поле `fullName` пользователя, содержащее полное ФИО, получаемое от sudir
|
||||||
|
* Обновлены зависимости
|
||||||
|
### v6.6.1
|
||||||
|
* Добавлено поле `roleNames` в метод `admin/user/get_profile`
|
||||||
|
### v6.6.0
|
||||||
|
* Добавлено отдельное событие 'user_blocked' для блокировки/разблокировки пользователей
|
||||||
|
* Обновлены зависимости
|
||||||
|
### v6.5.0
|
||||||
|
* Изменена уникальность учетных записей с "email" на связку "email + sudir_id"
|
||||||
|
* Добавлен метод `admin/auth/logout_with_reason` для вывода логов `Выхода по бездействию` в журнал ИБ
|
||||||
### v6.4.0
|
### v6.4.0
|
||||||
* Обнолвены зависимости
|
* Обновлены зависимости
|
||||||
### v6.3.1
|
### v6.3.1
|
||||||
* Корневой путь до методов СУДИР перенесён в конфигурацию
|
* Корневой путь до методов СУДИР перенесён в конфигурацию
|
||||||
* Ранее: В конфигурации `https://sudir-domain/` + фиксированно в коде `/blitz/oauth/*`
|
* Ранее: В конфигурации `https://sudir-domain/` + фиксированно в коде `/blitz/oauth/*`
|
||||||
|
|||||||
+2
-2
@@ -1,4 +1,4 @@
|
|||||||
FROM golang:1.24-alpine as builder
|
FROM golang:1.26-alpine as builder
|
||||||
WORKDIR /build
|
WORKDIR /build
|
||||||
ARG version
|
ARG version
|
||||||
ENV version_env=$version
|
ENV version_env=$version
|
||||||
@@ -13,7 +13,7 @@ RUN --mount=type=cache,target=/go/pkg/mod/ \
|
|||||||
--mount=type=bind,target=. \
|
--mount=type=bind,target=. \
|
||||||
go build -ldflags="-X 'main.version=$version_env'" -o /main .
|
go build -ldflags="-X 'main.version=$version_env'" -o /main .
|
||||||
|
|
||||||
FROM alpine:3.21
|
FROM alpine:3.23
|
||||||
|
|
||||||
RUN apk add --no-cache tzdata
|
RUN apk add --no-cache tzdata
|
||||||
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
|
RUN cp /usr/share/zoneinfo/Europe/Moscow /etc/localtime
|
||||||
|
|||||||
@@ -4,6 +4,11 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/conf"
|
||||||
|
"msp-admin-service/service/delete_old_audit_worker"
|
||||||
|
"msp-admin-service/service/inactive_worker"
|
||||||
|
"msp-admin-service/service/session_worker"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/isp-kit/app"
|
"github.com/txix-open/isp-kit/app"
|
||||||
"github.com/txix-open/isp-kit/bgjobx"
|
"github.com/txix-open/isp-kit/bgjobx"
|
||||||
@@ -15,9 +20,6 @@ import (
|
|||||||
"github.com/txix-open/isp-kit/http/httpcli"
|
"github.com/txix-open/isp-kit/http/httpcli"
|
||||||
"github.com/txix-open/isp-kit/http/httpclix"
|
"github.com/txix-open/isp-kit/http/httpclix"
|
||||||
"github.com/txix-open/isp-kit/log"
|
"github.com/txix-open/isp-kit/log"
|
||||||
"msp-admin-service/conf"
|
|
||||||
"msp-admin-service/service/delete_old_audit_worker"
|
|
||||||
"msp-admin-service/service/inactive_worker"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Assembly struct {
|
type Assembly struct {
|
||||||
@@ -80,6 +82,10 @@ func (a *Assembly) ReceiveConfig(ctx context.Context, remoteConfig []byte) error
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
a.logger.Fatal(ctx, errors.WithMessage(err, "seed inactive user worker"))
|
a.logger.Fatal(ctx, errors.WithMessage(err, "seed inactive user worker"))
|
||||||
}
|
}
|
||||||
|
err = session_worker.EnqueueSeedJob(ctx, a.bgjobCli)
|
||||||
|
if err != nil {
|
||||||
|
a.logger.Fatal(ctx, errors.WithMessage(err, "seed expire session worker"))
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-6
@@ -4,12 +4,6 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/txix-open/isp-kit/bgjobx"
|
|
||||||
"github.com/txix-open/isp-kit/db"
|
|
||||||
"github.com/txix-open/isp-kit/grpc/endpoint"
|
|
||||||
"github.com/txix-open/isp-kit/grpc/isp"
|
|
||||||
"github.com/txix-open/isp-kit/http/httpcli"
|
|
||||||
"github.com/txix-open/isp-kit/log"
|
|
||||||
"msp-admin-service/conf"
|
"msp-admin-service/conf"
|
||||||
"msp-admin-service/controller"
|
"msp-admin-service/controller"
|
||||||
"msp-admin-service/repository"
|
"msp-admin-service/repository"
|
||||||
@@ -18,7 +12,15 @@ import (
|
|||||||
"msp-admin-service/service/delete_old_audit_worker"
|
"msp-admin-service/service/delete_old_audit_worker"
|
||||||
"msp-admin-service/service/inactive_worker"
|
"msp-admin-service/service/inactive_worker"
|
||||||
"msp-admin-service/service/secure"
|
"msp-admin-service/service/secure"
|
||||||
|
"msp-admin-service/service/session_worker"
|
||||||
"msp-admin-service/transaction"
|
"msp-admin-service/transaction"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/bgjobx"
|
||||||
|
"github.com/txix-open/isp-kit/db"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/isp"
|
||||||
|
"github.com/txix-open/isp-kit/http/httpcli"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type DB interface {
|
type DB interface {
|
||||||
@@ -117,6 +119,7 @@ func (l Locator) Config(
|
|||||||
l.logger,
|
l.logger,
|
||||||
)
|
)
|
||||||
deleteOldAuditWorker := delete_old_audit_worker.NewService(l.logger, auditRepo, cfg.Audit.AuditTTl)
|
deleteOldAuditWorker := delete_old_audit_worker.NewService(l.logger, auditRepo, cfg.Audit.AuditTTl)
|
||||||
|
expireSessionWorker := session_worker.NewExpireSessionWorker(l.logger, txManager)
|
||||||
|
|
||||||
return Config{
|
return Config{
|
||||||
Handler: handler,
|
Handler: handler,
|
||||||
@@ -130,6 +133,11 @@ func (l Locator) Config(
|
|||||||
Concurrency: 1,
|
Concurrency: 1,
|
||||||
PollInterval: jobPollInterval,
|
PollInterval: jobPollInterval,
|
||||||
Handle: inactiveBlocker,
|
Handle: inactiveBlocker,
|
||||||
|
}, {
|
||||||
|
Queue: session_worker.QueueName,
|
||||||
|
Concurrency: 1,
|
||||||
|
PollInterval: jobPollInterval,
|
||||||
|
Handle: expireSessionWorker,
|
||||||
}},
|
}},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -20,6 +20,10 @@
|
|||||||
{
|
{
|
||||||
"event": "user_changed",
|
"event": "user_changed",
|
||||||
"name": "Изменение пользователя"
|
"name": "Изменение пользователя"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"event": "user_blocked",
|
||||||
|
"name": "Изменение статуса блокировки пользователя"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"auditTTl": {
|
"auditTTl": {
|
||||||
|
|||||||
+1
-1
@@ -13,7 +13,7 @@ import (
|
|||||||
func init() { //
|
func init() { //
|
||||||
schema.CustomGenerators.Register("logLevel", func(field reflect.StructField, t *jsonschema.Schema) {
|
schema.CustomGenerators.Register("logLevel", func(field reflect.StructField, t *jsonschema.Schema) {
|
||||||
t.Type = "string"
|
t.Type = "string"
|
||||||
t.Enum = []interface{}{"debug", "info", "error", "fatal"}
|
t.Enum = []any{"debug", "info", "error", "fatal"}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+13
-5
@@ -3,14 +3,15 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"msp-admin-service/domain"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuditService interface {
|
type AuditService interface {
|
||||||
All(ctx context.Context, limit int, offset int) (*domain.AuditResponse, error)
|
All(ctx context.Context, req domain.AuditPageRequest) (*domain.AuditResponse, error)
|
||||||
Events(ctx context.Context) ([]domain.AuditEvent, error)
|
Events(ctx context.Context) ([]domain.AuditEvent, error)
|
||||||
SetEvents(ctx context.Context, req []domain.SetAuditEvent) error
|
SetEvents(ctx context.Context, req []domain.SetAuditEvent) error
|
||||||
}
|
}
|
||||||
@@ -31,13 +32,20 @@ func NewAudit(service AuditService) Audit {
|
|||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param X-AUTH-ADMIN header string true "Токен администратора"
|
// @Param X-AUTH-ADMIN header string true "Токен администратора"
|
||||||
// @Param body body domain.PageRequest true "Тело запроса"
|
// @Param body body domain.AuditPageRequest true "Тело запроса"
|
||||||
// @Success 200 {object} domain.AuditResponse
|
// @Success 200 {object} domain.AuditResponse
|
||||||
// @Failure 400 {object} domain.GrpcError "Невалидное тело запроса"
|
// @Failure 400 {object} domain.GrpcError "Невалидное тело запроса"
|
||||||
// @Failure 500 {object} domain.GrpcError
|
// @Failure 500 {object} domain.GrpcError
|
||||||
// @Router /log/all [POST]
|
// @Router /log/all [POST]
|
||||||
func (c Audit) All(ctx context.Context, req domain.PageRequest) (*domain.AuditResponse, error) {
|
func (c Audit) All(ctx context.Context, req domain.AuditPageRequest) (*domain.AuditResponse, error) {
|
||||||
return c.service.All(ctx, req.Limit, req.Offset)
|
if req.Order == nil {
|
||||||
|
req.Order = &domain.OrderParams{
|
||||||
|
Field: domain.DefaultOrderField,
|
||||||
|
Type: domain.DefaultOrderType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.service.All(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Events
|
// Events
|
||||||
|
|||||||
+30
-3
@@ -4,19 +4,20 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/isp-kit/grpc"
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
"github.com/txix-open/isp-kit/log"
|
"github.com/txix-open/isp-kit/log"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/metadata"
|
"google.golang.org/grpc/metadata"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"msp-admin-service/domain"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type authService interface {
|
type authService interface {
|
||||||
Login(ctx context.Context, request domain.LoginRequest) (*domain.LoginResponse, error)
|
Login(ctx context.Context, request domain.LoginRequest) (*domain.LoginResponse, error)
|
||||||
LoginWithSudir(ctx context.Context, request domain.LoginSudirRequest) (*domain.LoginResponse, error)
|
LoginWithSudir(ctx context.Context, request domain.LoginSudirRequest) (*domain.LoginResponse, error)
|
||||||
Logout(ctx context.Context, adminId int64) error
|
Logout(ctx context.Context, adminId int64, request *domain.LogoutRequest) error
|
||||||
}
|
}
|
||||||
|
|
||||||
type Auth struct {
|
type Auth struct {
|
||||||
@@ -48,7 +49,33 @@ func (a Auth) Logout(ctx context.Context, authData grpc.AuthData) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
err = a.authService.Logout(ctx, adminId)
|
err = a.authService.Logout(ctx, adminId, nil)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "logout")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// LogoutWithReason
|
||||||
|
// @Tags auth
|
||||||
|
// @Summary Выход по бездействию из авторизованной сессии
|
||||||
|
// @Description Выход по бездействию из авторизованной сессии администрирования
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param body body domain.LogoutRequest true "Тело запроса"
|
||||||
|
// @Param X-AUTH-ADMIN header string true "Токен администратора"
|
||||||
|
// @Success 200
|
||||||
|
// @Failure 400 {object} domain.GrpcError "Невалидный токен"
|
||||||
|
// @Failure 500 {object} domain.GrpcError
|
||||||
|
// @Router /auth/logout_with_reason [POST]
|
||||||
|
func (a Auth) LogoutWithReason(ctx context.Context, authData grpc.AuthData, logoutRequest domain.LogoutRequest) error {
|
||||||
|
adminId, err := getAdminId(authData)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = a.authService.Logout(ctx, adminId, &logoutRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "logout")
|
return errors.WithMessage(err, "logout")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ func NewPermissions(permissionsService permissionsService) Permissions {
|
|||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Success 200 {array} domain.Permission
|
// @Success 200 {array} domain.Permission
|
||||||
// @Router /user/get_profile [POST]
|
// @Router /user/get_permissions [POST]
|
||||||
func (u Permissions) GetPermissions(ctx context.Context) []domain.Permission {
|
func (u Permissions) GetPermissions(ctx context.Context) []domain.Permission {
|
||||||
return u.permissionsService.All(ctx)
|
return u.permissionsService.All(ctx)
|
||||||
}
|
}
|
||||||
+12
-5
@@ -7,7 +7,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type SessionService interface {
|
type SessionService interface {
|
||||||
All(ctx context.Context, limit int, offset int) (*domain.SessionResponse, error)
|
All(ctx context.Context, req domain.SessionPageRequest) (*domain.SessionResponse, error)
|
||||||
Revoke(ctx context.Context, id int) error
|
Revoke(ctx context.Context, id int) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -27,13 +27,20 @@ func NewSession(service SessionService) Session {
|
|||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param X-AUTH-ADMIN header string true "Токен администратора"
|
// @Param X-AUTH-ADMIN header string true "Токен администратора"
|
||||||
// @Param body body domain.SessionRequest true "Тело запроса"
|
// @Param body body domain.SessionPageRequest true "Тело запроса"
|
||||||
// @Success 200 {object} domain.PageRequest
|
// @Success 200 {object} domain.SessionResponse
|
||||||
// @Failure 400 {object} domain.GrpcError "Невалидное тело запроса"
|
// @Failure 400 {object} domain.GrpcError "Невалидное тело запроса"
|
||||||
// @Failure 500 {object} domain.GrpcError
|
// @Failure 500 {object} domain.GrpcError
|
||||||
// @Router /session/all [POST]
|
// @Router /session/all [POST]
|
||||||
func (c Session) All(ctx context.Context, req domain.PageRequest) (*domain.SessionResponse, error) {
|
func (c Session) All(ctx context.Context, req domain.SessionPageRequest) (*domain.SessionResponse, error) {
|
||||||
return c.service.All(ctx, req.Limit, req.Offset)
|
if req.Order == nil {
|
||||||
|
req.Order = &domain.OrderParams{
|
||||||
|
Field: domain.DefaultOrderField,
|
||||||
|
Type: domain.DefaultOrderType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return c.service.All(ctx, req)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Revoke
|
// Revoke
|
||||||
|
|||||||
+35
-5
@@ -2,18 +2,21 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||||
|
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/isp-kit/grpc"
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"msp-admin-service/domain"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type userService interface {
|
type userService interface {
|
||||||
GetProfileById(ctx context.Context, userId int64) (*domain.AdminUserShort, error)
|
GetProfileById(ctx context.Context, userId int64) (*domain.AdminUserShort, error)
|
||||||
GetUsers(ctx context.Context, identities domain.UsersRequest) (*domain.UsersResponse, error)
|
GetUsers(ctx context.Context, req domain.UsersPageRequest) (*domain.UsersResponse, error)
|
||||||
|
GetAllUsers(ctx context.Context) (*domain.UsersResponse, error)
|
||||||
CreateUser(ctx context.Context, req domain.CreateUserRequest, adminId int64) (*domain.User, error)
|
CreateUser(ctx context.Context, req domain.CreateUserRequest, adminId int64) (*domain.User, error)
|
||||||
UpdateUser(ctx context.Context, req domain.UpdateUserRequest, adminId int64) (*domain.User, error)
|
UpdateUser(ctx context.Context, req domain.UpdateUserRequest, adminId int64) (*domain.User, error)
|
||||||
DeleteUsers(ctx context.Context, ids []int64, adminId int64) (int, error)
|
DeleteUsers(ctx context.Context, ids []int64, adminId int64) (int, error)
|
||||||
@@ -70,13 +73,20 @@ func (u User) GetProfile(ctx context.Context, authData grpc.AuthData) (*domain.A
|
|||||||
// @Accept json
|
// @Accept json
|
||||||
// @Produce json
|
// @Produce json
|
||||||
// @Param X-AUTH-ADMIN header string true "Токен администратора"
|
// @Param X-AUTH-ADMIN header string true "Токен администратора"
|
||||||
// @Param body body domain.UsersRequest true "Тело запроса"
|
// @Param body body domain.UsersPageRequest true "Тело запроса"
|
||||||
// @Success 200 {object} domain.UsersResponse
|
// @Success 200 {object} domain.UsersResponse
|
||||||
// @Failure 400 {object} domain.GrpcError
|
// @Failure 400 {object} domain.GrpcError
|
||||||
// @Failure 500 {object} domain.GrpcError
|
// @Failure 500 {object} domain.GrpcError
|
||||||
// @Router /user/get_users [POST]
|
// @Router /user/get_users [POST]
|
||||||
func (u User) GetUsers(ctx context.Context, identities domain.UsersRequest) (*domain.UsersResponse, error) {
|
func (u User) GetUsers(ctx context.Context, req domain.UsersPageRequest) (*domain.UsersResponse, error) {
|
||||||
users, err := u.userService.GetUsers(ctx, identities)
|
if req.Order == nil {
|
||||||
|
req.Order = &domain.OrderParams{
|
||||||
|
Field: domain.DefaultOrderField,
|
||||||
|
Type: domain.DefaultOrderType,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
users, err := u.userService.GetUsers(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "get users")
|
return nil, errors.WithMessage(err, "get users")
|
||||||
}
|
}
|
||||||
@@ -84,6 +94,26 @@ func (u User) GetUsers(ctx context.Context, identities domain.UsersRequest) (*do
|
|||||||
return users, nil
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAllUsers
|
||||||
|
// @Tags user
|
||||||
|
// @Summary Список пользователей
|
||||||
|
// @Description Получить список пользователей
|
||||||
|
// @Accept json
|
||||||
|
// @Produce json
|
||||||
|
// @Param X-AUTH-ADMIN header string true "Токен администратора"
|
||||||
|
// @Success 200 {object} domain.UsersResponse
|
||||||
|
// @Failure 400 {object} domain.GrpcError
|
||||||
|
// @Failure 500 {object} domain.GrpcError
|
||||||
|
// @Router /user/get_all_users [POST]
|
||||||
|
func (u User) GetAllUsers(ctx context.Context) (*domain.UsersResponse, error) {
|
||||||
|
users, err := u.userService.GetAllUsers(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "get all users")
|
||||||
|
}
|
||||||
|
|
||||||
|
return users, nil
|
||||||
|
}
|
||||||
|
|
||||||
// CreateUser
|
// CreateUser
|
||||||
// @Tags user
|
// @Tags user
|
||||||
// @Summary Создать пользователя
|
// @Summary Создать пользователя
|
||||||
|
|||||||
+209
-17
@@ -23,6 +23,8 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
firstName:
|
firstName:
|
||||||
type: string
|
type: string
|
||||||
|
fullName:
|
||||||
|
type: string
|
||||||
idleTimeoutMs:
|
idleTimeoutMs:
|
||||||
type: integer
|
type: integer
|
||||||
lastName:
|
lastName:
|
||||||
@@ -33,6 +35,10 @@ definitions:
|
|||||||
type: array
|
type: array
|
||||||
role:
|
role:
|
||||||
type: string
|
type: string
|
||||||
|
roleNames:
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
roles:
|
roles:
|
||||||
items:
|
items:
|
||||||
type: integer
|
type: integer
|
||||||
@@ -60,6 +66,32 @@ definitions:
|
|||||||
name:
|
name:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
|
domain.AuditPageRequest:
|
||||||
|
properties:
|
||||||
|
limit:
|
||||||
|
type: integer
|
||||||
|
offset:
|
||||||
|
type: integer
|
||||||
|
order:
|
||||||
|
$ref: '#/definitions/domain.OrderParams'
|
||||||
|
query:
|
||||||
|
$ref: '#/definitions/domain.AuditQuery'
|
||||||
|
required:
|
||||||
|
- limit
|
||||||
|
type: object
|
||||||
|
domain.AuditQuery:
|
||||||
|
properties:
|
||||||
|
createdAt:
|
||||||
|
$ref: '#/definitions/domain.DateFromToParams'
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
message:
|
||||||
|
type: string
|
||||||
|
userId:
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
type: array
|
||||||
|
type: object
|
||||||
domain.AuditResponse:
|
domain.AuditResponse:
|
||||||
properties:
|
properties:
|
||||||
items:
|
items:
|
||||||
@@ -112,6 +144,16 @@ definitions:
|
|||||||
- email
|
- email
|
||||||
- password
|
- password
|
||||||
type: object
|
type: object
|
||||||
|
domain.DateFromToParams:
|
||||||
|
properties:
|
||||||
|
from:
|
||||||
|
type: string
|
||||||
|
to:
|
||||||
|
type: string
|
||||||
|
required:
|
||||||
|
- from
|
||||||
|
- to
|
||||||
|
type: object
|
||||||
domain.DeleteResponse:
|
domain.DeleteResponse:
|
||||||
properties:
|
properties:
|
||||||
deleted:
|
deleted:
|
||||||
@@ -174,14 +216,22 @@ definitions:
|
|||||||
required:
|
required:
|
||||||
- authCode
|
- authCode
|
||||||
type: object
|
type: object
|
||||||
domain.PageRequest:
|
domain.LogoutRequest:
|
||||||
properties:
|
properties:
|
||||||
limit:
|
reason:
|
||||||
type: integer
|
type: string
|
||||||
offset:
|
type: object
|
||||||
type: integer
|
domain.OrderParams:
|
||||||
required:
|
properties:
|
||||||
- limit
|
field:
|
||||||
|
type: string
|
||||||
|
type:
|
||||||
|
enum:
|
||||||
|
- asc
|
||||||
|
- desc
|
||||||
|
- ASC
|
||||||
|
- DESC
|
||||||
|
type: string
|
||||||
type: object
|
type: object
|
||||||
domain.Permission:
|
domain.Permission:
|
||||||
properties:
|
properties:
|
||||||
@@ -228,7 +278,6 @@ definitions:
|
|||||||
domain.SecureAuthResponse:
|
domain.SecureAuthResponse:
|
||||||
properties:
|
properties:
|
||||||
adminId:
|
adminId:
|
||||||
format: int64
|
|
||||||
type: integer
|
type: integer
|
||||||
authenticated:
|
authenticated:
|
||||||
type: boolean
|
type: boolean
|
||||||
@@ -247,12 +296,57 @@ definitions:
|
|||||||
authorized:
|
authorized:
|
||||||
type: boolean
|
type: boolean
|
||||||
type: object
|
type: object
|
||||||
domain.SessionRequest:
|
domain.Session:
|
||||||
|
properties:
|
||||||
|
createdAt:
|
||||||
|
type: string
|
||||||
|
expiredAt:
|
||||||
|
type: string
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
status:
|
||||||
|
type: string
|
||||||
|
userId:
|
||||||
|
type: integer
|
||||||
|
type: object
|
||||||
|
domain.SessionPageRequest:
|
||||||
properties:
|
properties:
|
||||||
limit:
|
limit:
|
||||||
type: integer
|
type: integer
|
||||||
offset:
|
offset:
|
||||||
type: integer
|
type: integer
|
||||||
|
order:
|
||||||
|
$ref: '#/definitions/domain.OrderParams'
|
||||||
|
query:
|
||||||
|
$ref: '#/definitions/domain.SessionQuery'
|
||||||
|
required:
|
||||||
|
- limit
|
||||||
|
type: object
|
||||||
|
domain.SessionQuery:
|
||||||
|
properties:
|
||||||
|
createdAt:
|
||||||
|
$ref: '#/definitions/domain.DateFromToParams'
|
||||||
|
expiredAt:
|
||||||
|
$ref: '#/definitions/domain.DateFromToParams'
|
||||||
|
id:
|
||||||
|
type: integer
|
||||||
|
status:
|
||||||
|
items:
|
||||||
|
type: string
|
||||||
|
type: array
|
||||||
|
userId:
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
type: array
|
||||||
|
type: object
|
||||||
|
domain.SessionResponse:
|
||||||
|
properties:
|
||||||
|
items:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/domain.Session'
|
||||||
|
type: array
|
||||||
|
totalCount:
|
||||||
|
type: integer
|
||||||
type: object
|
type: object
|
||||||
domain.SetAuditEvent:
|
domain.SetAuditEvent:
|
||||||
properties:
|
properties:
|
||||||
@@ -309,8 +403,9 @@ definitions:
|
|||||||
type: string
|
type: string
|
||||||
firstName:
|
firstName:
|
||||||
type: string
|
type: string
|
||||||
|
fullName:
|
||||||
|
type: string
|
||||||
id:
|
id:
|
||||||
format: int64
|
|
||||||
type: integer
|
type: integer
|
||||||
lastName:
|
lastName:
|
||||||
type: string
|
type: string
|
||||||
@@ -323,19 +418,37 @@ definitions:
|
|||||||
updatedAt:
|
updatedAt:
|
||||||
type: string
|
type: string
|
||||||
type: object
|
type: object
|
||||||
domain.UsersRequest:
|
domain.UserQuery:
|
||||||
properties:
|
properties:
|
||||||
|
description:
|
||||||
|
type: string
|
||||||
email:
|
email:
|
||||||
type: string
|
type: string
|
||||||
ids:
|
id:
|
||||||
|
type: integer
|
||||||
|
lastSessionCreatedAt:
|
||||||
|
$ref: '#/definitions/domain.DateFromToParams'
|
||||||
|
roles:
|
||||||
items:
|
items:
|
||||||
format: int64
|
|
||||||
type: integer
|
type: integer
|
||||||
type: array
|
type: array
|
||||||
|
userId:
|
||||||
|
items:
|
||||||
|
type: integer
|
||||||
|
type: array
|
||||||
|
type: object
|
||||||
|
domain.UsersPageRequest:
|
||||||
|
properties:
|
||||||
limit:
|
limit:
|
||||||
type: integer
|
type: integer
|
||||||
offset:
|
offset:
|
||||||
type: integer
|
type: integer
|
||||||
|
order:
|
||||||
|
$ref: '#/definitions/domain.OrderParams'
|
||||||
|
query:
|
||||||
|
$ref: '#/definitions/domain.UserQuery'
|
||||||
|
required:
|
||||||
|
- limit
|
||||||
type: object
|
type: object
|
||||||
domain.UsersResponse:
|
domain.UsersResponse:
|
||||||
properties:
|
properties:
|
||||||
@@ -448,6 +561,39 @@ paths:
|
|||||||
summary: Выход из авторизованной сессии
|
summary: Выход из авторизованной сессии
|
||||||
tags:
|
tags:
|
||||||
- auth
|
- auth
|
||||||
|
/auth/logout_with_reason:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Выход по бездействию из авторизованной сессии администрирования
|
||||||
|
parameters:
|
||||||
|
- description: Тело запроса
|
||||||
|
in: body
|
||||||
|
name: body
|
||||||
|
required: true
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.LogoutRequest'
|
||||||
|
- description: Токен администратора
|
||||||
|
in: header
|
||||||
|
name: X-AUTH-ADMIN
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
"400":
|
||||||
|
description: Невалидный токен
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.GrpcError'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.GrpcError'
|
||||||
|
summary: Выход по бездействию из авторизованной сессии
|
||||||
|
tags:
|
||||||
|
- auth
|
||||||
/log/all:
|
/log/all:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
@@ -463,7 +609,7 @@ paths:
|
|||||||
name: body
|
name: body
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.PageRequest'
|
$ref: '#/definitions/domain.AuditPageRequest'
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
@@ -761,14 +907,14 @@ paths:
|
|||||||
name: body
|
name: body
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.SessionRequest'
|
$ref: '#/definitions/domain.SessionPageRequest'
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
"200":
|
"200":
|
||||||
description: OK
|
description: OK
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.PageRequest'
|
$ref: '#/definitions/domain.SessionResponse'
|
||||||
"400":
|
"400":
|
||||||
description: Невалидное тело запроса
|
description: Невалидное тело запроса
|
||||||
schema:
|
schema:
|
||||||
@@ -950,6 +1096,35 @@ paths:
|
|||||||
summary: Удалить пользователя
|
summary: Удалить пользователя
|
||||||
tags:
|
tags:
|
||||||
- user
|
- user
|
||||||
|
/user/get_all_users:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Получить список пользователей
|
||||||
|
parameters:
|
||||||
|
- description: Токен администратора
|
||||||
|
in: header
|
||||||
|
name: X-AUTH-ADMIN
|
||||||
|
required: true
|
||||||
|
type: string
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.UsersResponse'
|
||||||
|
"400":
|
||||||
|
description: Bad Request
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.GrpcError'
|
||||||
|
"500":
|
||||||
|
description: Internal Server Error
|
||||||
|
schema:
|
||||||
|
$ref: '#/definitions/domain.GrpcError'
|
||||||
|
summary: Список пользователей
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
/user/get_by_id:
|
/user/get_by_id:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
@@ -1008,6 +1183,23 @@ paths:
|
|||||||
summary: Получение внешнего вида
|
summary: Получение внешнего вида
|
||||||
tags:
|
tags:
|
||||||
- user
|
- user
|
||||||
|
/user/get_permissions:
|
||||||
|
post:
|
||||||
|
consumes:
|
||||||
|
- application/json
|
||||||
|
description: Получить все разрашения
|
||||||
|
produces:
|
||||||
|
- application/json
|
||||||
|
responses:
|
||||||
|
"200":
|
||||||
|
description: OK
|
||||||
|
schema:
|
||||||
|
items:
|
||||||
|
$ref: '#/definitions/domain.Permission'
|
||||||
|
type: array
|
||||||
|
summary: Получить все разрашения
|
||||||
|
tags:
|
||||||
|
- user
|
||||||
/user/get_profile:
|
/user/get_profile:
|
||||||
post:
|
post:
|
||||||
consumes:
|
consumes:
|
||||||
@@ -1057,7 +1249,7 @@ paths:
|
|||||||
name: body
|
name: body
|
||||||
required: true
|
required: true
|
||||||
schema:
|
schema:
|
||||||
$ref: '#/definitions/domain.UsersRequest'
|
$ref: '#/definitions/domain.UsersPageRequest'
|
||||||
produces:
|
produces:
|
||||||
- application/json
|
- application/json
|
||||||
responses:
|
responses:
|
||||||
|
|||||||
+12
-3
@@ -16,9 +16,18 @@ type AuditResponse struct {
|
|||||||
Items []Audit
|
Items []Audit
|
||||||
}
|
}
|
||||||
|
|
||||||
type PageRequest struct {
|
type AuditPageRequest struct {
|
||||||
Limit int `validate:"required"`
|
LimitOffestParams
|
||||||
Offset int
|
|
||||||
|
Order *OrderParams
|
||||||
|
Query *AuditQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
type AuditQuery struct {
|
||||||
|
Id *int
|
||||||
|
UserId []int
|
||||||
|
Message *string
|
||||||
|
CreatedAt *DateFromToParams
|
||||||
}
|
}
|
||||||
|
|
||||||
type SetAuditEvent struct {
|
type SetAuditEvent struct {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package domain
|
package domain
|
||||||
|
|
||||||
type GrpcError struct {
|
type GrpcError struct {
|
||||||
ErrorMessage string `json:"errorMessage"`
|
ErrorMessage string `json:"errorMessage"`
|
||||||
ErrorCode string `json:"errorCode"`
|
ErrorCode string `json:"errorCode"`
|
||||||
Details []interface{} `json:"details"`
|
Details []any `json:"details"`
|
||||||
}
|
}
|
||||||
+5
-1
@@ -1,4 +1,3 @@
|
|||||||
// nolint:tagliatelle
|
|
||||||
package domain
|
package domain
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -6,6 +5,10 @@ const (
|
|||||||
AdminAuthIdHeader = "x-admin-id"
|
AdminAuthIdHeader = "x-admin-id"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type LogoutRequest struct {
|
||||||
|
Reason string
|
||||||
|
}
|
||||||
|
|
||||||
type LoginRequest struct {
|
type LoginRequest struct {
|
||||||
Email string `validate:"required"`
|
Email string `validate:"required"`
|
||||||
Password string ` validate:"required"`
|
Password string ` validate:"required"`
|
||||||
@@ -15,6 +18,7 @@ type LoginSudirRequest struct {
|
|||||||
AuthCode string `validate:"required"`
|
AuthCode string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:tagliatelle,godoclint
|
||||||
type LoginResponse struct {
|
type LoginResponse struct {
|
||||||
Token string
|
Token string
|
||||||
Expired string `json:",omitempty"`
|
Expired string `json:",omitempty"`
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package domain
|
||||||
|
|
||||||
|
import "time"
|
||||||
|
|
||||||
|
const (
|
||||||
|
DefaultOrderField = "created_at"
|
||||||
|
DefaultOrderType = "desc"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LimitOffestParams struct {
|
||||||
|
Limit uint64 `validate:"required"`
|
||||||
|
Offset uint64
|
||||||
|
}
|
||||||
|
|
||||||
|
type OrderParams struct {
|
||||||
|
Field string
|
||||||
|
Type string `validate:"oneof=asc desc ASC DESC"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type DateFromToParams struct {
|
||||||
|
From time.Time `validate:"required"`
|
||||||
|
To time.Time `validate:"required"`
|
||||||
|
}
|
||||||
+15
-5
@@ -12,16 +12,26 @@ type Session struct {
|
|||||||
CreatedAt time.Time
|
CreatedAt time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SessionPageRequest struct {
|
||||||
|
LimitOffestParams
|
||||||
|
|
||||||
|
Order *OrderParams
|
||||||
|
Query *SessionQuery
|
||||||
|
}
|
||||||
|
|
||||||
|
type SessionQuery struct {
|
||||||
|
Id *int
|
||||||
|
UserId []int
|
||||||
|
Status []string
|
||||||
|
CreatedAt *DateFromToParams
|
||||||
|
ExpiredAt *DateFromToParams
|
||||||
|
}
|
||||||
|
|
||||||
type SessionResponse struct {
|
type SessionResponse struct {
|
||||||
TotalCount int
|
TotalCount int
|
||||||
Items []Session
|
Items []Session
|
||||||
}
|
}
|
||||||
|
|
||||||
type SessionRequest struct {
|
|
||||||
Limit int
|
|
||||||
Offset int
|
|
||||||
}
|
|
||||||
|
|
||||||
type RevokeRequest struct {
|
type RevokeRequest struct {
|
||||||
Id int `validate:"required"`
|
Id int `validate:"required"`
|
||||||
}
|
}
|
||||||
+17
-5
@@ -9,6 +9,7 @@ type User struct {
|
|||||||
Roles []int
|
Roles []int
|
||||||
FirstName string
|
FirstName string
|
||||||
LastName string
|
LastName string
|
||||||
|
FullName string
|
||||||
Email string
|
Email string
|
||||||
Description string
|
Description string
|
||||||
Blocked bool
|
Blocked bool
|
||||||
@@ -21,19 +22,30 @@ type UsersResponse struct {
|
|||||||
Items []User
|
Items []User
|
||||||
}
|
}
|
||||||
|
|
||||||
type UsersRequest struct {
|
type UserQuery struct {
|
||||||
Ids []int64
|
Id *int
|
||||||
Offset int
|
UserId []int
|
||||||
Limit int
|
Description *string
|
||||||
Email string
|
Email *string
|
||||||
|
Roles []int
|
||||||
|
LastSessionCreatedAt *DateFromToParams
|
||||||
|
}
|
||||||
|
|
||||||
|
type UsersPageRequest struct {
|
||||||
|
LimitOffestParams
|
||||||
|
|
||||||
|
Order *OrderParams
|
||||||
|
Query *UserQuery
|
||||||
}
|
}
|
||||||
|
|
||||||
type AdminUserShort struct {
|
type AdminUserShort struct {
|
||||||
FirstName string
|
FirstName string
|
||||||
LastName string
|
LastName string
|
||||||
|
FullName string
|
||||||
Email string `validate:"required"`
|
Email string `validate:"required"`
|
||||||
Role string
|
Role string
|
||||||
Roles []int
|
Roles []int
|
||||||
|
RoleNames []string
|
||||||
Permissions []string
|
Permissions []string
|
||||||
IdleTimeoutMs int
|
IdleTimeoutMs int
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ const (
|
|||||||
EventUserChanged = "user_changed"
|
EventUserChanged = "user_changed"
|
||||||
EventUserPasswordChanged = "success_change_password"
|
EventUserPasswordChanged = "success_change_password"
|
||||||
EventErrorPasswordChange = "error_change_password"
|
EventErrorPasswordChange = "error_change_password"
|
||||||
|
EventUserBlocked = "user_blocked"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuditEvent struct {
|
type AuditEvent struct {
|
||||||
|
|||||||
+4
-1
@@ -1,10 +1,10 @@
|
|||||||
// nolint:tagliatelle,errname
|
|
||||||
package entity
|
package entity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// nolint:tagliatelle,godoclint
|
||||||
type SudirAuthError struct {
|
type SudirAuthError struct {
|
||||||
ErrorName string `json:"error"`
|
ErrorName string `json:"error"`
|
||||||
ErrorDescription string `json:"error_description"`
|
ErrorDescription string `json:"error_description"`
|
||||||
@@ -14,6 +14,7 @@ func (s *SudirAuthError) Error() string {
|
|||||||
return fmt.Sprintf("error: %s; description: %s", s.ErrorName, s.ErrorDescription)
|
return fmt.Sprintf("error: %s; description: %s", s.ErrorName, s.ErrorDescription)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:tagliatelle,errname,godoclint
|
||||||
type SudirUserResponse struct {
|
type SudirUserResponse struct {
|
||||||
*SudirAuthError
|
*SudirAuthError
|
||||||
|
|
||||||
@@ -22,8 +23,10 @@ type SudirUserResponse struct {
|
|||||||
Sub string `json:"sub"`
|
Sub string `json:"sub"`
|
||||||
GivenName string `json:"given_name"`
|
GivenName string `json:"given_name"`
|
||||||
FamilyName string `json:"family_name"`
|
FamilyName string `json:"family_name"`
|
||||||
|
Name string `json:"name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:tagliatelle,errname,godoclint
|
||||||
type SudirTokenResponse struct {
|
type SudirTokenResponse struct {
|
||||||
*SudirAuthError
|
*SudirAuthError
|
||||||
|
|
||||||
|
|||||||
+15
-11
@@ -3,17 +3,19 @@ package entity
|
|||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
SudirUserId *string
|
SudirUserId *string
|
||||||
Id int64
|
Id int64
|
||||||
FirstName string
|
FirstName string
|
||||||
LastName string
|
LastName string
|
||||||
Description string
|
FullName string
|
||||||
Email string
|
Description string
|
||||||
Password string
|
Email string
|
||||||
Blocked bool
|
Password string
|
||||||
LastActiveAt time.Time
|
Blocked bool
|
||||||
UpdatedAt time.Time
|
LastActiveAt time.Time
|
||||||
CreatedAt time.Time
|
UpdatedAt time.Time
|
||||||
|
CreatedAt time.Time
|
||||||
|
LastSessionCreatedAt *time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
type SudirUser struct {
|
type SudirUser struct {
|
||||||
@@ -23,11 +25,13 @@ type SudirUser struct {
|
|||||||
LastName string
|
LastName string
|
||||||
Email string
|
Email string
|
||||||
Description string
|
Description string
|
||||||
|
FullName string
|
||||||
}
|
}
|
||||||
|
|
||||||
type UpdateUser struct {
|
type UpdateUser struct {
|
||||||
FirstName string
|
FirstName string
|
||||||
LastName string
|
LastName string
|
||||||
|
FullName string
|
||||||
Email string
|
Email string
|
||||||
Description string
|
Description string
|
||||||
}
|
}
|
||||||
@@ -1,82 +1,84 @@
|
|||||||
module msp-admin-service
|
module msp-admin-service
|
||||||
|
|
||||||
go 1.24
|
go 1.26
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/Masterminds/squirrel v1.5.4
|
github.com/Masterminds/squirrel v1.5.4
|
||||||
github.com/google/uuid v1.6.0
|
github.com/google/uuid v1.6.0
|
||||||
|
github.com/iancoleman/strcase v0.3.0
|
||||||
github.com/pkg/errors v0.9.1
|
github.com/pkg/errors v0.9.1
|
||||||
github.com/stretchr/testify v1.10.0
|
github.com/stretchr/testify v1.11.1
|
||||||
github.com/txix-open/bgjob v1.5.0
|
github.com/txix-open/bgjob v1.6.0
|
||||||
github.com/txix-open/isp-kit v1.54.1
|
github.com/txix-open/isp-kit v1.71.1
|
||||||
github.com/txix-open/jsonschema v1.3.0
|
github.com/txix-open/jsonschema v1.3.0
|
||||||
golang.org/x/crypto v0.41.0
|
golang.org/x/crypto v0.53.0
|
||||||
golang.org/x/sync v0.16.0
|
golang.org/x/sync v0.21.0
|
||||||
google.golang.org/grpc v1.74.2
|
google.golang.org/grpc v1.82.0
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/bahlo/generic-list-go v0.2.0 // indirect
|
github.com/bahlo/generic-list-go v0.2.0 // indirect
|
||||||
github.com/beorn7/perks v1.0.1 // indirect
|
github.com/beorn7/perks v1.0.1 // indirect
|
||||||
github.com/buger/jsonparser v1.1.1 // indirect
|
github.com/buger/jsonparser v1.2.0 // indirect
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
github.com/cespare/xxhash/v2 v2.3.0 // indirect
|
||||||
github.com/coder/websocket v1.8.13 // indirect
|
github.com/coder/websocket v1.8.15 // indirect
|
||||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
|
||||||
github.com/gabriel-vasile/mimetype v1.4.9 // indirect
|
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
|
||||||
github.com/getsentry/sentry-go v0.35.1 // indirect
|
github.com/getsentry/sentry-go v0.47.0 // indirect
|
||||||
github.com/go-logr/logr v1.4.3 // indirect
|
github.com/go-logr/logr v1.4.3 // indirect
|
||||||
github.com/go-logr/stdr v1.2.2 // indirect
|
github.com/go-logr/stdr v1.2.2 // indirect
|
||||||
github.com/go-playground/locales v0.14.1 // indirect
|
github.com/go-playground/locales v0.14.1 // indirect
|
||||||
github.com/go-playground/universal-translator v0.18.1 // indirect
|
github.com/go-playground/universal-translator v0.18.1 // indirect
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 // indirect
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 // indirect
|
||||||
github.com/iancoleman/strcase v0.3.0 // indirect
|
|
||||||
github.com/jackc/pgpassfile v1.0.0 // indirect
|
github.com/jackc/pgpassfile v1.0.0 // indirect
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect
|
||||||
github.com/jackc/pgx/v5 v5.7.5 // indirect
|
github.com/jackc/pgx/v5 v5.10.0 // indirect
|
||||||
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
github.com/jackc/puddle/v2 v2.2.2 // indirect
|
||||||
github.com/jmoiron/sqlx v1.4.0 // indirect
|
github.com/jmoiron/sqlx v1.4.0 // indirect
|
||||||
github.com/json-iterator/go v1.1.12 // indirect
|
github.com/json-iterator/go v1.1.12 // indirect
|
||||||
|
github.com/klauspost/compress v1.19.0 // indirect
|
||||||
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect
|
||||||
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect
|
||||||
github.com/leodido/go-urn v1.4.0 // indirect
|
github.com/leodido/go-urn v1.4.0 // indirect
|
||||||
github.com/mailru/easyjson v0.9.0 // indirect
|
github.com/mailru/easyjson v0.9.2 // indirect
|
||||||
github.com/mfridman/interpolate v0.0.2 // indirect
|
github.com/mfridman/interpolate v0.0.2 // indirect
|
||||||
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
github.com/mitchellh/mapstructure v1.5.0 // indirect
|
||||||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
|
||||||
github.com/modern-go/reflect2 v1.0.2 // indirect
|
github.com/modern-go/reflect2 v1.0.2 // indirect
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
|
||||||
github.com/pressly/goose/v3 v3.24.3 // indirect
|
github.com/pressly/goose/v3 v3.27.2 // indirect
|
||||||
github.com/prometheus/client_golang v1.23.0 // indirect
|
github.com/prometheus/client_golang v1.23.2 // indirect
|
||||||
github.com/prometheus/client_model v0.6.2 // indirect
|
github.com/prometheus/client_model v0.6.2 // indirect
|
||||||
github.com/prometheus/common v0.65.0 // indirect
|
github.com/prometheus/common v0.69.0 // indirect
|
||||||
github.com/prometheus/procfs v0.17.0 // indirect
|
github.com/prometheus/procfs v0.21.1 // indirect
|
||||||
|
github.com/robfig/cron/v3 v3.0.1 // indirect
|
||||||
github.com/sethvargo/go-retry v0.3.0 // indirect
|
github.com/sethvargo/go-retry v0.3.0 // indirect
|
||||||
github.com/txix-open/bellows v1.2.0 // indirect
|
github.com/txix-open/bellows v1.2.0 // indirect
|
||||||
github.com/txix-open/etp/v4 v4.0.1 // indirect
|
github.com/txix-open/etp/v4 v4.1.1 // indirect
|
||||||
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb // indirect
|
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb // indirect
|
||||||
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
|
github.com/wk8/go-ordered-map/v2 v2.1.8 // indirect
|
||||||
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
github.com/xeipuuv/gojsonpointer v0.0.0-20190905194746-02993c407bfb // indirect
|
||||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 // indirect
|
||||||
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
|
github.com/xeipuuv/gojsonschema v1.2.0 // indirect
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect
|
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.62.0 // indirect
|
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.69.0 // indirect
|
||||||
go.opentelemetry.io/otel v1.37.0 // indirect
|
go.opentelemetry.io/otel v1.44.0 // indirect
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.37.0 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 // indirect
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.37.0 // indirect
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0 // indirect
|
||||||
go.opentelemetry.io/otel/metric v1.37.0 // indirect
|
go.opentelemetry.io/otel/metric v1.44.0 // indirect
|
||||||
go.opentelemetry.io/otel/sdk v1.37.0 // indirect
|
go.opentelemetry.io/otel/sdk v1.44.0 // indirect
|
||||||
go.opentelemetry.io/otel/trace v1.37.0 // indirect
|
go.opentelemetry.io/otel/trace v1.44.0 // indirect
|
||||||
go.opentelemetry.io/proto/otlp v1.7.1 // indirect
|
go.opentelemetry.io/proto/otlp v1.10.0 // indirect
|
||||||
go.uber.org/multierr v1.11.0 // indirect
|
go.uber.org/multierr v1.11.0 // indirect
|
||||||
go.uber.org/zap v1.27.0 // indirect
|
go.uber.org/zap v1.28.0 // indirect
|
||||||
golang.org/x/net v0.43.0 // indirect
|
golang.org/x/net v0.56.0 // indirect
|
||||||
golang.org/x/sys v0.35.0 // indirect
|
golang.org/x/sys v0.46.0 // indirect
|
||||||
golang.org/x/text v0.28.0 // indirect
|
golang.org/x/text v0.38.0 // indirect
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250811230008-5f3141c8851a // indirect
|
google.golang.org/genproto/googleapis/api v0.0.0-20260630182238-925bb5da69e7 // indirect
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250811230008-5f3141c8851a // indirect
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260630182238-925bb5da69e7 // indirect
|
||||||
google.golang.org/protobuf v1.36.7 // indirect
|
google.golang.org/protobuf v1.36.11 // indirect
|
||||||
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
gopkg.in/natefinch/lumberjack.v2 v2.2.1 // indirect
|
||||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||||
)
|
)
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
|
|
||||||
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
|
||||||
|
filippo.io/edwards25519 v1.2.0 h1:crnVqOiS4jqYleHd9vaKZ+HKtHfllngJIiOpNpoJsjo=
|
||||||
|
filippo.io/edwards25519 v1.2.0/go.mod h1:xzAOLCNug/yB62zG1bQ8uziwrIqIuxhctzJT18Q77mc=
|
||||||
github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM=
|
github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM=
|
||||||
github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
|
github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
|
||||||
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
|
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 h1:DklsrG3dyBCFEj5IhUbnKptjxatkF07cF2ak3yi77so=
|
||||||
@@ -8,29 +9,30 @@ github.com/bahlo/generic-list-go v0.2.0 h1:5sz/EEAK+ls5wF+NeqDpk5+iNdMDXrh3z3nPn
|
|||||||
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
|
github.com/bahlo/generic-list-go v0.2.0/go.mod h1:2KvAjgMlE5NNynlg/5iLrrCCZ2+5xWbdbCW3pNTGyYg=
|
||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
|
github.com/buger/jsonparser v1.2.0 h1:4EFcvK1kD4jyj6YqNK6skK6w+y7FHHBR+XBCtxwu/6g=
|
||||||
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
|
github.com/buger/jsonparser v1.2.0/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0 h1:MyRJ/UdXutAwSAT+s3wNd7MfTIcy71VQueUuFK343L8=
|
|
||||||
github.com/cenkalti/backoff/v4 v4.3.0/go.mod h1:Y3VNntkOUPxTVeUxJ/G5vcM//AlwfmyYozVcomhLiZE=
|
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM=
|
||||||
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
|
||||||
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
|
||||||
github.com/coder/websocket v1.8.13 h1:f3QZdXy7uGVz+4uCJy2nTZyM0yTBj8yANEHhqlXZ9FE=
|
github.com/coder/websocket v1.8.15 h1:6B2JPeOGlpff2Uz6vOEH1Vzpi0iUz20A+lPVhPHtNUA=
|
||||||
github.com/coder/websocket v1.8.13/go.mod h1:LNVeNrXQZfe5qhS9ALED3uA+l5pPqvwXg3CKoDBB2gs=
|
github.com/coder/websocket v1.8.15/go.mod h1:NX3SzP+inril6yawo5CQXx8+fk145lPDC6pumgx0mVg=
|
||||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
|
||||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
|
||||||
|
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
github.com/dustin/go-humanize v1.0.1 h1:GzkhY7T5VNhEkwH0PVJgjz+fX1rhBrR7pRT3mDkpeCY=
|
||||||
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
github.com/dustin/go-humanize v1.0.1/go.mod h1:Mu1zIs6XwVuF/gI1OepvI0qD18qycQx+mFykh5fBlto=
|
||||||
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
|
||||||
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.9 h1:5k+WDwEsD9eTLL8Tz3L0VnmVh9QxGjRmjBvAG7U/oYY=
|
github.com/gabriel-vasile/mimetype v1.4.13 h1:46nXokslUBsAJE/wMsp5gtO500a4F3Nkz9Ufpk2AcUM=
|
||||||
github.com/gabriel-vasile/mimetype v1.4.9/go.mod h1:WnSQhFKJuBlRyLiKohA/2DtIlPFAbguNaG7QCHcyGok=
|
github.com/gabriel-vasile/mimetype v1.4.13/go.mod h1:d+9Oxyo1wTzWdyVUPMmXFvp4F9tea18J8ufA774AB3s=
|
||||||
github.com/getsentry/sentry-go v0.35.1 h1:iopow6UVLE2aXu46xKVIs8Z9D/YZkJrHkgozrxa+tOQ=
|
github.com/getsentry/sentry-go v0.47.0 h1:AnSMSyrYA5qZCIN/2xpgAAwv63sVULV+vBq37ajouc8=
|
||||||
github.com/getsentry/sentry-go v0.35.1/go.mod h1:C55omcY9ChRQIUcVcGcs+Zdy4ZpQGvNJ7JYHIoSWOtE=
|
github.com/getsentry/sentry-go v0.47.0/go.mod h1:h+b4VHpKnK7aUXB5wc+KDnPgp9ZtfliRD4eV85FbiSA=
|
||||||
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
|
||||||
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
|
||||||
|
github.com/go-faker/faker/v4 v4.9.0 h1:a4HXLwueuTCtgF93VpUsl8Zd2nG1VH2SgNWDPVEBg5U=
|
||||||
|
github.com/go-faker/faker/v4 v4.9.0/go.mod h1:u1dIRP5neLB6kTzgyVjdBOV5R1uP7BdxkcWk7tiKQXk=
|
||||||
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
|
||||||
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI=
|
||||||
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
|
||||||
@@ -42,11 +44,11 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o
|
|||||||
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY=
|
||||||
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY=
|
||||||
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY=
|
||||||
github.com/go-resty/resty/v2 v2.16.5 h1:hBKqmWrr7uRc3euHVqmh1HTHcKn99Smr7o5spptdhTM=
|
github.com/go-resty/resty/v2 v2.17.2 h1:FQW5oHYcIlkCNrMD2lloGScxcHJ0gkjshV3qcQAyHQk=
|
||||||
github.com/go-resty/resty/v2 v2.16.5/go.mod h1:hkJtXbA2iKHzJheXYvQ8snQES5ZLGKMwQ07xAwp/fiA=
|
github.com/go-resty/resty/v2 v2.17.2/go.mod h1:kCKZ3wWmwJaNc7S29BRtUhJwy7iqmn+2mLtQrOyQlVA=
|
||||||
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
|
||||||
github.com/go-sql-driver/mysql v1.9.2 h1:4cNKDYQ1I84SXslGddlsrMhc8k4LeDVj6Ad6WRjiHuU=
|
github.com/go-sql-driver/mysql v1.10.0 h1:Q+1LV8DkHJvSYAdR83XzuhDaTykuDx0l6fkXxoWCWfw=
|
||||||
github.com/go-sql-driver/mysql v1.9.2/go.mod h1:qn46aNg1333BRMNU69Lq93t8du/dwxI64Gl8i5p1WMU=
|
github.com/go-sql-driver/mysql v1.10.0/go.mod h1:M+cqaI7+xxXGG9swrdeUIoPG3Y3KCkF0pZej+SK+nWk=
|
||||||
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
|
||||||
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
|
||||||
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
|
||||||
@@ -54,16 +56,16 @@ github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX
|
|||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
|
||||||
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1 h1:X5VWvz21y3gzm9Nw/kaUeku/1+uBhcekkmy4IkffJww=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0 h1:5VipnvEpbqr2gA2VbM+nYVbkIF28c5ZQfqCBQ5g2xfk=
|
||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.27.1/go.mod h1:Zanoh4+gvIgluNqcfMVTJueD4wSS5hT7zTt4Mrutd90=
|
github.com/grpc-ecosystem/grpc-gateway/v2 v2.29.0/go.mod h1:Hyl3n6Twe1hvtd9XUXDec4pTvgMSEixRuQKPTMH2bNs=
|
||||||
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
|
github.com/iancoleman/strcase v0.3.0 h1:nTXanmYxhfFAMjZL34Ov6gkzEsSJZ5DbhxWjvSASxEI=
|
||||||
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
|
github.com/iancoleman/strcase v0.3.0/go.mod h1:iwCmte+B7n89clKwxIoIXy/HfoL7AsD47ZCWhYzw7ho=
|
||||||
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM=
|
||||||
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo=
|
||||||
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM=
|
||||||
github.com/jackc/pgx/v5 v5.7.5 h1:JHGfMnQY+IEtGM63d+NGMjoRpysB2JBwDr5fsngwmJs=
|
github.com/jackc/pgx/v5 v5.10.0 h1:VhSvgU2jSli8o3AqIEOTJr7rZwAEUVo4E4XhR94Zfr0=
|
||||||
github.com/jackc/pgx/v5 v5.7.5/go.mod h1:aruU7o91Tc2q2cFp5h4uP3f6ztExVpyVv88Xl/8Vl8M=
|
github.com/jackc/pgx/v5 v5.10.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4=
|
||||||
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo=
|
||||||
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
|
||||||
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
|
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
|
||||||
@@ -72,8 +74,8 @@ github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnr
|
|||||||
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
|
||||||
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
|
github.com/julienschmidt/httprouter v1.3.0 h1:U0609e9tgbseu3rBINet9P48AI/D3oJs4dN7jwJOQ1U=
|
||||||
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
github.com/julienschmidt/httprouter v1.3.0/go.mod h1:JR6WtHb+2LUe8TCKY3cZOxFyyO8IZAc4RVcycCCAKdM=
|
||||||
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
|
github.com/klauspost/compress v1.19.0 h1:sXLILfc9jV2QYWkzFOPWStmcUVH2RHEB1JCdY2oVvCQ=
|
||||||
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
|
github.com/klauspost/compress v1.19.0/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
|
||||||
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
|
||||||
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
|
||||||
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
|
||||||
@@ -88,10 +90,10 @@ github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ=
|
|||||||
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI=
|
||||||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw=
|
||||||
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
github.com/lib/pq v1.10.9/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
|
||||||
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
|
github.com/mailru/easyjson v0.9.2 h1:dX8U45hQsZpxd80nLvDGihsQ/OxlvTkVUXH2r/8cb2M=
|
||||||
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
|
github.com/mailru/easyjson v0.9.2/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
|
||||||
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
|
github.com/mattn/go-isatty v0.0.21 h1:xYae+lCNBP7QuW4PUnNG61ffM4hVIfm+zUzDuSzYLGs=
|
||||||
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
|
github.com/mattn/go-isatty v0.0.21/go.mod h1:ZXfXG4SQHsB/w3ZeOYbR0PrPwLy+n6xiMrJlRFqopa4=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
|
||||||
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
|
||||||
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
|
github.com/mfridman/interpolate v0.0.2 h1:pnuTK7MQIxxFz1Gr+rjSIx9u7qVjf5VOoM/u6BbAxPY=
|
||||||
@@ -105,28 +107,31 @@ github.com/modern-go/reflect2 v1.0.2 h1:xBagoLtFs94CBntxluKeaWgTMpvLxC4ur3nMaC9G
|
|||||||
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
github.com/modern-go/reflect2 v1.0.2/go.mod h1:yWuevngMOJpCy52FWWMvUC8ws7m/LJsjYzDa0/r8luk=
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
|
||||||
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
|
||||||
github.com/ncruces/go-strftime v0.1.9 h1:bY0MQC28UADQmHmaF5dgpLmImcShSi2kHU9XLdhx/f4=
|
github.com/ncruces/go-strftime v1.0.0 h1:HMFp8mLCTPp341M/ZnA4qaf7ZlsbTc+miZjCLOFAw7w=
|
||||||
github.com/ncruces/go-strftime v0.1.9/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
github.com/ncruces/go-strftime v1.0.0/go.mod h1:Fwc5htZGVVkseilnfgOVb9mKy6w1naJmn9CehxcKcls=
|
||||||
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
github.com/pingcap/errors v0.11.4 h1:lFuQV/oaUMGcD2tqt+01ROSmJs75VG1ToEOkZIZ4nE4=
|
||||||
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
github.com/pingcap/errors v0.11.4/go.mod h1:Oi8TUi2kEtXXLMJk9l1cGmz20kV3TaQ0usTwv5KuLY8=
|
||||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/pressly/goose/v3 v3.24.3 h1:DSWWNwwggVUsYZ0X2VitiAa9sKuqtBfe+Jr9zFGwWlM=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U=
|
||||||
github.com/pressly/goose/v3 v3.24.3/go.mod h1:v9zYL4xdViLHCUUJh/mhjnm6JrK7Eul8AS93IxiZM4E=
|
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/prometheus/client_golang v1.23.0 h1:ust4zpdl9r4trLY/gSjlm07PuiBq2ynaXXlptpfy8Uc=
|
github.com/pressly/goose/v3 v3.27.2 h1:FjKNzcmMdGrQlSIu5alMSmakQtJFBgtw+A0bb1p/LC8=
|
||||||
github.com/prometheus/client_golang v1.23.0/go.mod h1:i/o0R9ByOnHX0McrTMTyhYvKE4haaf2mW08I+jGAjEE=
|
github.com/pressly/goose/v3 v3.27.2/go.mod h1:qWW+/8dkVtJYjJrbIpwD5xxnEJTUKvxkQ9JKQp9LaIM=
|
||||||
|
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
|
||||||
|
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
|
||||||
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
|
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
|
||||||
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
|
github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE=
|
||||||
github.com/prometheus/common v0.65.0 h1:QDwzd+G1twt//Kwj/Ww6E9FQq1iVMmODnILtW1t2VzE=
|
github.com/prometheus/common v0.69.0 h1:OA85nJQS/T/MaYh/Q2CcgDKSGWqNIgrBDvDH85CuiNk=
|
||||||
github.com/prometheus/common v0.65.0/go.mod h1:0gZns+BLRQ3V6NdaerOhMbwwRbNh9hkGINtQAsP5GS8=
|
github.com/prometheus/common v0.69.0/go.mod h1:ZzL3f6u94qUxh9p+tJTrF+FvBS1XXbbRAZCQkytAL0Y=
|
||||||
github.com/prometheus/procfs v0.17.0 h1:FuLQ+05u4ZI+SS/w9+BWEM2TXiHKsUQ9TADiRH7DuK0=
|
github.com/prometheus/procfs v0.21.1 h1:GljZCt+zSTS+NZq88cyQ1LjZ+RCHp3uVuabBWA5+OJI=
|
||||||
github.com/prometheus/procfs v0.17.0/go.mod h1:oPQLaDAMRbA+u8H5Pbfq+dl3VDAvHxMUOVhe0wYB2zw=
|
github.com/prometheus/procfs v0.21.1/go.mod h1:aB55Cww9pdSJVHk0hUf0inxWyyjPogFIjmHKYgMKmtY=
|
||||||
github.com/rabbitmq/amqp091-go v1.10.0 h1:STpn5XsHlHGcecLmMFCtg7mqq0RnD+zFr4uzukfVhBw=
|
github.com/rabbitmq/amqp091-go v1.12.0 h1:V0v14Iqfs+MwHWihJt/nGS5Ulu0vw572b2Co3mwunkI=
|
||||||
github.com/rabbitmq/amqp091-go v1.10.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
|
github.com/rabbitmq/amqp091-go v1.12.0/go.mod h1:Hy4jKW5kQART1u+JkDTF9YYOQUHXqMuhrgxOEeS7G4o=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec h1:W09IVJc94icq4NjY3clb7Lk8O1qJ8BdBEF8z0ibU0rE=
|
||||||
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
github.com/remyoudompheng/bigfft v0.0.0-20230129092748-24d4a6f8daec/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
|
||||||
|
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
|
||||||
|
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
|
||||||
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
|
||||||
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
|
||||||
github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=
|
github.com/sethvargo/go-retry v0.3.0 h1:EEt31A35QhrcRZtrYFDTBg91cqZVnFL2navjDrah2SE=
|
||||||
@@ -142,18 +147,18 @@ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/
|
|||||||
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
|
||||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||||
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
|
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
|
||||||
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
|
||||||
github.com/txix-open/bellows v1.2.0 h1:CXv8nQaZtB/micraeRilYyj/gtfv+bqBgP5aPYQgjeY=
|
github.com/txix-open/bellows v1.2.0 h1:CXv8nQaZtB/micraeRilYyj/gtfv+bqBgP5aPYQgjeY=
|
||||||
github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o=
|
github.com/txix-open/bellows v1.2.0/go.mod h1:qbKCy+RTgD30Qpw1fyb3y3jp5Y9mGhLLxgae1l0W92o=
|
||||||
github.com/txix-open/bgjob v1.5.0 h1:/ZbHzb3EZDZSzaUxA7xfuYt9CS/hmXC33mJ4Z4Lvkhc=
|
github.com/txix-open/bgjob v1.6.0 h1:Vwj9cAsIhMrHPKRZVxfg6mHqE9LI/atDCq1aeihH3+I=
|
||||||
github.com/txix-open/bgjob v1.5.0/go.mod h1:aKbwpVclWmq82s7fchazp099yWjEpVKFkxT85i4hARM=
|
github.com/txix-open/bgjob v1.6.0/go.mod h1:aKbwpVclWmq82s7fchazp099yWjEpVKFkxT85i4hARM=
|
||||||
github.com/txix-open/etp/v4 v4.0.1 h1:5VSYgGsvnMz0tvUHsjVWFETI0qWBTCF1O3ARCHaCIgA=
|
github.com/txix-open/etp/v4 v4.1.1 h1:Yna+0mw/kQZP7Rl6QI4spCrO6qgO8ZhP8PjHlJj2lTU=
|
||||||
github.com/txix-open/etp/v4 v4.0.1/go.mod h1:FIu7TUDdwcgmtmF6tFTV1bGA2fRY/iVaPQdsGzvqYc8=
|
github.com/txix-open/etp/v4 v4.1.1/go.mod h1:9GK+Aje8BmLFq8Hk4j6Qb976LdU9WECCWAuLK1vAKgM=
|
||||||
github.com/txix-open/grmq v1.9.0 h1:ArDbJJcFX9zXKEcPf49rp9nYiRyGMJxGKJAxdbSsfaM=
|
github.com/txix-open/grmq v1.12.0 h1:lSPYvwLfTL0+b0xDQmuuN6RaKS3NCEJNK9ccWpOWa8Y=
|
||||||
github.com/txix-open/grmq v1.9.0/go.mod h1:EyFOP17KrwEFOUjR+PH8iH3LCtiN9TSQ8t0ysyk62po=
|
github.com/txix-open/grmq v1.12.0/go.mod h1:6m9CCTQao/HAFalu5rFOZGJ5KLEP6WzzIwj80Ml3KGE=
|
||||||
github.com/txix-open/isp-kit v1.54.1 h1:OY4dQgvhHpRicwpemnoHxs+w2/rMkc19Jf0Nj8QPIeI=
|
github.com/txix-open/isp-kit v1.71.1 h1:MNSuHy/HEvy7dKPQXkM+dgQpShDhcv1Sq1kLgep2LaA=
|
||||||
github.com/txix-open/isp-kit v1.54.1/go.mod h1:sVUjen989u4yz5SYAZ4LRCQzRfwlU/uJ5ogiU31zmks=
|
github.com/txix-open/isp-kit v1.71.1/go.mod h1:j2sj86byoKllCs+DaRWwg56NgcL2omr/bUzmU7+AF74=
|
||||||
github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4=
|
github.com/txix-open/jsonschema v1.3.0 h1:XGuOTg22G7PdqfKypjajM20/i5FyGfFYsJKmheebKi4=
|
||||||
github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
github.com/txix-open/jsonschema v1.3.0/go.mod h1:l8YDZ1nvJrw6uxWowSVOxCV/ebiMJyapffW87ZEqH00=
|
||||||
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0=
|
github.com/txix-open/validator/v10 v10.0.0-20250506161033-f8ce404fffdb h1:UJgT4u/QMv5QHKOQeJ7igShHa36c2/vIRqJiRLdDlf0=
|
||||||
@@ -167,54 +172,58 @@ github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415 h1:EzJWgHo
|
|||||||
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
github.com/xeipuuv/gojsonreference v0.0.0-20180127040603-bd5ef7bd5415/go.mod h1:GwrjFmJcFw6At/Gs6z4yjiIwzuJ1/+UwLxMQDVQXShQ=
|
||||||
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
|
github.com/xeipuuv/gojsonschema v1.2.0 h1:LhYJRs+L4fBtjZUfuSZIKGeVu0QRy8e5Xi7D17UxZ74=
|
||||||
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
github.com/xeipuuv/gojsonschema v1.2.0/go.mod h1:anYRn/JVcOK2ZgGU+IjEV4nwlhoK5sQluxsYJ78Id3Y=
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0 h1:cH53jehLUN6UFLY71z+NDOiNJqDdPRaXzTel0sJySYA=
|
go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64=
|
||||||
go.opentelemetry.io/auto/sdk v1.1.0/go.mod h1:3wSPjt5PWp2RhlCcmmOial7AvC4DQqZb7a7wCow3W8A=
|
go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y=
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.62.0 h1:wCeciVlAfb5DC8MQl/DlmAv/FVPNpQgFvI/71+hatuc=
|
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.69.0 h1:MCcYL7J6Vt/X0kjqbMZkekCmwsurbQRbL69vkiye2lk=
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.62.0/go.mod h1:WfEApdZDMlLUAev/0QQpr8EJ/z0VWDKYZ5tF5RH5T1U=
|
go.opentelemetry.io/contrib/instrumentation/net/http/httptrace/otelhttptrace v0.69.0/go.mod h1:3jnStNwSufK+f5ktjL4EPcwtig4rtd81NS70lqHuXl8=
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0 h1:Hf9xI/XLML9ElpiHVDNwvqI0hIFlzV8dgIr35kV1kRU=
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.69.0 h1:8tvICD4vSTOOsNrsI4Ljf6C+6UKvpTEH5XY3JMoyPoo=
|
||||||
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.62.0/go.mod h1:NfchwuyNoMcZ5MLHwPrODwUF1HWCXWrL31s8gSAdIKY=
|
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.69.0/go.mod h1:z9+yiacE0IHRqM4qFfkbt/JYlmYXgss8GY/jXoNuPJI=
|
||||||
go.opentelemetry.io/otel v1.37.0 h1:9zhNfelUvx0KBfu/gb+ZgeAfAgtWrfHJZcAqFC228wQ=
|
go.opentelemetry.io/otel v1.44.0 h1:JjwHmHpA4iZ3wBxluu2fbbE7j4kqlE8jXyAyPXH7HqU=
|
||||||
go.opentelemetry.io/otel v1.37.0/go.mod h1:ehE/umFRLnuLa/vSccNq9oS1ErUlkkK71gMcN34UG8I=
|
go.opentelemetry.io/otel v1.44.0/go.mod h1:BMgjTHL9WPRlRjL2oZCBTL4whCGtXch2H4BhOPIAyYc=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.37.0 h1:Ahq7pZmv87yiyn3jeFz/LekZmPLLdKejuO3NcK9MssM=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0 h1:4YsVu3B8+3qtWYYrsUYgn0OG78pN0rnNPRGX4SbokQI=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.37.0/go.mod h1:MJTqhM0im3mRLw1i8uGHnCvUEeS7VwRyxlLC78PA18M=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.44.0/go.mod h1:+wnlSn0mD1ADVMe3v9Z/WIaiz6q6gL2J/ejaAmdmv80=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.37.0 h1:bDMKF3RUSxshZ5OjOTi8rsHGaPKsAt76FaqgvIUySLc=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0 h1:lgh3PiVrRUWMLOVSkQicxzZll5NjF1r+AtsX1XRIHw0=
|
||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.37.0/go.mod h1:dDT67G/IkA46Mr2l9Uj7HsQVwsjASyV9SjGofsiUZDA=
|
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.44.0/go.mod h1:5Cnhth3m/AgOeTgE3ex12pPmiu/gGtZit03kSzx9X7s=
|
||||||
go.opentelemetry.io/otel/metric v1.37.0 h1:mvwbQS5m0tbmqML4NqK+e3aDiO02vsf/WgbsdpcPoZE=
|
go.opentelemetry.io/otel/metric v1.44.0 h1:1w0gILTcHdr3YI+ixLyjemwrVnsMURbTZFrSYCdDdmc=
|
||||||
go.opentelemetry.io/otel/metric v1.37.0/go.mod h1:04wGrZurHYKOc+RKeye86GwKiTb9FKm1WHtO+4EVr2E=
|
go.opentelemetry.io/otel/metric v1.44.0/go.mod h1:8O7hanEPBNgEMmybD3s2VBKcgWOCsA6tzHBPODAiquo=
|
||||||
go.opentelemetry.io/otel/sdk v1.37.0 h1:ItB0QUqnjesGRvNcmAcU0LyvkVyGJ2xftD29bWdDvKI=
|
go.opentelemetry.io/otel/sdk v1.44.0 h1:nHYwb9lK+fJPU/dnT6s7W7Z8itMWyqrnVfbheVYrZ58=
|
||||||
go.opentelemetry.io/otel/sdk v1.37.0/go.mod h1:VredYzxUvuo2q3WRcDnKDjbdvmO0sCzOvVAiY+yUkAg=
|
go.opentelemetry.io/otel/sdk v1.44.0/go.mod h1:Osuydd3Se74nqjAKxid74N5eC+jfEqfTegHRnq58oK0=
|
||||||
go.opentelemetry.io/otel/sdk/metric v1.37.0 h1:90lI228XrB9jCMuSdA0673aubgRobVZFhbjxHHspCPc=
|
go.opentelemetry.io/otel/sdk/metric v1.44.0 h1:3LlKgI+VjbVsjNRFZJZAJ30WjXC5VkNRks6si09iEfI=
|
||||||
go.opentelemetry.io/otel/sdk/metric v1.37.0/go.mod h1:cNen4ZWfiD37l5NhS+Keb5RXVWZWpRE+9WyVCpbo5ps=
|
go.opentelemetry.io/otel/sdk/metric v1.44.0/go.mod h1:5B5pMARnXxKhltooO4xUuCBorl65a4EpnTalObqOigA=
|
||||||
go.opentelemetry.io/otel/trace v1.37.0 h1:HLdcFNbRQBE2imdSEgm/kwqmQj1Or1l/7bW6mxVK7z4=
|
go.opentelemetry.io/otel/trace v1.44.0 h1:jxF5CsGYCe74MCRx2X4g7WsY/VBKRqqpNvXlX/6gtIk=
|
||||||
go.opentelemetry.io/otel/trace v1.37.0/go.mod h1:TlgrlQ+PtQO5XFerSPUYG0JSgGyryXewPGyayAWSBS0=
|
go.opentelemetry.io/otel/trace v1.44.0/go.mod h1:oLl1jrMQAVo6v3GAggN+1VH9VIz9iUSvW53sW1Q8PIE=
|
||||||
go.opentelemetry.io/proto/otlp v1.7.1 h1:gTOMpGDb0WTBOP8JaO72iL3auEZhVmAQg4ipjOVAtj4=
|
go.opentelemetry.io/proto/otlp v1.10.0 h1:IQRWgT5srOCYfiWnpqUYz9CVmbO8bFmKcwYxpuCSL2g=
|
||||||
go.opentelemetry.io/proto/otlp v1.7.1/go.mod h1:b2rVh6rfI/s2pHWNlB7ILJcRALpcNDzKhACevjI+ZnE=
|
go.opentelemetry.io/proto/otlp v1.10.0/go.mod h1:/CV4QoCR/S9yaPj8utp3lvQPoqMtxXdzn7ozvvozVqk=
|
||||||
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
|
||||||
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
|
||||||
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
|
||||||
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
go.uber.org/multierr v1.11.0/go.mod h1:20+QtiLqy0Nd6FdQB9TLXag12DsQkrbs3htMFfDN80Y=
|
||||||
go.uber.org/zap v1.27.0 h1:aJMhYGrd5QSmlpLMr2MftRKl7t8J8PTZPA732ud/XR8=
|
go.uber.org/zap v1.28.0 h1:IZzaP1Fv73/T/pBMLk4VutPl36uNC+OSUh3JLG3FIjo=
|
||||||
go.uber.org/zap v1.27.0/go.mod h1:GB2qFLM7cTU87MWRP2mPIjqfIDnGu+VIO4V/SdhGo2E=
|
go.uber.org/zap v1.28.0/go.mod h1:rDLpOi171uODNm/mxFcuYWxDsqWSAVkFdX4XojSKg/Q=
|
||||||
golang.org/x/crypto v0.41.0 h1:WKYxWedPGCTVVl5+WHSSrOBT0O8lx32+zxmHxijgXp4=
|
go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ=
|
||||||
golang.org/x/crypto v0.41.0/go.mod h1:pO5AFd7FA68rFak7rOAGVuygIISepHftHnr8dr6+sUc=
|
go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ=
|
||||||
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6 h1:y5zboxd6LQAqYIhHnB48p0ByQ/GnQx2BE33L8BOHQkI=
|
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
|
||||||
golang.org/x/exp v0.0.0-20250506013437-ce4c2cf36ca6/go.mod h1:U6Lno4MTRCDY+Ba7aCcauB9T60gsv5s4ralQzP72ZoQ=
|
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||||
golang.org/x/net v0.43.0 h1:lat02VYK2j4aLzMzecihNvTlJNQUq316m2Mr9rnM6YE=
|
golang.org/x/crypto v0.53.0 h1:QZ4Muo8THX6CizN2vPPd5fBGHyogrdK9fG4wLPFUsto=
|
||||||
golang.org/x/net v0.43.0/go.mod h1:vhO1fvI4dGsIjh73sWfUVjj3N7CA9WkKJNQm2svM6Jg=
|
golang.org/x/crypto v0.53.0/go.mod h1:DNLU434OwVakk9PzuwV8w62mAJpRJL3vsgcfp4Qnsio=
|
||||||
golang.org/x/sync v0.16.0 h1:ycBJEhp9p4vXvUZNszeOq0kGTPghopOL8q0fq3vstxw=
|
golang.org/x/net v0.56.0 h1:Rw8j/hFzGvJUZwNBXnAtf5sVDVt+65SK2C7IxCxZt5o=
|
||||||
golang.org/x/sync v0.16.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
|
golang.org/x/net v0.56.0/go.mod h1:D3Ku6r+V6JROoZK144D2XfMHFcMq/0zSfLelVTCFKec=
|
||||||
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
|
golang.org/x/sync v0.21.0 h1:HLII4xRRTtCRkxYp4HNFF0Js/Og6q2i++KXbg0gHCwM=
|
||||||
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
|
golang.org/x/sync v0.21.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
|
||||||
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
|
golang.org/x/sys v0.46.0 h1:noSf2Fq6F8DBgS+LysIkx7rIExoNHJsxOAtPp4rthXw=
|
||||||
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
|
golang.org/x/sys v0.46.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250811230008-5f3141c8851a h1:DMCgtIAIQGZqJXMVzJF4MV8BlWoJh2ZuFiRdAleyr58=
|
golang.org/x/text v0.38.0 h1:sXmwo9DwP3OK9EZ7PqAdaooSGozfl/3a6/xJcbzPRhE=
|
||||||
google.golang.org/genproto/googleapis/api v0.0.0-20250811230008-5f3141c8851a/go.mod h1:y2yVLIE/CSMCPXaHnSKXxu1spLPnglFLegmgdY23uuE=
|
golang.org/x/text v0.38.0/go.mod h1:YXZt3QhHUKYT53r2lLKFIVi6Ao1jdzrTR/KQ09qyxF4=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250811230008-5f3141c8851a h1:tPE/Kp+x9dMSwUm/uM0JKK0IfdiJkwAbSMSeZBXXJXc=
|
gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4=
|
||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20250811230008-5f3141c8851a/go.mod h1:gw1tLEfykwDz2ET4a12jcXt4couGAm7IwsVaTy0Sflo=
|
gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E=
|
||||||
google.golang.org/grpc v1.74.2 h1:WoosgB65DlWVC9FqI82dGsZhWFNBSLjQ84bjROOpMu4=
|
google.golang.org/genproto/googleapis/api v0.0.0-20260630182238-925bb5da69e7 h1:jQ9p21COKWjP3VwuFrNRiiOTMh3mPpN45R7SLrH/HUU=
|
||||||
google.golang.org/grpc v1.74.2/go.mod h1:CtQ+BGjaAIXHs/5YS3i473GqwBBa1zGQNevxdeBEXrM=
|
google.golang.org/genproto/googleapis/api v0.0.0-20260630182238-925bb5da69e7/go.mod h1:KqHwBx2upmfa1XSi1WuRvC+2VGCLtooKkfmyvRbUmqA=
|
||||||
google.golang.org/protobuf v1.36.7 h1:IgrO7UwFQGJdRNXH/sQux4R1Dj1WAKcLElzeeRaXV2A=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260630182238-925bb5da69e7 h1:eM/YSd5bBFagF51o1E745Ta7RwzpW0h+z+QDNZOgmQ8=
|
||||||
google.golang.org/protobuf v1.36.7/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
|
google.golang.org/genproto/googleapis/rpc v0.0.0-20260630182238-925bb5da69e7/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
|
||||||
|
google.golang.org/grpc v1.82.0 h1:vguDnZUPjE26w09A63VoxZPnvPjB5Riyc0mkXPFmAIU=
|
||||||
|
google.golang.org/grpc v1.82.0/go.mod h1:yzTZ1TB1Z3SG+LIYaI+WiE8D5+PZ3ArnrSp8zF3+/ZA=
|
||||||
|
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
|
||||||
|
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
|
||||||
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
|
||||||
@@ -223,11 +232,11 @@ gopkg.in/natefinch/lumberjack.v2 v2.2.1/go.mod h1:YD8tP3GAjkrDg1eZH7EGmyESg/lsYs
|
|||||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
modernc.org/libc v1.65.0 h1:e183gLDnAp9VJh6gWKdTy0CThL9Pt7MfcR/0bgb7Y1Y=
|
modernc.org/libc v1.73.4 h1:+ra4Ui8ngyt8HDcO1FTDPWlkAh6yOdaO2yAoh8MddQA=
|
||||||
modernc.org/libc v1.65.0/go.mod h1:7m9VzGq7APssBTydds2zBcxGREwvIGpuUBaKTXdm2Qs=
|
modernc.org/libc v1.73.4/go.mod h1:DXZ3eO8qMCNn2SnmTNCiC71nJ9Rcq3PsnpU6Vc4rWK8=
|
||||||
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
modernc.org/mathutil v1.7.1 h1:GCZVGXdaN8gTqB1Mf/usp1Y/hSqgI2vAGGP4jZMCxOU=
|
||||||
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
modernc.org/mathutil v1.7.1/go.mod h1:4p5IwJITfppl0G4sUEDtCr4DthTaT47/N3aT6MhfgJg=
|
||||||
modernc.org/memory v1.10.0 h1:fzumd51yQ1DxcOxSO+S6X7+QTuVU+n8/Aj7swYjFfC4=
|
modernc.org/memory v1.11.0 h1:o4QC8aMQzmcwCK3t3Ux/ZHmwFPzE6hf2Y5LbkRs+hbI=
|
||||||
modernc.org/memory v1.10.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
modernc.org/memory v1.11.0/go.mod h1:/JP4VbVC+K5sU2wZi9bHoq2MAkCnrt2r98UGeSK7Mjw=
|
||||||
modernc.org/sqlite v1.37.0 h1:s1TMe7T3Q3ovQiK2Ouz4Jwh7dw4ZDqbebSDTlSJdfjI=
|
modernc.org/sqlite v1.53.0 h1:20WG8N9q4ji/dEqGk4uiI0c6OPjSeLTNYGFCc3+7c1M=
|
||||||
modernc.org/sqlite v1.37.0/go.mod h1:5YiWv+YviqGMuGw4V+PNplcyaJ5v+vQd7TQOgkACoJM=
|
modernc.org/sqlite v1.53.0/go.mod h1:xoEpOIpGrgT48H5iiyt/YXPCZPEzlfmfFwtk8Lklw8s=
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/txix-open/isp-kit/bootstrap"
|
|
||||||
"github.com/txix-open/isp-kit/shutdown"
|
|
||||||
"msp-admin-service/assembly"
|
"msp-admin-service/assembly"
|
||||||
"msp-admin-service/conf"
|
"msp-admin-service/conf"
|
||||||
"msp-admin-service/routes"
|
"msp-admin-service/routes"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/bootstrap"
|
||||||
|
"github.com/txix-open/isp-kit/cluster"
|
||||||
|
"github.com/txix-open/isp-kit/shutdown"
|
||||||
)
|
)
|
||||||
|
|
||||||
var version = "1.0.0"
|
var version = "1.0.0"
|
||||||
@@ -22,7 +24,7 @@ var version = "1.0.0"
|
|||||||
//go:generate swag init --parseDependency
|
//go:generate swag init --parseDependency
|
||||||
//go:generate rm -f docs/swagger.json docs/docs.go
|
//go:generate rm -f docs/swagger.json docs/docs.go
|
||||||
func main() {
|
func main() {
|
||||||
boot := bootstrap.New(version, conf.Remote{}, routes.EndpointDescriptors())
|
boot := bootstrap.New(version, conf.Remote{}, routes.EndpointDescriptors(), cluster.GrpcTransport)
|
||||||
app := boot.App
|
app := boot.App
|
||||||
logger := app.Logger()
|
logger := app.Logger()
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
-- +goose Up
|
||||||
|
ALTER TABLE users DROP CONSTRAINT users_email_key;
|
||||||
|
ALTER TABLE users ADD CONSTRAINT users_email_sudir_user_id_key UNIQUE (email, sudir_user_id);
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
ALTER TABLE users DROP CONSTRAINT users_email_sudir_user_id_key;
|
||||||
|
ALTER TABLE users ADD CONSTRAINT users_email_key UNIQUE (email);
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
-- +goose Up
|
||||||
|
INSERT INTO audit_event (event, enable)
|
||||||
|
VALUES
|
||||||
|
('user_blocked', true);
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
DELETE FROM audit_event WHERE event = 'user_blocked';
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
-- +goose Up
|
||||||
|
alter table bgjob_job
|
||||||
|
add column request_id text;
|
||||||
|
|
||||||
|
alter table bgjob_dead_job
|
||||||
|
add column request_id text;
|
||||||
|
|
||||||
|
update bgjob_job
|
||||||
|
set request_id = ''
|
||||||
|
where request_id is null;
|
||||||
|
|
||||||
|
update bgjob_dead_job
|
||||||
|
set request_id = ''
|
||||||
|
where request_id is null;
|
||||||
|
|
||||||
|
alter table bgjob_job
|
||||||
|
alter column request_id set default '',
|
||||||
|
alter column request_id set not null;
|
||||||
|
|
||||||
|
alter table bgjob_dead_job
|
||||||
|
alter column request_id set default '',
|
||||||
|
alter column request_id set not null;
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
-- +goose Up
|
||||||
|
ALTER TABLE users ADD COLUMN full_name VARCHAR(255) DEFAULT '' NOT NULL;
|
||||||
|
|
||||||
|
UPDATE users u SET full_name=u.first_name
|
||||||
|
WHERE (u.last_name = '') AND (u.first_name <> '');
|
||||||
|
|
||||||
|
UPDATE users u SET full_name=u.last_name || ' ' || u.first_name
|
||||||
|
WHERE (u.last_name <> '') AND (u.first_name <> '');
|
||||||
|
|
||||||
|
-- +goose Down
|
||||||
|
ALTER TABLE users DROP COLUMN full_name;
|
||||||
+66
-14
@@ -4,11 +4,23 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
|
"github.com/Masterminds/squirrel"
|
||||||
|
"github.com/iancoleman/strcase"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/isp-kit/db"
|
"github.com/txix-open/isp-kit/db"
|
||||||
"github.com/txix-open/isp-kit/db/query"
|
"github.com/txix-open/isp-kit/db/query"
|
||||||
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
||||||
"msp-admin-service/entity"
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
idAuditColumn = "id"
|
||||||
|
userIdAuditColumn = "user_id"
|
||||||
|
messageAuditColumn = "message"
|
||||||
|
createdAtAuditColumn = "created_at"
|
||||||
|
eventAuditColumn = "event"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Audit struct {
|
type Audit struct {
|
||||||
@@ -43,35 +55,50 @@ func (r Audit) Insert(ctx context.Context, log entity.Audit) (int, error) {
|
|||||||
return id, nil
|
return id, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gosec
|
func (r Audit) AllByRequest(ctx context.Context, req domain.AuditPageRequest) ([]entity.Audit, error) {
|
||||||
func (r Audit) All(ctx context.Context, limit int, offset int) ([]entity.Audit, error) {
|
|
||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Audit.All")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "Audit.All")
|
||||||
|
|
||||||
query, args, err := query.New().
|
q := query.New().
|
||||||
Select("*").
|
Select(
|
||||||
|
idAuditColumn,
|
||||||
|
userIdAuditColumn,
|
||||||
|
messageAuditColumn,
|
||||||
|
createdAtAuditColumn,
|
||||||
|
eventAuditColumn,
|
||||||
|
).
|
||||||
From("audit").
|
From("audit").
|
||||||
OrderBy("created_at DESC").
|
OrderBy(strcase.ToSnake(req.Order.Field) + " " + req.Order.Type).
|
||||||
Offset(uint64(offset)).
|
Offset(req.Offset).
|
||||||
Limit(uint64(limit)).
|
Limit(req.Limit)
|
||||||
ToSql()
|
|
||||||
|
query, args, err := reqAuditQuery(q, req.Query).ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "build query")
|
return nil, errors.WithMessage(err, "build query")
|
||||||
}
|
}
|
||||||
|
|
||||||
tokens := make([]entity.Audit, 0)
|
logs := make([]entity.Audit, 0)
|
||||||
err = r.db.Select(ctx, &tokens, query, args...)
|
err = r.db.Select(ctx, &logs, query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessagef(err, "select query: %s", query)
|
return nil, errors.WithMessagef(err, "select query: %s", query)
|
||||||
}
|
}
|
||||||
|
|
||||||
return tokens, nil
|
return logs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Audit) Count(ctx context.Context) (int64, error) {
|
func (r Audit) Count(ctx context.Context, reqQuery *domain.AuditQuery) (int64, error) {
|
||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Audit.Count")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "Audit.Count")
|
||||||
|
|
||||||
|
q := query.New().
|
||||||
|
Select("count(*)").
|
||||||
|
From("audit")
|
||||||
|
|
||||||
|
query, args, err := reqAuditQuery(q, reqQuery).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, errors.WithMessage(err, "build query")
|
||||||
|
}
|
||||||
|
|
||||||
count := int64(0)
|
count := int64(0)
|
||||||
err := r.db.SelectRow(ctx, &count, "select count(*) from audit")
|
err = r.db.SelectRow(ctx, &count, query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.WithMessage(err, "select count")
|
return 0, errors.WithMessage(err, "select count")
|
||||||
}
|
}
|
||||||
@@ -96,3 +123,28 @@ func (r Audit) DeleteUpToCreatedAt(ctx context.Context, createdAt time.Time) err
|
|||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reqAuditQuery(q squirrel.SelectBuilder, reqQuery *domain.AuditQuery) squirrel.SelectBuilder {
|
||||||
|
if reqQuery == nil {
|
||||||
|
return q
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.Id != nil {
|
||||||
|
q = q.Where("id = ?", *reqQuery.Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.UserId != nil {
|
||||||
|
q = q.Where(squirrel.Eq{"user_id": reqQuery.UserId})
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.Message != nil {
|
||||||
|
q = q.Where(squirrel.ILike{"message": "%" + *reqQuery.Message + "%"})
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.CreatedAt != nil {
|
||||||
|
q = q.Where(squirrel.GtOrEq{"created_at": reqQuery.CreatedAt.From}).
|
||||||
|
Where(squirrel.Lt{"created_at": reqQuery.CreatedAt.To})
|
||||||
|
}
|
||||||
|
|
||||||
|
return q
|
||||||
|
}
|
||||||
@@ -4,12 +4,18 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/isp-kit/db"
|
"github.com/txix-open/isp-kit/db"
|
||||||
"github.com/txix-open/isp-kit/db/query"
|
"github.com/txix-open/isp-kit/db/query"
|
||||||
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
||||||
"msp-admin-service/entity"
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
eventAuditEventColumn = "event"
|
||||||
|
enableAuditEventColumn = "enable"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuditEvent struct {
|
type AuditEvent struct {
|
||||||
@@ -26,7 +32,7 @@ func (r AuditEvent) All(ctx context.Context) ([]entity.AuditEvent, error) {
|
|||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Audit_Event.All")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "Audit_Event.All")
|
||||||
|
|
||||||
q, args, err := query.New().
|
q, args, err := query.New().
|
||||||
Select("*").
|
Select(eventAuditEventColumn, enableAuditEventColumn).
|
||||||
From("audit_event").
|
From("audit_event").
|
||||||
OrderBy("enable DESC").
|
OrderBy("enable DESC").
|
||||||
ToSql()
|
ToSql()
|
||||||
|
|||||||
+31
-2
@@ -17,6 +17,17 @@ type Role struct {
|
|||||||
db db.DB
|
db db.DB
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
idRolesColumn = "id"
|
||||||
|
nameRolesColumn = "name"
|
||||||
|
createdAtRolesColumn = "created_at"
|
||||||
|
updatedAtRolesColumn = "updated_at"
|
||||||
|
permissionsRolesColumn = "permissions"
|
||||||
|
externalGroupRolesColumn = "external_group"
|
||||||
|
immutableRolesColumn = "immutable"
|
||||||
|
exclusiveRolesColumn = "exclusive"
|
||||||
|
)
|
||||||
|
|
||||||
func NewRole(db db.DB) Role {
|
func NewRole(db db.DB) Role {
|
||||||
return Role{db: db}
|
return Role{db: db}
|
||||||
}
|
}
|
||||||
@@ -48,7 +59,16 @@ func (r Role) GetRoleByName(ctx context.Context, name string) (*entity.Role, err
|
|||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Role.GetRoleByName")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "Role.GetRoleByName")
|
||||||
|
|
||||||
q, args, err := query.New().
|
q, args, err := query.New().
|
||||||
Select("*").
|
Select(
|
||||||
|
idRolesColumn,
|
||||||
|
nameRolesColumn,
|
||||||
|
createdAtRolesColumn,
|
||||||
|
updatedAtRolesColumn,
|
||||||
|
permissionsRolesColumn,
|
||||||
|
externalGroupRolesColumn,
|
||||||
|
immutableRolesColumn,
|
||||||
|
exclusiveRolesColumn,
|
||||||
|
).
|
||||||
From("roles").
|
From("roles").
|
||||||
Where(squirrel.Eq{"name": name}).
|
Where(squirrel.Eq{"name": name}).
|
||||||
ToSql()
|
ToSql()
|
||||||
@@ -73,7 +93,16 @@ func (r Role) GetRolesByExternalGroup(ctx context.Context, groups []string) ([]e
|
|||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Role.GetRolesByExternalGroup")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "Role.GetRolesByExternalGroup")
|
||||||
|
|
||||||
q, args, err := query.New().
|
q, args, err := query.New().
|
||||||
Select("*").
|
Select(
|
||||||
|
idRolesColumn,
|
||||||
|
nameRolesColumn,
|
||||||
|
createdAtRolesColumn,
|
||||||
|
updatedAtRolesColumn,
|
||||||
|
permissionsRolesColumn,
|
||||||
|
externalGroupRolesColumn,
|
||||||
|
immutableRolesColumn,
|
||||||
|
exclusiveRolesColumn,
|
||||||
|
).
|
||||||
From("roles").
|
From("roles").
|
||||||
Where(squirrel.Eq{"external_group": groups}).
|
Where(squirrel.Eq{"external_group": groups}).
|
||||||
ToSql()
|
ToSql()
|
||||||
|
|||||||
+111
-20
@@ -3,15 +3,29 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
"github.com/Masterminds/squirrel"
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/Masterminds/squirrel"
|
||||||
|
"github.com/iancoleman/strcase"
|
||||||
|
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/isp-kit/db"
|
"github.com/txix-open/isp-kit/db"
|
||||||
"github.com/txix-open/isp-kit/db/query"
|
"github.com/txix-open/isp-kit/db/query"
|
||||||
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
||||||
"msp-admin-service/domain"
|
)
|
||||||
"msp-admin-service/entity"
|
|
||||||
|
const (
|
||||||
|
idTokensColumn = "id"
|
||||||
|
tokenColumn = "token"
|
||||||
|
userIdTokensColumn = "user_id"
|
||||||
|
statusTokensColumn = "status"
|
||||||
|
expiredAtTokensColumn = "expired_at"
|
||||||
|
createdAtTokensColumn = "created_at"
|
||||||
|
updatedAtTokensColumn = "updated_at"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Token struct {
|
type Token struct {
|
||||||
@@ -76,17 +90,36 @@ func (r Token) RevokeByUserId(ctx context.Context, userId int64, updatedAt time.
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gosec
|
func (r Token) All(ctx context.Context) ([]entity.Token, error) {
|
||||||
func (r Token) All(ctx context.Context, limit int, offset int) ([]entity.Token, error) {
|
|
||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.All")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.All")
|
||||||
|
|
||||||
query, args, err := query.New().
|
query, args, err := query.New().Select(idTokensColumn, tokenColumn, userIdTokensColumn, statusTokensColumn,
|
||||||
Select("*").
|
expiredAtTokensColumn, createdAtTokensColumn, updatedAtTokensColumn).From("tokens").ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "build query")
|
||||||
|
}
|
||||||
|
|
||||||
|
tokens := make([]entity.Token, 0)
|
||||||
|
err = r.db.Select(ctx, &tokens, query, args...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessagef(err, "select query %s", query)
|
||||||
|
}
|
||||||
|
|
||||||
|
return tokens, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Token) AllByRequest(ctx context.Context, req domain.SessionPageRequest) ([]entity.Token, error) {
|
||||||
|
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.AllByRequest")
|
||||||
|
|
||||||
|
q := query.New().
|
||||||
|
Select(idTokensColumn, tokenColumn, userIdTokensColumn, statusTokensColumn, expiredAtTokensColumn, createdAtTokensColumn,
|
||||||
|
updatedAtTokensColumn).
|
||||||
From("tokens").
|
From("tokens").
|
||||||
OrderBy("created_at DESC").
|
OrderBy(strcase.ToSnake(req.Order.Field) + " " + req.Order.Type).
|
||||||
Offset(uint64(offset)).
|
Offset(req.Offset).
|
||||||
Limit(uint64(limit)).
|
Limit(req.Limit)
|
||||||
ToSql()
|
|
||||||
|
query, args, err := reqTokenQuery(q, req.Query).ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "build query")
|
return nil, errors.WithMessage(err, "build query")
|
||||||
}
|
}
|
||||||
@@ -114,11 +147,40 @@ func (r Token) UpdateStatus(ctx context.Context, id int, status string) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Token) Count(ctx context.Context) (int64, error) {
|
func (r Token) SetExpiredStatusByIds(ctx context.Context, ids []int) error {
|
||||||
|
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.SetExpiredStatusByIds")
|
||||||
|
|
||||||
|
query, args, err := query.New().
|
||||||
|
Update("tokens").
|
||||||
|
Set("status", entity.TokenStatusExpired).
|
||||||
|
Where(squirrel.Eq{"id": ids}).
|
||||||
|
ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "build query")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = r.db.Exec(ctx, query, args...)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "set tokens expired status")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r Token) Count(ctx context.Context, reqQuery *domain.SessionQuery) (int64, error) {
|
||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.Count")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.Count")
|
||||||
|
|
||||||
|
q := query.New().
|
||||||
|
Select("count(*)").
|
||||||
|
From("tokens")
|
||||||
|
|
||||||
|
query, args, err := reqTokenQuery(q, reqQuery).ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return 0, errors.WithMessage(err, "build query")
|
||||||
|
}
|
||||||
|
|
||||||
count := int64(0)
|
count := int64(0)
|
||||||
err := r.db.SelectRow(ctx, &count, "select count(*) from tokens")
|
err = r.db.SelectRow(ctx, &count, query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, errors.WithMessage(err, "select count")
|
return 0, errors.WithMessage(err, "select count")
|
||||||
}
|
}
|
||||||
@@ -140,9 +202,9 @@ func (r Token) UpdateStatusByUserId(ctx context.Context, userId int, status stri
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (r Token) LastAccessByUserIds(ctx context.Context, userIds []int) (map[int64]*time.Time, error) {
|
func (r Token) LastAccessByUserIds(ctx context.Context, userIds []int) (map[int64]*time.Time, error) {
|
||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.LastAccessNotBlockedUsers")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "Token.LastAccessByUserIds")
|
||||||
|
|
||||||
q, args, err := query.New().
|
query, args, err := query.New().
|
||||||
Select("user_id", "max(created_at) as created_at").
|
Select("user_id", "max(created_at) as created_at").
|
||||||
From("tokens").
|
From("tokens").
|
||||||
Where(squirrel.Eq{"user_id": userIds}).
|
Where(squirrel.Eq{"user_id": userIds}).
|
||||||
@@ -153,16 +215,45 @@ func (r Token) LastAccessByUserIds(ctx context.Context, userIds []int) (map[int6
|
|||||||
}
|
}
|
||||||
|
|
||||||
tokens := make([]entity.Token, 0)
|
tokens := make([]entity.Token, 0)
|
||||||
err = r.db.Select(ctx, &tokens, q, args...)
|
err = r.db.Select(ctx, &tokens, query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessagef(err, "select query: %s", q)
|
return nil, errors.WithMessagef(err, "select query: %s", query)
|
||||||
}
|
}
|
||||||
|
|
||||||
result := make(map[int64]*time.Time, 0)
|
result := make(map[int64]*time.Time)
|
||||||
for _, token := range tokens {
|
for _, token := range tokens {
|
||||||
createdAt := token.CreatedAt
|
result[token.UserId] = new(token.CreatedAt)
|
||||||
result[token.UserId] = &createdAt
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result, nil
|
return result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reqTokenQuery(q squirrel.SelectBuilder, reqQuery *domain.SessionQuery) squirrel.SelectBuilder {
|
||||||
|
if reqQuery == nil {
|
||||||
|
return q
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.Id != nil {
|
||||||
|
q = q.Where(squirrel.ILike{"id::text": "%" + strconv.Itoa(*reqQuery.Id) + "%"})
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.UserId != nil {
|
||||||
|
q = q.Where(squirrel.Eq{"user_id": reqQuery.UserId})
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.Status != nil {
|
||||||
|
q = q.Where(squirrel.Eq{"status": reqQuery.Status})
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.CreatedAt != nil {
|
||||||
|
q = q.Where(squirrel.GtOrEq{"created_at": reqQuery.CreatedAt.From}).
|
||||||
|
Where(squirrel.Lt{"created_at": reqQuery.CreatedAt.To})
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.ExpiredAt != nil {
|
||||||
|
q = q.Where(squirrel.GtOrEq{"expired_at": reqQuery.ExpiredAt.From}).
|
||||||
|
Where(squirrel.Lt{"expired_at": reqQuery.ExpiredAt.To})
|
||||||
|
}
|
||||||
|
|
||||||
|
return q
|
||||||
|
}
|
||||||
+158
-31
@@ -3,15 +3,33 @@ package repository
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"database/sql"
|
"database/sql"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
"github.com/Masterminds/squirrel"
|
"github.com/Masterminds/squirrel"
|
||||||
|
"github.com/iancoleman/strcase"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/isp-kit/db"
|
"github.com/txix-open/isp-kit/db"
|
||||||
"github.com/txix-open/isp-kit/db/query"
|
"github.com/txix-open/isp-kit/db/query"
|
||||||
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
"github.com/txix-open/isp-kit/metrics/sql_metrics"
|
||||||
"msp-admin-service/domain"
|
)
|
||||||
"msp-admin-service/entity"
|
|
||||||
|
const (
|
||||||
|
idUsersColumn = "id"
|
||||||
|
firstNameUsersColumn = "first_name"
|
||||||
|
lastNameUsersColumn = "last_name"
|
||||||
|
emailUsersColumn = "email"
|
||||||
|
passwordUsersColumn = "password"
|
||||||
|
createdAtUsersColumn = "created_at"
|
||||||
|
updatedAtUsersColumn = "updated_at"
|
||||||
|
sudirUserIdUsersColumn = "sudir_user_id"
|
||||||
|
blockedUsersColumn = "blocked"
|
||||||
|
descriptionUsersColumn = "description"
|
||||||
|
lastActiveAtUsersColumn = "last_active_at"
|
||||||
|
fullNameUsersColumn = "full_name"
|
||||||
)
|
)
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
@@ -26,7 +44,9 @@ func (u User) GetUserByEmail(ctx context.Context, email string) (*entity.User, e
|
|||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "User.GetUserByEmail")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "User.GetUserByEmail")
|
||||||
|
|
||||||
q, args, err := query.New().
|
q, args, err := query.New().
|
||||||
Select("*").
|
Select(idUsersColumn, firstNameUsersColumn, lastNameUsersColumn, emailUsersColumn, passwordUsersColumn, createdAtUsersColumn,
|
||||||
|
updatedAtUsersColumn, sudirUserIdUsersColumn, blockedUsersColumn, descriptionUsersColumn, lastActiveAtUsersColumn,
|
||||||
|
fullNameUsersColumn).
|
||||||
From("users").
|
From("users").
|
||||||
Where(squirrel.Eq{"email": email}).
|
Where(squirrel.Eq{"email": email}).
|
||||||
ToSql()
|
ToSql()
|
||||||
@@ -51,7 +71,9 @@ func (u User) GetUserById(ctx context.Context, identity int64) (*entity.User, er
|
|||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "User.GetUserById")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "User.GetUserById")
|
||||||
|
|
||||||
q, args, err := query.New().
|
q, args, err := query.New().
|
||||||
Select("*").
|
Select(idUsersColumn, firstNameUsersColumn, lastNameUsersColumn, emailUsersColumn, passwordUsersColumn, createdAtUsersColumn,
|
||||||
|
updatedAtUsersColumn, sudirUserIdUsersColumn, blockedUsersColumn, descriptionUsersColumn, lastActiveAtUsersColumn,
|
||||||
|
fullNameUsersColumn).
|
||||||
From("users").
|
From("users").
|
||||||
Where(squirrel.Eq{"id": identity}).
|
Where(squirrel.Eq{"id": identity}).
|
||||||
ToSql()
|
ToSql()
|
||||||
@@ -72,15 +94,48 @@ func (u User) GetUserById(ctx context.Context, identity int64) (*entity.User, er
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u User) GetUserByEmailAndSudirId(ctx context.Context, email string, sudirUserId string) (*entity.User, error) {
|
||||||
|
ctx = sql_metrics.OperationLabelToContext(ctx, "User.GetUserByEmail")
|
||||||
|
|
||||||
|
equalClause := squirrel.Eq{"email": email, "sudir_user_id": nil}
|
||||||
|
if sudirUserId != "" {
|
||||||
|
equalClause["sudir_user_id"] = sudirUserId
|
||||||
|
}
|
||||||
|
|
||||||
|
q, args, err := query.New().
|
||||||
|
Select(idUsersColumn, firstNameUsersColumn, lastNameUsersColumn, emailUsersColumn, passwordUsersColumn, createdAtUsersColumn,
|
||||||
|
updatedAtUsersColumn, sudirUserIdUsersColumn, blockedUsersColumn, descriptionUsersColumn, lastActiveAtUsersColumn,
|
||||||
|
fullNameUsersColumn).
|
||||||
|
From("users").
|
||||||
|
Where(equalClause).
|
||||||
|
ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "build query")
|
||||||
|
}
|
||||||
|
|
||||||
|
user := entity.User{}
|
||||||
|
err = u.db.SelectRow(ctx, &user, q, args...)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows):
|
||||||
|
return nil, domain.ErrNotFound
|
||||||
|
case err != nil:
|
||||||
|
return nil, errors.WithMessage(err, "db select")
|
||||||
|
default:
|
||||||
|
return &user, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (u User) UpsertBySudirUserId(ctx context.Context, user entity.User) (*entity.User, error) {
|
func (u User) UpsertBySudirUserId(ctx context.Context, user entity.User) (*entity.User, error) {
|
||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "User.UpsertBySudirUserId")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "User.UpsertBySudirUserId")
|
||||||
|
|
||||||
selectQ := `
|
selectQ := `
|
||||||
insert into users as u (first_name, last_name, email, created_at, updated_at, sudir_user_id)
|
insert into users as u (first_name, last_name, full_name, email, created_at, updated_at, sudir_user_id)
|
||||||
values ($1, $2, $3, $4, $5, $6)
|
values ($1, $2, $3, $4, $5, $6, $7)
|
||||||
on conflict (sudir_user_id) do update
|
on conflict (sudir_user_id) do update
|
||||||
set first_name = excluded.first_name,
|
set first_name = excluded.first_name,
|
||||||
last_name = excluded.last_name,
|
last_name = excluded.last_name,
|
||||||
|
full_name = excluded.full_name,
|
||||||
email = excluded.email,
|
email = excluded.email,
|
||||||
updated_at = excluded.updated_at
|
updated_at = excluded.updated_at
|
||||||
where u.blocked = false
|
where u.blocked = false
|
||||||
@@ -90,7 +145,7 @@ func (u User) UpsertBySudirUserId(ctx context.Context, user entity.User) (*entit
|
|||||||
err := u.db.SelectRow(ctx,
|
err := u.db.SelectRow(ctx,
|
||||||
&result,
|
&result,
|
||||||
selectQ,
|
selectQ,
|
||||||
user.FirstName, user.LastName, user.Email, user.CreatedAt, user.UpdatedAt, user.SudirUserId,
|
user.FirstName, user.LastName, user.FullName, user.Email, user.CreatedAt, user.UpdatedAt, user.SudirUserId,
|
||||||
)
|
)
|
||||||
if errors.Is(err, sql.ErrNoRows) {
|
if errors.Is(err, sql.ErrNoRows) {
|
||||||
return nil, domain.ErrUserIsBlocked
|
return nil, domain.ErrUserIsBlocked
|
||||||
@@ -102,31 +157,30 @@ func (u User) UpsertBySudirUserId(ctx context.Context, user entity.User) (*entit
|
|||||||
return &result, nil
|
return &result, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gosec
|
func (u User) GetUsers(ctx context.Context, req domain.UsersPageRequest) ([]entity.User, error) {
|
||||||
func (u User) GetUsers(ctx context.Context, ids []int64, offset, limit int, email string) ([]entity.User, error) {
|
|
||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "User.GetUsers")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "User.GetUsers")
|
||||||
|
|
||||||
q := query.New().
|
q := query.New().
|
||||||
Select("*").
|
Select(idUsersColumn, firstNameUsersColumn, lastNameUsersColumn, emailUsersColumn, passwordUsersColumn, createdAtUsersColumn,
|
||||||
From("users")
|
updatedAtUsersColumn, sudirUserIdUsersColumn, blockedUsersColumn, descriptionUsersColumn, lastActiveAtUsersColumn,
|
||||||
|
fullNameUsersColumn, "(SELECT max(created_at) FROM tokens WHERE tokens.user_id = users.id) as last_session_created_at").
|
||||||
|
From("users").
|
||||||
|
Offset(req.Offset).
|
||||||
|
Limit(req.Limit)
|
||||||
|
|
||||||
if len(ids) > 0 {
|
if req.Order.Field == "userId" {
|
||||||
q = q.Where(squirrel.Eq{"id": ids})
|
q = q.OrderBy("full_name " + req.Order.Type)
|
||||||
|
} else {
|
||||||
|
q = q.OrderBy(strcase.ToSnake(req.Order.Field) + " " + req.Order.Type)
|
||||||
}
|
}
|
||||||
if email != "" {
|
|
||||||
q = q.Where("email LIKE ?", "%"+email+"%")
|
query, args, err := reqUsersQuery(q, req.Query).ToSql()
|
||||||
}
|
|
||||||
qstring, args, err := q.
|
|
||||||
Limit(uint64(limit)).
|
|
||||||
Offset(uint64(offset)).
|
|
||||||
OrderBy("created_at DESC").
|
|
||||||
ToSql()
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "build query")
|
return nil, errors.WithMessage(err, "build query")
|
||||||
}
|
}
|
||||||
|
|
||||||
users := make([]entity.User, 0)
|
users := make([]entity.User, 0)
|
||||||
err = u.db.Select(ctx, &users, qstring, args...)
|
err = u.db.Select(ctx, &users, query, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "db select")
|
return nil, errors.WithMessage(err, "db select")
|
||||||
}
|
}
|
||||||
@@ -134,14 +188,62 @@ func (u User) GetUsers(ctx context.Context, ids []int64, offset, limit int, emai
|
|||||||
return users, nil
|
return users, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (u User) GetAllUsers(ctx context.Context) ([]entity.User, error) {
|
||||||
|
ctx = sql_metrics.OperationLabelToContext(ctx, "User.GetUsers")
|
||||||
|
|
||||||
|
query, args, err := query.New().
|
||||||
|
Select(idUsersColumn, firstNameUsersColumn, lastNameUsersColumn, emailUsersColumn, passwordUsersColumn, createdAtUsersColumn,
|
||||||
|
updatedAtUsersColumn, sudirUserIdUsersColumn, blockedUsersColumn, descriptionUsersColumn, lastActiveAtUsersColumn,
|
||||||
|
fullNameUsersColumn, "(SELECT max(created_at) FROM tokens WHERE tokens.user_id = users.id) as last_session_created_at").
|
||||||
|
From("users").ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "build query")
|
||||||
|
}
|
||||||
|
|
||||||
|
users := make([]entity.User, 0)
|
||||||
|
err = u.db.Select(ctx, &users, query, args...)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "db select")
|
||||||
|
}
|
||||||
|
|
||||||
|
return users, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u User) GetUsersByEmail(ctx context.Context, email string) ([]entity.User, error) {
|
||||||
|
ctx = sql_metrics.OperationLabelToContext(ctx, "User.GetUserByEmail")
|
||||||
|
|
||||||
|
q, args, err := query.New().
|
||||||
|
Select(idUsersColumn, firstNameUsersColumn, lastNameUsersColumn, emailUsersColumn, passwordUsersColumn, createdAtUsersColumn,
|
||||||
|
updatedAtUsersColumn, sudirUserIdUsersColumn, blockedUsersColumn, descriptionUsersColumn, lastActiveAtUsersColumn,
|
||||||
|
fullNameUsersColumn).
|
||||||
|
From("users").
|
||||||
|
Where(squirrel.Eq{"email": email}).
|
||||||
|
ToSql()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "build query")
|
||||||
|
}
|
||||||
|
|
||||||
|
users := make([]entity.User, 0)
|
||||||
|
err = u.db.Select(ctx, &users, q, args...)
|
||||||
|
|
||||||
|
switch {
|
||||||
|
case errors.Is(err, sql.ErrNoRows) || len(users) == 0:
|
||||||
|
return nil, domain.ErrNotFound
|
||||||
|
case err != nil:
|
||||||
|
return nil, errors.WithMessage(err, "db select")
|
||||||
|
default:
|
||||||
|
return users, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (u User) Insert(ctx context.Context, user entity.User) (int, error) {
|
func (u User) Insert(ctx context.Context, user entity.User) (int, error) {
|
||||||
ctx = sql_metrics.OperationLabelToContext(ctx, "User.Insert")
|
ctx = sql_metrics.OperationLabelToContext(ctx, "User.Insert")
|
||||||
|
|
||||||
insertQ, args, err := query.New().
|
insertQ, args, err := query.New().
|
||||||
Insert("users").
|
Insert("users").
|
||||||
Columns("first_name", "last_name", "description",
|
Columns(firstNameUsersColumn, lastNameUsersColumn, fullNameUsersColumn, descriptionUsersColumn,
|
||||||
"email", "password", "created_at", "updated_at").
|
emailUsersColumn, passwordUsersColumn, createdAtUsersColumn, updatedAtUsersColumn).
|
||||||
Values(user.FirstName, user.LastName, user.Description,
|
Values(user.FirstName, user.LastName, user.FullName, user.Description,
|
||||||
user.Email, user.Password, user.CreatedAt, user.UpdatedAt).
|
user.Email, user.Password, user.CreatedAt, user.UpdatedAt).
|
||||||
Suffix("returning id").
|
Suffix("returning id").
|
||||||
ToSql()
|
ToSql()
|
||||||
@@ -164,14 +266,15 @@ func (u User) UpdateUser(ctx context.Context, id int64, user entity.UpdateUser)
|
|||||||
// return every except password
|
// return every except password
|
||||||
q, args, err := query.New().
|
q, args, err := query.New().
|
||||||
Update("users").
|
Update("users").
|
||||||
SetMap(map[string]interface{}{
|
SetMap(map[string]any{
|
||||||
"first_name": user.FirstName,
|
firstNameUsersColumn: user.FirstName,
|
||||||
"last_name": user.LastName,
|
lastNameUsersColumn: user.LastName,
|
||||||
"email": user.Email,
|
fullNameUsersColumn: user.FullName,
|
||||||
"description": user.Description,
|
emailUsersColumn: user.Email,
|
||||||
|
descriptionUsersColumn: user.Description,
|
||||||
}).
|
}).
|
||||||
Where(squirrel.Eq{"id": id}).
|
Where(squirrel.Eq{"id": id}).
|
||||||
Suffix("RETURNING id, first_name, last_name, email, sudir_user_id, description, created_at, updated_at").
|
Suffix("RETURNING id, first_name, last_name, full_name, email, sudir_user_id, description, created_at, updated_at").
|
||||||
ToSql()
|
ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "build query")
|
return nil, errors.WithMessage(err, "build query")
|
||||||
@@ -290,3 +393,27 @@ func (u User) UpdateLastActiveAt(ctx context.Context, userId int64, lastActiveAt
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func reqUsersQuery(q squirrel.SelectBuilder, reqQuery *domain.UserQuery) squirrel.SelectBuilder {
|
||||||
|
if reqQuery == nil {
|
||||||
|
return q
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.Id != nil {
|
||||||
|
q = q.Where(squirrel.ILike{"id::text": "%" + strconv.Itoa(*reqQuery.Id) + "%"})
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.UserId != nil || len(reqQuery.UserId) != 0 { // поиск в ui по фио, но в бд - по id юзера
|
||||||
|
q = q.Where(squirrel.Eq{"id": reqQuery.UserId})
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.Description != nil {
|
||||||
|
q = q.Where(squirrel.ILike{"description": "%" + *reqQuery.Description + "%"})
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.Email != nil {
|
||||||
|
q = q.Where(squirrel.ILike{"email": "%" + *reqQuery.Email + "%"})
|
||||||
|
}
|
||||||
|
|
||||||
|
return q
|
||||||
|
}
|
||||||
+12
-1
@@ -1,11 +1,12 @@
|
|||||||
package routes
|
package routes
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"msp-admin-service/controller"
|
||||||
|
|
||||||
"github.com/txix-open/isp-kit/cluster"
|
"github.com/txix-open/isp-kit/cluster"
|
||||||
"github.com/txix-open/isp-kit/grpc"
|
"github.com/txix-open/isp-kit/grpc"
|
||||||
"github.com/txix-open/isp-kit/grpc/endpoint"
|
"github.com/txix-open/isp-kit/grpc/endpoint"
|
||||||
"github.com/txix-open/isp-kit/grpc/isp"
|
"github.com/txix-open/isp-kit/grpc/isp"
|
||||||
"msp-admin-service/controller"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Controllers struct {
|
type Controllers struct {
|
||||||
@@ -49,6 +50,11 @@ func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
|||||||
Inner: true,
|
Inner: true,
|
||||||
Handler: c.Auth.Logout,
|
Handler: c.Auth.Logout,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Path: "admin/auth/logout_with_reason",
|
||||||
|
Inner: true,
|
||||||
|
Handler: c.Auth.LogoutWithReason,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Path: "admin/user/get_profile",
|
Path: "admin/user/get_profile",
|
||||||
Inner: true,
|
Inner: true,
|
||||||
@@ -64,6 +70,11 @@ func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
|||||||
Inner: true,
|
Inner: true,
|
||||||
Handler: c.User.GetUsers,
|
Handler: c.User.GetUsers,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Path: "admin/user/get_all_users",
|
||||||
|
Inner: true,
|
||||||
|
Handler: c.User.GetAllUsers,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Path: "admin/user/create_user",
|
Path: "admin/user/create_user",
|
||||||
Inner: true,
|
Inner: true,
|
||||||
|
|||||||
+22
-18
@@ -4,18 +4,19 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"github.com/txix-open/isp-kit/log"
|
|
||||||
"golang.org/x/sync/errgroup"
|
|
||||||
"msp-admin-service/conf"
|
"msp-admin-service/conf"
|
||||||
"msp-admin-service/domain"
|
"msp-admin-service/domain"
|
||||||
"msp-admin-service/entity"
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuditRepository interface {
|
type AuditRepository interface {
|
||||||
Insert(ctx context.Context, log entity.Audit) (int, error)
|
Insert(ctx context.Context, log entity.Audit) (int, error)
|
||||||
All(ctx context.Context, limit int, offset int) ([]entity.Audit, error)
|
AllByRequest(ctx context.Context, req domain.AuditPageRequest) ([]entity.Audit, error)
|
||||||
Count(ctx context.Context) (int64, error)
|
Count(ctx context.Context, reqQuery *domain.AuditQuery) (int64, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuditEventRepository interface {
|
type AuditEventRepository interface {
|
||||||
@@ -45,6 +46,7 @@ func NewAudit(
|
|||||||
entity.EventSuccessLogout: true,
|
entity.EventSuccessLogout: true,
|
||||||
entity.EventRoleChanged: true,
|
entity.EventRoleChanged: true,
|
||||||
entity.EventUserChanged: true,
|
entity.EventUserChanged: true,
|
||||||
|
entity.EventUserBlocked: true,
|
||||||
}
|
}
|
||||||
|
|
||||||
eventName := make(map[string]conf.AuditEventSetting)
|
eventName := make(map[string]conf.AuditEventSetting)
|
||||||
@@ -85,44 +87,46 @@ func (s Audit) SaveAuditAsync(ctx context.Context, userId int64, message string,
|
|||||||
Event: event,
|
Event: event,
|
||||||
CreatedAt: time.Now().UTC(),
|
CreatedAt: time.Now().UTC(),
|
||||||
}
|
}
|
||||||
_, err = s.auditRep.Insert(context.Background(), audit)
|
_, err = s.auditRep.Insert(ctx, audit)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
s.logger.Error(ctx, "insert audit", log.Any("error", err))
|
s.logger.Error(ctx, "insert audit", log.Any("error", err))
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Audit) All(ctx context.Context, limit int, offset int) (*domain.AuditResponse, error) {
|
func (s Audit) All(ctx context.Context, req domain.AuditPageRequest) (*domain.AuditResponse, error) {
|
||||||
group, ctx := errgroup.WithContext(ctx)
|
var logs []entity.Audit
|
||||||
var tokens []entity.Audit
|
|
||||||
var total int64
|
var total int64
|
||||||
var err error
|
|
||||||
|
group, ctx := errgroup.WithContext(ctx)
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
tokens, err = s.auditRep.All(ctx, limit, offset)
|
var err error
|
||||||
|
logs, err = s.auditRep.AllByRequest(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "get all audit")
|
return errors.WithMessage(err, "get all audit")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
total, err = s.auditRep.Count(ctx)
|
var err error
|
||||||
|
total, err = s.auditRep.Count(ctx, req.Query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "count all audit")
|
return errors.WithMessage(err, "count all audit")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
err = group.Wait()
|
err := group.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "wait workers")
|
return nil, errors.WithMessage(err, "wait workers")
|
||||||
}
|
}
|
||||||
|
|
||||||
items := make([]domain.Audit, 0)
|
items := make([]domain.Audit, 0)
|
||||||
for _, token := range tokens {
|
for _, log := range logs {
|
||||||
items = append(items, domain.Audit{
|
items = append(items, domain.Audit{
|
||||||
Id: token.Id,
|
Id: log.Id,
|
||||||
UserId: token.UserId,
|
UserId: log.UserId,
|
||||||
Message: token.Message,
|
Message: log.Message,
|
||||||
CreatedAt: token.CreatedAt,
|
CreatedAt: log.CreatedAt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
result := domain.AuditResponse{
|
result := domain.AuditResponse{
|
||||||
|
|||||||
+10
-3
@@ -5,11 +5,12 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/isp-kit/log"
|
"github.com/txix-open/isp-kit/log"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"msp-admin-service/domain"
|
|
||||||
"msp-admin-service/entity"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AuthTransaction interface {
|
type AuthTransaction interface {
|
||||||
@@ -169,6 +170,7 @@ func (a Auth) LoginWithSudir(ctx context.Context, request domain.LoginSudirReque
|
|||||||
SudirUserId: &sudirUser.SudirUserId,
|
SudirUserId: &sudirUser.SudirUserId,
|
||||||
FirstName: sudirUser.FirstName,
|
FirstName: sudirUser.FirstName,
|
||||||
LastName: sudirUser.LastName,
|
LastName: sudirUser.LastName,
|
||||||
|
FullName: sudirUser.FullName,
|
||||||
Email: sudirUser.Email,
|
Email: sudirUser.Email,
|
||||||
Password: "",
|
Password: "",
|
||||||
Blocked: false,
|
Blocked: false,
|
||||||
@@ -213,7 +215,7 @@ func (a Auth) LoginWithSudir(ctx context.Context, request domain.LoginSudirReque
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a Auth) Logout(ctx context.Context, adminId int64) error {
|
func (a Auth) Logout(ctx context.Context, adminId int64, request *domain.LogoutRequest) error {
|
||||||
err := a.txRunner.AuthTransaction(ctx, func(ctx context.Context, tx AuthTransaction) error {
|
err := a.txRunner.AuthTransaction(ctx, func(ctx context.Context, tx AuthTransaction) error {
|
||||||
err := a.tokenService.RevokeAllByUserId(ctx, adminId)
|
err := a.tokenService.RevokeAllByUserId(ctx, adminId)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -226,6 +228,11 @@ func (a Auth) Logout(ctx context.Context, adminId int64) error {
|
|||||||
return errors.WithMessage(err, "update user last_active_at")
|
return errors.WithMessage(err, "update user last_active_at")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if request != nil && request.Reason == "idle" {
|
||||||
|
a.auditService.SaveAuditAsync(ctx, adminId, "Выход по бездействию", entity.EventSuccessLogout)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
a.auditService.SaveAuditAsync(ctx, adminId, "Выход", entity.EventSuccessLogout)
|
a.auditService.SaveAuditAsync(ctx, adminId, "Выход", entity.EventSuccessLogout)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,11 +4,12 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/conf"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/bgjob"
|
"github.com/txix-open/bgjob"
|
||||||
"github.com/txix-open/isp-kit/bgjobx/handler"
|
"github.com/txix-open/isp-kit/bgjobx/handler"
|
||||||
"github.com/txix-open/isp-kit/log"
|
"github.com/txix-open/isp-kit/log"
|
||||||
"msp-admin-service/conf"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -45,7 +46,7 @@ func (s Service) Handle(ctx context.Context, _ bgjob.Job) handler.Result {
|
|||||||
return handler.Retry(defaultRetryTimeout, errors.WithMessage(err, "sync state with worker"))
|
return handler.Retry(defaultRetryTimeout, errors.WithMessage(err, "sync state with worker"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return handler.Reschedule(s.syncPeriod)
|
return handler.Reschedule(handler.ByAfterTime(s.syncPeriod, time.Now()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Service) deleteOldAudit(ctx context.Context) error {
|
func (s Service) deleteOldAudit(ctx context.Context) error {
|
||||||
|
|||||||
@@ -4,12 +4,13 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/conf"
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/bgjob"
|
"github.com/txix-open/bgjob"
|
||||||
"github.com/txix-open/isp-kit/bgjobx/handler"
|
"github.com/txix-open/isp-kit/bgjobx/handler"
|
||||||
"github.com/txix-open/isp-kit/log"
|
"github.com/txix-open/isp-kit/log"
|
||||||
"msp-admin-service/conf"
|
|
||||||
"msp-admin-service/entity"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -63,7 +64,7 @@ func (w Service) Handle(ctx context.Context, _ bgjob.Job) handler.Result {
|
|||||||
return handler.Retry(defaultRetryTimeout, errors.WithMessage(err, "sync state with worker"))
|
return handler.Retry(defaultRetryTimeout, errors.WithMessage(err, "sync state with worker"))
|
||||||
}
|
}
|
||||||
w.logger.Debug(ctx, "end work")
|
w.logger.Debug(ctx, "end work")
|
||||||
return handler.Reschedule(w.syncPeriod)
|
return handler.Reschedule(handler.ByAfterTime(w.syncPeriod, time.Now()))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (w Service) do(ctx context.Context) error {
|
func (w Service) do(ctx context.Context) error {
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ func (s *Permission) All(_ context.Context) []domain.Permission {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func toDomain(permissions []conf.Permission) []domain.Permission {
|
func toDomain(permissions []conf.Permission) []domain.Permission {
|
||||||
permList := make([]domain.Permission, 0)
|
permList := make([]domain.Permission, 0, len(permissions))
|
||||||
for _, perm := range permissions {
|
for _, perm := range permissions {
|
||||||
permList = append(permList, domain.Permission{
|
permList = append(permList, domain.Permission{
|
||||||
Key: perm.Key,
|
Key: perm.Key,
|
||||||
|
|||||||
+2
-4
@@ -81,8 +81,7 @@ func (u Role) Create(ctx context.Context, req domain.CreateRoleRequest, adminId
|
|||||||
entity.EventRoleChanged,
|
entity.EventRoleChanged,
|
||||||
)
|
)
|
||||||
|
|
||||||
result := u.toDomain(*role)
|
return new(u.toDomain(*role)), nil
|
||||||
return &result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u Role) Update(ctx context.Context, req domain.UpdateRoleRequest, adminId int64) (*domain.Role, error) {
|
func (u Role) Update(ctx context.Context, req domain.UpdateRoleRequest, adminId int64) (*domain.Role, error) {
|
||||||
@@ -131,8 +130,7 @@ func (u Role) Update(ctx context.Context, req domain.UpdateRoleRequest, adminId
|
|||||||
fmt.Sprintf("Роль. Изменение роли %s. Причина: %s. \n %s", req.Name, req.ChangeMessage, diff),
|
fmt.Sprintf("Роль. Изменение роли %s. Причина: %s. \n %s", req.Name, req.ChangeMessage, diff),
|
||||||
entity.EventRoleChanged,
|
entity.EventRoleChanged,
|
||||||
)
|
)
|
||||||
result := u.toDomain(*role)
|
return new(u.toDomain(*role)), nil
|
||||||
return &result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u Role) Delete(ctx context.Context, req domain.DeleteRoleRequest, adminId int64) error {
|
func (u Role) Delete(ctx context.Context, req domain.DeleteRoleRequest, adminId int64) error {
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package session_worker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/bgjob"
|
||||||
|
"github.com/txix-open/isp-kit/bgjobx"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
QueueName = "set_session_expired"
|
||||||
|
)
|
||||||
|
|
||||||
|
func EnqueueSeedJob(ctx context.Context, client *bgjobx.Client) error {
|
||||||
|
err := client.Enqueue(ctx, bgjob.EnqueueRequest{
|
||||||
|
Id: "set_session_expired",
|
||||||
|
Queue: QueueName,
|
||||||
|
Type: "set_session_expired",
|
||||||
|
})
|
||||||
|
if err != nil && !errors.Is(err, bgjob.ErrJobAlreadyExist) {
|
||||||
|
return errors.WithMessage(err, "enqueue job")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
package session_worker
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/txix-open/bgjob"
|
||||||
|
"github.com/txix-open/isp-kit/bgjobx/handler"
|
||||||
|
"github.com/txix-open/isp-kit/log"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
defaultRetryTimeout = 5 * time.Minute
|
||||||
|
rescheduleInterval = 1 * time.Minute
|
||||||
|
)
|
||||||
|
|
||||||
|
type TokenTransactionRunner interface {
|
||||||
|
TokenTransaction(ctx context.Context, tx func(ctx context.Context, tx TokenTransaction) error) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type TokenTransaction interface {
|
||||||
|
All(ctx context.Context) ([]entity.Token, error)
|
||||||
|
SetExpiredStatusByIds(ctx context.Context, ids []int) error
|
||||||
|
}
|
||||||
|
|
||||||
|
type Service struct {
|
||||||
|
logger log.Logger
|
||||||
|
txRunner TokenTransactionRunner
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewExpireSessionWorker(
|
||||||
|
logger log.Logger,
|
||||||
|
txRunner TokenTransactionRunner,
|
||||||
|
) Service {
|
||||||
|
return Service{
|
||||||
|
logger: logger,
|
||||||
|
txRunner: txRunner,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w Service) Handle(ctx context.Context, _ bgjob.Job) handler.Result {
|
||||||
|
ctx = log.ToContext(ctx, log.String("worker", "expireSessionWorker"))
|
||||||
|
w.logger.Debug(ctx, "begin work")
|
||||||
|
|
||||||
|
err := w.do(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return handler.Retry(defaultRetryTimeout, errors.WithMessage(err, "expireSessionWorker do"))
|
||||||
|
}
|
||||||
|
|
||||||
|
w.logger.Debug(ctx, "end work")
|
||||||
|
return handler.Reschedule(handler.ByAfterTime(rescheduleInterval, time.Now()))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (w Service) do(ctx context.Context) error {
|
||||||
|
err := w.txRunner.TokenTransaction(ctx, func(ctx context.Context, tx TokenTransaction) error {
|
||||||
|
tokens, err := tx.All(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "get all tokens")
|
||||||
|
}
|
||||||
|
|
||||||
|
expiredTokenIds := make([]int, 0)
|
||||||
|
now := time.Now().UTC()
|
||||||
|
for _, token := range tokens {
|
||||||
|
if now.After(token.ExpiredAt) {
|
||||||
|
expiredTokenIds = append(expiredTokenIds, token.Id)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(expiredTokenIds) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
err = tx.SetExpiredStatusByIds(ctx, expiredTokenIds)
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "set expired status by id")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return errors.WithMessage(err, "token transaction")
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
+3
-1
@@ -3,10 +3,11 @@ package service
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"msp-admin-service/conf"
|
"msp-admin-service/conf"
|
||||||
"msp-admin-service/domain"
|
"msp-admin-service/domain"
|
||||||
"msp-admin-service/entity"
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sudirRepo interface {
|
type sudirRepo interface {
|
||||||
@@ -72,6 +73,7 @@ func (s Sudir) Authenticate(ctx context.Context, authCode string, roleRepo roleR
|
|||||||
SudirUserId: user.Sub,
|
SudirUserId: user.Sub,
|
||||||
FirstName: user.GivenName,
|
FirstName: user.GivenName,
|
||||||
LastName: user.FamilyName,
|
LastName: user.FamilyName,
|
||||||
|
FullName: user.Name,
|
||||||
Email: email,
|
Email: email,
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
+15
-15
@@ -6,18 +6,19 @@ import (
|
|||||||
"encoding/hex"
|
"encoding/hex"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"golang.org/x/sync/errgroup"
|
|
||||||
"msp-admin-service/domain"
|
"msp-admin-service/domain"
|
||||||
"msp-admin-service/entity"
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
)
|
)
|
||||||
|
|
||||||
type TokenRep interface {
|
type TokenRep interface {
|
||||||
TokenSaver
|
TokenSaver
|
||||||
Get(ctx context.Context, token string) (*entity.Token, error)
|
Get(ctx context.Context, token string) (*entity.Token, error)
|
||||||
RevokeByUserId(ctx context.Context, userId int64, updatedAt time.Time) error
|
RevokeByUserId(ctx context.Context, userId int64, updatedAt time.Time) error
|
||||||
All(ctx context.Context, limit int, offset int) ([]entity.Token, error)
|
AllByRequest(ctx context.Context, req domain.SessionPageRequest) ([]entity.Token, error)
|
||||||
Count(ctx context.Context) (int64, error)
|
Count(ctx context.Context, reqQuery *domain.SessionQuery) (int64, error)
|
||||||
UpdateStatus(ctx context.Context, id int, status string) error
|
UpdateStatus(ctx context.Context, id int, status string) error
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,44 +74,43 @@ func (s Token) RevokeAllByUserId(ctx context.Context, userId int64) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s Token) All(ctx context.Context, limit int, offset int) (*domain.SessionResponse, error) {
|
func (s Token) All(ctx context.Context, req domain.SessionPageRequest) (*domain.SessionResponse, error) {
|
||||||
group, ctx := errgroup.WithContext(ctx)
|
|
||||||
var tokens []entity.Token
|
var tokens []entity.Token
|
||||||
var total int64
|
var total int64
|
||||||
var err error
|
|
||||||
|
group, ctx := errgroup.WithContext(ctx)
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
tokens, err = s.tokenRep.All(ctx, limit, offset)
|
var err error
|
||||||
|
tokens, err = s.tokenRep.AllByRequest(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "get all tokens")
|
return errors.WithMessage(err, "get all tokens")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
group.Go(func() error {
|
group.Go(func() error {
|
||||||
total, err = s.tokenRep.Count(ctx)
|
var err error
|
||||||
|
total, err = s.tokenRep.Count(ctx, req.Query)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "count all tokens")
|
return errors.WithMessage(err, "count all tokens")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
err = group.Wait()
|
err := group.Wait()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "wait workers")
|
return nil, errors.WithMessage(err, "wait workers")
|
||||||
}
|
}
|
||||||
|
|
||||||
items := make([]domain.Session, 0)
|
items := make([]domain.Session, 0)
|
||||||
for _, token := range tokens {
|
for _, token := range tokens {
|
||||||
status := token.Status
|
|
||||||
if time.Now().UTC().After(token.ExpiredAt) {
|
|
||||||
status = entity.TokenStatusExpired
|
|
||||||
}
|
|
||||||
items = append(items, domain.Session{
|
items = append(items, domain.Session{
|
||||||
Id: token.Id,
|
Id: token.Id,
|
||||||
UserId: int(token.UserId),
|
UserId: int(token.UserId),
|
||||||
Status: status,
|
Status: token.Status,
|
||||||
ExpiredAt: token.ExpiredAt,
|
ExpiredAt: token.ExpiredAt,
|
||||||
CreatedAt: token.CreatedAt,
|
CreatedAt: token.CreatedAt,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
result := domain.SessionResponse{
|
result := domain.SessionResponse{
|
||||||
TotalCount: int(total),
|
TotalCount: int(total),
|
||||||
Items: items,
|
Items: items,
|
||||||
|
|||||||
+144
-46
@@ -8,11 +8,12 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/isp-kit/log"
|
"github.com/txix-open/isp-kit/log"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"msp-admin-service/domain"
|
|
||||||
"msp-admin-service/entity"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserTransaction interface {
|
type UserTransaction interface {
|
||||||
@@ -25,10 +26,13 @@ type UserTransactionRunner interface {
|
|||||||
UserTransaction(ctx context.Context, tx func(ctx context.Context, tx UserTransaction) error) error
|
UserTransaction(ctx context.Context, tx func(ctx context.Context, tx UserTransaction) error) error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// nolint:interfacebloat
|
||||||
type UserRepo interface {
|
type UserRepo interface {
|
||||||
GetUserById(ctx context.Context, identity int64) (*entity.User, error)
|
GetUserById(ctx context.Context, identity int64) (*entity.User, error)
|
||||||
GetUsers(ctx context.Context, ids []int64, offset, limit int, email string) ([]entity.User, error)
|
GetUsers(ctx context.Context, req domain.UsersPageRequest) ([]entity.User, error)
|
||||||
GetUserByEmail(ctx context.Context, email string) (*entity.User, error)
|
GetAllUsers(ctx context.Context) ([]entity.User, error)
|
||||||
|
GetUserByEmailAndSudirId(ctx context.Context, email string, sudirUserId string) (*entity.User, error)
|
||||||
|
GetUsersByEmail(ctx context.Context, email string) ([]entity.User, error)
|
||||||
UpdateUser(ctx context.Context, id int64, user entity.UpdateUser) (*entity.User, error)
|
UpdateUser(ctx context.Context, id int64, user entity.UpdateUser) (*entity.User, error)
|
||||||
DeleteUser(ctx context.Context, ids []int64) (int, error)
|
DeleteUser(ctx context.Context, ids []int64) (int, error)
|
||||||
Insert(ctx context.Context, user entity.User) (int, error)
|
Insert(ctx context.Context, user entity.User) (int, error)
|
||||||
@@ -103,8 +107,9 @@ func (u User) GetProfileById(ctx context.Context, userId int64) (*domain.AdminUs
|
|||||||
roleIds := RolesIds(roles)
|
roleIds := RolesIds(roles)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
roleList []entity.Role
|
roleList []entity.Role
|
||||||
roleName string
|
roleName string
|
||||||
|
roleNames []string
|
||||||
)
|
)
|
||||||
if len(roleIds) != 0 {
|
if len(roleIds) != 0 {
|
||||||
roleList, err = u.roleRepoUser.GetRoleByIds(ctx, roleIds)
|
roleList, err = u.roleRepoUser.GetRoleByIds(ctx, roleIds)
|
||||||
@@ -113,22 +118,27 @@ func (u User) GetProfileById(ctx context.Context, userId int64) (*domain.AdminUs
|
|||||||
}
|
}
|
||||||
if len(roleList) > 0 {
|
if len(roleList) > 0 {
|
||||||
roleName = roleList[0].Name
|
roleName = roleList[0].Name
|
||||||
|
for _, r := range roleList {
|
||||||
|
roleNames = append(roleNames, r.Name)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return &domain.AdminUserShort{
|
return &domain.AdminUserShort{
|
||||||
FirstName: user.FirstName,
|
FirstName: user.FirstName,
|
||||||
LastName: user.LastName,
|
LastName: user.LastName,
|
||||||
|
FullName: user.FullName,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
Role: roleName,
|
Role: roleName,
|
||||||
Roles: roleIds,
|
Roles: roleIds,
|
||||||
|
RoleNames: roleNames,
|
||||||
IdleTimeoutMs: u.idleTimeoutMs,
|
IdleTimeoutMs: u.idleTimeoutMs,
|
||||||
Permissions: mergePermissions(roleList),
|
Permissions: mergePermissions(roleList),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) GetUsers(ctx context.Context, req domain.UsersRequest) (*domain.UsersResponse, error) {
|
func (u User) GetUsers(ctx context.Context, req domain.UsersPageRequest) (*domain.UsersResponse, error) {
|
||||||
users, err := u.userRepo.GetUsers(ctx, req.Ids, req.Offset, req.Limit, req.Email)
|
users, err := u.userRepo.GetUsers(ctx, req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "get users from repo")
|
return nil, errors.WithMessage(err, "get users from repo")
|
||||||
}
|
}
|
||||||
@@ -138,27 +148,56 @@ func (u User) GetUsers(ctx context.Context, req domain.UsersRequest) (*domain.Us
|
|||||||
userIds = append(userIds, int(user.Id))
|
userIds = append(userIds, int(user.Id))
|
||||||
}
|
}
|
||||||
|
|
||||||
rolesByUsers, err := u.userRoleRepo.GetRolesByUserIds(ctx, userIds)
|
userRoles, err := u.userRoleRepo.GetRolesByUserIds(ctx, userIds)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.WithMessage(err, "get roles by user ids")
|
return nil, errors.WithMessage(err, "get roles by user ids and roles id")
|
||||||
}
|
|
||||||
|
|
||||||
lastSessionsByUsers, err := u.tokenRepo.LastAccessByUserIds(ctx, userIds)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.WithMessage(err, "get last sessions by user ids")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
items := make([]domain.User, 0, len(users))
|
items := make([]domain.User, 0, len(users))
|
||||||
for _, user := range users {
|
for _, user := range users {
|
||||||
roles := make([]int, 0)
|
roles := make([]int, 0)
|
||||||
|
|
||||||
for _, role := range rolesByUsers {
|
for _, role := range userRoles {
|
||||||
if role.UserId == int(user.Id) {
|
if role.UserId == int(user.Id) {
|
||||||
roles = append(roles, role.RoleId)
|
roles = append(roles, role.RoleId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
items = append(items, u.toDomain(user, roles, lastSessionsByUsers[user.Id]))
|
if filteredRoles(req.Query, roles) && filteredLastSession(req.Query, user.LastSessionCreatedAt) {
|
||||||
|
items = append(items, u.toDomain(user, roles, user.LastSessionCreatedAt))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &domain.UsersResponse{Items: items}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (u User) GetAllUsers(ctx context.Context) (*domain.UsersResponse, error) {
|
||||||
|
users, err := u.userRepo.GetAllUsers(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "get all users from repo")
|
||||||
|
}
|
||||||
|
|
||||||
|
userIds := make([]int, 0)
|
||||||
|
for _, user := range users {
|
||||||
|
userIds = append(userIds, int(user.Id))
|
||||||
|
}
|
||||||
|
|
||||||
|
userRoles, err := u.userRoleRepo.GetRolesByUserIds(ctx, userIds)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.WithMessage(err, "get roles by user ids and roles id")
|
||||||
|
}
|
||||||
|
|
||||||
|
items := make([]domain.User, 0, len(users))
|
||||||
|
for _, user := range users {
|
||||||
|
roles := make([]int, 0)
|
||||||
|
|
||||||
|
for _, role := range userRoles {
|
||||||
|
if role.UserId == int(user.Id) {
|
||||||
|
roles = append(roles, role.RoleId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
items = append(items, u.toDomain(user, roles, user.LastSessionCreatedAt))
|
||||||
}
|
}
|
||||||
|
|
||||||
return &domain.UsersResponse{Items: items}, nil
|
return &domain.UsersResponse{Items: items}, nil
|
||||||
@@ -168,7 +207,7 @@ func (u User) CreateUser(ctx context.Context, req domain.CreateUserRequest, admi
|
|||||||
var usr entity.User
|
var usr entity.User
|
||||||
|
|
||||||
err := u.txRunner.UserTransaction(ctx, func(ctx context.Context, tx UserTransaction) error {
|
err := u.txRunner.UserTransaction(ctx, func(ctx context.Context, tx UserTransaction) error {
|
||||||
user, err := tx.GetUserByEmail(ctx, req.Email)
|
user, err := tx.GetUserByEmailAndSudirId(ctx, req.Email, "")
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, domain.ErrNotFound):
|
case errors.Is(err, domain.ErrNotFound):
|
||||||
break
|
break
|
||||||
@@ -188,6 +227,7 @@ func (u User) CreateUser(ctx context.Context, req domain.CreateUserRequest, admi
|
|||||||
Id: 0,
|
Id: 0,
|
||||||
FirstName: req.FirstName,
|
FirstName: req.FirstName,
|
||||||
LastName: req.LastName,
|
LastName: req.LastName,
|
||||||
|
FullName: createFullName(req.FirstName, req.LastName),
|
||||||
Email: req.Email,
|
Email: req.Email,
|
||||||
Password: encryptedPassword,
|
Password: encryptedPassword,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
@@ -213,14 +253,12 @@ func (u User) CreateUser(ctx context.Context, req domain.CreateUserRequest, admi
|
|||||||
|
|
||||||
slices.Sort(req.Roles)
|
slices.Sort(req.Roles)
|
||||||
diff := diffToString(map[string]any{
|
diff := diffToString(map[string]any{
|
||||||
"Имя": "",
|
"ФИО": "",
|
||||||
"Фамилия": "",
|
|
||||||
"Описание": "",
|
"Описание": "",
|
||||||
"Email": "",
|
"Email": "",
|
||||||
"Роли (ID)": []int{},
|
"Роли (ID)": []int{},
|
||||||
}, map[string]any{
|
}, map[string]any{
|
||||||
"Имя": req.FirstName,
|
"ФИО": usr.FullName,
|
||||||
"Фамилия": req.LastName,
|
|
||||||
"Описание": req.Description,
|
"Описание": req.Description,
|
||||||
"Email": req.Email,
|
"Email": req.Email,
|
||||||
"Роли (ID)": req.Roles,
|
"Роли (ID)": req.Roles,
|
||||||
@@ -230,13 +268,14 @@ func (u User) CreateUser(ctx context.Context, req domain.CreateUserRequest, admi
|
|||||||
entity.EventUserChanged,
|
entity.EventUserChanged,
|
||||||
)
|
)
|
||||||
|
|
||||||
result := u.toDomain(usr, req.Roles, nil)
|
return new(u.toDomain(usr, req.Roles, nil)), nil
|
||||||
return &result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//nolint:cyclop,funlen
|
||||||
func (u User) UpdateUser(ctx context.Context, req domain.UpdateUserRequest, adminId int64) (*domain.User, error) {
|
func (u User) UpdateUser(ctx context.Context, req domain.UpdateUserRequest, adminId int64) (*domain.User, error) {
|
||||||
var (
|
var (
|
||||||
user *entity.User
|
user *entity.User
|
||||||
|
updatedUser *entity.User
|
||||||
lastSessionCreatedAt *time.Time
|
lastSessionCreatedAt *time.Time
|
||||||
)
|
)
|
||||||
oldRoles, err := u.userRoleRepo.GetRolesByUserIds(ctx, []int{int(req.Id)})
|
oldRoles, err := u.userRoleRepo.GetRolesByUserIds(ctx, []int{int(req.Id)})
|
||||||
@@ -244,7 +283,7 @@ func (u User) UpdateUser(ctx context.Context, req domain.UpdateUserRequest, admi
|
|||||||
return nil, errors.WithMessage(err, "get user roles")
|
return nil, errors.WithMessage(err, "get user roles")
|
||||||
}
|
}
|
||||||
err = u.txRunner.UserTransaction(ctx, func(ctx context.Context, tx UserTransaction) error {
|
err = u.txRunner.UserTransaction(ctx, func(ctx context.Context, tx UserTransaction) error {
|
||||||
_, err := tx.GetUserById(ctx, req.Id)
|
user, err = tx.GetUserById(ctx, req.Id)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, domain.ErrNotFound):
|
case errors.Is(err, domain.ErrNotFound):
|
||||||
return err // nolint:wrapcheck
|
return err // nolint:wrapcheck
|
||||||
@@ -252,37 +291,48 @@ func (u User) UpdateUser(ctx context.Context, req domain.UpdateUserRequest, admi
|
|||||||
return errors.WithMessage(err, "get user by id")
|
return errors.WithMessage(err, "get user by id")
|
||||||
}
|
}
|
||||||
|
|
||||||
user, err = tx.GetUserByEmail(ctx, req.Email)
|
users, err := tx.GetUsersByEmail(ctx, req.Email)
|
||||||
switch {
|
switch {
|
||||||
case errors.Is(err, domain.ErrNotFound):
|
case errors.Is(err, domain.ErrNotFound):
|
||||||
break
|
break
|
||||||
case err != nil:
|
case err != nil:
|
||||||
return errors.WithMessage(err, "get user by email or phone")
|
return errors.WithMessage(err, "get user by email or phone")
|
||||||
case user.Id != req.Id:
|
}
|
||||||
return domain.ErrAlreadyExists
|
|
||||||
|
for _, usr := range users {
|
||||||
|
// check in internal user space
|
||||||
|
if (user.SudirUserId == nil && usr.SudirUserId == nil) && (usr.Id != req.Id) {
|
||||||
|
return domain.ErrAlreadyExists
|
||||||
|
}
|
||||||
|
|
||||||
|
// check in sudir user space
|
||||||
|
if usr.SudirUserId != nil && user.SudirUserId != nil && (*user.SudirUserId != *usr.SudirUserId) {
|
||||||
|
return domain.ErrAlreadyExists
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateEntity := entity.UpdateUser{
|
updateEntity := entity.UpdateUser{
|
||||||
FirstName: req.FirstName,
|
FirstName: req.FirstName,
|
||||||
LastName: req.LastName,
|
LastName: req.LastName,
|
||||||
|
FullName: createFullName(req.FirstName, req.LastName),
|
||||||
Email: req.Email,
|
Email: req.Email,
|
||||||
Description: req.Description,
|
Description: req.Description,
|
||||||
}
|
}
|
||||||
user, err = tx.UpdateUser(ctx, req.Id, updateEntity)
|
updatedUser, err = tx.UpdateUser(ctx, req.Id, updateEntity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "update user")
|
return errors.WithMessage(err, "update user")
|
||||||
}
|
}
|
||||||
|
|
||||||
err = tx.UpsertUserRoleLinks(ctx, int(user.Id), req.Roles)
|
err = tx.UpsertUserRoleLinks(ctx, int(updatedUser.Id), req.Roles)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "update user role links")
|
return errors.WithMessage(err, "update user role links")
|
||||||
}
|
}
|
||||||
|
|
||||||
userLastSession, err := tx.LastAccessByUserIds(ctx, []int{int(user.Id)})
|
userLastSession, err := tx.LastAccessByUserIds(ctx, []int{int(updatedUser.Id)})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.WithMessage(err, "get last user session")
|
return errors.WithMessage(err, "get last user session")
|
||||||
}
|
}
|
||||||
lastSessionCreatedAt = userLastSession[user.Id]
|
lastSessionCreatedAt = userLastSession[updatedUser.Id]
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
@@ -292,25 +342,22 @@ func (u User) UpdateUser(ctx context.Context, req domain.UpdateUserRequest, admi
|
|||||||
|
|
||||||
slices.Sort(req.Roles)
|
slices.Sort(req.Roles)
|
||||||
diff := diffToString(map[string]any{
|
diff := diffToString(map[string]any{
|
||||||
"Имя": user.FirstName,
|
"ФИО": user.FullName,
|
||||||
"Фамилия": user.LastName,
|
|
||||||
"Описание": user.Description,
|
"Описание": user.Description,
|
||||||
"Email": user.Email,
|
"Email": user.Email,
|
||||||
"Роли (ID)": RolesIds(oldRoles),
|
"Роли (ID)": RolesIds(oldRoles),
|
||||||
}, map[string]any{
|
}, map[string]any{
|
||||||
"Имя": req.FirstName,
|
"ФИО": updatedUser.FullName,
|
||||||
"Фамилия": req.LastName,
|
|
||||||
"Описание": req.Description,
|
"Описание": req.Description,
|
||||||
"Email": req.Email,
|
"Email": req.Email,
|
||||||
"Роли (ID)": req.Roles,
|
"Роли (ID)": req.Roles,
|
||||||
})
|
})
|
||||||
u.auditService.SaveAuditAsync(ctx, adminId,
|
u.auditService.SaveAuditAsync(ctx, adminId,
|
||||||
fmt.Sprintf("Пользователь. Изменение пользователя %d.\n %s", user.Id, diff),
|
fmt.Sprintf("Пользователь. Изменение пользователя %d.\n %s", updatedUser.Id, diff),
|
||||||
entity.EventUserChanged,
|
entity.EventUserChanged,
|
||||||
)
|
)
|
||||||
|
|
||||||
result := u.toDomain(*user, req.Roles, lastSessionCreatedAt)
|
return new(u.toDomain(*updatedUser, req.Roles, lastSessionCreatedAt)), nil
|
||||||
return &result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) DeleteUsers(ctx context.Context, ids []int64, adminId int64) (int, error) {
|
func (u User) DeleteUsers(ctx context.Context, ids []int64, adminId int64) (int, error) {
|
||||||
@@ -347,8 +394,7 @@ func (u User) GetById(ctx context.Context, userId int) (*domain.User, error) {
|
|||||||
return nil, errors.WithMessage(err, "get last sessions by user id")
|
return nil, errors.WithMessage(err, "get last sessions by user id")
|
||||||
}
|
}
|
||||||
|
|
||||||
result := u.toDomain(*user, RolesIds(roles), lastSessions[int64(userId)])
|
return new(u.toDomain(*user, RolesIds(roles), lastSessions[int64(userId)])), nil
|
||||||
return &result, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (u User) Block(ctx context.Context, adminId int64, userId int) error {
|
func (u User) Block(ctx context.Context, adminId int64, userId int) error {
|
||||||
@@ -384,14 +430,14 @@ func (u User) Block(ctx context.Context, adminId int64, userId int) error {
|
|||||||
|
|
||||||
u.auditService.SaveAuditAsync(ctx, adminId,
|
u.auditService.SaveAuditAsync(ctx, adminId,
|
||||||
fmt.Sprintf("Пользователь. %s пользователя ID %d.", userBlocked, userId),
|
fmt.Sprintf("Пользователь. %s пользователя ID %d.", userBlocked, userId),
|
||||||
entity.EventUserChanged,
|
entity.EventUserBlocked,
|
||||||
)
|
)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func RolesIds(roles []entity.UserRole) []int {
|
func RolesIds(roles []entity.UserRole) []int {
|
||||||
roleList := make([]int, 0)
|
roleList := make([]int, 0, len(roles))
|
||||||
|
|
||||||
for _, role := range roles {
|
for _, role := range roles {
|
||||||
roleList = append(roleList, role.RoleId)
|
roleList = append(roleList, role.RoleId)
|
||||||
@@ -445,7 +491,8 @@ func (u User) ChangePassword(ctx context.Context, adminId int64, oldPassword str
|
|||||||
return errors.WithMessage(err, "user.service.ChangePassword: get user by id")
|
return errors.WithMessage(err, "user.service.ChangePassword: get user by id")
|
||||||
}
|
}
|
||||||
|
|
||||||
if err = bcrypt.CompareHashAndPassword([]byte(admin.Password), []byte(oldPassword)); err != nil {
|
err = bcrypt.CompareHashAndPassword([]byte(admin.Password), []byte(oldPassword))
|
||||||
|
if err != nil {
|
||||||
u.auditService.SaveAuditAsync(ctx, adminId, "Указан неверный старый пароль", entity.EventErrorPasswordChange)
|
u.auditService.SaveAuditAsync(ctx, adminId, "Указан неверный старый пароль", entity.EventErrorPasswordChange)
|
||||||
return domain.ErrInvalidPassword
|
return domain.ErrInvalidPassword
|
||||||
}
|
}
|
||||||
@@ -482,7 +529,6 @@ func (u User) ChangePassword(ctx context.Context, adminId int64, oldPassword str
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gomnd
|
|
||||||
func (u User) cryptPassword(password string) (string, error) {
|
func (u User) cryptPassword(password string) (string, error) {
|
||||||
passwordBytes, err := bcrypt.GenerateFromPassword([]byte(password), 12) //nolint:mnd
|
passwordBytes, err := bcrypt.GenerateFromPassword([]byte(password), 12) //nolint:mnd
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -497,8 +543,9 @@ func (u User) toDomain(user entity.User, roleIds []int, lastSessionCreatedAt *ti
|
|||||||
Id: user.Id,
|
Id: user.Id,
|
||||||
Roles: roleIds,
|
Roles: roleIds,
|
||||||
FirstName: user.FirstName,
|
FirstName: user.FirstName,
|
||||||
Description: user.Description,
|
|
||||||
LastName: user.LastName,
|
LastName: user.LastName,
|
||||||
|
FullName: user.FullName,
|
||||||
|
Description: user.Description,
|
||||||
Email: user.Email,
|
Email: user.Email,
|
||||||
Blocked: user.Blocked,
|
Blocked: user.Blocked,
|
||||||
UpdatedAt: user.UpdatedAt,
|
UpdatedAt: user.UpdatedAt,
|
||||||
@@ -506,3 +553,54 @@ func (u User) toDomain(user entity.User, roleIds []int, lastSessionCreatedAt *ti
|
|||||||
LastSessionCreatedAt: lastSessionCreatedAt,
|
LastSessionCreatedAt: lastSessionCreatedAt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func filteredRoles(reqQuery *domain.UserQuery, roleIds []int) bool {
|
||||||
|
if reqQuery == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.Roles == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if len(reqQuery.Roles) == 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, roleId := range roleIds {
|
||||||
|
if slices.Contains(reqQuery.Roles, roleId) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func filteredLastSession(reqQuery *domain.UserQuery, lastSessionCreatedAt *time.Time) bool {
|
||||||
|
if reqQuery == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.LastSessionCreatedAt == nil {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
if lastSessionCreatedAt == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if reqQuery.LastSessionCreatedAt.From.Compare(*lastSessionCreatedAt) <= 0 &&
|
||||||
|
reqQuery.LastSessionCreatedAt.To.Compare(*lastSessionCreatedAt) > 0 {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func createFullName(firstName string, lastName string) string {
|
||||||
|
if len(lastName) == 0 {
|
||||||
|
return firstName
|
||||||
|
}
|
||||||
|
|
||||||
|
return strings.Join([]string{lastName, firstName}, " ")
|
||||||
|
}
|
||||||
+79
-6
@@ -5,6 +5,12 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/assembly"
|
||||||
|
"msp-admin-service/conf"
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
"msp-admin-service/repository"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/txix-open/isp-kit/dbx"
|
"github.com/txix-open/isp-kit/dbx"
|
||||||
"github.com/txix-open/isp-kit/grpc/client"
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
@@ -14,11 +20,6 @@ import (
|
|||||||
"github.com/txix-open/isp-kit/test/grpct"
|
"github.com/txix-open/isp-kit/test/grpct"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"msp-admin-service/assembly"
|
|
||||||
"msp-admin-service/conf"
|
|
||||||
"msp-admin-service/domain"
|
|
||||||
"msp-admin-service/entity"
|
|
||||||
"msp-admin-service/repository"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestAuditSuite(t *testing.T) {
|
func TestAuditSuite(t *testing.T) {
|
||||||
@@ -28,6 +29,7 @@ func TestAuditSuite(t *testing.T) {
|
|||||||
|
|
||||||
type AuditSuite struct {
|
type AuditSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
test *test.Test
|
test *test.Test
|
||||||
db *dbt.TestDb
|
db *dbt.TestDb
|
||||||
grpcCli *client.Client
|
grpcCli *client.Client
|
||||||
@@ -61,6 +63,10 @@ func (t *AuditSuite) SetupTest() {
|
|||||||
Event: entity.EventUserChanged,
|
Event: entity.EventUserChanged,
|
||||||
Name: "изменение пользователя",
|
Name: "изменение пользователя",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Event: entity.EventUserBlocked,
|
||||||
|
Name: "изменение статуса блокировки пользователя",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
AuditTTl: conf.AuditTTlSetting{},
|
AuditTTl: conf.AuditTTlSetting{},
|
||||||
},
|
},
|
||||||
@@ -68,6 +74,8 @@ func (t *AuditSuite) SetupTest() {
|
|||||||
cfg := assembly.NewLocator(testInstance.Logger(), httpcli.New(), t.db).
|
cfg := assembly.NewLocator(testInstance.Logger(), httpcli.New(), t.db).
|
||||||
Config(context.Background(), remote, time.Minute)
|
Config(context.Background(), remote, time.Minute)
|
||||||
|
|
||||||
|
t.insertAuditLogs()
|
||||||
|
|
||||||
server, apiCli := grpct.TestServer(testInstance, cfg.Handler)
|
server, apiCli := grpct.TestServer(testInstance, cfg.Handler)
|
||||||
t.grpcCli = apiCli
|
t.grpcCli = apiCli
|
||||||
|
|
||||||
@@ -90,6 +98,7 @@ func (t *AuditSuite) Test_Events_DefaultEvents() {
|
|||||||
entity.EventSuccessLogout: "успешный выход",
|
entity.EventSuccessLogout: "успешный выход",
|
||||||
entity.EventRoleChanged: "изменение роли",
|
entity.EventRoleChanged: "изменение роли",
|
||||||
entity.EventUserChanged: "изменение пользователя",
|
entity.EventUserChanged: "изменение пользователя",
|
||||||
|
entity.EventUserBlocked: "изменение статуса блокировки пользователя",
|
||||||
}
|
}
|
||||||
for _, event := range response {
|
for _, event := range response {
|
||||||
name, found := expectedEventList[event.Event]
|
name, found := expectedEventList[event.Event]
|
||||||
@@ -109,6 +118,7 @@ func (t *AuditSuite) Test_Events_SortEvents() {
|
|||||||
{Event: entity.EventSuccessLogout, Enable: true},
|
{Event: entity.EventSuccessLogout, Enable: true},
|
||||||
{Event: entity.EventRoleChanged, Enable: false},
|
{Event: entity.EventRoleChanged, Enable: false},
|
||||||
{Event: entity.EventUserChanged, Enable: true},
|
{Event: entity.EventUserChanged, Enable: true},
|
||||||
|
{Event: entity.EventUserBlocked, Enable: true},
|
||||||
{Event: "новый#2", Enable: false},
|
{Event: "новый#2", Enable: false},
|
||||||
})
|
})
|
||||||
t.Require().NoError(err)
|
t.Require().NoError(err)
|
||||||
@@ -121,7 +131,7 @@ func (t *AuditSuite) Test_Events_SortEvents() {
|
|||||||
t.Require().NoError(err)
|
t.Require().NoError(err)
|
||||||
|
|
||||||
expectedSort := []bool{
|
expectedSort := []bool{
|
||||||
true, true, true, false, false, false, false,
|
true, true, true, true, false, false, false, false,
|
||||||
}
|
}
|
||||||
t.Require().Equal(len(expectedSort), len(response)) // nolint:testifylint
|
t.Require().Equal(len(expectedSort), len(response)) // nolint:testifylint
|
||||||
for i, event := range response {
|
for i, event := range response {
|
||||||
@@ -145,6 +155,7 @@ func (t *AuditSuite) Test_SetEvents_HappyPath() {
|
|||||||
entity.EventSuccessLogout: true,
|
entity.EventSuccessLogout: true,
|
||||||
entity.EventRoleChanged: false,
|
entity.EventRoleChanged: false,
|
||||||
entity.EventUserChanged: true,
|
entity.EventUserChanged: true,
|
||||||
|
entity.EventUserBlocked: true,
|
||||||
}
|
}
|
||||||
eventRep := repository.NewAuditEvent(t.db)
|
eventRep := repository.NewAuditEvent(t.db)
|
||||||
eventList, err := eventRep.All(context.Background())
|
eventList, err := eventRep.All(context.Background())
|
||||||
@@ -171,3 +182,65 @@ func (t *AuditSuite) Test_SetEvents_InvalidEvent() {
|
|||||||
t.Require().True(isStatus)
|
t.Require().True(isStatus)
|
||||||
t.Require().Equal(codes.InvalidArgument, s.Code())
|
t.Require().Equal(codes.InvalidArgument, s.Code())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (t *AuditSuite) Test_All_Logs() {
|
||||||
|
request := domain.AuditPageRequest{
|
||||||
|
LimitOffestParams: domain.LimitOffestParams{
|
||||||
|
Limit: 3,
|
||||||
|
Offset: 5,
|
||||||
|
},
|
||||||
|
Order: &domain.OrderParams{
|
||||||
|
Field: "user_id",
|
||||||
|
Type: "desc",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var response *domain.AuditResponse
|
||||||
|
err := t.grpcCli.
|
||||||
|
Invoke("admin/log/all").
|
||||||
|
JsonRequestBody(request).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
t.Require().NoError(err)
|
||||||
|
|
||||||
|
t.Require().Len(response.Items, 3)
|
||||||
|
t.Require().EqualValues(5, response.Items[0].UserId)
|
||||||
|
t.Require().EqualValues(4, response.Items[1].UserId)
|
||||||
|
t.Require().EqualValues(3, response.Items[2].UserId)
|
||||||
|
|
||||||
|
request.Query = &domain.AuditQuery{
|
||||||
|
Message: new("Выход"),
|
||||||
|
}
|
||||||
|
request.Limit = 10
|
||||||
|
request.Offset = 0
|
||||||
|
|
||||||
|
err = t.grpcCli.
|
||||||
|
Invoke("admin/log/all").
|
||||||
|
JsonRequestBody(request).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
t.Require().NoError(err)
|
||||||
|
|
||||||
|
t.Require().Len(response.Items, 6)
|
||||||
|
t.Require().EqualValues(6, response.TotalCount)
|
||||||
|
t.Require().EqualValues(10, response.Items[0].UserId)
|
||||||
|
t.Require().EqualValues(9, response.Items[1].UserId)
|
||||||
|
t.Require().EqualValues(8, response.Items[2].UserId)
|
||||||
|
t.Require().EqualValues(7, response.Items[3].UserId)
|
||||||
|
t.Require().EqualValues(6, response.Items[4].UserId)
|
||||||
|
t.Require().EqualValues(5, response.Items[5].UserId)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *AuditSuite) insertAuditLogs() {
|
||||||
|
t.db.Must().Exec(`INSERT INTO audit (user_id, message, created_at, event)
|
||||||
|
VALUES (1, 'Успешный вход', NOW(), 'success_login'),
|
||||||
|
(2, 'Успешный вход', NOW(), 'success_login'),
|
||||||
|
(3, 'Неуспешный вход', NOW(), 'unsuccess_login'),
|
||||||
|
(4, 'Неуспешный вход', NOW(), 'unsuccess_login'),
|
||||||
|
(5, 'Успешный выход', NOW(), 'success_logout'),
|
||||||
|
(6, 'Успешный выход', NOW(), 'success_logout'),
|
||||||
|
(7, 'Неуспешный выход', NOW(), 'unsuccess_logout'),
|
||||||
|
(8, 'Неуспешный выход', NOW(), 'unsuccess_logout'),
|
||||||
|
(9, 'Выход', NOW(), 'logout'),
|
||||||
|
(10, 'Выход', NOW(), 'logout')`)
|
||||||
|
}
|
||||||
+36
-5
@@ -11,14 +11,15 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
"golang.org/x/sync/errgroup"
|
|
||||||
"msp-admin-service/assembly"
|
"msp-admin-service/assembly"
|
||||||
"msp-admin-service/conf"
|
"msp-admin-service/conf"
|
||||||
"msp-admin-service/domain"
|
"msp-admin-service/domain"
|
||||||
"msp-admin-service/entity"
|
"msp-admin-service/entity"
|
||||||
"msp-admin-service/repository"
|
"msp-admin-service/repository"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"golang.org/x/sync/errgroup"
|
||||||
|
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/txix-open/isp-kit/dbx"
|
"github.com/txix-open/isp-kit/dbx"
|
||||||
"github.com/txix-open/isp-kit/grpc/client"
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
@@ -38,6 +39,7 @@ func TestAuthTestSuite(t *testing.T) {
|
|||||||
|
|
||||||
type AuthTestSuite struct {
|
type AuthTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
test *test.Test
|
test *test.Test
|
||||||
db *dbt.TestDb
|
db *dbt.TestDb
|
||||||
grpcCli *client.Client
|
grpcCli *client.Client
|
||||||
@@ -98,6 +100,8 @@ func (s *AuthTestSuite) TestLoginHappyPath() {
|
|||||||
|
|
||||||
tokenInfo := SelectTokenEntityByToken(s.db, response.Token)
|
tokenInfo := SelectTokenEntityByToken(s.db, response.Token)
|
||||||
s.Require().Equal(tokenInfo.UserId, id)
|
s.Require().Equal(tokenInfo.UserId, id)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) TestLoginNotFound() {
|
func (s *AuthTestSuite) TestLoginNotFound() {
|
||||||
@@ -111,6 +115,8 @@ func (s *AuthTestSuite) TestLoginNotFound() {
|
|||||||
st, ok := status.FromError(err)
|
st, ok := status.FromError(err)
|
||||||
s.Require().True(ok)
|
s.Require().True(ok)
|
||||||
s.Require().Equal(codes.Unauthenticated, st.Code())
|
s.Require().Equal(codes.Unauthenticated, st.Code())
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) TestBlockedUser() {
|
func (s *AuthTestSuite) TestBlockedUser() {
|
||||||
@@ -132,6 +138,8 @@ func (s *AuthTestSuite) TestBlockedUser() {
|
|||||||
st, ok := status.FromError(err)
|
st, ok := status.FromError(err)
|
||||||
s.Require().True(ok)
|
s.Require().True(ok)
|
||||||
s.Require().Equal(codes.Unauthenticated, st.Code())
|
s.Require().Equal(codes.Unauthenticated, st.Code())
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) TestLoginWrongPassword() {
|
func (s *AuthTestSuite) TestLoginWrongPassword() {
|
||||||
@@ -152,6 +160,8 @@ func (s *AuthTestSuite) TestLoginWrongPassword() {
|
|||||||
st, ok := status.FromError(err)
|
st, ok := status.FromError(err)
|
||||||
s.Require().True(ok)
|
s.Require().True(ok)
|
||||||
s.Require().Equal(codes.Unauthenticated, st.Code())
|
s.Require().Equal(codes.Unauthenticated, st.Code())
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) TestSudirLoginHappyPath() {
|
func (s *AuthTestSuite) TestSudirLoginHappyPath() {
|
||||||
@@ -165,11 +175,14 @@ func (s *AuthTestSuite) TestSudirLoginHappyPath() {
|
|||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
user := entity.User{}
|
user := entity.User{}
|
||||||
s.db.Must().SelectRow(&user, "select id, email from users where sudir_user_id = $1", "sudirUser1")
|
s.db.Must().SelectRow(&user, "select id, email, full_name from users where sudir_user_id = $1", "sudirUser1")
|
||||||
s.Require().Equal("sudir@email.ru", user.Email)
|
s.Require().Equal("sudir@email.ru", user.Email)
|
||||||
|
s.Require().Equal("surname name patronymic", user.FullName)
|
||||||
|
|
||||||
tokenInfo := SelectTokenEntityByToken(s.db, response.Token)
|
tokenInfo := SelectTokenEntityByToken(s.db, response.Token)
|
||||||
s.Require().Equal(tokenInfo.UserId, user.Id)
|
s.Require().Equal(tokenInfo.UserId, user.Id)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) Test_Logout_HappyPath() {
|
func (s *AuthTestSuite) Test_Logout_HappyPath() {
|
||||||
@@ -188,6 +201,8 @@ func (s *AuthTestSuite) Test_Logout_HappyPath() {
|
|||||||
|
|
||||||
tokenInfo := SelectTokenEntityByToken(s.db, "token-841297641213")
|
tokenInfo := SelectTokenEntityByToken(s.db, "token-841297641213")
|
||||||
s.Require().Equal(entity.TokenStatusRevoked, tokenInfo.Status)
|
s.Require().Equal(entity.TokenStatusRevoked, tokenInfo.Status)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) Test_Logout_NotFound() {
|
func (s *AuthTestSuite) Test_Logout_NotFound() {
|
||||||
@@ -198,10 +213,21 @@ func (s *AuthTestSuite) Test_Logout_NotFound() {
|
|||||||
|
|
||||||
time.Sleep(time.Second)
|
time.Sleep(time.Second)
|
||||||
audit := repository.NewAudit(s.db)
|
audit := repository.NewAudit(s.db)
|
||||||
auditList, err := audit.All(context.Background(), 10, 0)
|
auditList, err := audit.AllByRequest(context.Background(), domain.AuditPageRequest{
|
||||||
|
LimitOffestParams: domain.LimitOffestParams{
|
||||||
|
Limit: 10,
|
||||||
|
Offset: 0,
|
||||||
|
},
|
||||||
|
Order: &domain.OrderParams{
|
||||||
|
Field: "created_at",
|
||||||
|
Type: "desc",
|
||||||
|
},
|
||||||
|
})
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.Require().Len(auditList, 1) //nolint:mnd
|
s.Require().Len(auditList, 1)
|
||||||
s.Require().Equal(entity.EventSuccessLogout, auditList[0].Event)
|
s.Require().Equal(entity.EventSuccessLogout, auditList[0].Event)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) Test_Logout_AlreadyRevoke() {
|
func (s *AuthTestSuite) Test_Logout_AlreadyRevoke() {
|
||||||
@@ -220,6 +246,8 @@ func (s *AuthTestSuite) Test_Logout_AlreadyRevoke() {
|
|||||||
|
|
||||||
tokenInfo := SelectTokenEntityByToken(s.db, "token-148623719462")
|
tokenInfo := SelectTokenEntityByToken(s.db, "token-148623719462")
|
||||||
s.Require().Equal(entity.TokenStatusRevoked, tokenInfo.Status)
|
s.Require().Equal(entity.TokenStatusRevoked, tokenInfo.Status)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) TestBruteForceLogin() {
|
func (s *AuthTestSuite) TestBruteForceLogin() {
|
||||||
@@ -266,6 +294,8 @@ func (s *AuthTestSuite) TestBruteForceLogin() {
|
|||||||
|
|
||||||
s.Require().EqualValues(97, tooManyRequestsErrorCount.Load())
|
s.Require().EqualValues(97, tooManyRequestsErrorCount.Load())
|
||||||
s.Require().EqualValues(3, unauthorizedErrorCount.Load())
|
s.Require().EqualValues(3, unauthorizedErrorCount.Load())
|
||||||
|
|
||||||
|
time.Sleep(2 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) initMockSudir() (*httptest.Server, string) {
|
func (s *AuthTestSuite) initMockSudir() (*httptest.Server, string) {
|
||||||
@@ -289,6 +319,7 @@ func (s *AuthTestSuite) initMockSudir() (*httptest.Server, string) {
|
|||||||
Sub: "sudirUser1",
|
Sub: "sudirUser1",
|
||||||
GivenName: "name",
|
GivenName: "name",
|
||||||
FamilyName: "surname",
|
FamilyName: "surname",
|
||||||
|
Name: "surname name patronymic",
|
||||||
}
|
}
|
||||||
data, err := json.Marshal(res)
|
data, err := json.Marshal(res)
|
||||||
s.Require().NoError(err) //nolint:testifylint
|
s.Require().NoError(err) //nolint:testifylint
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ func TestCustomizationTestSuite(t *testing.T) {
|
|||||||
|
|
||||||
type CustomizationTestSuite struct {
|
type CustomizationTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
test *test.Test
|
test *test.Test
|
||||||
db *dbt.TestDb
|
db *dbt.TestDb
|
||||||
grpcCli *client.Client
|
grpcCli *client.Client
|
||||||
|
|||||||
@@ -1,31 +1,31 @@
|
|||||||
package tests_test
|
package tests_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/txix-open/isp-kit/db/query"
|
"github.com/txix-open/isp-kit/db/query"
|
||||||
"github.com/txix-open/isp-kit/test/dbt"
|
"github.com/txix-open/isp-kit/test/dbt"
|
||||||
"golang.org/x/crypto/bcrypt"
|
"golang.org/x/crypto/bcrypt"
|
||||||
"msp-admin-service/entity"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
//nolint:gomnd
|
|
||||||
func InsertUser(db *dbt.TestDb, user entity.User) int64 {
|
func InsertUser(db *dbt.TestDb, user entity.User) int64 {
|
||||||
if user.Password != "" {
|
if user.Password != "" {
|
||||||
passwordBytes, _ := bcrypt.GenerateFromPassword([]byte(user.Password), 12)
|
passwordBytes, _ := bcrypt.GenerateFromPassword([]byte(user.Password), 12)
|
||||||
user.Password = string(passwordBytes)
|
user.Password = string(passwordBytes)
|
||||||
}
|
}
|
||||||
var id int64
|
var id int64
|
||||||
db.Must().SelectRow(&id, `insert into users (first_name, last_name, email, password, blocked, last_active_at)
|
db.Must().SelectRow(&id, `insert into users (first_name, last_name, full_name, email, password, blocked, last_active_at)
|
||||||
values($1,$2,$3,$4,$5,$6) returning id`,
|
values($1,$2,$3,$4,$5,$6,$7) returning id`,
|
||||||
user.FirstName, user.LastName, user.Email, user.Password, user.Blocked, user.LastActiveAt)
|
user.FirstName, user.LastName, user.FullName, user.Email, user.Password, user.Blocked, user.LastActiveAt)
|
||||||
return id
|
return id
|
||||||
}
|
}
|
||||||
|
|
||||||
func InsertSudirUser(db *dbt.TestDb, user entity.SudirUser) int64 {
|
func InsertSudirUser(db *dbt.TestDb, user entity.SudirUser) int64 {
|
||||||
q, args, err := query.New().
|
q, args, err := query.New().
|
||||||
Insert("users").
|
Insert("users").
|
||||||
Columns("sudir_user_id", "first_name", "last_name", "email").
|
Columns("sudir_user_id", "first_name", "last_name", "full_name", "email").
|
||||||
Values(user.SudirUserId, user.FirstName, user.LastName, user.Email).
|
Values(user.SudirUserId, user.FirstName, user.LastName, user.FullName, user.Email).
|
||||||
Suffix("RETURNING id").
|
Suffix("RETURNING id").
|
||||||
ToSql()
|
ToSql()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+20
-6
@@ -1,18 +1,21 @@
|
|||||||
package tests_test
|
package tests_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"msp-admin-service/service/inactive_worker"
|
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
"msp-admin-service/service/inactive_worker"
|
||||||
|
|
||||||
|
"msp-admin-service/assembly"
|
||||||
|
"msp-admin-service/conf"
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
"msp-admin-service/repository"
|
||||||
|
|
||||||
"github.com/txix-open/isp-kit/bgjobx"
|
"github.com/txix-open/isp-kit/bgjobx"
|
||||||
"github.com/txix-open/isp-kit/dbx"
|
"github.com/txix-open/isp-kit/dbx"
|
||||||
"github.com/txix-open/isp-kit/test"
|
"github.com/txix-open/isp-kit/test"
|
||||||
"github.com/txix-open/isp-kit/test/dbt"
|
"github.com/txix-open/isp-kit/test/dbt"
|
||||||
"msp-admin-service/assembly"
|
|
||||||
"msp-admin-service/conf"
|
|
||||||
"msp-admin-service/entity"
|
|
||||||
"msp-admin-service/repository"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestInactiveWorker(t *testing.T) {
|
func TestInactiveWorker(t *testing.T) {
|
||||||
@@ -44,7 +47,18 @@ func TestInactiveWorker(t *testing.T) {
|
|||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
require.True(user.Blocked)
|
require.True(user.Blocked)
|
||||||
|
|
||||||
list, err := repository.NewAudit(db).All(t.Context(), 10, 0)
|
list, err := repository.NewAudit(db).AllByRequest(t.Context(), domain.AuditPageRequest{
|
||||||
|
LimitOffestParams: domain.LimitOffestParams{
|
||||||
|
Limit: 10,
|
||||||
|
Offset: 0,
|
||||||
|
},
|
||||||
|
Order: &domain.OrderParams{
|
||||||
|
Field: "created_at",
|
||||||
|
Type: "desc",
|
||||||
|
},
|
||||||
|
})
|
||||||
require.NoError(err)
|
require.NoError(err)
|
||||||
require.Len(list, 1)
|
require.Len(list, 1)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
@@ -26,6 +26,7 @@ func TestSecureSuite(t *testing.T) {
|
|||||||
|
|
||||||
type SecureSuite struct {
|
type SecureSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
test *test.Test
|
test *test.Test
|
||||||
require *require.Assertions
|
require *require.Assertions
|
||||||
db *dbt.TestDb
|
db *dbt.TestDb
|
||||||
|
|||||||
@@ -0,0 +1,274 @@
|
|||||||
|
package tests_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"strconv"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"msp-admin-service/assembly"
|
||||||
|
"msp-admin-service/conf"
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
"msp-admin-service/service/session_worker"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/suite"
|
||||||
|
"github.com/txix-open/isp-kit/bgjobx"
|
||||||
|
"github.com/txix-open/isp-kit/dbx"
|
||||||
|
"github.com/txix-open/isp-kit/grpc/client"
|
||||||
|
"github.com/txix-open/isp-kit/http/httpcli"
|
||||||
|
"github.com/txix-open/isp-kit/test"
|
||||||
|
"github.com/txix-open/isp-kit/test/dbt"
|
||||||
|
"github.com/txix-open/isp-kit/test/grpct"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestSessionSuite(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
suite.Run(t, &SessionSuite{})
|
||||||
|
}
|
||||||
|
|
||||||
|
type SessionSuite struct {
|
||||||
|
suite.Suite
|
||||||
|
|
||||||
|
test *test.Test
|
||||||
|
db *dbt.TestDb
|
||||||
|
config assembly.Config
|
||||||
|
grpcCli *client.Client
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *SessionSuite) SetupTest() {
|
||||||
|
testInstance, _ := test.New(t.T())
|
||||||
|
t.test = testInstance
|
||||||
|
t.db = dbt.New(testInstance, dbx.WithMigrationRunner("../migrations", testInstance.Logger()))
|
||||||
|
|
||||||
|
remote := conf.Remote{
|
||||||
|
Audit: conf.Audit{
|
||||||
|
EventSettings: []conf.AuditEventSetting{
|
||||||
|
{
|
||||||
|
Event: entity.EventSuccessLogin,
|
||||||
|
Name: "успешный вход",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: entity.EventErrorLogin,
|
||||||
|
Name: "неуспешный вход",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: entity.EventSuccessLogout,
|
||||||
|
Name: "успешный выход",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: entity.EventRoleChanged,
|
||||||
|
Name: "изменение роли",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: entity.EventUserChanged,
|
||||||
|
Name: "изменение пользователя",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Event: entity.EventUserBlocked,
|
||||||
|
Name: "изменение статуса блокировки пользователя",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
AuditTTl: conf.AuditTTlSetting{},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
t.config = assembly.NewLocator(testInstance.Logger(), httpcli.New(), t.db).
|
||||||
|
Config(context.Background(), remote, 500*time.Millisecond)
|
||||||
|
|
||||||
|
server, apiCli := grpct.TestServer(testInstance, t.config.Handler)
|
||||||
|
t.grpcCli = apiCli
|
||||||
|
|
||||||
|
testInstance.T().Cleanup(func() {
|
||||||
|
server.Shutdown()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
//nolint:funlen
|
||||||
|
func (t *SessionSuite) Test_All_Session() {
|
||||||
|
userId := InsertUser(t.db, entity.User{Email: "test_1@aa.ru"})
|
||||||
|
timeNow := time.Now().UTC()
|
||||||
|
|
||||||
|
InsertTokenEntity(t.db, entity.Token{
|
||||||
|
Token: "test_token_1",
|
||||||
|
UserId: userId,
|
||||||
|
Status: entity.TokenStatusAllowed,
|
||||||
|
ExpiredAt: timeNow.Add(1 * time.Hour),
|
||||||
|
CreatedAt: timeNow.Add(-1 * time.Hour),
|
||||||
|
UpdatedAt: timeNow,
|
||||||
|
})
|
||||||
|
InsertTokenEntity(t.db, entity.Token{
|
||||||
|
Token: "test_token_2",
|
||||||
|
UserId: userId,
|
||||||
|
Status: entity.TokenStatusRevoked,
|
||||||
|
ExpiredAt: timeNow.Add(1 * time.Hour),
|
||||||
|
CreatedAt: timeNow.Add(-2 * time.Hour),
|
||||||
|
UpdatedAt: timeNow,
|
||||||
|
})
|
||||||
|
InsertTokenEntity(t.db, entity.Token{
|
||||||
|
Token: "test_token_3",
|
||||||
|
UserId: userId,
|
||||||
|
Status: entity.TokenStatusExpired,
|
||||||
|
ExpiredAt: timeNow.Add(-1 * time.Hour),
|
||||||
|
CreatedAt: timeNow.Add(-3 * time.Hour),
|
||||||
|
UpdatedAt: timeNow,
|
||||||
|
})
|
||||||
|
|
||||||
|
// Дефолт сортировка, лимит и оффсет
|
||||||
|
request := domain.SessionPageRequest{
|
||||||
|
LimitOffestParams: domain.LimitOffestParams{
|
||||||
|
Limit: 5,
|
||||||
|
Offset: 1,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
var response *domain.SessionResponse
|
||||||
|
err := t.grpcCli.
|
||||||
|
Invoke("admin/session/all").
|
||||||
|
JsonRequestBody(request).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
t.Require().NoError(err)
|
||||||
|
|
||||||
|
t.Require().Len(response.Items, 2)
|
||||||
|
t.Require().EqualValues(3, response.TotalCount)
|
||||||
|
t.Require().EqualValues(2, response.Items[0].Id)
|
||||||
|
t.Require().EqualValues(3, response.Items[1].Id)
|
||||||
|
|
||||||
|
// Дефолт сортировка, поиск по expired_at
|
||||||
|
request.Offset = 0
|
||||||
|
request.Query = &domain.SessionQuery{
|
||||||
|
ExpiredAt: &domain.DateFromToParams{
|
||||||
|
From: timeNow,
|
||||||
|
To: timeNow.Add(24 * time.Hour),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err = t.grpcCli.
|
||||||
|
Invoke("admin/session/all").
|
||||||
|
JsonRequestBody(request).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
t.Require().NoError(err)
|
||||||
|
|
||||||
|
t.Require().Len(response.Items, 2)
|
||||||
|
t.Require().EqualValues(2, response.TotalCount)
|
||||||
|
t.Require().EqualValues(1, response.Items[0].Id)
|
||||||
|
t.Require().EqualValues(2, response.Items[1].Id)
|
||||||
|
|
||||||
|
// Сортировка по статусу, пустой запрос
|
||||||
|
request.Query = nil
|
||||||
|
request.Order = &domain.OrderParams{
|
||||||
|
Field: "status",
|
||||||
|
Type: "asc",
|
||||||
|
}
|
||||||
|
|
||||||
|
err = t.grpcCli.
|
||||||
|
Invoke("admin/session/all").
|
||||||
|
JsonRequestBody(request).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
t.Require().NoError(err)
|
||||||
|
|
||||||
|
t.Require().Len(response.Items, 3)
|
||||||
|
t.Require().EqualValues(3, response.TotalCount)
|
||||||
|
t.Require().EqualValues(1, response.Items[0].Id)
|
||||||
|
t.Require().EqualValues(3, response.Items[1].Id)
|
||||||
|
t.Require().EqualValues(2, response.Items[2].Id)
|
||||||
|
|
||||||
|
// Сортировка по статусу, поиск по userId & status
|
||||||
|
resUserId := int(userId)
|
||||||
|
request.Query = &domain.SessionQuery{
|
||||||
|
UserId: []int{resUserId},
|
||||||
|
Status: []string{entity.TokenStatusExpired},
|
||||||
|
}
|
||||||
|
|
||||||
|
err = t.grpcCli.
|
||||||
|
Invoke("admin/session/all").
|
||||||
|
JsonRequestBody(request).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
t.Require().NoError(err)
|
||||||
|
|
||||||
|
t.Require().Len(response.Items, 1)
|
||||||
|
t.Require().EqualValues(1, response.TotalCount)
|
||||||
|
t.Require().EqualValues(3, response.Items[0].Id)
|
||||||
|
|
||||||
|
// Сортировка по id, поиск по id
|
||||||
|
for i := range 20 {
|
||||||
|
userId = InsertUser(t.db, entity.User{Email: "test_11" + strconv.Itoa(i) + "@aa.ru"})
|
||||||
|
InsertTokenEntity(t.db, entity.Token{
|
||||||
|
Token: "test_token_1" + strconv.Itoa(i),
|
||||||
|
UserId: userId,
|
||||||
|
Status: entity.TokenStatusAllowed,
|
||||||
|
ExpiredAt: timeNow.Add(1 * time.Hour),
|
||||||
|
CreatedAt: timeNow,
|
||||||
|
UpdatedAt: timeNow,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
request = domain.SessionPageRequest{
|
||||||
|
LimitOffestParams: domain.LimitOffestParams{
|
||||||
|
Limit: 5,
|
||||||
|
Offset: 0,
|
||||||
|
},
|
||||||
|
Order: &domain.OrderParams{
|
||||||
|
Field: "id",
|
||||||
|
Type: "desc",
|
||||||
|
},
|
||||||
|
Query: &domain.SessionQuery{
|
||||||
|
Id: new(2),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
err = t.grpcCli.
|
||||||
|
Invoke("admin/session/all").
|
||||||
|
JsonRequestBody(request).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
t.Require().NoError(err)
|
||||||
|
|
||||||
|
t.Require().Len(response.Items, 5)
|
||||||
|
t.Require().EqualValues(6, response.TotalCount)
|
||||||
|
t.Require().EqualValues(23, response.Items[0].Id)
|
||||||
|
t.Require().EqualValues(22, response.Items[1].Id)
|
||||||
|
t.Require().EqualValues(21, response.Items[2].Id)
|
||||||
|
t.Require().EqualValues(20, response.Items[3].Id)
|
||||||
|
t.Require().EqualValues(12, response.Items[4].Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (t *SessionSuite) Test_Session_Expired_Worker() {
|
||||||
|
userId := InsertUser(t.db, entity.User{Email: "a@test"})
|
||||||
|
|
||||||
|
InsertTokenEntity(t.db, entity.Token{
|
||||||
|
Token: "token_allowed",
|
||||||
|
UserId: userId,
|
||||||
|
Status: entity.TokenStatusAllowed,
|
||||||
|
ExpiredAt: time.Now().UTC().Add(24 * time.Hour)})
|
||||||
|
|
||||||
|
InsertTokenEntity(t.db, entity.Token{
|
||||||
|
Token: "token_expired",
|
||||||
|
UserId: userId,
|
||||||
|
Status: entity.TokenStatusAllowed,
|
||||||
|
ExpiredAt: time.Now().UTC().Add(-2 * time.Hour)})
|
||||||
|
|
||||||
|
InsertTokenEntity(t.db, entity.Token{
|
||||||
|
Token: "token_expired2",
|
||||||
|
UserId: userId,
|
||||||
|
Status: entity.TokenStatusAllowed,
|
||||||
|
ExpiredAt: time.Now().UTC().Add(-24 * time.Hour)})
|
||||||
|
|
||||||
|
bgjobCli := bgjobx.NewClient(t.db, t.test.Logger())
|
||||||
|
|
||||||
|
err := session_worker.EnqueueSeedJob(t.T().Context(), bgjobCli)
|
||||||
|
t.Require().NoError(err)
|
||||||
|
|
||||||
|
err = bgjobCli.Upgrade(t.T().Context(), t.config.BgJobCfg)
|
||||||
|
t.Require().NoError(err)
|
||||||
|
|
||||||
|
time.Sleep(2 * time.Second)
|
||||||
|
|
||||||
|
tokens := make([]entity.Token, 0)
|
||||||
|
t.db.Must().Select(&tokens, "SELECT * FROM tokens ORDER BY status ASC")
|
||||||
|
|
||||||
|
t.Require().EqualValues(entity.TokenStatusAllowed, tokens[0].Status)
|
||||||
|
t.Require().EqualValues(entity.TokenStatusExpired, tokens[1].Status)
|
||||||
|
t.Require().EqualValues(entity.TokenStatusExpired, tokens[2].Status)
|
||||||
|
}
|
||||||
+264
-20
@@ -2,12 +2,20 @@ package tests_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"github.com/txix-open/isp-kit/grpc/apierrors"
|
|
||||||
"golang.org/x/crypto/bcrypt"
|
|
||||||
"strconv"
|
"strconv"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/grpc/apierrors"
|
||||||
|
"golang.org/x/crypto/bcrypt"
|
||||||
|
|
||||||
|
"msp-admin-service/assembly"
|
||||||
|
"msp-admin-service/conf"
|
||||||
|
"msp-admin-service/domain"
|
||||||
|
"msp-admin-service/entity"
|
||||||
|
"msp-admin-service/repository"
|
||||||
|
"msp-admin-service/service"
|
||||||
|
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/stretchr/testify/suite"
|
"github.com/stretchr/testify/suite"
|
||||||
"github.com/txix-open/isp-kit/dbx"
|
"github.com/txix-open/isp-kit/dbx"
|
||||||
@@ -18,12 +26,6 @@ import (
|
|||||||
"github.com/txix-open/isp-kit/test/grpct"
|
"github.com/txix-open/isp-kit/test/grpct"
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
"msp-admin-service/assembly"
|
|
||||||
"msp-admin-service/conf"
|
|
||||||
"msp-admin-service/domain"
|
|
||||||
"msp-admin-service/entity"
|
|
||||||
"msp-admin-service/repository"
|
|
||||||
"msp-admin-service/service"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type tokenService interface {
|
type tokenService interface {
|
||||||
@@ -37,6 +39,7 @@ func TestUserTestSuite(t *testing.T) {
|
|||||||
|
|
||||||
type UserTestSuite struct {
|
type UserTestSuite struct {
|
||||||
suite.Suite
|
suite.Suite
|
||||||
|
|
||||||
test *test.Test
|
test *test.Test
|
||||||
db *dbt.TestDb
|
db *dbt.TestDb
|
||||||
grpcCli *client.Client
|
grpcCli *client.Client
|
||||||
@@ -71,6 +74,7 @@ func (s *UserTestSuite) TestGetProfileHappyPath() {
|
|||||||
id := InsertUser(s.db, entity.User{
|
id := InsertUser(s.db, entity.User{
|
||||||
FirstName: "name",
|
FirstName: "name",
|
||||||
LastName: "surname",
|
LastName: "surname",
|
||||||
|
FullName: "surname name",
|
||||||
Email: "a@a.ru",
|
Email: "a@a.ru",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
})
|
})
|
||||||
@@ -93,9 +97,11 @@ func (s *UserTestSuite) TestGetProfileHappyPath() {
|
|||||||
expected := domain.AdminUserShort{
|
expected := domain.AdminUserShort{
|
||||||
FirstName: "name",
|
FirstName: "name",
|
||||||
LastName: "surname",
|
LastName: "surname",
|
||||||
|
FullName: "surname name",
|
||||||
Email: "a@a.ru",
|
Email: "a@a.ru",
|
||||||
Role: "admin",
|
Role: "admin",
|
||||||
Roles: []int{1},
|
Roles: []int{1},
|
||||||
|
RoleNames: []string{"admin"},
|
||||||
Permissions: []string{},
|
Permissions: []string{},
|
||||||
}
|
}
|
||||||
s.Require().Equal(expected, response)
|
s.Require().Equal(expected, response)
|
||||||
@@ -105,6 +111,7 @@ func (s *UserTestSuite) TestGetProfileNotFound() {
|
|||||||
id := InsertUser(s.db, entity.User{
|
id := InsertUser(s.db, entity.User{
|
||||||
FirstName: "name",
|
FirstName: "name",
|
||||||
LastName: "surname",
|
LastName: "surname",
|
||||||
|
FullName: "surname name",
|
||||||
Email: "a@b.ru",
|
Email: "a@b.ru",
|
||||||
Password: "password",
|
Password: "password",
|
||||||
})
|
})
|
||||||
@@ -123,6 +130,7 @@ func (s *UserTestSuite) TestGetProfileSudir() {
|
|||||||
SudirUserId: "sudirUser1",
|
SudirUserId: "sudirUser1",
|
||||||
FirstName: "name",
|
FirstName: "name",
|
||||||
LastName: "surname",
|
LastName: "surname",
|
||||||
|
FullName: "surname name",
|
||||||
Email: "a@b.ru",
|
Email: "a@b.ru",
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -145,9 +153,11 @@ func (s *UserTestSuite) TestGetProfileSudir() {
|
|||||||
expected := domain.AdminUserShort{
|
expected := domain.AdminUserShort{
|
||||||
FirstName: "name",
|
FirstName: "name",
|
||||||
LastName: "surname",
|
LastName: "surname",
|
||||||
|
FullName: "surname name",
|
||||||
Email: "a@b.ru",
|
Email: "a@b.ru",
|
||||||
Role: "admin",
|
Role: "admin",
|
||||||
Roles: []int{1},
|
Roles: []int{1},
|
||||||
|
RoleNames: []string{"admin"},
|
||||||
Permissions: []string{},
|
Permissions: []string{},
|
||||||
}
|
}
|
||||||
s.Require().Equal(expected, response)
|
s.Require().Equal(expected, response)
|
||||||
@@ -156,23 +166,194 @@ func (s *UserTestSuite) TestGetProfileSudir() {
|
|||||||
func (s *UserTestSuite) TestGetUsers() {
|
func (s *UserTestSuite) TestGetUsers() {
|
||||||
InsertUser(s.db, entity.User{Email: "a1@a.ru"})
|
InsertUser(s.db, entity.User{Email: "a1@a.ru"})
|
||||||
InsertUser(s.db, entity.User{Email: "b1@a.ru"})
|
InsertUser(s.db, entity.User{Email: "b1@a.ru"})
|
||||||
InsertUser(s.db, entity.User{Email: "a1@b.ru"})
|
userId1 := InsertUser(s.db, entity.User{Email: "a1@b.ru"})
|
||||||
InsertUser(s.db, entity.User{Email: "a1@c.ru"})
|
userId2 := InsertUser(s.db, entity.User{Email: "a1@c.ru"})
|
||||||
|
userId3 := InsertUser(s.db, entity.User{Email: "a1@d.ru"})
|
||||||
|
|
||||||
|
roleId1 := InsertRole(s.db, entity.Role{Name: "test_role_1"})
|
||||||
|
roleId2 := InsertRole(s.db, entity.Role{Name: "test_role_2"})
|
||||||
|
|
||||||
|
InsertUserRole(s.db, entity.UserRole{RoleId: int(roleId1), UserId: int(userId1)})
|
||||||
|
InsertUserRole(s.db, entity.UserRole{RoleId: int(roleId1), UserId: int(userId2)})
|
||||||
|
InsertUserRole(s.db, entity.UserRole{RoleId: int(roleId1), UserId: int(userId3)})
|
||||||
|
|
||||||
|
InsertUserRole(s.db, entity.UserRole{RoleId: int(roleId2), UserId: int(userId1)})
|
||||||
|
InsertUserRole(s.db, entity.UserRole{RoleId: int(roleId2), UserId: int(userId2)})
|
||||||
|
|
||||||
|
email := "a1@"
|
||||||
|
|
||||||
response := domain.UsersResponse{}
|
response := domain.UsersResponse{}
|
||||||
err := s.grpcCli.Invoke("admin/user/get_users").
|
err := s.grpcCli.Invoke("admin/user/get_users").
|
||||||
JsonRequestBody(domain.UsersRequest{
|
JsonRequestBody(domain.UsersPageRequest{
|
||||||
Ids: []int64{3, 4, 5, 6},
|
LimitOffestParams: domain.LimitOffestParams{
|
||||||
Offset: 1,
|
Limit: 5,
|
||||||
Limit: 1,
|
Offset: 1,
|
||||||
Email: "a1@",
|
},
|
||||||
|
Order: &domain.OrderParams{
|
||||||
|
Field: "email",
|
||||||
|
Type: "asc",
|
||||||
|
},
|
||||||
|
Query: &domain.UserQuery{
|
||||||
|
Email: &email,
|
||||||
|
Roles: []int{int(roleId2)},
|
||||||
|
},
|
||||||
}).
|
}).
|
||||||
JsonResponseBody(&response).
|
JsonResponseBody(&response).
|
||||||
Do(context.Background())
|
Do(context.Background())
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().Len(response.Items, 1) //nolint:mnd
|
roles := []int{int(roleId1), int(roleId2)}
|
||||||
s.Require().Equal(int64(5), response.Items[0].Id)
|
|
||||||
|
s.Require().Len(response.Items, 2)
|
||||||
|
s.Require().EqualValues("a1@b.ru", response.Items[0].Email)
|
||||||
|
s.Require().EqualValues(roles, response.Items[0].Roles)
|
||||||
|
s.Require().EqualValues("a1@c.ru", response.Items[1].Email)
|
||||||
|
s.Require().EqualValues(roles, response.Items[1].Roles)
|
||||||
|
|
||||||
|
email = "test@mail.ru"
|
||||||
|
err = s.grpcCli.Invoke("admin/user/get_users").
|
||||||
|
JsonRequestBody(domain.UsersPageRequest{
|
||||||
|
LimitOffestParams: domain.LimitOffestParams{
|
||||||
|
Limit: 10,
|
||||||
|
Offset: 0,
|
||||||
|
},
|
||||||
|
Order: &domain.OrderParams{
|
||||||
|
Field: "id",
|
||||||
|
Type: "asc",
|
||||||
|
},
|
||||||
|
Query: &domain.UserQuery{
|
||||||
|
Id: new(int(userId2)),
|
||||||
|
Email: &email,
|
||||||
|
},
|
||||||
|
}).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
s.Require().Empty(response.Items)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserTestSuite) TestAllGetUsers() {
|
||||||
|
InsertUser(s.db, entity.User{Email: "a1@a.ru"})
|
||||||
|
InsertUser(s.db, entity.User{Email: "b1@a.ru"})
|
||||||
|
userId1 := InsertUser(s.db, entity.User{Email: "a1@b.ru"})
|
||||||
|
userId2 := InsertUser(s.db, entity.User{Email: "a1@c.ru"})
|
||||||
|
userId3 := InsertUser(s.db, entity.User{Email: "a1@d.ru"})
|
||||||
|
|
||||||
|
roleId1 := InsertRole(s.db, entity.Role{Name: "test_role_1"})
|
||||||
|
roleId2 := InsertRole(s.db, entity.Role{Name: "test_role_2"})
|
||||||
|
|
||||||
|
InsertUserRole(s.db, entity.UserRole{RoleId: int(roleId1), UserId: int(userId1)})
|
||||||
|
InsertUserRole(s.db, entity.UserRole{RoleId: int(roleId1), UserId: int(userId2)})
|
||||||
|
InsertUserRole(s.db, entity.UserRole{RoleId: int(roleId1), UserId: int(userId3)})
|
||||||
|
|
||||||
|
InsertUserRole(s.db, entity.UserRole{RoleId: int(roleId2), UserId: int(userId1)})
|
||||||
|
InsertUserRole(s.db, entity.UserRole{RoleId: int(roleId2), UserId: int(userId2)})
|
||||||
|
|
||||||
|
response := domain.UsersResponse{}
|
||||||
|
err := s.grpcCli.Invoke("admin/user/get_all_users").JsonResponseBody(&response).Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
s.Require().Len(response.Items, 7)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserTestSuite) TestGetUsersFilterByLastActiveAt() {
|
||||||
|
userId1 := InsertUser(s.db, entity.User{Email: "test1@a.ru"})
|
||||||
|
userId2 := InsertUser(s.db, entity.User{Email: "test2@a.ru"})
|
||||||
|
userId3 := InsertUser(s.db, entity.User{Email: "test3@a.ru"})
|
||||||
|
|
||||||
|
userTime1, err := time.Parse("2006-01-02T15:04:05Z", "2018-01-01T00:00:00Z")
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
userTime2, err := time.Parse("2006-01-02T15:04:05Z", "2020-01-01T00:00:00Z")
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
InsertTokenEntity(s.db, entity.Token{
|
||||||
|
Token: "test_token1",
|
||||||
|
UserId: userId1,
|
||||||
|
Status: entity.TokenStatusAllowed,
|
||||||
|
ExpiredAt: userTime1.Add(1 * time.Hour),
|
||||||
|
CreatedAt: userTime1,
|
||||||
|
UpdatedAt: userTime1,
|
||||||
|
})
|
||||||
|
|
||||||
|
InsertTokenEntity(s.db, entity.Token{
|
||||||
|
Token: "test_token2",
|
||||||
|
UserId: userId2,
|
||||||
|
Status: entity.TokenStatusAllowed,
|
||||||
|
ExpiredAt: userTime1.Add(25 * time.Hour),
|
||||||
|
CreatedAt: userTime1.Add(24 * time.Hour),
|
||||||
|
UpdatedAt: userTime1.Add(24 * time.Hour),
|
||||||
|
})
|
||||||
|
|
||||||
|
InsertTokenEntity(s.db, entity.Token{
|
||||||
|
Token: "test_token3",
|
||||||
|
UserId: userId3,
|
||||||
|
Status: entity.TokenStatusAllowed,
|
||||||
|
ExpiredAt: userTime2.Add(1 * time.Hour),
|
||||||
|
CreatedAt: userTime2,
|
||||||
|
UpdatedAt: userTime2,
|
||||||
|
})
|
||||||
|
|
||||||
|
response := domain.UsersResponse{}
|
||||||
|
err = s.grpcCli.Invoke("admin/user/get_users").
|
||||||
|
JsonRequestBody(domain.UsersPageRequest{
|
||||||
|
LimitOffestParams: domain.LimitOffestParams{
|
||||||
|
Limit: 5,
|
||||||
|
Offset: 0,
|
||||||
|
},
|
||||||
|
Order: &domain.OrderParams{
|
||||||
|
Field: "lastSessionCreatedAt",
|
||||||
|
Type: "desc",
|
||||||
|
},
|
||||||
|
Query: &domain.UserQuery{
|
||||||
|
LastSessionCreatedAt: &domain.DateFromToParams{
|
||||||
|
From: userTime1.Add(-48 * time.Hour),
|
||||||
|
To: userTime1.Add(48 * time.Hour),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
s.Require().Len(response.Items, 2)
|
||||||
|
s.Require().EqualValues(userId2, response.Items[0].Id)
|
||||||
|
s.Require().EqualValues(userId1, response.Items[1].Id)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserTestSuite) TestGetUsersSortByName() {
|
||||||
|
userIdViser1 := InsertUser(s.db, entity.User{Email: "a1@a.ru",
|
||||||
|
FirstName: "admin_viser", LastName: "admin_viser", FullName: "admin_viser admin_viser"})
|
||||||
|
userIdViser2 := InsertUser(s.db, entity.User{Email: "a1@b.ru",
|
||||||
|
FirstName: "admin_viser", LastName: "admin_viser2", FullName: "admin_viser2 admin_viser"})
|
||||||
|
userIdScripts := InsertUser(s.db, entity.User{Email: "a1@c.ru",
|
||||||
|
FirstName: "admin_scripts", LastName: "admin_scripts", FullName: "admin_scripts admin_scripts"})
|
||||||
|
userIdAL := InsertUser(s.db, entity.User{Email: "a1@d.ru", FirstName: "А", LastName: "Л", FullName: "Л А"})
|
||||||
|
|
||||||
|
response := domain.UsersResponse{}
|
||||||
|
err := s.grpcCli.Invoke("admin/user/get_users").
|
||||||
|
JsonRequestBody(domain.UsersPageRequest{
|
||||||
|
LimitOffestParams: domain.LimitOffestParams{
|
||||||
|
Limit: 10,
|
||||||
|
Offset: 0,
|
||||||
|
},
|
||||||
|
Order: &domain.OrderParams{
|
||||||
|
Field: "userId",
|
||||||
|
Type: "asc",
|
||||||
|
},
|
||||||
|
Query: &domain.UserQuery{
|
||||||
|
UserId: []int{int(userIdViser1), int(userIdViser2), int(userIdScripts), int(userIdAL)},
|
||||||
|
},
|
||||||
|
}).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
s.Require().Len(response.Items, 4)
|
||||||
|
s.Require().EqualValues(userIdScripts, response.Items[0].Id)
|
||||||
|
s.Require().EqualValues(userIdViser1, response.Items[1].Id)
|
||||||
|
s.Require().EqualValues(userIdViser2, response.Items[2].Id)
|
||||||
|
s.Require().EqualValues(userIdAL, response.Items[3].Id)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserTestSuite) TestCreateUserHappyPath() {
|
func (s *UserTestSuite) TestCreateUserHappyPath() {
|
||||||
@@ -199,6 +380,35 @@ func (s *UserTestSuite) TestCreateUserHappyPath() {
|
|||||||
s.db.Must().SelectRow(&postCount, "select count(*) from users")
|
s.db.Must().SelectRow(&postCount, "select count(*) from users")
|
||||||
|
|
||||||
s.Require().Equal(preCount+1, postCount)
|
s.Require().Equal(preCount+1, postCount)
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *UserTestSuite) TestCreateUserWithSameEmailSudirHappyPath() {
|
||||||
|
firstSudirId := "user_a"
|
||||||
|
admin := InsertSudirUser(s.db, entity.SudirUser{SudirUserId: firstSudirId, Email: "a2@a.ru"})
|
||||||
|
|
||||||
|
preCount := 0
|
||||||
|
s.db.Must().SelectRow(&preCount, "select count(*) from users")
|
||||||
|
|
||||||
|
response := entity.User{}
|
||||||
|
err := s.grpcCli.
|
||||||
|
Invoke("admin/user/create_user").
|
||||||
|
AppendMetadata(domain.AdminAuthIdHeader, strconv.Itoa(int(admin))).
|
||||||
|
JsonRequestBody(domain.CreateUserRequest{
|
||||||
|
FirstName: "name",
|
||||||
|
LastName: "surname",
|
||||||
|
Email: "a2@a.ru",
|
||||||
|
Password: "password",
|
||||||
|
}).
|
||||||
|
JsonResponseBody(&response).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().NoError(err)
|
||||||
|
|
||||||
|
postCount := 0
|
||||||
|
s.db.Must().SelectRow(&postCount, "select count(*) from users")
|
||||||
|
|
||||||
|
s.Require().Equal(preCount+1, postCount)
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserTestSuite) TestCreateUserAlreadyExist() {
|
func (s *UserTestSuite) TestCreateUserAlreadyExist() {
|
||||||
@@ -243,14 +453,16 @@ func (s *AuthTestSuite) TestUpdateUserHappyPath() {
|
|||||||
Email: response.Email,
|
Email: response.Email,
|
||||||
}
|
}
|
||||||
s.Require().Equal(expected, req)
|
s.Require().Equal(expected, req)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) TestUpdateSudirUserHappyPath() {
|
func (s *AuthTestSuite) TestUpdateSudirUserHappyPath() {
|
||||||
id := InsertSudirUser(s.db, entity.SudirUser{Email: "sudir@a.ru"})
|
id := InsertSudirUser(s.db, entity.SudirUser{SudirUserId: "123", Email: "sudir@a.ru", FullName: "surname name patronymic"})
|
||||||
req := domain.UpdateUserRequest{
|
req := domain.UpdateUserRequest{
|
||||||
Id: id,
|
Id: id,
|
||||||
FirstName: "name",
|
FirstName: "nameUpd",
|
||||||
LastName: "surname",
|
LastName: "surnameUpd",
|
||||||
Email: "sudir@a.ru",
|
Email: "sudir@a.ru",
|
||||||
}
|
}
|
||||||
response := domain.User{}
|
response := domain.User{}
|
||||||
@@ -268,6 +480,9 @@ func (s *AuthTestSuite) TestUpdateSudirUserHappyPath() {
|
|||||||
Email: response.Email,
|
Email: response.Email,
|
||||||
}
|
}
|
||||||
s.Require().Equal(expected, req)
|
s.Require().Equal(expected, req)
|
||||||
|
s.Require().Equal("surnameUpd nameUpd", response.FullName)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *AuthTestSuite) TestUpdateUserAlreadyExist() {
|
func (s *AuthTestSuite) TestUpdateUserAlreadyExist() {
|
||||||
@@ -290,6 +505,29 @@ func (s *AuthTestSuite) TestUpdateUserAlreadyExist() {
|
|||||||
s.Require().Equal(codes.AlreadyExists, st.Code())
|
s.Require().Equal(codes.AlreadyExists, st.Code())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (s *AuthTestSuite) TestUpdateUserWithSudirAlreadyExist() {
|
||||||
|
firstSudirId := "user_a"
|
||||||
|
secondSudirId := "user_b"
|
||||||
|
|
||||||
|
admin := InsertSudirUser(s.db, entity.SudirUser{SudirUserId: firstSudirId, Email: "a_exists@a.ru"})
|
||||||
|
id := InsertSudirUser(s.db, entity.SudirUser{SudirUserId: secondSudirId, Email: "b_exists@b.ru"})
|
||||||
|
req := domain.UpdateUserRequest{
|
||||||
|
Id: id,
|
||||||
|
FirstName: "name",
|
||||||
|
LastName: "surname",
|
||||||
|
Email: "a_exists@a.ru",
|
||||||
|
}
|
||||||
|
err := s.grpcCli.
|
||||||
|
Invoke("admin/user/update_user").
|
||||||
|
AppendMetadata(domain.AdminAuthIdHeader, strconv.Itoa(int(admin))).
|
||||||
|
JsonRequestBody(req).
|
||||||
|
Do(context.Background())
|
||||||
|
s.Require().Error(err)
|
||||||
|
st, ok := status.FromError(err)
|
||||||
|
s.Require().True(ok)
|
||||||
|
s.Require().Equal(codes.AlreadyExists, st.Code())
|
||||||
|
}
|
||||||
|
|
||||||
func (s *UserTestSuite) TestDeleteUsers() {
|
func (s *UserTestSuite) TestDeleteUsers() {
|
||||||
admin := InsertUser(s.db, entity.User{Email: "a_del@a.ru"})
|
admin := InsertUser(s.db, entity.User{Email: "a_del@a.ru"})
|
||||||
InsertUser(s.db, entity.User{Email: "b_del@a.ru"})
|
InsertUser(s.db, entity.User{Email: "b_del@a.ru"})
|
||||||
@@ -306,6 +544,8 @@ func (s *UserTestSuite) TestDeleteUsers() {
|
|||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
|
|
||||||
s.Require().Equal(2, response.Deleted)
|
s.Require().Equal(2, response.Deleted)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserTestSuite) TestBlockUser() {
|
func (s *UserTestSuite) TestBlockUser() {
|
||||||
@@ -339,6 +579,8 @@ func (s *UserTestSuite) TestBlockUser() {
|
|||||||
t, err := repository.NewToken(s.db).Get(context.Background(), token)
|
t, err := repository.NewToken(s.db).Get(context.Background(), token)
|
||||||
s.Require().NoError(err)
|
s.Require().NoError(err)
|
||||||
s.EqualValues(entity.TokenStatusRevoked, t.Status)
|
s.EqualValues(entity.TokenStatusRevoked, t.Status)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserTestSuite) TestChangePasswordUser() {
|
func (s *UserTestSuite) TestChangePasswordUser() {
|
||||||
@@ -380,4 +622,6 @@ func (s *UserTestSuite) TestChangePasswordUser() {
|
|||||||
|
|
||||||
tokenInfo := SelectTokenEntityByToken(s.db, "token-841297641213")
|
tokenInfo := SelectTokenEntityByToken(s.db, "token-841297641213")
|
||||||
s.Require().Equal(entity.TokenStatusRevoked, tokenInfo.Status)
|
s.Require().Equal(entity.TokenStatusRevoked, tokenInfo.Status)
|
||||||
|
|
||||||
|
time.Sleep(1 * time.Second) // wait for go SaveAuditAsync()
|
||||||
}
|
}
|
||||||
+14
-1
@@ -3,9 +3,11 @@ package transaction
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
"github.com/txix-open/isp-kit/db"
|
|
||||||
"msp-admin-service/repository"
|
"msp-admin-service/repository"
|
||||||
"msp-admin-service/service"
|
"msp-admin-service/service"
|
||||||
|
"msp-admin-service/service/session_worker"
|
||||||
|
|
||||||
|
"github.com/txix-open/isp-kit/db"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Manager struct {
|
type Manager struct {
|
||||||
@@ -25,6 +27,10 @@ type userTx struct {
|
|||||||
repository.Token
|
repository.Token
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type tokenTx struct {
|
||||||
|
repository.Token
|
||||||
|
}
|
||||||
|
|
||||||
func (m Manager) UserTransaction(ctx context.Context, msgTx func(ctx context.Context, tx service.UserTransaction) error) error {
|
func (m Manager) UserTransaction(ctx context.Context, msgTx func(ctx context.Context, tx service.UserTransaction) error) error {
|
||||||
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||||
user := repository.NewUser(tx)
|
user := repository.NewUser(tx)
|
||||||
@@ -44,3 +50,10 @@ func (m Manager) AuthTransaction(ctx context.Context, msgTx func(ctx context.Con
|
|||||||
return msgTx(ctx, userTx{user, role, userRole, token})
|
return msgTx(ctx, userTx{user, role, userRole, token})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Manager) TokenTransaction(ctx context.Context, msgTx func(ctx context.Context, tx session_worker.TokenTransaction) error) error {
|
||||||
|
return m.db.RunInTransaction(ctx, func(ctx context.Context, tx *db.Tx) error {
|
||||||
|
token := repository.NewToken(tx)
|
||||||
|
return msgTx(ctx, tokenTx{token})
|
||||||
|
})
|
||||||
|
}
|
||||||
Reference in new issue
Block a user