Get Authorized Repositories and Folders for a given User

Post your questions regarding using the Vault and Fortress API in your programs.

Moderator: SourceGear

Post Reply
ejhansen71
Posts: 61
Joined: Thu Nov 13, 2014 10:12 am
Location: Lake in the Hills, IL

Get Authorized Repositories and Folders for a given User

Post by ejhansen71 » Mon Apr 27, 2015 12:42 pm

Hi Beth - I'm back again for another difficult question.

I'm logged in as administrator on this GUI tool I built using Visual Studio and coding in C#.

I want to find out what Repositories and Folders a user is authorized to use. So I need to pass the server a username "ehansen" and have returned the Repositories the user has access to and then find out which folders under that Repository (root folders only...anything directly under "$/") the user has access to.

Can you provide the proper classes/methods to use and perhaps an example?
Thanks!

Eric

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: Get Authorized Repositories and Folders for a given User

Post by Beth » Mon Apr 27, 2015 4:10 pm

I moved this to the Development Forum since it relates to this.

I don't think you can get a listing of user rights from the API. I need to do a little more digging to see if I can come up with anything. I could maybe get a SQL query if that would help.
Beth Kieler
SourceGear Technical Support

ejhansen71
Posts: 61
Joined: Thu Nov 13, 2014 10:12 am
Location: Lake in the Hills, IL

Re: Get Authorized Repositories and Folders for a given User

Post by ejhansen71 » Tue Apr 28, 2015 10:43 am

A SQL query is better than nothing.

In the standard Vault GUI, When a user has access to only 1 repository (we have 6 totals) and he logs in, only the repository he has access to appears in the Repository selection box. This is what we want on our GUI as well.

In addition, once the repository is open, we want only the folders the user has access to to appear and suppress the rest. Currently your Vault GUI, while only allowing the Repositories they have access to to be selected from, still show all of the possible folders under that repository even if the user has no access to them..
Thanks!

Eric

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: Get Authorized Repositories and Folders for a given User

Post by Beth » Tue Apr 28, 2015 1:44 pm

When the user logs in, Vault should refuse to return anything to which the user doesn't have access. You shouldn't need to check the security yourself.
Beth Kieler
SourceGear Technical Support

ejhansen71
Posts: 61
Joined: Thu Nov 13, 2014 10:12 am
Location: Lake in the Hills, IL

Re: Get Authorized Repositories and Folders for a given User

Post by ejhansen71 » Wed Apr 29, 2015 1:55 pm

I am doing this in a Windows form via C# and VisualStudio
Two Questions.
Question 1 : Return a list Top Level Folders from a given repository.

I started with getting the repository the User has permission to access. I was able to do that with the following code:

Code: Select all

 VaultRepositoryInfo[] vri = ServerOperations.ProcessCommandListRepositories();
                List<string> repos = null;
                foreach ( VaultRepositoryInfo vrio in vri )
                {
                        repos.Add(vrio.RepName);
                        Console.Writeline(vrio.RepName);
                }
This collected and then wrote out to the Console all of the repositories the user has access to. So far - so good.

Now I want to list the folders inside the Repository. A full list is ok - but even better would be only the top level folders the user has access to.

We call each of the top level folders in a repository "Projects" and it is only the top level "Projects" I wish to list... preferably just the ones they have access to. In your GUI, you limit the repositories, but not the folders. So in your GUI, if I had access to repository AAA and there were 7 folders but I was only granted access to repository AAA folder 3 I would still see repository AAA and all folders 1-7. Really, I would prefer to ONLY see repository AAA and folder 3. When using

Code: Select all

ServerOperations.ProcessCommandListFolder("[b][color=#FF4000]????[/color][/b]", true).Folders;
what is the default folder path for a repository so I can list all the top level folders? Is it "$" or "$/"...or am I using the wrong method entirely?

Questions
1a. How do I get a list of top level folders from a repository?
1b. Can I limit the list of top level folders to only the ones the user has permission to access? If so, how?

Question 2: List Repositories for a different user.

I am logged in as administrator AAA. I have full access to all repositories and all top level folders and everything else available in Vault.

a. What if I want to pass a different username and get the repositories for that user? Can I do that without logging in as that user? Say I have a listbox of users, I select one and I want to see the repositories they have permission to see and the folders under it. Can I pass the AD username and get access to it?

Code: Select all

 ServerOperations.client.LoginOptions.User = GlobalUser;
                ServerOperations.client.LoginOptions.Password = GlobalPassword;
                ServerOperations.Login(); 
                VaultRepositoryInfo[] vri = ServerOperations.ProcessCommandListRepositories();

// Switch user code here
I can get my own userid with this bit of code:

Code: Select all

System.DirectoryServices.AccountManagement.UserPrincipal.Current.SamAccountName;
But I don't know how to switch the Vault User to that login name. Is it possible?
Thanks!

Eric

Beth
Posts: 8550
Joined: Wed Jun 21, 2006 8:24 pm
Location: SourceGear
Contact:

Re: Get Authorized Repositories and Folders for a given User

Post by Beth » Fri May 01, 2015 1:34 pm

Are you possibly trying to recreate the Repository Access Report? Do you know that we have that in the web client?

Or one thing you could try is to make a web request to the Repository Access Report and look at look into what it returns for you.
Beth Kieler
SourceGear Technical Support

Post Reply