parent
e0cebfd80e
commit
1b0384da11
pkg
@ -6,6 +6,7 @@ import (
|
|||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/auth"
|
"git.itzana.me/strafesnet/go-grpc/auth"
|
||||||
"git.itzana.me/strafesnet/go-grpc/maps"
|
"git.itzana.me/strafesnet/go-grpc/maps"
|
||||||
|
"git.itzana.me/strafesnet/go-grpc/users"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore/gormstore"
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore/gormstore"
|
||||||
internal "git.itzana.me/strafesnet/maps-service/pkg/internal"
|
internal "git.itzana.me/strafesnet/maps-service/pkg/internal"
|
||||||
@ -126,6 +127,7 @@ func serve(ctx *cli.Context) error {
|
|||||||
DB: db,
|
DB: db,
|
||||||
Nats: js,
|
Nats: js,
|
||||||
Maps: maps.NewMapsServiceClient(conn),
|
Maps: maps.NewMapsServiceClient(conn),
|
||||||
|
Users: users.NewUsersServiceClient(conn),
|
||||||
}
|
}
|
||||||
|
|
||||||
conn, err = grpc.Dial(ctx.String("auth-rpc-host"), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
conn, err = grpc.Dial(ctx.String("auth-rpc-host"), grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
|
||||||
|
"git.itzana.me/strafesnet/go-grpc/users"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
"git.itzana.me/strafesnet/maps-service/pkg/model"
|
||||||
@ -83,6 +84,27 @@ func (svc *Service) ListMapfixAuditEvents(ctx context.Context, params api.ListMa
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
idMap := make(map[int64]bool)
|
||||||
|
for _, item := range items {
|
||||||
|
idMap[int64(item.User)] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var idList users.IdList
|
||||||
|
idList.ID = make([]int64,len(idMap))
|
||||||
|
for userId := range idMap {
|
||||||
|
idList.ID = append(idList.ID, userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
userList, err := svc.Users.GetList(ctx, &idList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
userMap := make(map[int64]*users.UserResponse)
|
||||||
|
for _,user := range userList.Users {
|
||||||
|
userMap[user.ID] = user
|
||||||
|
}
|
||||||
|
|
||||||
var resp []api.AuditEvent
|
var resp []api.AuditEvent
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
EventData := api.AuditEventEventData{}
|
EventData := api.AuditEventEventData{}
|
||||||
@ -90,10 +112,15 @@ func (svc *Service) ListMapfixAuditEvents(ctx context.Context, params api.ListMa
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
username := ""
|
||||||
|
if userMap[int64(item.User)] != nil {
|
||||||
|
username = userMap[int64(item.User)].Username
|
||||||
|
}
|
||||||
resp = append(resp, api.AuditEvent{
|
resp = append(resp, api.AuditEvent{
|
||||||
ID: item.ID,
|
ID: item.ID,
|
||||||
Date: item.CreatedAt.Unix(),
|
Date: item.CreatedAt.Unix(),
|
||||||
User: int64(item.User),
|
User: int64(item.User),
|
||||||
|
Username: username,
|
||||||
ResourceType: int32(item.ResourceType),
|
ResourceType: int32(item.ResourceType),
|
||||||
ResourceID: item.ResourceID,
|
ResourceID: item.ResourceID,
|
||||||
EventType: int32(item.EventType),
|
EventType: int32(item.EventType),
|
||||||
@ -178,6 +205,27 @@ func (svc *Service) ListSubmissionAuditEvents(ctx context.Context, params api.Li
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
idMap := make(map[int64]bool)
|
||||||
|
for _, item := range items {
|
||||||
|
idMap[int64(item.User)] = true
|
||||||
|
}
|
||||||
|
|
||||||
|
var idList users.IdList
|
||||||
|
idList.ID = make([]int64,len(idMap))
|
||||||
|
for userId := range idMap {
|
||||||
|
idList.ID = append(idList.ID, userId)
|
||||||
|
}
|
||||||
|
|
||||||
|
userList, err := svc.Users.GetList(ctx, &idList)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
userMap := make(map[int64]*users.UserResponse)
|
||||||
|
for _,user := range userList.Users {
|
||||||
|
userMap[user.ID] = user
|
||||||
|
}
|
||||||
|
|
||||||
var resp []api.AuditEvent
|
var resp []api.AuditEvent
|
||||||
for _, item := range items {
|
for _, item := range items {
|
||||||
EventData := api.AuditEventEventData{}
|
EventData := api.AuditEventEventData{}
|
||||||
@ -185,10 +233,15 @@ func (svc *Service) ListSubmissionAuditEvents(ctx context.Context, params api.Li
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
username := ""
|
||||||
|
if userMap[int64(item.User)] != nil {
|
||||||
|
username = userMap[int64(item.User)].Username
|
||||||
|
}
|
||||||
resp = append(resp, api.AuditEvent{
|
resp = append(resp, api.AuditEvent{
|
||||||
ID: item.ID,
|
ID: item.ID,
|
||||||
Date: item.CreatedAt.Unix(),
|
Date: item.CreatedAt.Unix(),
|
||||||
User: int64(item.User),
|
User: int64(item.User),
|
||||||
|
Username: username,
|
||||||
ResourceType: int32(item.ResourceType),
|
ResourceType: int32(item.ResourceType),
|
||||||
ResourceID: item.ResourceID,
|
ResourceID: item.ResourceID,
|
||||||
EventType: int32(item.EventType),
|
EventType: int32(item.EventType),
|
||||||
|
@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"git.itzana.me/strafesnet/go-grpc/maps"
|
"git.itzana.me/strafesnet/go-grpc/maps"
|
||||||
|
"git.itzana.me/strafesnet/go-grpc/users"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
"git.itzana.me/strafesnet/maps-service/pkg/api"
|
||||||
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
"git.itzana.me/strafesnet/maps-service/pkg/datastore"
|
||||||
"github.com/nats-io/nats.go"
|
"github.com/nats-io/nats.go"
|
||||||
@ -33,6 +34,7 @@ type Service struct {
|
|||||||
DB datastore.Datastore
|
DB datastore.Datastore
|
||||||
Nats nats.JetStreamContext
|
Nats nats.JetStreamContext
|
||||||
Maps maps.MapsServiceClient
|
Maps maps.MapsServiceClient
|
||||||
|
Users users.UsersServiceClient
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewError creates *ErrorStatusCode from error returned by handler.
|
// NewError creates *ErrorStatusCode from error returned by handler.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user