Jazz Forum Welcome to the Jazz Community Forum Connect and collaborate with IBM Engineering experts and users

How to prevent the users to add invalid approvers?

Hi All,

In our project we have many roles like (Analyst, SC manager, Project manager, Developers, etc ..)

Lets take a workitem "Task" and I need to permit the endusers to add only the members of Project Managers as approvers in the approval tab.

I can enforce the pre condition to permit approvals only Project Mangers, but how to prevent the enduser to add a incorrect approver?

Is that possible?

Cheers,
Jose

0 votes



8 answers

Permanent link
I never tried to change any dialog. I think attribute Validators or Providers may be easier to implement, but I also never tried it.

You can easily make an IOperationAdvisor like this:



public class CheckApproverAdvisor extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
IApprovals approvals = workItem.getApprovals();
if (approvals!=null) {
IProcessServerService processServerService = getService(IProcessServerService.class);
List<IApproval> apprList = approvals.getContents();
for (IApproval appr : apprList) {
if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {
IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");
collector.addInfo(info);
break;
}
}
}
}
}
}

private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {
try {
IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);
for (IRole role : contributorRoles) {
if (role.getId().equals("project_manager")) {
return true;
}
}
return false;
} catch (TeamRepositoryException e) {
return false;
}
}
}



I didn't test it, but I think it would be something like that.

1 vote


Permanent link
Hi Jose,

I don't believe you can prevent users from adding an incorrect approver in the first place, the dialog will let you choose from any users in the repository. But as you said, this is something you can do with a precondition.

Parker
Jazz Foundation | Process team

0 votes


Permanent link
Hi Parker,

Thanks for your reply.

Could you please update me if you find any sample customized precondition examples?

Cheers,
Jose

Hi Jose,

I don't believe you can prevent users from adding an incorrect approver in the first place, the dialog will let you choose from any users in the repository. But as you said, this is something you can do with a precondition.

Parker
Jazz Foundation | Process team

0 votes


Permanent link
Hi Jose,

Depending on how you want things to work, this is something you could do with the pre-canned preconditions that come with RTC. Depending on what version of RTC you are using (I'm looking at 3.0.1 as I type this) you can put a precondition on Team Configuration > Operation Behavior > Source Control > Deliver (server) called Require Work Item Approval. This will prevent deliveries, but will not prevent the work item from being saved.

Parker
Jazz Foundation | Process team

0 votes


Permanent link
Hi Parker,

Thanks a lot.

Is there is any way to customize the dialog, so that the users can select the members only from "Project Manager" role?

Cheers,
Simon

Hi Jose,

Depending on how you want things to work, this is something you could do with the pre-canned preconditions that come with RTC. Depending on what version of RTC you are using (I'm looking at 3.0.1 as I type this) you can put a precondition on Team Configuration > Operation Behavior > Source Control > Deliver (server) called Require Work Item Approval. This will prevent deliveries, but will not prevent the work item from being saved.

Parker
Jazz Foundation | Process team

0 votes


Permanent link
Hi Edwardo,

Good Morning.

I have created a plugin project and tried to use your code.It has unresolved methods.

Source code:
CheckApprovers.java

package checkapprovers;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.apt.api.common.process.IProcessArea;
import com.ibm.team.apt.api.common.workitem.IWorkItem;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.IRole;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfo;

importcom.ibm.team.process.common.advice.IAdvisorInfoCollector;

import com.ibm.team.process.common.advice.runtime.IOperationAdvisor;

import com.ibm.team.process.service.IProcessServerService;

import com.ibm.team.repository.common.IAuditable;

import com.ibm.team.repository.common.IContributorHandle;

import com.ibm.team.repository.common.TeamRepositoryException;

import com.ibm.team.repository.service.AbstractService;

import com.ibm.team.workitem.common.ISaveParameter;

import com.ibm.team.workitem.common.model.IApproval;

import com.ibm.team.workitem.common.model.IApprovals;


public class CheckApprovers extends AbstractService implements IOperationAdvisor {


public void run(AdvisableOperation operation,

IProcessConfigurationElement advisorConfiguration,

IAdvisorInfoCollector collector, IProgressMonitor monitor)

throws TeamRepositoryException {

Object data = operation.getOperationData();

// The action is save

if (data instanceof ISaveParameter) {

ISaveParameter saveParameter = (ISaveParameter) data;

IAuditable auditable = saveParameter.getNewState();

// WorkItem Object

if (auditable instanceof IWorkItem) {

IWorkItem workItem = (IWorkItem) auditable;

IApprovals approvals = workItem.getApprovals();

if (approvals!=null) {

IProcessServerService processServerService = getService(IProcessServerService.class);

List<IApproval> apprList = approvals.getContents();

for (IApproval appr : apprList) {

if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {

IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");

collector.addInfo(info);

break;

}

}

}

}


}

}



private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {

try {

IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);

for (IRole role : contributorRoles) {

if (role.getId().equals("project_manager")) {

return true;

}

}

return false;

} catch (TeamRepositoryException e) {

return false;

}

}

}

##############################################################

Unresolved Methods:

IApprovals approvals = workItem.getApprovals();

Any idea on this? Do I need to include any more libraries?

Waiting for your reply.

Cheers,

jose





I never tried to change any dialog. I think attribute Validators or Providers may be easier to implement, but I also never tried it.

You can easily make an IOperationAdvisor like this:



public class CheckApproverAdvisor extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
IApprovals approvals = workItem.getApprovals();
if (approvals!=null) {
IProcessServerService processServerService = getService(IProcessServerService.class);
List<IApproval> apprList = approvals.getContents();
for (IApproval appr : apprList) {
if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {
IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");
collector.addInfo(info);
break;
}
}
}
}
}
}

