Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can I get a list of users on a repo/project?

Rocco DeMalia September 1, 2014

I want to retrieve a list of users based on the project or repository, is this possible using the stash api?

Example link would be like ../rest/api/1.0/projects/{project_key}/repo/users

Is there anything like this at all?

3 answers

1 accepted

0 votes
Answer accepted
Rocco DeMalia September 18, 2014

I have solved it.

If you are using Perl and get the project name, and repo name you can do this to get the people on a porject/repo just by using the API.

for my $group(  @{$groupJson_array->{values}} ){
		 		# print "\t\t\t". $group->{group}->{name} ."\n";
		 		# print "\t\t\t". $group->{permission} ."\n";
		 		#Connect to the users link of the stash API to retrieve a list of all if the users.
		 		my $userResponse = $client->GET("/rest/api/1.0/admin/groups/more-members?context=".$group->{group}->{name});
				#Format our JSON object that is returned into something useable.
				my $userJson = JSON->new->utf8->allow_nonref;
				my $userJson_text = $client->responseContent();
				my $userJson_array = $userJson->decode( $userJson_text);
				#Loop through the users to the get their names and corpID's and print them to the respective file.
				for my $user(  @{$userJson_array->{values}} ){
					print $fuser $group->{group}->{name}, ",", $group->{permission}, ",", $user->{name}, ",", $user->{displayName}, "\n";
				}
		 	}
0 votes
TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2014

Hi Rocco,

It's possible to get a list of users who have been granted permissions on a particular to a repository using:

/rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/permissions/users

or a particular project using:

/rest/api/1.0/projects/{projectKey}/permissions/users

However, this will only show the users that have explicit been granted permissions to a resource. To determine who actually has permission to READ, WRITE or ADMIN a particular repository, you'll need to make several requests:

  1. A request retrieving explicitly granted permissions for the repository (listed above)
  2. A request retrieving explicitly granted permissions applied to any groups for the repository
  3. A request for users granted permissions for the repository's parent project (as these permissions cascade down to the underlying repositories)
  4. A request for users granted permissions for the repository's parent project
  5. A request to determine any users granted Administrator or System Administrator privileges (as these cascade to all projects and repositories on the server)
  6. A request to determine any groups granted Administrator or System Administrator privileges

You can find the resources used to query these permissions in the Stash REST documentation.

The layered permissioning approach in Stash offers a lot of convenience and flexibility, but unfortunately makes it a little complicated to query via existing REST resources :)

The permission viewer plugin that Balazs mentioned may be a simpler solution.

cheers,

Tim

Rocco DeMalia September 2, 2014

Fair enough, thank you for the answer Tim. Is there a way to get the information that the plugin shows and export it to a CSV file?

TimP
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2014

I don't have any experience with the plugin but from the looks of it I'd say no. To get the kind of report you're talking about you may need to use the REST API as I outlined above.

Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 3, 2014

If you want to end up with a CSV file, it might be easier to do an SQL query on the database. Somebody had a question here about that already and there was a detailed answer, as far as I remember.

0 votes
Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 2, 2014

If you do not insist on doing this via REST, take a look at this plugin.

Rocco DeMalia September 2, 2014

I am just writing a script to get details that are not native and figured this would be easiest. I assume that means that it is not possible with the API?

Just to confirm this plugin, this will show a list of users who can see the repo, whether they have Read, Write, or Admin privelages, correct? Also, is there a way to export a list fo those users to a CSV file or is this report just native to stash?

Balázs Szakmáry
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 3, 2014

It shows the groups and the users in two groups: read and write. Admins are not listed separately. (There are some screenshots on the page I linked.) There is no export functionality.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events