Conditional task filters based on user

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 example_template_hook.py over to your config/core/hooks folder and perhaps rename it to template_workfiles_task_filter.py

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]:
            self.logger.info("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
2 Likes