From 24a8ea2578195350ed65c7b61547073757f8cf3d Mon Sep 17 00:00:00 2001 From: chashintv Date: Fri, 20 Nov 2026 18:43:43 +0300 Subject: [PATCH] MSP-8974 fix --- assembly/locator.go | 2 +- controller/audit.go | 63 +++++------ controller/auth.go | 92 ++++++++-------- controller/customization.go | 21 ++-- controller/download.go | 66 ++++++------ controller/permissions.go | 17 +-- controller/role.go | 99 +++++++++--------- controller/secure.go | 38 +++---- controller/session.go | 42 ++++---- controller/ui_settings.go | 23 ++-- controller/user.go | 203 +++++++++++++++++++----------------- docs/swagger.json | 8 +- domain/errors.go | 3 +- main.go | 12 +-- service/permission.go | 6 +- 15 files changed, 362 insertions(+), 333 deletions(-) diff --git a/assembly/locator.go b/assembly/locator.go index 0e3cbae..e5a1421 100644 --- a/assembly/locator.go +++ b/assembly/locator.go @@ -103,7 +103,7 @@ func (l Locator) Config( userService, tokenService, roleService, - *permissionsService, + permissionsService, ) userController := controller.NewUser(userService) diff --git a/controller/audit.go b/controller/audit.go index 3650203..c93d1b2 100644 --- a/controller/audit.go +++ b/controller/audit.go @@ -27,16 +27,17 @@ func NewAudit(service AuditService) Audit { } // All -// @Tags log -// @Summary Получение списка логов -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.AuditPageRequest true "Тело запроса (пагинация, сортировка, фильтры)" -// @Success 200 {object} domain.AuditResponse -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" -// @Failure 500 {object} apierrors.Error -// @Router /log/all [POST] +// +// @Tags log +// @Summary Получение списка логов +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.AuditPageRequest true "Тело запроса (пагинация, сортировка, фильтры)" +// @Success 200 {object} domain.AuditResponse +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 500 {object} apierrors.Error +// @Router /log/all [POST] func (c Audit) All(ctx context.Context, req domain.AuditPageRequest) (*domain.AuditResponse, error) { if req.Order == nil { req.Order = &domain.OrderParams{ @@ -49,31 +50,33 @@ func (c Audit) All(ctx context.Context, req domain.AuditPageRequest) (*domain.Au } // Events -// @Tags log -// @Summary Получение списка событий аудита -// @Description Возвращает полный список доступных событий аудита -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Success 200 {array} domain.AuditEvent -// @Failure 500 {object} apierrors.Error -// @Router /log/events [POST] +// +// @Tags log +// @Summary Получение списка событий аудита +// @Description Возвращает полный список доступных событий аудита +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Success 200 {array} domain.AuditEvent +// @Failure 500 {object} apierrors.Error +// @Router /log/events [POST] func (c Audit) Events(ctx context.Context) ([]domain.AuditEvent, error) { return c.service.Events(ctx) } // SetEvents -// @Tags log -// @Summary Установить события аудита -// @Description Устанавливает (обновляет) набор активных событий аудита. -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body []domain.SetAuditEvent true "Список событий аудита для установки" -// @Success 200 {object} map[string]interface{} "События успешно установлены" -// @Failure 400 {object} apierrors.Error "Неизвестное событие аудита" -// @Failure 500 {object} apierrors.Error -// @Router /log/set_events [POST] +// +// @Tags log +// @Summary Установить события аудита +// @Description Устанавливает (обновляет) набор активных событий аудита. +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body []domain.SetAuditEvent true "Список событий аудита для установки" +// @Success 200 {object} map[string]interface{} "События успешно установлены" +// @Failure 400 {object} apierrors.Error "Неизвестное событие аудита" +// @Failure 500 {object} apierrors.Error +// @Router /log/set_events [POST] func (c Audit) SetEvents(ctx context.Context, req []domain.SetAuditEvent) error { err := c.service.SetEvents(ctx, req) switch { diff --git a/controller/auth.go b/controller/auth.go index a849497..6f900fd 100644 --- a/controller/auth.go +++ b/controller/auth.go @@ -32,16 +32,17 @@ func NewAuth(authService authService, logger log.Logger) Auth { } // Logout -// @Tags auth -// @Summary Выход из авторизованной сессии -// @Description Выход из авторизованной сессии администрирования -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Success 200 {object} map[string]interface{} "Успешный выход" -// @Failure 400 {object} apierrors.Error "Невалидный токен" -// @Failure 500 {object} apierrors.Error -// @Router /auth/logout [POST] +// +// @Tags auth +// @Summary Выход из авторизованной сессии +// @Description Выход из авторизованной сессии администрирования +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Success 200 {object} map[string]interface{} "Успешный выход" +// @Failure 400 {object} apierrors.Error "Невалидный токен" +// @Failure 500 {object} apierrors.Error +// @Router /auth/logout [POST] func (a Auth) Logout(ctx context.Context, r *http.Request) error { adminId, err := getAdminId(r) if err != nil { @@ -57,17 +58,18 @@ func (a Auth) Logout(ctx context.Context, r *http.Request) error { } // LogoutWithReason -// @Tags auth -// @Summary Выход по бездействию из авторизованной сессии -// @Description Выход по бездействию из авторизованной сессии администрирования -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.LogoutRequest true "Тело запроса" -// @Success 200 {object} map[string]interface{} "Успешный выход" -// @Failure 400 {object} apierrors.Error "Невалидный токен" -// @Failure 500 {object} apierrors.Error -// @Router /auth/logout_with_reason [POST] +// +// @Tags auth +// @Summary Выход по бездействию из авторизованной сессии +// @Description Выход по бездействию из авторизованной сессии администрирования +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.LogoutRequest true "Тело запроса" +// @Success 200 {object} map[string]interface{} "Успешный выход" +// @Failure 400 {object} apierrors.Error "Невалидный токен" +// @Failure 500 {object} apierrors.Error +// @Router /auth/logout_with_reason [POST] func (a Auth) LogoutWithReason(ctx context.Context, logoutRequest domain.LogoutRequest, r *http.Request) error { adminId, err := getAdminId(r) if err != nil { @@ -83,18 +85,19 @@ func (a Auth) LogoutWithReason(ctx context.Context, logoutRequest domain.LogoutR } // Login -// @Tags auth -// @Summary Авторизация по логину и паролю -// @Description Авторизация с получением токена администратора -// @Accept json -// @Produce json -// @Param body body domain.LoginRequest true "Тело запроса" -// @Success 200 {object} domain.LoginResponse -// @Failure 400 {object} apierrors.Error -// @Failure 401 {object} apierrors.Error "Данные для авторизации не верны" -// @Failure 429 {object} apierrors.Error "Слишком много запросов на авторизацию" -// @Failure 500 {object} apierrors.Error -// @Router /auth/login [POST] +// +// @Tags auth +// @Summary Авторизация по логину и паролю +// @Description Авторизация с получением токена администратора +// @Accept json +// @Produce json +// @Param body body domain.LoginRequest true "Тело запроса" +// @Success 200 {object} domain.LoginResponse +// @Failure 400 {object} apierrors.Error +// @Failure 401 {object} apierrors.Error "Данные для авторизации не верны" +// @Failure 429 {object} apierrors.Error "Слишком много запросов на авторизацию" +// @Failure 500 {object} apierrors.Error +// @Router /auth/login [POST] func (a Auth) Login(ctx context.Context, authRequest domain.LoginRequest) (*domain.LoginResponse, error) { auth, err := a.authService.Login(ctx, authRequest) @@ -114,17 +117,18 @@ func (a Auth) Login(ctx context.Context, authRequest domain.LoginRequest) (*doma } // LoginWithOauth -// @Tags auth -// @Summary Авторизация по авторизационному коду от OAuth -// @Description Авторизация с получением токена администратора. -// @Accept json -// @Produce json -// @Param body body domain.LoginOauthRequest true "Тело запроса" -// @Success 200 {object} domain.LoginResponse -// @Failure 400 {object} apierrors.Error "Авторизация OAuth не настроена на сервере" -// @Failure 401 {object} apierrors.Error "Некорректный код для авторизации или неизвестное название клиента" -// @Failure 500 {object} apierrors.Error -// @Router /auth/login_with_oauth [POST] +// +// @Tags auth +// @Summary Авторизация по авторизационному коду от OAuth +// @Description Авторизация с получением токена администратора. +// @Accept json +// @Produce json +// @Param body body domain.LoginOauthRequest true "Тело запроса" +// @Success 200 {object} domain.LoginResponse +// @Failure 400 {object} apierrors.Error "Авторизация OAuth не настроена на сервере" +// @Failure 401 {object} apierrors.Error "Некорректный код для авторизации или неизвестное название клиента" +// @Failure 500 {object} apierrors.Error +// @Router /auth/login_with_oauth [POST] func (a Auth) LoginWithOauth(ctx context.Context, request domain.LoginOauthRequest) (*domain.LoginResponse, error) { auth, err := a.authService.LoginWithOauth(ctx, request) diff --git a/controller/customization.go b/controller/customization.go index 3681fe7..89bc0c4 100644 --- a/controller/customization.go +++ b/controller/customization.go @@ -19,16 +19,17 @@ func NewCustomization(uiCfg conf.UIDesign) Customization { } // GetUIDesign -// @Tags user -// @Summary Получение внешнего вида -// @Description Получение внешнего вида (палитра и наименование) админ-интерфейса -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Success 200 {object} domain.UIDesign -// @Failure 400 {object} apierrors.Error "Невалидный токен" -// @Failure 500 {object} apierrors.Error -// @Router /user/get_design [POST] +// +// @Tags user +// @Summary Получение внешнего вида +// @Description Получение внешнего вида (палитра и наименование) админ-интерфейса +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Success 200 {object} domain.UIDesign +// @Failure 400 {object} apierrors.Error "Невалидный токен" +// @Failure 500 {object} apierrors.Error +// @Router /user/get_design [POST] func (c Customization) GetUIDesign() (domain.UIDesign, error) { return c.uiCfg, nil } diff --git a/controller/download.go b/controller/download.go index 6b10796..b2a3929 100644 --- a/controller/download.go +++ b/controller/download.go @@ -27,14 +27,15 @@ func NewDownload(service DownloadService) Download { } // Users -// @Tags Download -// @Summary Скачать список пользователей в csv -// @Accept json -// @Produce json -// @Param body body domain.UsersPageRequest true "Тело запроса" -// @Success 200 -// @Failure 500 {object} apierrors.Error "Внутренняя ошибка сервиса ```{errorCode: -1}```" -// @Router /user/download [POST] +// +// @Tags Download +// @Summary Скачать список пользователей в csv +// @Accept json +// @Produce text/csv +// @Param body body domain.UsersPageRequest true "Тело запроса" +// @Success 200 +// @Failure 500 {object} apierrors.Error "Внутренняя ошибка сервиса ```{errorCode: -1}```" +// @Router /user/download [POST] func (c Download) Users(ctx context.Context, req domain.UsersPageRequest, w http.ResponseWriter) error { err := c.service.DownloadUsers(ctx, req, w) if err != nil { @@ -45,14 +46,15 @@ func (c Download) Users(ctx context.Context, req domain.UsersPageRequest, w http } // Sessions -// @Tags Download -// @Summary Скачать список сессий в csv -// @Accept json -// @Produce json -// @Param body body domain.SessionPageRequest true "Тело запроса" -// @Success 200 -// @Failure 500 {object} apierrors.Error "Внутренняя ошибка сервиса ```{errorCode: -1}```" -// @Router /session/download [POST] +// +// @Tags Download +// @Summary Скачать список сессий в csv +// @Accept json +// @Produce text/csv +// @Param body body domain.SessionPageRequest true "Тело запроса" +// @Success 200 +// @Failure 500 {object} apierrors.Error "Внутренняя ошибка сервиса ```{errorCode: -1}```" +// @Router /session/download [POST] func (c Download) Sessions(ctx context.Context, req domain.SessionPageRequest, w http.ResponseWriter) error { err := c.service.DownloadSessions(ctx, req, w) if err != nil { @@ -63,14 +65,15 @@ func (c Download) Sessions(ctx context.Context, req domain.SessionPageRequest, w } // Audit -// @Tags Download -// @Summary Скачать журнал аудита в csv -// @Accept json -// @Produce json -// @Param body body domain.AuditPageRequest true "Тело запроса" -// @Success 200 -// @Failure 500 {object} apierrors.Error "Внутренняя ошибка сервиса ```{errorCode: -1}```" -// @Router /log/download [POST] +// +// @Tags Download +// @Summary Скачать журнал аудита в csv +// @Accept json +// @Produce text/csv +// @Param body body domain.AuditPageRequest true "Тело запроса" +// @Success 200 +// @Failure 500 {object} apierrors.Error "Внутренняя ошибка сервиса ```{errorCode: -1}```" +// @Router /log/download [POST] func (c Download) Audit(ctx context.Context, req domain.AuditPageRequest, w http.ResponseWriter) error { err := c.service.DownloadAudit(ctx, req, w) if err != nil { @@ -81,13 +84,14 @@ func (c Download) Audit(ctx context.Context, req domain.AuditPageRequest, w http } // Roles -// @Tags Download -// @Summary Скачать матрицу ролей в csv -// @Accept json -// @Produce json -// @Success 200 -// @Failure 500 {object} apierrors.Error "Внутренняя ошибка сервиса ```{errorCode: -1}```" -// @Router /role/download [POST] +// +// @Tags Download +// @Summary Скачать матрицу ролей в csv +// @Accept json +// @Produce text/csv +// @Success 200 +// @Failure 500 {object} apierrors.Error "Внутренняя ошибка сервиса ```{errorCode: -1}```" +// @Router /role/download [POST] func (c Download) Roles(ctx context.Context, w http.ResponseWriter) error { err := c.service.DownloadRoles(ctx, w) if err != nil { diff --git a/controller/permissions.go b/controller/permissions.go index e8afb81..9a69671 100644 --- a/controller/permissions.go +++ b/controller/permissions.go @@ -21,14 +21,15 @@ func NewPermissions(permissionsService permissionsService) Permissions { } // GetPermissions -// @Tags user -// @Summary Получить все разрешения -// @Description Получить все разрешения -// @Accept json -// @Produce json -// @Success 200 {array} domain.Permission -// @Failure 500 {object} apierrors.Error -// @Router /user/get_permissions [POST] +// +// @Tags user +// @Summary Получить все разрешения +// @Description Получить все разрешения +// @Accept json +// @Produce json +// @Success 200 {array} domain.Permission +// @Failure 500 {object} apierrors.Error +// @Router /user/get_permissions [POST] func (u Permissions) GetPermissions(ctx context.Context) []domain.Permission { return u.permissionsService.All(ctx) } diff --git a/controller/role.go b/controller/role.go index 876bacf..fd0fa6b 100644 --- a/controller/role.go +++ b/controller/role.go @@ -28,19 +28,19 @@ func NewRole(roleService roleService) Role { } // All -// @Tags role -// @Summary Список ролей -// @Description Получить список ролей -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.RoleAllRequest true "Тело запроса" -// @Success 200 {array} domain.Role -// @Failure 400 {object} apierrors.Error -// @Failure 500 {object} apierrors.Error -// @Router /role/all [POST] -func (u Role) All(ctx context.Context, req domain.RoleAllRequest) ([]domain.Role, error) { - users, err := u.roleService.All(ctx, req) +// +// @Tags role +// @Summary Список ролей +// @Description Получить список ролей +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Success 200 {array} domain.Role +// @Failure 400 {object} apierrors.Error +// @Failure 500 {object} apierrors.Error +// @Router /role/all [POST] +func (u Role) All(ctx context.Context) ([]domain.Role, error) { + users, err := u.roleService.All(ctx) if err != nil { return nil, errors.WithMessage(err, "get roles") } @@ -49,18 +49,19 @@ func (u Role) All(ctx context.Context, req domain.RoleAllRequest) ([]domain.Role } // CreateRole -// @Tags role -// @Summary Создать роль -// @Description Создать роль -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.CreateRoleRequest true "Тело запроса" -// @Success 200 {object} domain.Role -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" -// @Failure 409 {object} apierrors.Error "Роль с указанным именем уже существует" -// @Failure 500 {object} apierrors.Error -// @Router /role/create [POST] +// +// @Tags role +// @Summary Создать роль +// @Description Создать роль +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.CreateRoleRequest true "Тело запроса" +// @Success 200 {object} domain.Role +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 409 {object} apierrors.Error "Роль с указанным именем уже существует" +// @Failure 500 {object} apierrors.Error +// @Router /role/create [POST] func (u Role) CreateRole(ctx context.Context, req domain.CreateRoleRequest, r *http.Request) (*domain.Role, error) { adminId, err := getAdminId(r) if err != nil { @@ -79,18 +80,19 @@ func (u Role) CreateRole(ctx context.Context, req domain.CreateRoleRequest, r *h } // UpdateRole -// @Tags role -// @Summary Обновить роль -// @Description Обновить данные существующую роль -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.UpdateRoleRequest true "Тело запроса" -// @Success 200 {object} domain.Role -// @Failure 404 {object} apierrors.Error "Роль с указанным id не существует" -// @Failure 409 {object} apierrors.Error "Роль с указанным именем уже существует" -// @Failure 500 {object} apierrors.Error -// @Router /role/update [POST] +// +// @Tags role +// @Summary Обновить роль +// @Description Обновить данные существующую роль +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.UpdateRoleRequest true "Тело запроса" +// @Success 200 {object} domain.Role +// @Failure 404 {object} apierrors.Error "Роль с указанным id не существует" +// @Failure 409 {object} apierrors.Error "Роль с указанным именем уже существует" +// @Failure 500 {object} apierrors.Error +// @Router /role/update [POST] func (u Role) UpdateRole(ctx context.Context, req domain.UpdateRoleRequest, r *http.Request) (*domain.Role, error) { adminId, err := getAdminId(r) if err != nil { @@ -111,17 +113,18 @@ func (u Role) UpdateRole(ctx context.Context, req domain.UpdateRoleRequest, r *h } // DeleteRole -// @Tags role -// @Summary Удалить роль -// @Description Удалить существующую роль -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.DeleteRoleRequest true "Тело запроса" -// @Success 200 -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" -// @Failure 500 {object} apierrors.Error -// @Router /role/delete [POST] +// +// @Tags role +// @Summary Удалить роль +// @Description Удалить существующую роль +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.DeleteRoleRequest true "Тело запроса" +// @Success 200 +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 500 {object} apierrors.Error +// @Router /role/delete [POST] func (u Role) DeleteRole(ctx context.Context, req domain.DeleteRoleRequest, r *http.Request) error { adminId, err := getAdminId(r) if err != nil { diff --git a/controller/secure.go b/controller/secure.go index 4b78e0a..f804902 100644 --- a/controller/secure.go +++ b/controller/secure.go @@ -25,15 +25,16 @@ func NewSecure(service SecureService) Secure { } // Authenticate -// @Tags secure -// @Summary Метод аутентификации токена -// @Description Проверяет токен и возвращает идентификатор администратора -// @Accept json -// @Produce json -// @Param body body domain.SecureAuthRequest true "Тело запроса" -// @Success 200 {object} domain.SecureAuthResponse -// @Failure 500 {object} apierrors.Error -// @Router /secure/authenticate [POST] +// +// @Tags secure +// @Summary Метод аутентификации токена +// @Description Проверяет токен и возвращает идентификатор администратора +// @Accept json +// @Produce json +// @Param body body domain.SecureAuthRequest true "Тело запроса" +// @Success 200 {object} domain.SecureAuthResponse +// @Failure 500 {object} apierrors.Error +// @Router /secure/authenticate [POST] func (s Secure) Authenticate(ctx context.Context, req domain.SecureAuthRequest) (*domain.SecureAuthResponse, error) { adminId, err := s.service.Authenticate(ctx, req.Token) switch { @@ -61,15 +62,16 @@ func (s Secure) Authenticate(ctx context.Context, req domain.SecureAuthRequest) } // Authorize -// @Tags secure -// @Summary Метод авторизации для администратора -// @Description Проверяет наличие у администратора необходимого разрешения -// @Accept json -// @Produce json -// @Param body body domain.SecureAuthzRequest true "Тело запроса" -// @Success 200 {object} domain.SecureAuthzResponse -// @Failure 500 {object} apierrors.Error -// @Router /secure/authorize [POST] +// +// @Tags secure +// @Summary Метод авторизации для администратора +// @Description Проверяет наличие у администратора необходимого разрешения +// @Accept json +// @Produce json +// @Param body body domain.SecureAuthzRequest true "Тело запроса" +// @Success 200 {object} domain.SecureAuthzResponse +// @Failure 500 {object} apierrors.Error +// @Router /secure/authorize [POST] func (s Secure) Authorize(ctx context.Context, req domain.SecureAuthzRequest) (*domain.SecureAuthzResponse, error) { ok, err := s.service.Authorize(ctx, req.AdminId, req.Permission) if err != nil { diff --git a/controller/session.go b/controller/session.go index eb0fda6..bd89666 100644 --- a/controller/session.go +++ b/controller/session.go @@ -22,16 +22,17 @@ func NewSession(service SessionService) Session { } // All -// @Tags session -// @Summary Получение списка сессий -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.SessionPageRequest true "Тело запроса" -// @Success 200 {object} domain.SessionResponse -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" -// @Failure 500 {object} apierrors.Error -// @Router /session/all [POST] +// +// @Tags session +// @Summary Получение списка сессий +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.SessionPageRequest true "Тело запроса" +// @Success 200 {object} domain.SessionResponse +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 500 {object} apierrors.Error +// @Router /session/all [POST] func (c Session) All(ctx context.Context, req domain.SessionPageRequest) (*domain.SessionResponse, error) { if req.Order == nil { req.Order = &domain.OrderParams{ @@ -44,16 +45,17 @@ func (c Session) All(ctx context.Context, req domain.SessionPageRequest) (*domai } // Revoke -// @Tags session -// @Summary Отзыв сессии -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.RevokeRequest true "Тело запроса" -// @Success 200 -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" -// @Failure 500 {object} apierrors.Error -// @Router /session/revoke [POST] +// +// @Tags session +// @Summary Отзыв сессии +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.RevokeRequest true "Тело запроса" +// @Success 200 +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 500 {object} apierrors.Error +// @Router /session/revoke [POST] func (c Session) Revoke(ctx context.Context, req domain.RevokeRequest) error { return c.service.Revoke(ctx, req.Id) } diff --git a/controller/ui_settings.go b/controller/ui_settings.go index b2e1e2b..bc13f2b 100644 --- a/controller/ui_settings.go +++ b/controller/ui_settings.go @@ -24,17 +24,18 @@ func NewUiSettings(service UiSettingsService) UiSettings { } // UiOauthSettings -// @Tags ui_settings -// @Summary Получение настроек для ui для авторизации через OAuth -// @Description Получение настроек для ui для авторизации через OAuth -// @Accept json -// @Produce json -// @Param body body domain.ClientNameRequest true "Тело запроса" -// @Success 200 {object} domain.UiOauthSetting -// @Failure 400 {object} apierrors.Error -// @Failure 401 {object} apierrors.Error "Неизвестное название клиента" -// @Failure 500 {object} apierrors.Error -// @Router /ui_settings/oauth [POST] +// +// @Tags ui_settings +// @Summary Получение настроек для ui для авторизации через OAuth +// @Description Получение настроек для ui для авторизации через OAuth +// @Accept json +// @Produce json +// @Param body body domain.ClientNameRequest true "Тело запроса" +// @Success 200 {object} domain.UiOauthSetting +// @Failure 400 {object} apierrors.Error +// @Failure 401 {object} apierrors.Error "Неизвестное название клиента" +// @Failure 500 {object} apierrors.Error +// @Router /ui_settings/oauth [POST] func (c UiSettings) OauthSettings(ctx context.Context, req domain.ClientNameRequest) (*domain.UiOauthSetting, error) { resp, err := c.service.OauthSettings(ctx, req) switch { diff --git a/controller/user.go b/controller/user.go index 4234993..4834b02 100644 --- a/controller/user.go +++ b/controller/user.go @@ -34,17 +34,18 @@ func NewUser(userService userService) User { } // GetProfile -// @Tags user -// @Summary Получить профиль -// @Description Получить данные профиля -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Success 200 {object} domain.AdminUserShort -// @Failure 401 {object} apierrors.Error "Невалидный токен" -// @Failure 404 {object} apierrors.Error "Пользователя не существует" -// @Failure 500 {object} apierrors.Error -// @Router /user/get_profile [POST] +// +// @Tags user +// @Summary Получить профиль +// @Description Получить данные профиля +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Success 200 {object} domain.AdminUserShort +// @Failure 401 {object} apierrors.Error "Невалидный токен" +// @Failure 404 {object} apierrors.Error "Пользователя не существует" +// @Failure 500 {object} apierrors.Error +// @Router /user/get_profile [POST] func (u User) GetProfile(ctx context.Context, r *http.Request) (*domain.AdminUserShort, error) { adminId, err := getAdminId(r) if err != nil { @@ -65,17 +66,18 @@ func (u User) GetProfile(ctx context.Context, r *http.Request) (*domain.AdminUse } // GetUsers -// @Tags user -// @Summary Список пользователей -// @Description Получить список пользователей -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.UsersPageRequest true "Тело запроса" -// @Success 200 {object} domain.UsersResponse -// @Failure 400 {object} apierrors.Error -// @Failure 500 {object} apierrors.Error -// @Router /user/get_users [POST] +// +// @Tags user +// @Summary Список пользователей +// @Description Получить список пользователей +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.UsersPageRequest true "Тело запроса" +// @Success 200 {object} domain.UsersResponse +// @Failure 400 {object} apierrors.Error +// @Failure 500 {object} apierrors.Error +// @Router /user/get_users [POST] func (u User) GetUsers(ctx context.Context, req domain.UsersPageRequest) (*domain.UsersResponse, error) { if req.Order == nil { req.Order = &domain.OrderParams{ @@ -93,16 +95,17 @@ func (u User) GetUsers(ctx context.Context, req domain.UsersPageRequest) (*domai } // GetAllUsers -// @Tags user -// @Summary Список пользователей -// @Description Получить список пользователей -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Success 200 {object} domain.UsersResponse -// @Failure 400 {object} apierrors.Error -// @Failure 500 {object} apierrors.Error -// @Router /user/get_all_users [POST] +// +// @Tags user +// @Summary Список пользователей +// @Description Получить список пользователей +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Success 200 {object} domain.UsersResponse +// @Failure 400 {object} apierrors.Error +// @Failure 500 {object} apierrors.Error +// @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 { @@ -113,18 +116,19 @@ func (u User) GetAllUsers(ctx context.Context) (*domain.UsersResponse, error) { } // CreateUser -// @Tags user -// @Summary Создать пользователя -// @Description Создать пользователя -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.CreateUserRequest true "Тело запроса" -// @Success 200 {object} domain.User -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" -// @Failure 409 {object} apierrors.Error "Пользователь с указанным email уже существует" -// @Failure 500 {object} apierrors.Error -// @Router /user/create_user [POST] +// +// @Tags user +// @Summary Создать пользователя +// @Description Создать пользователя +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.CreateUserRequest true "Тело запроса" +// @Success 200 {object} domain.User +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 409 {object} apierrors.Error "Пользователь с указанным email уже существует" +// @Failure 500 {object} apierrors.Error +// @Router /user/create_user [POST] func (u User) CreateUser(ctx context.Context, req domain.CreateUserRequest, r *http.Request) (*domain.User, error) { adminId, err := getAdminId(r) if err != nil { @@ -143,19 +147,20 @@ func (u User) CreateUser(ctx context.Context, req domain.CreateUserRequest, r *h } // UpdateUser -// @Tags user -// @Summary Обновить пользователя -// @Description Обновить данные существующего пользователя -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.UpdateUserRequest true "Тело запроса" -// @Success 200 {object} domain.User -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" -// @Failure 404 {object} apierrors.Error "Пользователь с указанным id не существует" -// @Failure 409 {object} apierrors.Error "Пользователь с указанным email уже существует" -// @Failure 500 {object} apierrors.Error -// @Router /user/update_user [POST] +// +// @Tags user +// @Summary Обновить пользователя +// @Description Обновить данные существующего пользователя +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.UpdateUserRequest true "Тело запроса" +// @Success 200 {object} domain.User +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 404 {object} apierrors.Error "Пользователь с указанным id не существует" +// @Failure 409 {object} apierrors.Error "Пользователь с указанным email уже существует" +// @Failure 500 {object} apierrors.Error +// @Router /user/update_user [POST] func (u User) UpdateUser(ctx context.Context, req domain.UpdateUserRequest, r *http.Request) (*domain.User, error) { adminId, err := getAdminId(r) if err != nil { @@ -178,17 +183,18 @@ func (u User) UpdateUser(ctx context.Context, req domain.UpdateUserRequest, r *h } // DeleteUser -// @Tags user -// @Summary Удалить пользователя -// @Description Удалить существующего пользователя -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.IdentitiesRequest true "Тело запроса" -// @Success 200 {object} domain.DeleteResponse -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" -// @Failure 500 {object} apierrors.Error -// @Router /user/delete_user [POST] +// +// @Tags user +// @Summary Удалить пользователя +// @Description Удалить существующего пользователя +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.IdentitiesRequest true "Тело запроса" +// @Success 200 {object} domain.DeleteResponse +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 500 {object} apierrors.Error +// @Router /user/delete_user [POST] func (u User) DeleteUser(ctx context.Context, identities domain.IdentitiesRequest, r *http.Request) (*domain.DeleteResponse, error) { adminId, err := getAdminId(r) if err != nil { @@ -204,16 +210,17 @@ func (u User) DeleteUser(ctx context.Context, identities domain.IdentitiesReques } // Block -// @Tags user -// @Summary Метод блокировки/разблокировки пользователя -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.IdRequest true "Тело запроса" -// @Success 200 -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" -// @Failure 500 {object} apierrors.Error -// @Router /user/block_user [POST] +// +// @Tags user +// @Summary Метод блокировки/разблокировки пользователя +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.IdRequest true "Тело запроса" +// @Success 200 +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 500 {object} apierrors.Error +// @Router /user/block_user [POST] func (u User) Block(ctx context.Context, identities domain.IdRequest, r *http.Request) error { adminId, err := getAdminId(r) if err != nil { @@ -228,30 +235,32 @@ func (u User) Block(ctx context.Context, identities domain.IdRequest, r *http.Re } // GetById -// @Tags user -// @Summary Метод получения данных по пользователю -// @Accept json -// @Produce json -// @Param body body domain.IdRequest true "Тело запроса" -// @Success 200 {object} domain.User -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" -// @Failure 500 {object} apierrors.Error -// @Router /user/get_by_id [POST] +// +// @Tags user +// @Summary Метод получения данных по пользователю +// @Accept json +// @Produce json +// @Param body body domain.IdRequest true "Тело запроса" +// @Success 200 {object} domain.User +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса" +// @Failure 500 {object} apierrors.Error +// @Router /user/get_by_id [POST] func (u User) GetById(ctx context.Context, identities domain.IdRequest) (*domain.User, error) { return u.userService.GetById(ctx, identities.UserId) } // ChangePassword -// @Tags user -// @Summary Метод изменения пароля пользователя -// @Accept json -// @Produce json -// @Param X-AUTH-ADMIN header string true "Токен администратора" -// @Param body body domain.ChangePasswordRequest true "Тело запроса" -// @Success 200 -// @Failure 400 {object} apierrors.Error "Невалидное тело запроса или неверный старый пароль" -// @Failure 500 {object} apierrors.Error "Внутренняя ошибка" -// @Router /user/change_password [POST] +// +// @Tags user +// @Summary Метод изменения пароля пользователя +// @Accept json +// @Produce json +// @Param X-AUTH-ADMIN header string true "Токен администратора" +// @Param body body domain.ChangePasswordRequest true "Тело запроса" +// @Success 200 +// @Failure 400 {object} apierrors.Error "Невалидное тело запроса или неверный старый пароль" +// @Failure 500 {object} apierrors.Error "Внутренняя ошибка" +// @Router /user/change_password [POST] func (u User) ChangePassword(ctx context.Context, req domain.ChangePasswordRequest, r *http.Request) error { adminId, err := getAdminId(r) if err != nil { diff --git a/docs/swagger.json b/docs/swagger.json index 2c2b503..a13951b 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -279,7 +279,7 @@ "application/json" ], "produces": [ - "application/json" + "text/csv" ], "tags": [ "Download" @@ -578,7 +578,7 @@ "application/json" ], "produces": [ - "application/json" + "text/csv" ], "tags": [ "Download" @@ -794,7 +794,7 @@ "application/json" ], "produces": [ - "application/json" + "text/csv" ], "tags": [ "Download" @@ -1141,7 +1141,7 @@ "application/json" ], "produces": [ - "application/json" + "text/csv" ], "tags": [ "Download" diff --git a/domain/errors.go b/domain/errors.go index 416c46d..fe5d62b 100644 --- a/domain/errors.go +++ b/domain/errors.go @@ -26,8 +26,7 @@ var ( ErrUnknownClient = errors.New("unknown client") ) -// nolint:gochecknoglobals -var ( +const ( UnknownAuditEventErrorCode = 601 ErrOauthAuthorizationCode = 602 ErrUnauthenticatedCode = 603 diff --git a/main.go b/main.go index 8dea5e8..e868859 100644 --- a/main.go +++ b/main.go @@ -12,14 +12,14 @@ import ( var version = "1.0.0" -// @title isp-admin-service -// @version 1.0.0 -// @description сервис управления администраторами +// @title isp-admin-service +// @version 1.0.0 +// @description сервис управления администраторами -// @license.name GNU GPL v3.0 +// @license.name GNU GPL v3.0 -// @host localhost:9000 -// @BasePath /api/admin +// @host localhost:9000 +// @BasePath /api/admin //go:generate swag init -pd -ot json -eot json func main() { diff --git a/service/permission.go b/service/permission.go index 1d2a79d..63a3bf9 100644 --- a/service/permission.go +++ b/service/permission.go @@ -11,12 +11,12 @@ type Permission struct { permissions []domain.Permission } -func NewPermission(permissions []conf.Permission) *Permission { - return &Permission{ +func NewPermission(permissions []conf.Permission) Permission { + return Permission{ permissions: toDomain(permissions), } } -func (s *Permission) All(_ context.Context) []domain.Permission { +func (s Permission) All(_ context.Context) []domain.Permission { return s.permissions }