private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {
try {
IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);
for (IRole role : contributorRoles) {
if (role.getId().equals("project_manager")) {
return true;
}
}
return false;
} catch (TeamRepositoryException e) {
return false;
}
}
}



I didn't test it, but I think it would be something like that.

0 votes


Permanent link
Hi Edwardo,

I changed "com.ibm.team.apt.api.common.workitem.IWorkItem;" to "com.ibm.team.workitem.common.model.IWorkItem;" and workItem.getApprovals(); method get resolved.

Now only one method is not resolving.

IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);

Source code:
CheckApprovers.java

package checkapprovers;

import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;

import com.ibm.team.apt.api.common.process.IProcessArea;
//import com.ibm.team.apt.api.common.workitem.IWorkItem;
import com.ibm.team.workitem.common.model.IWorkItem;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.IRole;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfo;
import com.ibm.team.process.common.advice.IAdvisorInfoCollector;
import com.ibm.team.process.common.advice.runtime.IOperationAdvisor;
import com.ibm.team.process.service.IProcessServerService;
import com.ibm.team.repository.common.IAuditable;
import com.ibm.team.repository.common.IContributorHandle;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.service.AbstractService;
import com.ibm.team.workitem.common.ISaveParameter;
import com.ibm.team.workitem.common.model.IApproval;
import com.ibm.team.workitem.common.model.IApprovals;

public class CheckApprovers extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
IApprovals approvals = workItem.getApprovals();
if (approvals!=null) {
IProcessServerService processServerService = getService(IProcessServerService.class);
List<IApproval> apprList = approvals.getContents();
for (IApproval appr : apprList) {
if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {
IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");
collector.addInfo(info);
break;
}
}
}
}
}
}

private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {
try {
IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);
for (IRole role : contributorRoles) {
if (role.getId().equals("project_manager")) {
return true;
}
}
return false;
} catch (TeamRepositoryException e) {
return false;
}
}
}



Cheers,
Jose





Hi Edwardo,

Good Morning.

I have created a plugin project and tried to use your code.It has unresolved methods.

Source code:
CheckApprovers.java

package checkapprovers;
import java.util.List;

import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.apt.api.common.process.IProcessArea;
import com.ibm.team.apt.api.common.workitem.IWorkItem;
import com.ibm.team.process.common.IProcessConfigurationElement;
import com.ibm.team.process.common.IRole;
import com.ibm.team.process.common.advice.AdvisableOperation;
import com.ibm.team.process.common.advice.IAdvisorInfo;

importcom.ibm.team.process.common.advice.IAdvisorInfoCollector;

import com.ibm.team.process.common.advice.runtime.IOperationAdvisor;

import com.ibm.team.process.service.IProcessServerService;

import com.ibm.team.repository.common.IAuditable;

import com.ibm.team.repository.common.IContributorHandle;

import com.ibm.team.repository.common.TeamRepositoryException;

import com.ibm.team.repository.service.AbstractService;

import com.ibm.team.workitem.common.ISaveParameter;

import com.ibm.team.workitem.common.model.IApproval;

import com.ibm.team.workitem.common.model.IApprovals;


