Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

trivial. fix audit when user failed login #466

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading