How to get user who triggered folder creation on asset entity Shotgun web interface

The folder creation menu item on assets triggers the process_folder_creation.py script in the toolkit.
However there is not context in self.parent when I try to find the user who clicked that menu item.

Is there a way to get the user info for whoever started the folder creation process?

Thanks!

1 Like

Hey,
It would help to know a little bit more about why you need the user info, if its merely a query to know what user did what to track what users are running what actions. Then the place to look is the “Event Log Entries” page which is accessible under any project.

Projects > Project Name > Other > Event Log Entries

then you can type in the little search box to filter just “folder” events, this will return back to you the “Toolkit_Folders_Create Events” or more explicitly you can type in “Toolkit_Folders_Create” and get back exactly and only those events.

@philip.scadding might have so good pointers if you wanted to do specific things based on what user, or usergroup activated the folder_creation.
-Ross

1 Like

I have some custom code that runs through process_folder_creation and I wish to keep a log of who triggered the process. Going through the event log is not a feasible solution since it’s all going to be automated.

I have a few suggestions.

First I just wanted to clarify when exactly you want to log this information.
Do you only want to log this information when run from the action in the Browser, or do you want to capture this information whenever folder creation is run.
Since folder creation can be ran automatically during certain processes like launching software or saving a file, user’s may end up creating folder without even realising they are.

If you wanted to only catch it when folder creation is run as an action, then I would recomend taking over the tk-shotgun-folders which is the app that runs the action from the browser. Usually I wouldn’t recommend taking over an app unless you have to, but it’s not a very complicated app, and we don’t updated it very frequently.

If you want to capture the logging whenever folder creation is run, then I think the process_folder_creation.py hook is probably a good place to do it.

There are a couple of approaches you could use I think, but I’ve not tested.

  1. Grab the context from the engine:

    engine = sgtk.platform.current_engine()
    if engine:
        user = engine.context.user
    

    However, if you have code that runs the folder creation using the API when an engine isn’t started, then there won’t be an engine, but I think this would probably work for most use cases. Also, the user won’t be in the context if you are using script authentication, and your OS user’s login name doesn’t match your Shotgun user login name.

  2. You could capture the OS user name and try and match it to a Shotgun user?

This is actually what I started doing. I realized that the shotgun user was somewhat less important than the person who triggered it.

However:

This is exactly what I was looking to do. Thanks!

2 Likes