It's all about the answers!

Ask a question

How to fetch role of a logged in user


Chandan M B (1132963) | asked Jun 20 '15, 12:24 p.m.
edited Jun 20 '15, 4:15 p.m. by Ralph Schoon (62.0k33643)
 Hi,
From my server side rtc extension plugin I need to fetch the role of a logged in user. Please let me know how to do it...


Accepted answer


permanent link
sam detweiler (12.5k6189201) | answered Jun 20 '15, 4:04 p.m.
I use this method to GET the users roles in a project area.
it is deprecated, and I haven't found what the replacement is yet.

com.ibm.team.process.internal.common.RolePersistence.getPersistentRoleData(IProkectArea.getTeamData(), IContrinutorHandle srcuser)

note that a user might have multiple roles.
Chandan M B selected this answer as the correct answer

Comments
Chandan M B commented Jun 22 '15, 2:12 a.m.

Hi Sam,
Thank you.
One more question, how to fetch details of Approval tab.
Do you have any sample snippet?

Regards,
Chandan


sam detweiler commented Jun 22 '15, 6:20 a.m.

IApprovals =  IWorkItem.getApprovals()

see the javadoc that is provided as part of the product downloads


Chandan M B commented Jun 22 '15, 7:34 a.m.

Thanks for the Approval code.
But i feel role of a logged in user, i am not able to fetch from the server extensions plugin.
How to do it... ?


sam detweiler commented Jun 22 '15, 7:56 a.m.

I used the code from my server participant plugin, built on Ralph's

I showed you the types, not the exact code..

I am not aware of any role restriction that would prevent you from reading the approvals from a workitem.

the newstate is a workitem, so, once you cast, then you should be able to use the getApprovals() method.

here are the two exact statements

            // Get the full state of the parent work item so we can edit it
            IWorkItem workingCopy = (IWorkItem) fWorkItemServer.getAuditableCommon().resolveAuditable(workItem, IWorkItem.FULL_PROFILE, monitor).getWorkingCopy();
   
            IApprovals approvals = workingCopy.getApprovals();


Chandan M B commented Jun 22 '15, 8:55 a.m.

I am able to fetch approval details.

I need to fetch the roles of logged-in alm user. I am not able to achieve it.
I need a snippet to fetch user role for a project Area.


sam detweiler commented Jun 22 '15, 9:05 a.m. | edited Jun 22 '15, 9:06 a.m.

the AbstractService your plugin extends, provides a method,
getAuthenticatedContributor(), which returns the current Contributor (aka  user ) handle

which you can then use on the prior RolePersistance method


Ralph Schoon commented Jun 22 '15, 9:09 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

Consider reading some of the links provided below. They show the API that you can use to get the roles of a user. The API is common and can be used on client as well as server. Especially read https://rsjazz.wordpress.com/2015/06/19/a-custom-condition-to-make-attributes-required-or-read-only-by-role/

showing 5 of 7 show 2 more comments

One other answer



permanent link
Ralph Schoon (62.0k33643) | answered Jun 22 '15, 2:27 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER
 Also see https://rsjazz.wordpress.com/2015/06/19/a-custom-condition-to-make-attributes-required-or-read-only-by-role/ for how to do that.

Comments
Ralph Schoon commented Jun 22 '15, 6:46 a.m.
FORUM ADMINISTRATOR / FORUM MODERATOR / JAZZ DEVELOPER

also see https://rsjazz.wordpress.com/2012/10/01/adding-approvals-to-work-items-using-the-plain-java-client-libraries/ and https://rsjazz.wordpress.com/2012/11/30/a-create-approval-work-item-save-participant/ for how to use the approval API.

Your answer


Register or to post your answer.