MSP-9044 filter with app group for download flow

This commit is contained in:
chashintv committed 2026-11-23 14:57:33 +03:00
1 parent e2af9c4978
commit 2cea7a516c
5 files changed
+46 -6

No files matched your search

+3 -3
View File
@@ -13,7 +13,7 @@ type DownloadService interface {
DownloadUsers(ctx context.Context, req domain.UsersPageRequest, w http.ResponseWriter) error
DownloadSessions(ctx context.Context, req domain.SessionPageRequest, w http.ResponseWriter) error
DownloadAudit(ctx context.Context, req domain.AuditPageRequest, w http.ResponseWriter) error
DownloadRoles(ctx context.Context, w http.ResponseWriter) error
DownloadRoles(ctx context.Context, req domain.RoleAllRequest, w http.ResponseWriter) error
}
type Download struct {
@@ -92,8 +92,8 @@ func (c Download) Audit(ctx context.Context, req domain.AuditPageRequest, w http
// @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)
func (c Download) Roles(ctx context.Context, req domain.RoleAllRequest, w http.ResponseWriter) error {
err := c.service.DownloadRoles(ctx, req, w)
if err != nil {
return errors.WithMessage(err, "download roles")
}
+5
View File
@@ -2353,6 +2353,11 @@
"limit"
],
"properties": {
"applicationGroup": {
"description": "Фильтр по группе приложений",
"type": "string",
"minLength": 1
},
"limit": {
"description": "Максимальное количество записей",
"type": "integer"
+1
View File
@@ -33,6 +33,7 @@ type UserQuery struct {
type UsersPageRequest struct {
LimitOffsetParams
RoleAllRequest
Order *OrderParams // Параметры сортировки
Query *UserQuery // Параметры выборки
+3 -3
View File
@@ -178,7 +178,7 @@ func (s Download) DownloadUsers(ctx context.Context, req domain.UsersPageRequest
return errors.WithMessage(err, "get users")
}
roles, err := s.roleService.All(ctx, domain.RoleAllRequest{})
roles, err := s.roleService.All(ctx, req.RoleAllRequest)
if err != nil {
return errors.WithMessage(err, "get roles")
}
@@ -216,8 +216,8 @@ func (s Download) DownloadUsers(ctx context.Context, req domain.UsersPageRequest
return nil
}
func (s Download) DownloadRoles(ctx context.Context, w http.ResponseWriter) error {
roles, err := s.roleService.All(ctx, domain.RoleAllRequest{})
func (s Download) DownloadRoles(ctx context.Context, req domain.RoleAllRequest, w http.ResponseWriter) error {
roles, err := s.roleService.All(ctx, req)
if err != nil {
return errors.WithMessage(err, "get roles")
}
+34
View File
@@ -232,7 +232,22 @@ func (s *DownloadSuite) TestAuditHappyPath() {
}
func (s *DownloadSuite) TestRolesHappyPath() {
InsertRole(s.db, entity.Role{
Name: "admin_1",
ApplicationGroup: "123",
Permissions: s.permissions,
})
InsertRole(s.db, entity.Role{
Name: "admin_2",
ApplicationGroup: "456",
Permissions: s.permissions,
})
applicationGroup := "123"
resp, err := s.httpCli.Post("role/download").
JsonRequestBody(domain.RoleAllRequest{
ApplicationGroup: &applicationGroup,
}).
StatusCodeToError().
Do(s.T().Context())
s.Require().NoError(err)
@@ -240,4 +255,23 @@ func (s *DownloadSuite) TestRolesHappyPath() {
records, err := csv.NewReader(resp.Raw.Body).ReadAll()
s.Require().NoError(err)
s.Require().NotEmpty(records)
header := records[0]
col := make(map[string]int, len(header))
for i, name := range header {
col[name] = i
}
moveIdx, ok := col["Действие"]
s.Require().True(ok)
keyIdx, ok := col["Ключ в системе"]
s.Require().True(ok)
nameIdx, ok := col["admin_1"]
s.Require().True(ok)
s.Require().Len(records, 2)
row := records[1]
s.Require().EqualValues("123", row[moveIdx])
s.Require().EqualValues("data_download", row[keyIdx])
s.Require().EqualValues("+", row[nameIdx])
}