Check executes a permission check based on the provided request. The permission field in the request can either be a relation or an permission. This function performs various checks and returns the permission check response along with any errors that may have occurred.
(ctx context.Context, request *base.PermissionCheckRequest)
| 61 | // This function performs various checks and returns the permission check response |
| 62 | // along with any errors that may have occurred. |
| 63 | func (engine *CheckEngine) Check(ctx context.Context, request *base.PermissionCheckRequest) (response *base.PermissionCheckResponse, err error) { |
| 64 | emptyResp := denied(emptyResponseMetadata()) |
| 65 | |
| 66 | // Retrieve entity definition |
| 67 | var en *base.EntityDefinition |
| 68 | en, _, err = engine.schemaReader.ReadEntityDefinition(ctx, request.GetTenantId(), request.GetEntity().GetType(), request.GetMetadata().GetSchemaVersion()) |
| 69 | if err != nil { |
| 70 | return emptyResp, err |
| 71 | } |
| 72 | |
| 73 | // Perform permission check |
| 74 | var res *base.PermissionCheckResponse |
| 75 | res, err = engine.check(ctx, request, en)(ctx) |
| 76 | if err != nil { |
| 77 | return emptyResp, err |
| 78 | } |
| 79 | |
| 80 | return &base.PermissionCheckResponse{ |
| 81 | Can: res.Can, |
| 82 | Metadata: res.Metadata, |
| 83 | }, nil |
| 84 | } |
| 85 | |
| 86 | // CheckFunction is a type that represents a function that takes a context |
| 87 | // and returns a PermissionCheckResponse along with an error. It is used |
nothing calls this directly
no test coverage detected