MCPcopy
hub / github.com/weaviate/weaviate / ValidateObject

Method ValidateObject

usecases/objects/validate.go:28–59  ·  view source on GitHub ↗

ValidateObject without adding it to the database. Can be used in UIs for async validation before submitting

(ctx context.Context, principal *models.Principal,
	obj *models.Object, repl *additional.ReplicationProperties,
)

Source from the content-addressed store, hash-verified

26// ValidateObject without adding it to the database. Can be used in UIs for
27// async validation before submitting
28func (m *Manager) ValidateObject(ctx context.Context, principal *models.Principal,
29 obj *models.Object, repl *additional.ReplicationProperties,
30) error {
31 className, _, err := m.resolveNS(principal, obj.Class)
32 if err != nil {
33 return NewErrInvalidUserInput("%v", err)
34 }
35 obj.Class = className
36
37 if err := m.authorizer.Authorize(ctx, principal, authorization.READ, authorization.Objects(className, obj.Tenant, obj.ID)); err != nil {
38 return err
39 }
40
41 ctx = classcache.ContextWithClassCache(ctx)
42
43 // we don't reveal any info that the end users cannot get through the structure of the data anyway
44 fetchedClasses, err := m.schemaManager.GetCachedClassNoAuth(ctx, className)
45 if err != nil {
46 return err
47 }
48
49 err = m.validateObjectAndNormalizeNames(ctx, principal, repl, obj, nil, fetchedClasses)
50 if err != nil {
51 var forbidden autherrs.Forbidden
52 if errors.As(err, &forbidden) {
53 return err
54 }
55 return NewErrInvalidUserInput("invalid object: %v", err)
56 }
57
58 return nil
59}

Callers

nothing calls this directly

Calls 7

resolveNSMethod · 0.95
ObjectsFunction · 0.92
ContextWithClassCacheFunction · 0.92
NewErrInvalidUserInputFunction · 0.85
AuthorizeMethod · 0.65
GetCachedClassNoAuthMethod · 0.65

Tested by

no test coverage detected