UpdateObjectReferences of a specific data object. If the class contains a network ref, it has a side-effect on the schema: The schema will be updated to include this particular network ref class.
(ctx context.Context, principal *models.Principal, input *PutReferenceInput, repl *additional.ReplicationProperties, tenant string, )
| 45 | // ref, it has a side-effect on the schema: The schema will be updated to |
| 46 | // include this particular network ref class. |
| 47 | func (m *Manager) UpdateObjectReferences(ctx context.Context, principal *models.Principal, |
| 48 | input *PutReferenceInput, repl *additional.ReplicationProperties, tenant string, |
| 49 | ) *Error { |
| 50 | m.metrics.UpdateReferenceInc() |
| 51 | defer m.metrics.UpdateReferenceDec() |
| 52 | |
| 53 | ctx = classcache.ContextWithClassCache(ctx) |
| 54 | if input.Class != "" { |
| 55 | class, _, err := m.resolveNS(principal, input.Class) |
| 56 | if err != nil { |
| 57 | return &Error{err.Error(), StatusUnprocessableEntity, err} |
| 58 | } |
| 59 | input.Class = class |
| 60 | } |
| 61 | |
| 62 | if err := m.authorizer.Authorize(ctx, principal, authorization.UPDATE, authorization.ShardsData(input.Class, tenant)...); err != nil { |
| 63 | return &Error{err.Error(), StatusForbidden, err} |
| 64 | } |
| 65 | |
| 66 | if input.Class == "" { |
| 67 | // NS-enabled: refuse the legacy scan-all-collections fallback. The |
| 68 | // REST layer rejects the deprecated route with 410 before this point; |
| 69 | // this is defensive for direct callers. |
| 70 | if m.config.Config.Namespaces.Enabled { |
| 71 | err := fmt.Errorf("replacing references without a class is not supported; use /objects/{className}/{id}/references/{propertyName}") |
| 72 | return &Error{err.Error(), StatusGone, err} |
| 73 | } |
| 74 | if err := m.authorizer.Authorize(ctx, principal, authorization.READ, authorization.Collections()...); err != nil { |
| 75 | return &Error{err.Error(), StatusForbidden, err} |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | res, err := m.getObjectFromRepo(ctx, input.Class, input.ID, additional.Properties{}, nil, tenant) |
| 80 | if err != nil { |
| 81 | errnf := ErrNotFound{} |
| 82 | if errors.As(err, &errnf) { |
| 83 | if input.Class == "" { // for backward comp reasons |
| 84 | return &Error{"source object deprecated", StatusBadRequest, err} |
| 85 | } |
| 86 | return &Error{"source object", StatusNotFound, err} |
| 87 | } else if errors.As(err, &ErrMultiTenancy{}) { |
| 88 | return &Error{"source object", StatusUnprocessableEntity, err} |
| 89 | } |
| 90 | return &Error{"source object", StatusInternalServerError, err} |
| 91 | } |
| 92 | input.Class = res.ClassName |
| 93 | |
| 94 | if err := validateReferenceName(input.Class, input.Property); err != nil { |
| 95 | return &Error{err.Error(), StatusBadRequest, err} |
| 96 | } |
| 97 | |
| 98 | class, schemaVersion, _, typedErr := m.getAuthorizedFromClass(ctx, principal, input.Class) |
| 99 | if typedErr != nil { |
| 100 | return typedErr |
| 101 | } |
| 102 | |
| 103 | validator := validation.New(m.vectorRepo.Exists, m.config, repl, |
| 104 | principal, m.config.Config.Namespaces.Enabled) |
nothing calls this directly
no test coverage detected