How to link two registry schema's #163
Replies: 6 comments 5 replies
-
Hi @shiva-rakshith, A possible solution is to add two properties to the
User Schema
{
// This must be at the top of all schemas. See http://json-schema.org/understanding-json-schema/reference/schema.html#schema
"$schema": "http://json-schema.org/draft-07/schema",
// This is a schema object...
"type": "object",
// ...that declares the User entity
"properties": {
"User": { "$ref": "#/definitions/User" }
},
"required": ["User"],
"definitions": {
// The actual definition of the User entity
"User": {
// The path to the declaration in the schema entity
"$id": "#/definitions/User",
// A User is an object...
"type": "object",
// ...with the `name`, `email`, `phone`, `organization` and `role` fields:
"required": ["name", "email", "phone", "organization", "role"],
"uniqueIndexFields": ["email"],
"properties": {
"name": { "type": "string" },
"email": { "type": "string" },
"phone": { "type": "string" },
"organization": {
// An organization is a link to an Organization entity in the registry
"$ref": "organization.json/#/definitions/Organization"
},
"role": { "type": "string" }
}
}
},
"_osConfig": {
// The following fields are used to create a corresponding user in Keycloak,
// the authentication service used by Sunbird RC.
"ownershipAttributes": [
{
// The path to the field to consider the email of the entity
"email": "/email",
// The path to the field to consider the phone number of the entity
"mobile": "/phone",
// The path to the field to consider as unique ID of the entity
"userId": "/email"
}
],
// The `organization` and `role` fields must be attested before they can be considered valid
"attestationAttributes": ["organization", "role"],
"attestationPolicies": [
{
// The name of the field
"property": "organization",
// The path to the field (dot-separate fields if the field is nested, $
// is the root of the entity)
"paths": ["$.organization"],
// The claim must be attested by a `User` entity manually
"type": "MANUAL",
"attestorEntity": "User",
// The attesting entity must be in the same organization AND be an admin in that organization
"conditions": "(ATTESTOR#$.organization#.contains(REQUESTER#$.organization#) && (ATTESTOR#$.role#.contains('admin'))"
},
{
// The name of the field
"property": "role",
// The path to the field (dot-separate fields if the field is nested, $
// is the root of the entity)
"paths": ["$.role"],
// The claim must be attested by a `User` entity manually
"type": "MANUAL",
"attestorEntity": "User",
// The attesting entity must be in the same organization AND be an admin in that organization
"conditions": "(ATTESTOR#$.organization#.contains(REQUESTER#$.organization#) && (ATTESTOR#$.role#.contains('admin'))"
}
]
}
} Organization Schema
{
// This must be at the top of all schemas. See http://json-schema.org/understanding-json-schema/reference/schema.html#schema
"$schema": "http://json-schema.org/draft-07/schema",
// This is a schema object...
"type": "object",
// ...that declares the Organization entity
"properties": {
"Organization": { "$ref": "#/definitions/Organization" }
},
"required": ["Organization"],
"definitions": {
// The actual definition of the Organization entity
"Organization": {
// The path to the declaration in the schema entity
"$id": "#/definitions/Organization",
// An Organization is an object...
"type": "object",
// ...with the `name` field:
"required": ["name"],
"properties": {
"name": { "type": "string" }
}
}
}
} Also, take a look at this step by step guide on making API calls to retrieve and create entities as well as making and attesting claims. Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
@dileepbapat could you help with this ? |
Beta Was this translation helpful? Give feedback.
-
Hi @dileepbapat @tejash-jl @kesavanp123 |
Beta Was this translation helpful? Give feedback.
-
Hi @dileepbapat @tejash-jl @kesavanp123 |
Beta Was this translation helpful? Give feedback.
-
yes, in the schema there is owership attribute that allows setting owner field for the entity. I guess this is useful in this usecase. |
Beta Was this translation helpful? Give feedback.
-
Hi @kesavanp123, I noticed that you can enforce the type of entity that can create a new type of entity in the registry (i.e.: Only a |
Beta Was this translation helpful? Give feedback.
-
We have two schema's(Organization and User), a few users may be admins who will have the special privileges to make changes to rest of the users. How can we link the users to Organization and validate that a particular user belongs to that organization?
cc: @vrayulu @maheshkumargangula
Beta Was this translation helpful? Give feedback.
All reactions