It's all about the answers!

Ask a question

How to programmatically get all streams that user has access to? (server side)

Eduardo Bello (4401922) | asked Sep 10 '14, 12:34 p.m.

  I'm trying to build something that returns all streams that logged user has access to.

  I was unable to get proper services within IValueSetProvider (getPeer and requiredInterfaces doesn't works).

  So my idea is to build a RestService (based on

  I'm able to get the contributor with getAuthenticatedContributor(). But now, I want to find all streams that this user has access to.

  My first approach was to use IScmQueryService. Using findWorkspace() method requires IWorkspaceSearchCriteria, but this method doesn't give me option for a "access" criteria, only owner criteria (which can be ProjectArea or TeamArea or Contributor...)

  I'm afraid that I'll have to use IProcessService.findTeamAreas to find out all user's team areas, then loop those team areas using IScmQueryService.findWorkspace() passing ownerName = TeamArea Name...

   Is there an easier way to do it? Please say "yes" :)



3 answers

permanent link
Remy Suen (426224) | answered Sep 12 '14, 10:40 a.m.
You can use the getFilterByOwnerOptional() List in IWorkspaceSearchCriteria to append the project areas' and team areas' IProcessAreaHandles. When you ask the server for the workspaces, it will already filter out any streams that are owned by a team area that the currently logged in user is not a part of (assuming the visibility has been set as such).

That is, consider a stream X owned by team area Y whose visibility is set to be private to the team area. If I ask the server to return the list of streams owned by team area Y, it will not return stream X if I am not a member of team area Y.

permanent link
Ralph Schoon (63.3k33646) | answered Sep 11 '14, 4:25 a.m.
What does access mean? Read access? Write Access?

I don't think it would be that easy. I am not sure how to approach this. You would have to evaluate which roles in which team areas a user has and then, from the ownership and the visibility of a stream deduce if the user has access to it.

This is certainly going to be complex. If you are logged in as a user you could get all the streams and would only get the ones you have read access to, I believe. The permission aware API should only show these.

Eduardo Bello commented Sep 11 '14, 6:59 a.m.
Read access is fine.

There must to exist some internal function that does that. Because it is just what we see in IDE Client when we expand "Source Control" item, a list of streams that are visible to the user.

I'll investigate a little more. Thanks.

Ralph Schoon commented Sep 11 '14, 8:36 a.m.

If your use case would be clearer, there might be ways. However, the API that shows the views works with a certain user being logged in and provided him with what he can see. If you want to do the same with a different user being logged in (to create a report) it is an entirely different approach that could be very hard. See for some clues - however, this is client code.

permanent link
Eduardo Bello (4401922) | answered Sep 11 '14, 1:32 p.m.
 My use case would be something like:

   An workitem has an attribute for StreamName and another for ComponentName.

  1. The user creates an work item and choose a value for the attribute StreamName (String), using presentation "Value Set Picker". The values presented to user would be only the names of streams that user has at least read access.

  2. After that, the user choose a value  for the attribute ComponentName (String), using another presentation "Value Set Picker". The value presented to the user would be only components added to the stream previously choosed

Currently I have this solution:

  The StreamName attribute is choosed with a 'HTTP Filtered Value Set' that points to the URL: 

  But this returns every existing streams. (note parameter 'size=600', soon I'll have to increase this value to return more results)

  And the 'ComponentName' attribute is choosed with another 'HTTP Filtered Value Set' that points to the URL: 

  This also returns every component in repository.

  I tried to use Java Value Sets, but I was unable to instantiate needed services. Now, my approach is to create webservices that provides the corrects names. And use 'HTTP Filtered Value Set' to get it in workitem.

Ralph Schoon commented Sep 12 '14, 4:53 a.m.

I would be interested in the solution to that use case too. However, I don't have the time currently to look into it.

I would look into Java Value Provider The issue here is that you only have the IWorkItemCommon interface. This leads to AudibleCommon. As getPeer() is deprecated, I don't know how to get to the SCM service. Also, as this has to run in the server as well as in the client,it would have to run on common interfaces only.

Your answer

Register or 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.