Skip to content

Commit

Permalink
Merge pull request #881 from EvanBldy/master
Browse files Browse the repository at this point in the history
various improvements
  • Loading branch information
EvanBldy authored Nov 8, 2024
2 parents 7f217f6 + 40e3112 commit 04654d0
Show file tree
Hide file tree
Showing 28 changed files with 83 additions and 31 deletions.
8 changes: 4 additions & 4 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ install_requires =
matterhook==0.2
meilisearch==0.31.6
numpy==2.0.1; python_version == '3.9'
numpy==2.1.2; python_version >= '3.10'
numpy==2.1.3; python_version >= '3.10'
opencv-python==4.10.0.84
OpenTimelineIO==0.17.0
OpenTimelineIO-Plugins==0.17.0
orjson==3.10.10
orjson==3.10.11
pillow==11.0.0
psutil==6.1.0
psycopg[binary]==3.2.3
Expand Down Expand Up @@ -97,13 +97,13 @@ dev =
test =
fakeredis==2.26.1
mixer==7.2.2
pytest-cov==5.0.0
pytest-cov==6.0.0
pytest==8.3.3

monitoring =
prometheus-flask-exporter==0.23.1
pygelf==0.4.2
sentry-sdk==2.17.0
sentry-sdk==2.18.0

lint =
autoflake==2.3.1
Expand Down
32 changes: 31 additions & 1 deletion tests/services/test_breakdown_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,10 @@ def test_is_asset_ready(self):
self.assertEqual(priority_map[self.task_type_layout_id], 1)
self.assertEqual(priority_map[self.task_type_animation_id], 2)
self.assertEqual(priority_map[self.task_type_compositing_id], 3)
asset = {"ready_for": str(self.task_type_animation.id)}
asset = {
"ready_for": str(self.task_type_animation.id),
"is_shared": False,
}
self.assertTrue(
breakdown_service._is_asset_ready(
asset, self.task_layout, priority_map
Expand All @@ -305,6 +308,33 @@ def test_is_asset_ready(self):
)
)

asset = {
"ready_for": str(self.task_type_animation.id),
"is_shared": True,
"project_id": self.project_id,
}
self.assertTrue(
breakdown_service._is_asset_ready(
asset, self.task_layout, priority_map
)
)
self.assertTrue(
breakdown_service._is_asset_ready(
asset, self.task_animation, priority_map
)
)
self.assertFalse(
breakdown_service._is_asset_ready(
asset, self.task_compositing, priority_map
)
)
asset["project_id"] = "000000000000000000000000"
self.assertTrue(
breakdown_service._is_asset_ready(
asset, self.task_layout, priority_map
)
)

self.shot_id = str(self.shot.id)
self.sequence_id = str(self.sequence.id)
self.asset_id = str(self.asset.id)
Expand Down
5 changes: 3 additions & 2 deletions zou/app/blueprints/crud/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ def apply_filters(self, query, options):

return query

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return permissions.check_admin_permissions()

