Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Workfiles tool: Author visible in UI #552

Merged
3 changes: 3 additions & 0 deletions client/ayon_core/tools/common_models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
)
from .thumbnails import ThumbnailsModel
from .selection import HierarchyExpectedSelection
from .users import UsersModel


__all__ = (
Expand All @@ -32,4 +33,6 @@
"ThumbnailsModel",

"HierarchyExpectedSelection",

"UsersModel",
)
84 changes: 84 additions & 0 deletions client/ayon_core/tools/common_models/users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import ayon_api

from ayon_core.lib import CacheItem


class UserItem:
def __init__(
self,
username,
full_name,
email,
avatar_url,
active,
):
self.username = username
self.full_name = full_name
self.email = email
self.avatar_url = avatar_url
self.active = active

@classmethod
def from_entity_data(cls, user_data):
return cls(
user_data["name"],
user_data["attrib"]["fullName"],
user_data["attrib"]["email"],
user_data["attrib"]["avatarUrl"],
user_data["active"],
)


class UsersModel:
def __init__(self, controller):
self._controller = controller
self._users_cache = CacheItem(default_factory=list)

def get_user_items(self):
"""Get user items.

Returns:
List[UserItem]: List of user items.

"""
self._invalidate_cache()
return self._users_cache.get_data()

def get_user_items_by_name(self):
"""Get user items by name.

Implemented as most of cases using this model will need to find
user information by username.

Returns:
Dict[str, UserItem]: Dictionary of user items by name.

"""
return {
user_item.username: user_item
for user_item in self.get_user_items()
}

def get_user_item_by_username(self, username):
"""Get user item by username.

Args:
username (str): Username.

Returns:
Union[UserItem, None]: User item or None if not found.

"""
self._invalidate_cache()
for user_item in self.get_user_items():
if user_item.username == username:
return user_item
return None

def _invalidate_cache(self):
if self._users_cache.is_valid:
return
self._users_cache.update_data([
UserItem.from_entity_data(user)
for user in ayon_api.get_users()
])
28 changes: 26 additions & 2 deletions client/ayon_core/tools/workfiles/abstract.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ class WorkfileInfo:
task_id (str): Task id.
filepath (str): Filepath.
filesize (int): File size.
creation_time (int): Creation time (timestamp).
modification_time (int): Modification time (timestamp).
creation_time (float): Creation time (timestamp).
modification_time (float): Modification time (timestamp).
created_by (Union[str, none]): User who created the file.
updated_by (Union[str, none]): User who last updated the file.
note (str): Note.
"""

Expand All @@ -26,6 +28,8 @@ def __init__(
filesize,
creation_time,
modification_time,
created_by,
updated_by,
note,
):
self.folder_id = folder_id
Expand All @@ -34,6 +38,8 @@ def __init__(
self.filesize = filesize
self.creation_time = creation_time
self.modification_time = modification_time
self.created_by = created_by
self.updated_by = updated_by
self.note = note

def to_data(self):
Expand All @@ -50,6 +56,8 @@ def to_data(self):
"filesize": self.filesize,
"creation_time": self.creation_time,
"modification_time": self.modification_time,
"created_by": self.created_by,
"updated_by": self.updated_by,
"note": self.note,
}

Expand Down Expand Up @@ -212,6 +220,7 @@ class FileItem:
dirpath (str): Directory path of file.
filename (str): Filename.
modified (float): Modified timestamp.
created_by (Optional[str]): Username.
representation_id (Optional[str]): Representation id of published
workfile.
filepath (Optional[str]): Prepared filepath.
Expand All @@ -223,13 +232,17 @@ def __init__(
dirpath,
filename,
modified,
created_by=None,
updated_by=None,
representation_id=None,
filepath=None,
exists=None
):
self.filename = filename
self.dirpath = dirpath
self.modified = modified
self.created_by = created_by
self.updated_by = updated_by
self.representation_id = representation_id
self._filepath = filepath
self._exists = exists
Expand Down Expand Up @@ -269,6 +282,7 @@ def to_data(self):
"filename": self.filename,
"dirpath": self.dirpath,
"modified": self.modified,
"created_by": self.created_by,
"representation_id": self.representation_id,
"filepath": self.filepath,
"exists": self.exists,
Expand Down Expand Up @@ -522,6 +536,16 @@ def register_event_callback(self, topic, callback):

pass

@abstractmethod
def get_user_items_by_name(self):
"""Get user items available on AYON server.

Returns:
Dict[str, UserItem]: User items by username.

"""
pass

# Host information
@abstractmethod
def get_workfile_extensions(self):
Expand Down
14 changes: 11 additions & 3 deletions client/ayon_core/tools/workfiles/control.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
HierarchyModel,
HierarchyExpectedSelection,
ProjectsModel,
UsersModel,
)

from .abstract import (
Expand Down Expand Up @@ -161,6 +162,7 @@ def __init__(self, host=None):
self._save_is_enabled = True

# Expected selected folder and task
self._users_model = self._create_users_model()
self._expected_selection = self._create_expected_selection_obj()
self._selection_model = self._create_selection_model()
self._projects_model = self._create_projects_model()
Expand All @@ -176,6 +178,12 @@ def log(self):
def is_host_valid(self):
return self._host_is_valid

def _create_users_model(self):
return UsersModel(self)

def _create_workfiles_model(self):
return WorkfilesModel(self)

def _create_expected_selection_obj(self):
return WorkfilesToolExpectedSelection(self)

Expand All @@ -188,9 +196,6 @@ def _create_selection_model(self):
def _create_hierarchy_model(self):
return HierarchyModel(self)

def _create_workfiles_model(self):
return WorkfilesModel(self)

@property
def event_system(self):
"""Inner event system for workfiles tool controller.
Expand Down Expand Up @@ -272,6 +277,9 @@ def set_save_enabled(self, enabled):
{"enabled": enabled}
)

def get_user_items_by_name(self):
return self._users_model.get_user_items_by_name()

# Host information
def get_workfile_extensions(self):
host = self._host
Expand Down
Loading