Merge branch 'MSP-6148' into 'MSP-6168'
Resolve MSP-6148 See merge request isp/msp-admin-service!13
This commit is contained in:
commit
a18deb8762
6 files changed
+82
-6
No files matched your search
@@ -1,5 +1,6 @@
|
||||
### v6.5.0
|
||||
* Изменена уникальность учетных записей с "email" на связку "email + sudir_id"
|
||||
* Добавлен метод `admin/auth/logout_with_reason` для вывода логов `Выхода по бездействию` в журнал ИБ
|
||||
### v6.4.0
|
||||
* Обнолвены зависимости
|
||||
### v6.3.1
|
||||
|
||||
+28
-2
@@ -16,7 +16,7 @@ import (
|
||||
type authService interface {
|
||||
Login(ctx context.Context, request domain.LoginRequest) (*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 {
|
||||
@@ -48,7 +48,33 @@ func (a Auth) Logout(ctx context.Context, authData grpc.AuthData) error {
|
||||
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 {
|
||||
return errors.WithMessage(err, "logout")
|
||||
}
|
||||
|
||||
+38
-3
@@ -174,6 +174,11 @@ definitions:
|
||||
required:
|
||||
- authCode
|
||||
type: object
|
||||
domain.LogoutRequest:
|
||||
properties:
|
||||
reason:
|
||||
type: string
|
||||
type: object
|
||||
domain.PageRequest:
|
||||
properties:
|
||||
limit:
|
||||
@@ -228,7 +233,6 @@ definitions:
|
||||
domain.SecureAuthResponse:
|
||||
properties:
|
||||
adminId:
|
||||
format: int64
|
||||
type: integer
|
||||
authenticated:
|
||||
type: boolean
|
||||
@@ -310,7 +314,6 @@ definitions:
|
||||
firstName:
|
||||
type: string
|
||||
id:
|
||||
format: int64
|
||||
type: integer
|
||||
lastName:
|
||||
type: string
|
||||
@@ -329,7 +332,6 @@ definitions:
|
||||
type: string
|
||||
ids:
|
||||
items:
|
||||
format: int64
|
||||
type: integer
|
||||
type: array
|
||||
limit:
|
||||
@@ -448,6 +450,39 @@ paths:
|
||||
summary: Выход из авторизованной сессии
|
||||
tags:
|
||||
- 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:
|
||||
post:
|
||||
consumes:
|
||||
|
||||
@@ -6,6 +6,10 @@ const (
|
||||
AdminAuthIdHeader = "x-admin-id"
|
||||
)
|
||||
|
||||
type LogoutRequest struct {
|
||||
Reason string
|
||||
}
|
||||
|
||||
type LoginRequest struct {
|
||||
Email string `validate:"required"`
|
||||
Password string ` validate:"required"`
|
||||
|
||||
@@ -49,6 +49,11 @@ func endpointDescriptors(c Controllers) []cluster.EndpointDescriptor {
|
||||
Inner: true,
|
||||
Handler: c.Auth.Logout,
|
||||
},
|
||||
{
|
||||
Path: "admin/auth/logout_with_reason",
|
||||
Inner: true,
|
||||
Handler: c.Auth.LogoutWithReason,
|
||||
},
|
||||
{
|
||||
Path: "admin/user/get_profile",
|
||||
Inner: true,
|
||||
|
||||
+6
-1
@@ -213,7 +213,7 @@ func (a Auth) LoginWithSudir(ctx context.Context, request domain.LoginSudirReque
|
||||
}, 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.tokenService.RevokeAllByUserId(ctx, adminId)
|
||||
if err != nil {
|
||||
@@ -226,6 +226,11 @@ func (a Auth) Logout(ctx context.Context, adminId int64) error {
|
||||
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)
|
||||
return nil
|
||||
})
|
||||
|
||||
Reference in new issue
Block a user