l37sedoc
(Lloyd S)
January 31, 2020, 12:41pm
#1
Hi,
I saw the topic “How to lock edit screen” and the given solution, which is fine. I almost need the same solution, but after the boolean is set to true and the whole edit screen is locked(no field can be edited only viewed) i want to be able to assign certain users (admin) who stil can remove the approved (boolean) and make the record editable again. In the previous topic this was the solution:
public class ContractEdit extends AbstractEditor<Contract> {
@Inject
private FieldGroup fieldGroup;
@Override
public void init(Map<String, Object> params) {
super.init(params);
Contract contract = (Contract) WindowParams.ITEM.getEntity(params);
if (contract != null && contract.getStatus() == Status.APPROVED) {
fieldGroup.setEditable(false);
}
}
}
How can i add a user role to this solution and lock all fields?
Regards,
Lloyd
sukhova
(Mariya Sukhova)
February 5, 2020, 10:23am
#3
Hi Lloyd,
The most reliable way is to introduce named permissions in your system:
Define specific permission :
<permission-config xmlns="http://schemas.haulmont.com/cuba/permissions.xsd">
<specific>
<category id="app">
<permission id="app.contractEdit"/>
</category>
</specific>
</permission-config>
Set it for your role
Now you will be able to check your permissions in the controller as follows:
@Inject
private Security security;
@Inject
private FieldGroup fieldGroup;
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
NewContract contract = getEditedEntity();
if (contract != null && !security.isSpecificPermitted("app.contractEdit"))
if (Boolean.TRUE.equals(contract.getStatus()))
fieldGroup.setEditable(true);
else
fieldGroup.setEditable(false);
}
l37sedoc
(Lloyd S)
February 7, 2020, 1:26pm
#5
I tried the last solution which will work perfect for me, but i keep getting method onBeforeShowEvent is never used. Am i missing something?
l37sedoc
(Lloyd S)
February 7, 2020, 1:39pm
#6
Controller:
@Subscribe
public void onBeforeShow(BeforeShowEvent event) {
NewDistrictMarowijne districtMarowijne = getEditedEntity();
if (districtMarowijne != null && !security.isSpecificPermitted("grs.districtMarowijneEdit"))
if (Boolean.TRUE.equals(districtMarowijne.getAkkoordDc()))
fieldGroup.setEditable(true);
else
fieldGroup.setEditable(false);
}
l37sedoc
(Lloyd S)
February 7, 2020, 5:51pm
#7
Question can this be applied in cuba 6.10.15?
sukhova
(Mariya Sukhova)
February 11, 2020, 9:03am
#8
Hello,
You should use the postInit()
method:
public class ContractEdit extends AbstractEditor<Contract> {
@Inject
private FieldGroup fieldGroup;
@Inject
private Security security;
@Inject
private EntityStates entityStates;
@Override
protected void postInit() {
if (!entityStates.isNew(getItem())) {
Contract contract = getItem();
if (contract != null && !security.isSpecificPermitted("app.contractEdit"))
if (Boolean.TRUE.equals(contract.getStatus()))
fieldGroup.setEditable(true);
else
fieldGroup.setEditable(false);
}
}
}
l37sedoc
(Lloyd S)
February 11, 2020, 2:53pm
#9
Thanks Mariya,
I followed the steps as discribed but still the edit page is editable after the boolean is set to true.
These are my steps:
I created the named permission:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
I assigned the permission to a role:
I set the boolean to true in the edit page.
When i login as a user with the role to which the permission is assigned. the page is still editable.
Am I missing something?
p.s. I upgrade the project to Cuba 7.1.4.
sukhova
(Mariya Sukhova)
February 13, 2020, 6:26am
#10
Hello, Lloyd!
I suggest you debug your code. We have a tutorial on Youtube: