work item customization: getting current user as logged in user
Hello,
is there possible to get current logged user with JavaScript API?
I 've tried with custom attribute of type contributor with setting default value as authenticated user.
As authenticated user I can only get the user who created work item, not really logged user. So, this is the same if I used work item creator, right?
Currently, I am doing some important implementation with work items where I have next rules defined:
Let's say that I have a custom attribute verified with two choises: Yes and No. By default, No is chosen.
Now, let's say that only one role (project lead) can set this attribute to Yes, and when another role (wi owner-developer) wants to set up this attribute to Yes, on wi saving, it resets automatically to No.
As I can't access with JavaScript to user role, I created Default Value Role Based user list, and got the user with specific role.
So, I created the rule when the work item owner (developer) and role based user (project lead) are different, on wi saving, custom attribute verified resets automatically to No.
Also, I created another rule when role based user (project lead) and authenticated user are the same, on wi saving, custom attribute verified resets automatically to Yes.
So, the problem is that authenticated user is always the same user who created work item, not currently logged in user.
My problem would be solved if any of these funcionality are supported:
accessing user role or getting currently logged in user.
Can anyone help me with this or tell me if any of mentioned functionalities are supported?
Thanks,
Accepted answer
Very easy
...
dojo.require("com.ibm.team.repository.web.client.session.Session");
...
(function() {
...
var WorkItemAttributes = com.ibm.team.workitem.api.common.WorkItemAttributes;
var getAuthenticatedContributor = com.ibm.team.repository.web.client.session.getAuthenticatedContributor;
dojo.declare("com.ibm.san.ariadna.process.SampleReadOnlyCondition", null,
{
matches : function(workItem, configuration) {
var loggedInUser = getAuthenticatedContributor().itemId;
var owner = workItem.getValue(WorkItemAttributes.OWNER);
var result = (loggedInUser != owner);
return result;
}
});
})();
Hope this help
Comments
showing 5 of 8
show 3 more comments
2 other answers
Milan, look at rsjazz.wordpress.com for API examples. Dependent on what API u use, you can access the logged in user using methods on the team repository object or through the abstract service. You can search the blog. Search for authenticated user for example.
Comments
1 vote
showing 5 of 14
show 9 more comments
Hi Ralph,
thank you very much for the help.
Now, I have a situation where I created calculate value provider in Java, and deployed it successfully. I was able to see it in Project Area Attribute Customization, but when I want to put it to be shown on some wi attribute, I can't choose it, it looks like it doesn't exist, but in Project Area Attribute Customization it really exists.
What could be a problem?
Here is my java code (regarding the current user role, I want to retrieve some string):
--------------------------------------------------------------------------------
package hr.apisit.hello;
import java.util.List;
import org.eclipse.core.runtime.IProgressMonitor;
import com.ibm.team.repository.common.TeamRepositoryException;
import com.ibm.team.repository.common.IContributorHandle;
import com.ibm.team.workitem.common.IWorkItemCommon;
import com.ibm.team.workitem.common.internal.attributeValueProviders.IConfiguration;
import com.ibm.team.workitem.common.internal.attributeValueProviders.IValueProvider;
import com.ibm.team.workitem.common.model.IAttribute;
import com.ibm.team.workitem.common.model.IWorkItem;
public class IzracunRole implements IValueProvider<String> {
@Override
public String getValue(IAttribute attribute, IWorkItem workItem,
IWorkItemCommon workItemCommon, IConfiguration configuration,
IProgressMonitor monitor) throws TeamRepositoryException {
List lookupRoles = ContributorUtil.getConfiguration(configuration);
IContributorHandle user= workItemCommon.getAuditableCommon().getUser();
Boolean usrRole = ContributorUtil.hasRole(workItem, user, lookupRoles, workItemCommon, monitor);
if(usrRole == true){
return "right role";
}
else
{
return "wrong role";
}
}
}
-------------------------------------------------------------------------------
Comments
1 vote
showing 5 of 7
show 2 more comments