Skip to content

Commit

Permalink
Merge pull request #466 from openinfradev/minor_fix
Browse files Browse the repository at this point in the history
trivial. fix audit when user failed login
  • Loading branch information
cho4036 authored May 3, 2024
2 parents ec7cc9d + 5bb7630 commit dbcd7ff
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 49 deletions.
37 changes: 15 additions & 22 deletions internal/usecase/audit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"

"github.com/google/uuid"
"github.com/openinfradev/tks-api/internal/middleware/auth/request"
"github.com/openinfradev/tks-api/internal/model"
"github.com/openinfradev/tks-api/internal/pagination"
"github.com/openinfradev/tks-api/internal/repository"
Expand All @@ -31,31 +30,25 @@ func NewAuditUsecase(r repository.Repository) IAuditUsecase {
}

func (u *AuditUsecase) Create(ctx context.Context, dto model.Audit) (auditId uuid.UUID, err error) {
if dto.UserId == nil || *dto.UserId == uuid.Nil {
userInfo, ok := request.UserFrom(ctx)
if ok {
id := userInfo.GetUserId()
dto.UserId = &id
if dto.UserId != nil && *dto.UserId == uuid.Nil {
user, err := u.userRepo.GetByUuid(ctx, *dto.UserId)
if err != nil {
return auditId, err
}
}

user, err := u.userRepo.GetByUuid(ctx, *dto.UserId)
if err != nil {
return auditId, err
}

userRoles := ""
for i, role := range user.Roles {
if i > 0 {
userRoles = userRoles + ","
userRoles := ""
for i, role := range user.Roles {
if i > 0 {
userRoles = userRoles + ","
}
userRoles = userRoles + role.Name
}
userRoles = userRoles + role.Name
dto.OrganizationId = user.Organization.ID
dto.OrganizationName = user.Organization.Name
dto.UserAccountId = user.AccountId
dto.UserName = user.Name
dto.UserRoles = userRoles
}
dto.OrganizationId = user.Organization.ID
dto.OrganizationName = user.Organization.Name
dto.UserAccountId = user.AccountId
dto.UserName = user.Name
dto.UserRoles = userRoles

auditId, err = u.repo.Create(ctx, dto)
if err != nil {
Expand Down
Loading

0 comments on commit dbcd7ff

Please sign in to comment.