Read - edit mode [Not Appearing together]

Hi Team ,

Currently as per current implementation of the Entity permissions
[read update create delete]

If user is granted [read] permission he will be able to see View Button
If user is granted [update] permission he will be able to see Edit Button
If user is granted [read update] permission he will be able to see Edit Button without View Button

Is their is a way to show both buttons other than adding below code snipt

<action id="view"  type="view" /> 
<button action="Table.view">

Cause if the user is granted the read only mode when he open the browser screen he will see two view buttons one which is reversing Edit button to View the other one is the View action which is defined inside XML

Thanks

Hi,

No, because these are different actions: edit and view. In case a user has no permission to UPDATE an entity, the edit action changes its caption in the refreshState() method:

...
if (security.isEntityOpPermitted(metaClass, EntityOp.UPDATE)) {
    setCaption(messages.getMainMessage("actions.Edit"));
} else {
    setCaption(messages.getMainMessage("actions.View"));
}
...

If you want to have two actions edit and view if a user has permission to UPDATE an entity and only one otherwise, I would recommend making one of the actions invisible programmatically in a screen controller, e.g.:

public class PetTypeBrowse extends StandardLookup<PetType> {
    @Named("petTypesTable.view")
    private ViewAction<PetType> petTypesTableView;

    @Inject
    private CollectionContainer<PetType> petTypesDc;

    @Inject
    private Security security;

    @Subscribe
    public void onInit(InitEvent event) {
        boolean entityOpPermitted = security.isEntityOpPermitted(petTypesDc.getEntityMetaClass(), EntityOp.UPDATE);
        petTypesTableView.setVisible(entityOpPermitted);
    }
}

Regards,
Gleb

1 Like