Lock edit screen after approval

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

Hi Lloyd,

The most reliable way is to introduce named permissions in your system:

  1. 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>
  1. Set it for your role

  2. 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);
}

I tried the last solution which will work perfect for me, but i keep getting method onBeforeShowEvent is never used. Am i missing something?

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);
}

Question can this be applied in cuba 6.10.15?

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);
        }
    }
}

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:

  1. I created the named permission:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
  1. I assigned the permission to a role:
    afbeelding

  2. 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.

Hello, Lloyd!

I suggest you debug your code. We have a tutorial on Youtube: