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?
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"; } }
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:
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you do not insist on doing this via REST, take a look at this plugin.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.