Skip to content

Commit

Permalink
chore: pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ale8k committed Dec 13, 2024
1 parent 2ad39e0 commit 69d2604
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions internal/jimm/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -1370,6 +1370,12 @@ func (j *JIMM) ListModels(ctx context.Context, user *openfga.User) ([]base.UserM
return nil, errors.E(op, err, "failed to get models by uuid")
}

// Create map for lookup later
modelsMap := make(map[string]dbmodel.Model)
for _, m := range models {
modelsMap[m.UUID.String] = m
}

// Find the controllers these models reside on and remove duplicates
var controllers []dbmodel.Controller
seen := make(map[uint]bool)
Expand Down Expand Up @@ -1406,15 +1412,8 @@ func (j *JIMM) ListModels(ctx context.Context, user *openfga.User) ([]base.UserM
for _, um := range ums {
// Filter models that match authorised uuids list
if slices.Contains(uuids, um.UUID) {
// Find that model in the db models
index := slices.IndexFunc(models, func(m dbmodel.Model) bool {
return m.UUID.String == um.UUID
})
if index != -1 {
// Override owner and append to result
um.Owner = models[index].OwnerIdentityName
userModels = append(userModels, um)
}
um.Owner = modelsMap[um.UUID].OwnerIdentityName
userModels = append(userModels, um)
}
}
return nil
Expand Down

0 comments on commit 69d2604

Please sign in to comment.