Search the FirstSpirit Knowledge Base
Hi all,
I'm trying to set the worfklow permissions for certain groups via api.
The problem I have is that if the check for workflow allowed is not set, the groups I am setting via api is not saved.
If this check is marked, my code for setting the permissions works without problems.
Is there some way to set this check via api? Because so far I haven't been able to find it.
Code so far, try/catch omitted.
store.setLock(true);
Workflow workflow = templateStoreRoot.getWorkflowByName(workflowConfig.getName());
WorkflowPermission workflowPermission = store.getCreateWorkflowPermission(workflow);
for (Group group : groups) {
for(WorkflowConfiguration.Group configuredGroups : workflowConfig.getGroups()) {
if (group.getName().equals(configuredGroups.getName())) {
workflowPermission.allowGroup(group);
}
}
}
store.setWorkflowPermission(workflowPermission);
store.save(null, false);
store.release(false);
store.setLock(false);
Hello E-spirit,
I have exactly the same behavior like ncbruckner.
At the point of store.save() all information are lost and store.getWorkflowPermissions() returns an empty list.
Is there a solution?
Best regards
Matthias
Hi Matthias,
I didn't find one. In the end I went through all the projects and set the check marks and afterwards ran my script. That still saved me some time when going through 30 something projects but it's only a workaround and not a particularly satisfying one either.
Best regards,
Nina
Hi Nina-Christine,
thanks for that - not good - information.
I have to go through ~90 projects.
As long as the API does not work as expected i think I have to do it manually too. 😕
Best regards,
Matthias
Hi all,
this behavior is probably a bug. It seems that the workflow permissions can only be set if the corresponding permission object already exists.
Contact our TechSupport if you would like to be actively informed when this has been resolved or check the future FirstSpirit release notes for the ID "CORE-12618".
Best regards,
Holger
Hello Holger,
i already opend a bug report in TechSupport
Thank you for the Ticket ID.
Best regards,
Matthias
Hello everyone,
the TechSupport answered.
You need to add the following line:
store.setInheritWorkflowPermission(false);
It seems that you need to break the Inheritance.
The following script sets a permission on a folder.
Full example:
import de.espirit.firstspirit.access.store.Store;
userService = context.getUserService();
pageStoreFolder = context.getElement();
pageStoreFolder.setLock(true, false);
workflow = userService.getStore(Store.Type.TEMPLATESTORE, true, false).getWorkflowByName("release");
wfpermission = pageStoreFolder.getCreateWorkflowPermission(workflow);
group = context.project.getGroups().get(0);
wfpermission.allowGroup(group);
pageStoreFolder.setWorkflowPermission(wfpermission);
pageStoreFolder.setInheritWorkflowPermission(false);
pageStoreFolder.save("Saved Workflow rights", false);
pageStoreFolder.setLock(false, false);
Best regards
Matthias