MSP-2243 update interface

This commit is contained in:
gr-dv authored and d1slike committed 2023-10-18 13:24:47 +03:00
1 parent 1517f744d3
commit c1d4680a02
4 files changed
+24 -17

No files matched your search

+6 -6
View File
@@ -24,7 +24,7 @@ type AuthTransactionRunner interface {
}
type auditService interface {
SaveAuditAsync(ctx context.Context, userId int64, message string)
SaveAuditAsync(ctx context.Context, userId int64, message string, event string)
}
type userRepository interface {
@@ -103,13 +103,13 @@ func (a Auth) Login(ctx context.Context, request domain.LoginRequest) (*domain.L
}
if user.Blocked {
a.auditService.SaveAuditAsync(ctx, user.Id, "Неуспешный вход. Пользователь заблокирован")
a.auditService.SaveAuditAsync(ctx, user.Id, "Неуспешный вход. Пользователь заблокирован", entity.EventErrorLogin)
return errors.WithMessagef(domain.ErrUnauthenticated, "user '%d' is blocked", user.Id)
}
err = bcrypt.CompareHashAndPassword([]byte(user.Password), []byte(request.Password))
if err != nil {
a.auditService.SaveAuditAsync(ctx, user.Id, "Неуспешный вход. Неверный пароль")
a.auditService.SaveAuditAsync(ctx, user.Id, "Неуспешный вход. Неверный пароль", entity.EventErrorLogin)
return errors.WithMessage(domain.ErrUnauthenticated, "wrong password")
}
@@ -118,7 +118,7 @@ func (a Auth) Login(ctx context.Context, request domain.LoginRequest) (*domain.L
return errors.WithMessage(err, "generate token")
}
a.auditService.SaveAuditAsync(ctx, user.Id, "Успешный вход через форму входа")
a.auditService.SaveAuditAsync(ctx, user.Id, "Успешный вход через форму входа", entity.EventSuccessLogin)
updateEntity := entity.UpdateUser{
FirstName: user.FirstName,
@@ -211,7 +211,7 @@ func (a Auth) LoginWithSudir(ctx context.Context, request domain.LoginSudirReque
return nil, err
}
a.auditService.SaveAuditAsync(ctx, user.Id, "Успешный вход через СУДИР")
a.auditService.SaveAuditAsync(ctx, user.Id, "Успешный вход через СУДИР", entity.EventSuccessLogin)
return &domain.LoginResponse{
Token: tokenString,
@@ -226,7 +226,7 @@ func (a Auth) Logout(ctx context.Context, adminId int64) error {
return errors.WithMessage(err, "revoke all tokens by user id")
}
a.auditService.SaveAuditAsync(ctx, adminId, "Выход")
a.auditService.SaveAuditAsync(ctx, adminId, "Выход", entity.EventSuccessLogout)
return nil
}
+11 -9
View File
@@ -65,10 +65,10 @@ func (u Role) Create(ctx context.Context, req domain.CreateRoleRequest, adminId
return nil, errors.WithMessage(err, "create role")
}
u.auditService.SaveAuditAsync(ctx, adminId, fmt.Sprintf("Роль. Создание новой роли %s. Причина: %s",
req.Name,
req.ChangeMessage,
))
u.auditService.SaveAuditAsync(ctx, adminId,
fmt.Sprintf("Роль. Создание новой роли %s. Причина: %s", req.Name, req.ChangeMessage),
entity.EventRoleChanged,
)
result := u.toDomain(*role)
return &result, nil
@@ -104,10 +104,10 @@ func (u Role) Update(ctx context.Context, req domain.UpdateRoleRequest, adminId
return nil, errors.WithMessage(err, "update role")
}
u.auditService.SaveAuditAsync(ctx, adminId, fmt.Sprintf("Роль. Изменение роли %s. Причина: %s",
req.Name,
req.ChangeMessage,
))
u.auditService.SaveAuditAsync(ctx, adminId,
fmt.Sprintf("Роль. Изменение роли %s. Причина: %s", req.Name, req.ChangeMessage),
entity.EventRoleChanged,
)
result := u.toDomain(*role)
return &result, nil
}
@@ -118,7 +118,9 @@ func (u Role) Delete(ctx context.Context, req domain.DeleteRoleRequest, adminId
return errors.WithMessage(err, "delete role")
}
u.auditService.SaveAuditAsync(ctx, adminId, fmt.Sprintf("Роль. Удаление роли. ID: %d", req.Id))
u.auditService.SaveAuditAsync(ctx, adminId, fmt.Sprintf("Роль. Удаление роли. ID: %d", req.Id),
entity.EventRoleChanged,
)
return nil
}
+4
View File
@@ -198,6 +198,7 @@ func (u User) CreateUser(ctx context.Context, req domain.CreateUserRequest, admi
u.auditService.SaveAuditAsync(ctx, adminId,
fmt.Sprintf("Пользователь. Создание пользователя %s.", usr.Email),
entity.EventUserChanged,
)
result := u.toDomain(usr, req.Roles, nil)
@@ -261,6 +262,7 @@ func (u User) UpdateUser(ctx context.Context, req domain.UpdateUserRequest, admi
u.auditService.SaveAuditAsync(ctx, adminId,
fmt.Sprintf("Пользователь. Изменение пользователя %s.", user.Email),
entity.EventUserChanged,
)
result := u.toDomain(*user, req.Roles, lastSessionCreatedAt)
@@ -278,6 +280,7 @@ func (u User) DeleteUsers(ctx context.Context, ids []int64, adminId int64) (int,
u.auditService.SaveAuditAsync(ctx, adminId,
fmt.Sprintf("Пользователь. Удаление пользователей %d.", ids),
entity.EventUserChanged,
)
return count, err
@@ -331,6 +334,7 @@ func (u User) Block(ctx context.Context, adminId int64, userId int) error {
u.auditService.SaveAuditAsync(ctx, adminId,
fmt.Sprintf("Пользователь. %s пользователя ID %d.", userBlocked, userId),
entity.EventUserChanged,
)
return nil
+3 -2
View File
@@ -6,10 +6,11 @@ import (
"github.com/integration-system/isp-kit/log"
"github.com/pkg/errors"
"msp-admin-service/entity"
)
type AuditRepo interface {
SaveAuditAsync(ctx context.Context, userId int64, message string)
SaveAuditAsync(ctx context.Context, userId int64, message string, event string)
}
type TokenRepo interface {
@@ -72,7 +73,7 @@ func (w InactiveBlocker) do(ctx context.Context) error {
if err != nil {
return errors.WithMessagef(err, "block user %d", userId)
}
w.auditRepo.SaveAuditAsync(ctx, userId, "Блокировка неактивной УЗ")
w.auditRepo.SaveAuditAsync(ctx, userId, "Блокировка неактивной УЗ", entity.EventUserChanged)
}
return nil