Repository navigation
Move draft user description docu from Java to Fiori guide #2969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -482,6 +482,55 @@ You can override generated side-effect annotations per entity, for example: | |
| Can be disabled with <Config>cds.fiori.draft_messages: false</Config>. | ||
| ::: | ||
|
|
||
| ### Showing a Custom User Description { #draft-user-description} | ||
|
|
||
| By default, the SAP Fiori draft UI displays the unique user name in fields such as *Locked by*. To show a human-readable name instead, enable the `draftUserDescription` CDS compiler option and populate the generated `InProcessByUserDescription` field via a custom handler. | ||
|
|
||
| **1. Enable the compiler option** in your `.cdsrc.json`: | ||
|
|
||
| ```json | ||
| { | ||
| "cdsc": { | ||
| "draftUserDescription": true | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The compiler now adds `InProcessByUserDescription`, `CreatedByUserDescription`, and `LastChangedByUserDescription` to the `DraftAdministrativeData` entity. | ||
|
|
||
| **2. Register a handler** on draft events across all draft services to populate the field: | ||
|
|
||
| This is how the handler could look for CAP Java: | ||
|
|
||
| ```java | ||
| @Component | ||
| @ServiceName(value = "*", type = DraftService.class) | ||
| public class UserDescriptionHandler implements EventHandler { | ||
|
|
||
| @Autowired private UserInfo userInfo; | ||
|
|
||
| @Before | ||
| protected void addDraftFields(DraftPatchEventContext context, Order order) { | ||
| order.setInProcessByUserDescription(userInfo.getAdditionalAttribute("given_name") + " " | ||
| + userInfo.getAdditionalAttribute("family_name")description()); | ||
| } | ||
| } | ||
| ``` | ||
|
Comment on lines
+505
to
+518
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This handler is specific for CAP Java. I guess it should be possible to have a corresponding handler for CAP Node.js -> https://github.tools.sap/cap/cdsnode/issues/708#issuecomment-677683
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This handler is specific for @Before
protected void addDraftFields(DraftCreateEventContext context, List<Order> orders) {
orders.forEach(o -> o.setInProcessByUserDescription(description()));
}
private String description() {
return userInfo.getAdditionalAttribute("given_name")
+ " "
+ userInfo.getAdditionalAttribute("family_name");
}
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please check if this looks good now :) |
||
|
|
||
| This is the corresponding handler for CAP node.js: | ||
|
|
||
| ```javascript | ||
| srv.on('PATCH', Order, req => { | ||
| req.data.InProcessByUserDescription = req.user.attr.givenName + ' ' + req.user.attr.familyName | ||
| }) | ||
| ``` | ||
|
|
||
|
|
||
| ::: tip | ||
| The attribute names `given_name` and `family_name` correspond to JWT token claims provided by your IdP. Adjust them to match the claims configured in your environment. | ||
| ::: | ||
|
|
||
|
|
||
| ### Draft for Localized Data | ||
|
|
||
| Annotate the underlying base entity in the base model with `@fiori.draft.enabled` to also support drafts for [localized data](./localized-data): | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.