Skip to content

Commit 02215ec

Browse files
authored
Align Identity Resolver (#2369)
* adjust identity resolver, no name match, external first, validate UUID * do not validate against uuids for external
1 parent 2d7ff9b commit 02215ec

File tree

1 file changed

+15
-16
lines changed

1 file changed

+15
-16
lines changed

taco/internal/repositories/identifier_resolver.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -31,36 +31,35 @@ func (r *gormIdentifierResolver) ResolveOrganization(ctx context.Context, identi
3131
return "", err
3232
}
3333

34-
// If already a UUID, return it
34+
var result struct{ ID string }
35+
lookupValue := parsed.Name
3536
if parsed.Type == domain.IdentifierTypeUUID {
36-
return parsed.UUID, nil
37+
lookupValue = parsed.UUID
3738
}
3839

39-
// Try to resolve by internal name first
40-
var result struct{ ID string }
4140
err = r.db.WithContext(ctx).
4241
Table("organizations").
4342
Select("id").
44-
Where("name = ?", parsed.Name).
43+
Where("external_org_id = ?", lookupValue).
4544
First(&result).Error
4645

4746
if err == nil {
4847
return result.ID, nil
4948
}
5049

51-
// If not found by name, try external org ID
52-
// This handles cases where someone passes an external ID directly
53-
err = r.db.WithContext(ctx).
54-
Table("organizations").
55-
Select("id").
56-
Where("external_org_id = ?", parsed.Name).
57-
First(&result).Error
58-
59-
if err == nil {
60-
return result.ID, nil
50+
if parsed.Type == domain.IdentifierTypeUUID {
51+
err = r.db.WithContext(ctx).
52+
Table("organizations").
53+
Select("id").
54+
Where("id = ?", parsed.UUID).
55+
First(&result).Error
56+
57+
if err == nil {
58+
return parsed.UUID, nil
59+
}
6160
}
6261

63-
return "", fmt.Errorf("organization not found: %s", parsed.Name)
62+
return "", fmt.Errorf("organization not found: %s", lookupValue)
6463
}
6564

6665
// ResolveUnit resolves unit identifier to UUID within an organization

0 commit comments

Comments
 (0)