def add_project_permission_filter(self, query):
Expand Down Expand Up @@ -165,13 +165,14 @@ def get(self):
description: Permission denied
"""
try:
self.check_read_permissions()
query = self.model.query
if not request.args:
self.check_read_permissions()
query = self.add_project_permission_filter(query)
return self.all_entries(query)
else:
options = request.args
self.check_read_permissions(options)
query = self.apply_filters(query, options)
query = self.add_project_permission_filter(query)
page = int(options.get("page", "-1"))
Expand Down
13 changes: 13 additions & 0 deletions zou/app/blueprints/crud/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,19 @@ class CommentsResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, Comment)

def check_read_permissions(self, options=None):
if options is not None:
if "project_id" in options:
user_service.check_project_access(options["project_id"])
if (
permissions.has_vendor_permissions()
or permissions.has_client_permissions()
):
raise permissions.PermissionDenied
else:
return True
return permissions.check_admin_permissions()


class CommentResource(BaseModelResource):
def __init__(self):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/custom_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class CustomActionsResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, CustomAction)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
user_service.block_access_to_vendor()
return True

Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/department.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DepartmentsResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, Department)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def post_creation(self, instance):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def check_create_permissions(self, entity):
def emit_create_event(self, entity_dict):
self.emit_event("new", entity_dict)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def add_project_permission_filter(self, query):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/entity_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def all_entries(self, query=None, relations=False):
for asset_type in query.all()
]

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def emit_create_event(self, instance_dict):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/file_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class FileStatusesResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, FileStatus)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True


Expand Down
3 changes: 2 additions & 1 deletion zou/app/blueprints/crud/metadata_descriptor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from zou.app.blueprints.crud.base import BaseModelResource, BaseModelsResource
from zou.app.utils import permissions
from zou.app.models.project import Project
from zou.app.services import user_service

from zou.app.services.exception import (
WrongParameterException,
Expand All @@ -16,7 +17,7 @@ class MetadataDescriptorsResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, MetadataDescriptor)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return not permissions.has_vendor_permissions()

def add_project_permission_filter(self, query):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/organisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class OrganisationsResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, Organisation)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True


Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/output_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class OutputFilesResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, OutputFile)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
user_service.block_access_to_vendor()
return True

Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/output_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class OutputTypesResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, OutputType)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True


Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/person.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def all_entries(self, query=None, relations=False):
for person in query.all()
]

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def check_create_permissions(self, data):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/playlist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PlaylistsResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, Playlist)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def check_create_permissions(self, playlist):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/preview_background_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PreviewBackgroundFilesResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, PreviewBackgroundFile)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def update_data(self, data):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/preview_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def add_project_permission_filter(self, query):

return query

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True


Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def add_project_permission_filter(self, query):
else:
return query.filter(user_service.build_related_projects_filter())

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def check_creation_integrity(self, data):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/project_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ProjectStatussResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, ProjectStatus)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True


Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/software.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class SoftwaresResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, Software)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True


Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/status_automation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class StatusAutomationsResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, StatusAutomation)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
user_service.block_access_to_vendor()
return True

Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/studio.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class StudiosResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, Studio)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def post_creation(self, instance):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class TasksResource(BaseModelsResource, ArgsMixin):
def __init__(self):
BaseModelsResource.__init__(self, Task)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def add_project_permission_filter(self, query):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/task_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TaskStatusesResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, TaskStatus)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def post_creation(self, instance):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/task_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class TaskTypesResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, TaskType)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
return True

def update_data(self, data):
Expand Down
2 changes: 1 addition & 1 deletion zou/app/blueprints/crud/working_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class WorkingFilesResource(BaseModelsResource):
def __init__(self):
BaseModelsResource.__init__(self, WorkingFile)

def check_read_permissions(self):
def check_read_permissions(self, options=None):
"""
Overriding so that people without admin credentials can still access
this resource.
Expand Down
7 changes: 6 additions & 1 deletion zou/app/blueprints/tasks/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,6 @@ class ProjectCommentsResource(Resource, ArgsMixin):
"""

@jwt_required()
@permissions.require_admin
def get(self, project_id):
"""
Retrieve all comments to tasks related to given project.
Expand All @@ -1538,6 +1537,12 @@ def get(self, project_id):
description: All comments to tasks related to given project
"""
projects_service.get_project(project_id)
user_service.check_project_access(project_id)
if (
permissions.has_vendor_permissions()
or permissions.has_client_permissions()
):
raise permissions.PermissionDenied
page = self.get_page()
return tasks_service.get_comments_for_project(project_id, page)

Expand Down
4 changes: 3 additions & 1 deletion zou/app/services/breakdown_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,9 @@ def _get_task_type_priority_map(project_id):

def _is_asset_ready(asset, task, priority_map):
is_ready = False
if "ready_for" in asset and asset["ready_for"] is not None:
if asset["is_shared"] and asset["project_id"] != str(task.project_id):
is_ready = True
elif "ready_for" in asset and asset["ready_for"] is not None:
priority_ready = priority_map.get(asset["ready_for"], -1) or -1
priority_task = priority_map.get(str(task.task_type_id), 0) or 0
is_ready = priority_task <= priority_ready
Expand Down

0 comments on commit 04654d0

Please sign in to comment.