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

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

Accepted Answer
0 votes

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";
				}
		 	}

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

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?

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.

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

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?

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.

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.

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted yesterday in Featured Groups

Tuesday tips & tricks: What is the Atlassian Community?

It's officially Tuesday, which means it's officially time for another tip to help you better navigate this space we call the Atlassian Community. 😄 I got a great question from community member, Sa...

43 views 2 4
View post

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you