1
0
mirror of https://github.com/rancher/norman.git synced 2025-09-16 15:21:33 +00:00

Major refactor of subcontexts

This commit is contained in:
Darren Shepherd
2018-02-09 13:31:12 -07:00
parent b62e043067
commit 722cedfe01
17 changed files with 319 additions and 300 deletions

View File

@@ -147,17 +147,26 @@ func (j *JSONResponseWriter) addLinks(b *builder.Builder, schema *types.Schema,
rawResource.Links["remove"] = self
}
subContextVersion := context.Schemas.SubContextVersionForSchema(schema)
for _, backRef := range context.Schemas.References(schema) {
if !backRef.Schema.CanList(context) {
continue
}
if schema.SubContext == "" {
if subContextVersion == nil {
rawResource.Links[backRef.Schema.PluralName] = context.URLBuilder.FilterLink(backRef.Schema, backRef.FieldName, rawResource.ID)
} else {
rawResource.Links[backRef.Schema.PluralName] = context.URLBuilder.SubContextCollection(schema, rawResource.ID, backRef.Schema)
}
}
if subContextVersion != nil {
for _, subSchema := range context.Schemas.SchemasForVersion(*subContextVersion) {
if subSchema.CanList(context) {
rawResource.Links[subSchema.PluralName] = context.URLBuilder.SubContextCollection(schema, rawResource.ID, subSchema)
}
}
}
}
func newCollection(apiContext *types.APIContext) *types.GenericCollection {