03-23-2017 11:55 AM
Hi guys,
do you know if there is a way, in Activiti, to can make a process available just to a certain group of users?
For instance, we would like that only the "managers" could start an "Expense approval request" process.
Thanks
03-23-2017 01:47 PM
Kobe_,
This has been discussed once before on the Activiti forums. Please take a look at their findings for reference, and see if that gets you going in the right direction.
-JEarles
03-23-2017 01:47 PM
Kobe_,
This has been discussed once before on the Activiti forums. Please take a look at their findings for reference, and see if that gets you going in the right direction.
-JEarles
03-25-2017 07:16 AM
I think that, thanks to Jonathan, we solved the issue.
We modified the class ProcessDefinitionListQuery and recompiled the jar activiti-explorer-5.22.0.jar.
I post here is the new code for the class ProcessDefinitionListQuery just in case someone needs it.
package org.activiti.explorer.ui.process;
import java.util.ArrayList;
import java.util.List;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.identity.Group;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.repository.ProcessDefinitionQuery;
import org.activiti.engine.task.IdentityLink;
import org.activiti.explorer.ExplorerApp;
import org.activiti.explorer.data.AbstractLazyLoadingQuery;
import com.vaadin.data.Item;
import com.vaadin.data.util.PropertysetItem;
public class ProcessDefinitionListQuery extends AbstractLazyLoadingQuery {
protected transient RepositoryService repositoryService;
protected ProcessDefinitionFilter filter;
public ProcessDefinitionListQuery(RepositoryService repositoryService, ProcessDefinitionFilter filter) {
this.repositoryService = repositoryService;
this.filter = filter;
}
// we modified that method
public List<Item> loadItems(int start, int count) {
List<ProcessDefinition> processDefinitions = filter.getQuery(repositoryService).listPage(start, count);
List<Item> items = new ArrayList<Item>();
for (ProcessDefinition processDefinition : processDefinitions) {
boolean display=isVisibileToUser(processDefinition);
if(display){
items.add(filter.createItem(processDefinition));
}
}
return items;
}
// Method added
private boolean isVisibileToUser(ProcessDefinition processDefinition) {
// TODO Auto-generated method stub
boolean display= false;
if(!ExplorerApp.get().getLoggedInUser().isAdmin()){
List<Group> userGroups = ExplorerApp.get().getLoggedInUser().getGroups();
List<IdentityLink> candidateGroups = repositoryService.getIdentityLinksForProcessDefinition(processDefinition.getId());
for(int k=0;userGroups!=null && k<userGroups.size();k++){
Group usrGrp=userGroups.get(k);
for(int n=0; candidateGroups!=null && n<candidateGroups.size();n++){
IdentityLink allowGrp=candidateGroups.get(n);
if(allowGrp.getGroupId().equalsIgnoreCase(usrGrp.getId()) || allowGrp.getGroupId()==null || allowGrp.getGroupId().length()==0)
display=true;
}
// if no Candidate group is provided for that process, we show it to all the users
if(candidateGroups==null || candidateGroups.size()==0)
display=true;
}
}
else
display=true;
return display;
}
// we modified that method
public Item loadSingleResult(String id) {
ProcessDefinition definition = repositoryService.createProcessDefinitionQuery().processDefinitionId(id).singleResult();
if (definition != null && isVisibileToUser(definition)) {
return filter.createItem(definition);
}
return null;
}
public int size() {
// we modified that method
// is not that efficent but for our small environment (less than 50 processes deployed) it works
List<Item> totale = this.loadItems(0,10000);
return (int) totale.size();
}
public void setSorting(Object[] propertyId, boolean[] ascending) {
throw new UnsupportedOperationException();
}
public static class ProcessDefinitionListItem extends PropertysetItem implements Comparable<ProcessDefinitionListItem>{
private static final long serialVersionUID = 1L;
public int compareTo(ProcessDefinitionListItem other) {
// process definitions are ordered by name (see #loadItems in query)
String name = (String) getItemProperty("name").getValue();
String otherName = (String) other.getItemProperty("name").getValue();
int comparison = name.compareTo(otherName);
// Name is not unique for process definition
// But the list is sorted on process definition key also, so we can use it to compare if the name is equal
if (comparison != 0) {
return comparison;
} else {
String key = (String) getItemProperty("key").getValue();
String otherKey = (String) other.getItemProperty("key").getValue();
return key.compareTo(otherKey);
}
}
}
}
Explore our Alfresco products with the links below. Use labels to filter content by product module.