Conditional task filters based on user

Hi everyone. What would be the best approach to give some users the ability to see all tasks from a given project while going trough the tk-workfiles2 GUI inside Maya (mainly the File Open menu) ?

I know we have some control over the task filter via the my_task_filters = [[‘task_assignees’, ‘is’, ‘{context.user}’]] inside the config yml but how could I make this conditional ?

Exemple if contex.user is ‘A’ then list all available tasks within the project. If context.user is ‘B’ only return his assigned tasks.

The idea behind this would be to give some specific users the possibility to see all tasks from a project while artists continue to see only their assigned tasks.


Hi, Pierre-Luc!

Welcome to the Shotgun forum!

I just wanted to let you know that I’m moving your question from the “Uncategorized” category to our “Pipeline Integrations” category so that the right folks with the right know-how will see it. Just letting you know so that you’re not alarmed when you see I’ve moved it :slight_smile:


1 Like

Hi, Pierre-Luc

I think there might be a way to do this. You could use the template hook to dynamically resolve the my_task_filters setting.

This hook can be used to dynamically set a value in the env settings, however, it should be noted that it only evaluates when the environment is loaded and no every time the app is opened. So it should be fine for this sort of logic as the user won’t change during the session.

To set this up you would copy the over to your config/core/hooks folder and perhaps rename it to

Then in your app’s environment settings, you would define the my_task_filters accordingly.

my_tasks_filters: "hook:template_workfiles_task_filter:[[task_assignees, is, '{context.user}']]"

Then in the hook, you would have something like this:

from tank import Hook

class ExampleTemplateHook(Hook):

    def execute(self, setting, bundle_obj, extra_params, **kwargs):
        import sgtk
        currentEngine = sgtk.platform.current_engine()
        if currentEngine.context.user["id"] in [86]:
  "We have a matching user showing all tasks!")
            # We could show every task by returning an empty list, though I would recomend
            # filtering out by status to keep it relevant.
            return [["sg_status_list", "not_in", ["fin","omt"] ]]
        # not a matching user so return the preset filter.
        template_name = extra_params[0]
        return template_name
1 Like

Hi Philip,

Thank you for the detailed feedback. I was able to achieve what I was aiming for with your input !

Thanks again !

Le mer. 31 juil. 2019 à 05:46, Philip Scadding via Community @ Shotgun a écrit :