Workfiles tab order

Is it possible to change the order of the tabs in the workfiles app depending on what department or a group a user is in?
assets first for the asset team, uis first for the ui team?

2 Likes

Hi Joe

I think I can see two potential routes.

  1. You branch your env yml files based on the user’s group by modifying the core/hooks/pick_environment.py file so that it checks the user’s group and then chooses a different environment file appropriately. Though I could imagine that’s a bit much if all you want to do is reorder the tabs.

  2. You could use the core template hook, to dynamically resolve the entities values. The hook would query the user’s group and then return back the settings in the appropriate order.

You can access the user’s group by running something similar to this in a hook:

user = context.user
user = self.sgtk.shotgun.find_one("HumanUser",[["id", "is", user["id"]]], ["groups", "department"])
...

Cheers
Phil

2 Likes

Template hook sounds like it would be the way to go.
Would I have to define the entities in the hook or can I keep it in the yml and pass it to the hook somehow? There aren’t a lot of examples of template hooks out there.

1 Like

You can do either, but it does get a bit messy here. Obviously it’s nicer if it is defined in the yml file so all your settings are kept together. But to do this you would need to pass the settings as a string args to the hook. Each : after the hook name denotes args. So you could, in theory, pass the settings through as string args.

Here is an example
In the yaml file I’m passing two parameters through to my custom hook called example_template_hook, though the hook can be renamed to something else, it just needs to live in the .../config/core/hooks/ directory).
Each tab is passed as a separate parameter so that we can easily separate them in the hook, Notice the : character after the hierarchy; [step] of the first tab settings.
Since we are passing each parameter as a string and we don’t want the yaml parser to interpret our string as a yaml just yet, I’ve temporarily switched all the : for ; characters. If we didn’t do this then each : it encountered would be treated as a separate parameter to pass to the hook.
The > character at the beginning allows us to provide a multiline value.

settings.tk-multi-workfiles2.launch_at_startup:
  launch_at_startup: true
  entities: >
    hook:example_template_hook:- caption; Shots
      entity_type; Shot
      filters;
      hierarchy; [sg_sequence, code]
      sub_hierarchy;
        entity_type; Task
        filters;
        link_field; entity
        hierarchy; [step]:
    - caption; Assets
      entity_type; Asset
      hierarchy; [sg_asset_type, code]
      filters;
      sub_hierarchy;
        entity_type; Task
        filters;
        link_field; entity
        hierarchy; [step]
  location: "@apps.tk-multi-workfiles2.location"

Then in the hook we can resolve each tab parameter and then return them in what ever order we like:

from tank import Hook
from tank_vendor import ruamel_yaml

class ExampleTemplateHook(Hook):

    def execute(self, setting, bundle_obj, extra_params, **kwargs):
        
        # grab each tab from the separate params, and resolve them
        shot_tab = self.resolve_yaml_string(extra_params[0])
        asset_tab = self.resolve_yaml_string(extra_params[1])

        # now combine the tabs in what ever order we like
        all_tabs = asset_tab + shot_tab
        self.logger.info("tabs: %s" % all_tabs)

        return all_tabs

    def resolve_yaml_string(self, yaml_string):
        # resolve the string into actual python object using yaml
        # first we need to substitute the ; for the correct :
        yaml_string = yaml_string.replace(";", ":")
        return ruamel_yaml.load(yaml_string)
2 Likes