public class CheckApprovers extends AbstractService implements IOperationAdvisor {


public void run(AdvisableOperation operation,

IProcessConfigurationElement advisorConfiguration,

IAdvisorInfoCollector collector, IProgressMonitor monitor)

throws TeamRepositoryException {

Object data = operation.getOperationData();

// The action is save

if (data instanceof ISaveParameter) {

ISaveParameter saveParameter = (ISaveParameter) data;

IAuditable auditable = saveParameter.getNewState();

// WorkItem Object

if (auditable instanceof IWorkItem) {

IWorkItem workItem = (IWorkItem) auditable;

IApprovals approvals = workItem.getApprovals();

if (approvals!=null) {

IProcessServerService processServerService = getService(IProcessServerService.class);

List<IApproval> apprList = approvals.getContents();

for (IApproval appr : apprList) {

if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {

IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");

collector.addInfo(info);

break;

}

}

}

}


}

}



private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {

try {

IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);

for (IRole role : contributorRoles) {

if (role.getId().equals("project_manager")) {

return true;

}

}

return false;

} catch (TeamRepositoryException e) {

return false;

}

}

}

##############################################################

Unresolved Methods:

IApprovals approvals = workItem.getApprovals();

Any idea on this? Do I need to include any more libraries?

Waiting for your reply.

Cheers,

jose





I never tried to change any dialog. I think attribute Validators or Providers may be easier to implement, but I also never tried it.

You can easily make an IOperationAdvisor like this:



public class CheckApproverAdvisor extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
IApprovals approvals = workItem.getApprovals();
if (approvals!=null) {
IProcessServerService processServerService = getService(IProcessServerService.class);
List<IApproval> apprList = approvals.getContents();
for (IApproval appr : apprList) {
if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {
IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");
collector.addInfo(info);
break;
}
}
}
}
}
}

private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {
try {
IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);
for (IRole role : contributorRoles) {
if (role.getId().equals("project_manager")) {
return true;
}
}
return false;
} catch (TeamRepositoryException e) {
return false;
}
}
}



I didn't test it, but I think it would be something like that.

0 votes


Permanent link
Hi, for the following demo code, which operation should I extend?
Save Work Item? or others?
Thanks!
I never tried to change any dialog. I think attribute Validators or Providers may be easier to implement, but I also never tried it.

You can easily make an IOperationAdvisor like this:



public class CheckApproverAdvisor extends AbstractService implements IOperationAdvisor {

public void run(AdvisableOperation operation, IProcessConfigurationElement advisorConfiguration, IAdvisorInfoCollector collector, IProgressMonitor monitor) throws TeamRepositoryException {
Object data = operation.getOperationData();
// The action is save
if (data instanceof ISaveParameter) {
ISaveParameter saveParameter = (ISaveParameter) data;
IAuditable auditable = saveParameter.getNewState();
// WorkItem Object
if (auditable instanceof IWorkItem) {
IWorkItem workItem = (IWorkItem) auditable;
IApprovals approvals = workItem.getApprovals();
if (approvals!=null) {
IProcessServerService processServerService = getService(IProcessServerService.class);
List<IApproval> apprList = approvals.getContents();
for (IApproval appr : apprList) {
if (!isProjectManager(processServerService, operation.getProcessArea(), appr.getApprover())) {
IAdvisorInfo info = collector.createProblemInfo("Only Project Managers can be set as Approver", "Only Project Managers can be set as Approver", "error");
collector.addInfo(info);
break;
}
}
}
}
}
}

private boolean isProjectManager(IProcessServerService processServerService, IProcessArea processArea, IContributorHandle approver) {
try {
IRole[] contributorRoles = processServerService.getServerProcess(processArea).getContributorRoles( approver, processArea);
for (IRole role : contributorRoles) {
if (role.getId().equals("project_manager")) {
return true;
}
}
return false;
} catch (TeamRepositoryException e) {
return false;
}
}
}



I didn't test it, but I think it would be something like that.

0 votes

Your answer

Register or log in to post your answer.

Dashboards and work items are no longer publicly available, so some links may be invalid. We now provide similar information through other means. Learn more here.

Search context
Follow this question

By Email: 

Once you sign in you will be able to subscribe for any updates here.

By RSS:

Answers
Answers and Comments
Question details

Question asked: Dec 14 '11, 10:52 a.m.

Question was seen: 6,809 times

Last updated: Dec 14 '11, 10:52 a.m.

Confirmation Cancel Confirm