Get into the habit of writing together! This is the 8th day of my participation in the "Nuggets Daily New Plan · April Update Challenge", click to view the details of the event .
Use to cds init
initialize a CAP application, then npm install
, cds watch
start the server.
Create a schema file with the following content:
namespace sap.ui.riskmanagement;
using { managed } from '@sap/cds/common';
entity Risks : managed {
key ID : UUID @(Core.Computed : true);
title : String(100);
}
entity Mitigations : managed {
key ID : UUID @(Core.Computed : true);
risks : Association to many Risks on risks.miti = $self;
}
复制代码
Note that schema files can define namespaces.
The keys for these two models are automatically populated by the CAP server, which is exposed to service users using the annotation @(Core.Computed : true).
Only the entity cannot be consumed by the end user and needs to be exposed to the outside through the service.
Create a new file in srv
the folder risk-service.cds
, note that this file and the entity schema file are in a different folder (the former is in db
):
using { sap.ui.riskmanagement as my } from '../db/schema';
@path: 'service/risk'
service RiskService {
entity Risks as projection on my.Risks;
annotate Risks with @odata.draft.enabled;
entity Mitigations as projection on my.Mitigations;
annotate Mitigations with @odata.draft.enabled;
}
复制代码
Use the auto-generated page to cds watch
see :
The template file location for this index.html:
node_modules@sap\cds-dk\node_modules@sap\cds\app\index.html
roles
In the application security file (xs-security.json), the role templates property enables you to define an array that lists one or more (with corresponding scopes and any required properties) required to access a particular application module ). Multiple role templates can be defined, each with their own scope and properties.
one example:
"role-templates": [
{
"name" : "Editor",
"description" : "View, edit, delete books",
"scope-references" : [
"$XSAPPNAME.Edit", "$XSAPPNAME.Delete"
],
"attribute-references": [
"Country", "CostCenter"
]
},
]
复制代码
A role template must be instantiated. This is especially true for any attributes and concrete attribute values defined in the role template, which require customization and therefore cannot be provided automatically. Role templates that contain only "local" scope can be instantiated without user interaction. The same is true for foreign scopes, where the scope owner has declared consent in some kind of whitelist (eg for "public" use or known "friends").