tagBrowse at specified depth

Is there a way to tagBrowse at a particular depth? Our tag structure is a predictable hierarchy of company/area/field/location. In SQL Server there is a table for handling permissions by user. An admin would have an entry with [default]; a user with company access would have [default]Company Name; a user with access to one location would have [default]company name/area/field/location.

When creating a list of locations that a user is permitted to access, users at a location level is simple, but when someone is an admin or any other permission level above just location access, I have a python function that recursively assembles the list of accessible locations by looking for tags in a tagBrowse that have four slashes ('/'). Here's the code I use:

def getAccessibleSubFolders(parentFolder, origParent, paths=):
tb = system.tag.browseTags(parentPath=parentFolder, recursive=0)

if origParent == '[default]':
for t in tb:
if t.fullPath.count('/') == 4:
paths.append(t.fullPath.encode("utf-8"))
else:
getAccessibleSubFolders(t.fullPath, origParent)
else:
for t in tb:
if t.fullPath.count('/') == 4:
paths.append(t.fullPath.encode("utf-8"))
else:
getAccessibleSubFolders(t.fullPath, origParent)

return paths

Is there a way to essentially browseTags at a certain depth? Something like browseTags(parentPath="///*/")?

While my current function gets the job done, I worry how well it will scale as the number of locations increase and wonder if there is a more efficient way to perform this same task that I may have missed.

Once I have the list of accessible locations, that list is used to populate a treeView in a Navigation window, so as new locations are added, if the project is updated, the treeView will have to be updated and for admin users, this could present a burdensome issue.

I’m not sure how your databases are setup, but we use a combination of Roles and a SQL Table.
The table lists all locations, then on login we loop through the table of roles and do a HasRole call to see if the user has that role, if they do we add it to a dataset and fill a treeview with the locations they can access for trending.

That was one way we had considered doing it, but there was something partially built out when we inherited the projected. Also there was going to be too many roles to create because someone could have access to a few locations from one area of one company, and then some from another.

I had initially considered doing a table for each level of the location hierarchy so that there would be an Area/Field table. If someone had access to an area, they automatically would have a record per location in that area in the permission table. The customer was concerned about table size though, and wanted it reduced to one record per hierarchy level allowed, plus one off locations here and there.

While we were considering how to keep the tables up to date with the tag paths for the locations, we came upon the partially pre-built tag-path option, but didn’t foresee the difficulty of loading the tags for locations beneath a higher level of the hierarchy (admins, for example having to loop from the [default] parent folder down to the forth recursion.

Do you have a form that simultaneously adds a location in ignition and SQL Server?

We have a table that has a record for each location.
Then on each gateway we create a role titled the name of the location.
So when a user logs in, we call the function to loop and and build the dataset.