# Conditional task filters based on user

**URL:** <https://community.shotgridsoftware.com/t/conditional-task-filters-based-on-user/366>\
**Category:** Pipeline Integrations\
**Created:** [July 30, 2019, 5:44pm UTC](https://community.shotgridsoftware.com/t/conditional-task-filters-based-on-user/366 "2019-07-30T17:44:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pls84](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/pls84/32/305_2.png) [@pls84](https://community.shotgridsoftware.com/u/pls84)\
**Post date:** [July 30, 2019, 5:44pm UTC](https://community.shotgridsoftware.com/t/conditional-task-filters-based-on-user/366/1 "2019-07-30T17:44:11Z")

</div>

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.

Thanks

---

<div class="post-metadata">

**Author:** ![tony](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/tony/32/197_2.png) [@tony](https://community.shotgridsoftware.com/u/tony)\
**Post date:** [July 30, 2019, 11:22pm UTC](https://community.shotgridsoftware.com/t/conditional-task-filters-based-on-user/366/4 "2019-07-30T23:22:13Z")

</div>

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 🙂

-tony.

---

<div class="post-metadata">

**Author:** ![philip.scadding](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/philip.scadding/32/30_2.png) [@philip.scadding](https://community.shotgridsoftware.com/u/philip.scadding)\
**Post date:** [July 31, 2019, 9:45am UTC](https://community.shotgridsoftware.com/t/conditional-task-filters-based-on-user/366/5 "2019-07-31T09:45:13Z")

</div>

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.

> <https://github.com/shotgunsoftware/tk-core/blob/master/hooks/example_template_hook.py#L33-L58>

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.

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

```

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

```python
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

```

---

<div class="post-metadata">

**Author:** ![pls84](https://sea1.discourse-cdn.com/shotgunsoftware/user_avatar/community.shotgridsoftware.com/pls84/32/305_2.png) [@pls84](https://community.shotgridsoftware.com/u/pls84)\
**Post date:** [August 1, 2019, 1:03pm UTC](https://community.shotgridsoftware.com/t/conditional-task-filters-based-on-user/366/7 "2019-08-01T13:03:33Z")

</div>

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 [shotgunsoftware@discoursemail.com](mailto:shotgunsoftware@discoursemail.com) a écrit :
