Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2cea7a516c |
No files matched your search
@@ -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")
|
||||
}
|
||||
|
||||
@@ -2353,6 +2353,11 @@
|
||||
"limit"
|
||||
],
|
||||
"properties": {
|
||||
"applicationGroup": {
|
||||
"description": "Фильтр по группе приложений",
|
||||
"type": "string",
|
||||
"minLength": 1
|
||||
},
|
||||
"limit": {
|
||||
"description": "Максимальное количество записей",
|
||||
"type": "integer"
|
||||
|
||||
@@ -33,6 +33,7 @@ type UserQuery struct {
|
||||
|
||||
type UsersPageRequest struct {
|
||||
LimitOffsetParams
|
||||
RoleAllRequest
|
||||
|
||||
Order *OrderParams // Параметры сортировки
|
||||
Query *UserQuery // Параметры выборки
|
||||
|
||||
+3
-3
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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])
|
||||
}
|
||||
Reference in new issue
Block a user