This seems like a simple requirement:
We have a document model, let’s call it “RequestConfig_DM”.
- Some users should be able to see all documents for this model in an overview engine and be able to add and edit documents.
- Other users should be able to just see all documents for this model, without being able to add or edit anything.
Would be nice if I can control this by using two access rights, let’s call those REQUEST_CONFIG_WRITE and REQUEST_CONFIG_WRITE, so that I can add these rights to existing roles as needed.
Authorization for other document models must not be affected.
So
- How do I hide/show the “Add” button in the overview engine accordingly?
- How do I show the associated form model in editable or read-only view accordingly?
- How do I secure the RPC endpoints accordingly (specifically for this model)?
Thanks a lot for your help!
I participate in a training right now, but will try it this afternoon.
So, I managed to get the Save button in the form disabled.
But how do I set the whole form to readonly? (I think it’s a usability bug if the fields are still editable.)
I tried this
function FormEngineWithAccessCheck(props: FormEngineViews.FormEngineProps): React.JSX.Element {
const user = useSelector(UaaSelectors.user) as UaaExtendedUser;
const selectedActivity: Activity | undefined = useSelector(ActivitySelectors.activityById(props.activityId));
const hasReadOnlyAccess = !checkFormModelEditAccessRights(user, selectedActivity);
const enablements = {
readonly: true, // <===== Does not work
byButtonName: {
["SaveButton"]: {
hidden: hasReadOnlyAccess
},
}
};
return (
<CRUDViews.FormEngineView
configuration={{readonly: true}} // <===== Does not work
enablements={enablements}
{...props}
/>
);
}
In the docs I found
- nice to know that the form engine “as a whole can be set … readonly”. But HOW?
- The warning says the settings “must not be used to enforce authorization”. I suppose this should read “these settings alone must not… You have to secure the serveer side, too”, right?
Also: How to enhance your example of the OverviewEngine, so that the actual required access right name is not hardcoded (like “WRITE”) here, but read from an annotation on either the OverviewModel or the DocumentModel?
(There are multiple overview engines and they should have different access right configuration.)
I can get the overview model name from props, but failed to access the actual model (as it may not even be loaded at the time the overview engine is instantiated.)
Once you have the overview model name, you can retrieve the overview model using something like ModelSelectors.modelByName(overviewModelName)(store.getState()) as OverviewModel.
From there, you’ll be able to access the annotations of the overview model.