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

Various Improvements #873

Merged
merged 2 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
223 changes: 186 additions & 37 deletions tests/user/test_route_context.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
from tests.base import ApiDBTestCase


from zou.app.services import (
tasks_service,
notifications_service,
persons_service,
projects_service,
user_service,
)

from zou.app.models.project import Project
Expand Down Expand Up @@ -510,7 +511,6 @@ def test_subscribe_sequence(self):
self.sequence_dict["id"],
self.task_type_dict["id"],
)
print(path)
self.post(path, {})

recipients = notifications_service.get_notification_recipients(
Expand Down Expand Up @@ -565,108 +565,257 @@ def test_get_metadata_columns(self):
def test_shared_filters(self):
project_id = str(self.project.id)
self.generate_fixture_user_cg_artist()

# Create a filter for artist
self.log_in_cg_artist()
path = "data/user/filters/"
filter_1 = {
"list_type": "asset",
"name": "props",
"name": "my filter",
"query": "props",
"project_id": project_id,
"is_shared": True,
}
self.post(path, filter_1)

# Admin cannot see artist's filter
self.log_in_admin()
result = self.get(path)
self.assertEqual(len(result["asset"][project_id]), 1)
self.assertEqual(
result["asset"][project_id][0]["search_query"], "props"
)
self.assertEqual(result["asset"][project_id][0]["is_shared"], True)
self.assertEqual(result, {})

# Add artist to the project and a department
self.log_in_admin()
projects_service.add_team_member(
self.project_id, self.user_cg_artist["id"]
)
self.log_in_cg_artist()
artist = persons_service.get_person_raw(self.user_cg_artist["id"])
artist.departments.append(self.department)
artist.save()

# Create a shared filter
filter_2 = {
"list_type": "asset",
"name": "myfilter",
"name": "team filter",
"query": "character",
"project_id": project_id,
"is_shared": True,
}
self.post(path, filter_2)
filter_2 = self.post(path, filter_2)

# Artist can see their filters and the shared filters
self.log_in_cg_artist()
result = self.get(path)
self.assertEqual(len(result["asset"][project_id]), 2)
self.assertEqual(
result["asset"][project_id][0]["search_query"], "props"
)
self.assertEqual(result["asset"][project_id][0]["is_shared"], True)
self.assertEqual(
result["asset"][project_id][1]["search_query"], "character"
self.assertEqual(result["asset"][project_id][0]["name"], "my filter")
self.assertEqual(result["asset"][project_id][0]["is_shared"], False)
self.assertEqual(result["asset"][project_id][1]["name"], "team filter")
self.assertEqual(result["asset"][project_id][1]["is_shared"], True)

projects_service.add_team_member(
self.project_id, self.user_cg_artist["id"]
)
self.assertEqual(result["asset"][project_id][1]["is_shared"], False)
self.log_in_cg_artist()

# Admin can update filter
self.log_in_admin()
self.put(
"data/user/filters/%s" % result["asset"][project_id][1]["id"],
{"name": "updated", "is_shared": True},
"data/user/filters/%s" % filter_2["id"],
{"name": "team updated"},
)
result = self.get(path)
self.assertEqual(result["asset"][project_id][1]["is_shared"], False)
self.assertEqual(result["asset"][project_id][1]["is_shared"], False)
user_service.clear_filter_cache()
self.assertEqual(result["asset"][project_id][0]["name"], "team updated")
self.assertEqual(result["asset"][project_id][0]["is_shared"], True)

# Artist cannot update admin's filter
self.log_in_cg_artist()
self.put(
"data/user/filters/%s" % result["asset"][project_id][0]["id"],
"data/user/filters/%s"
% result["asset"][project_id][0]["id"],
{"name": "updated", "is_shared": True},
404,
)

# Admin can create a shared filter for a department
self.log_in_admin()
filter_3 = {
"list_type": "asset",
"name": "department filter",
"query": "character",
"project_id": project_id,
"is_shared": True,
"department_id": self.department_animation.id,
}
filter_3 = self.post(path, filter_3)
result = self.get(path)
user_service.clear_filter_cache()
self.assertEqual(len(result["asset"][project_id]), 2)

# Artist can't see the department filter
# because he is not in the department.
self.log_in_cg_artist()
result = self.get(path)
user_service.clear_filter_cache()
self.assertEqual(len(result["asset"][project_id]), 2)
self.assertEqual(result["asset"][project_id][0]["name"], "my filter")
self.assertEqual(result["asset"][project_id][1]["name"], "team updated")

# Filter is shared with the artist's department
self.log_in_admin()
self.put(
"data/user/filters/%s" % filter_3["id"],
{
"name": "department updated",
"is_shared": True,
"department_id": self.department.id
},
)
result = self.get(path)
user_service.clear_filter_cache()
self.assertEqual(len(result["asset"][project_id]), 2)
self.assertEqual(result["asset"][project_id][0]["name"], "team updated")
self.assertEqual(result["asset"][project_id][1]["name"], "department updated")

# Now artist can see the department filter
self.log_in_cg_artist()
user_service.clear_filter_cache()
result = self.get(path)
self.assertEqual(len(result["asset"][project_id]), 3)
self.assertEqual(
result["asset"][project_id][2]["name"], "department updated")
self.assertEqual(
result["asset"][project_id][1]["name"], "team updated")
self.assertEqual(
result["asset"][project_id][0]["name"], "my filter")

def test_shared_group_filters(self):
project_id = str(self.project.id)
self.generate_fixture_user_cg_artist()

# Create a filter group for artist
self.log_in_cg_artist()
path = "data/user/filter-groups/"
filter_group_1 = {
"list_type": "asset",
"name": "props",
"project_id": project_id,
"is_shared": True,
"is_shared": False,
"name": "my group",
"color": "",
}
self.post(path, filter_group_1)

# Admin cannot see artist's filter group
self.log_in_admin()
result = self.get(path)
self.assertEqual(result, {})

# Artist can see their filter groups
self.log_in_cg_artist()
result = self.get(path)
self.assertEqual(len(result["asset"][project_id]), 1)
self.assertEqual(result["asset"][project_id][0]["name"], "props")
self.assertEqual(result["asset"][project_id][0]["is_shared"], True)
self.assertEqual(result["asset"][project_id][0]["name"], "my group")
self.assertEqual(result["asset"][project_id][0]["is_shared"], False)

# Add artist to the project and a department
self.log_in_admin()
projects_service.add_team_member(
self.project_id, self.user_cg_artist["id"]
)
self.log_in_cg_artist()
artist = persons_service.get_person_raw(self.user_cg_artist["id"])
artist.departments.append(self.department)
artist.save()

# Create a shared filter group
filter_group_2 = {
"list_type": "asset",
"name": "myfilter",
"project_id": project_id,
"is_shared": True,
"name": "team group",
"color": "",
}
self.post(path, filter_group_2)

# Artist can see their groups and the shared groups
self.log_in_cg_artist()
result = self.get(path)
self.assertEqual(len(result["asset"][project_id]), 2)
self.assertEqual(result["asset"][project_id][0]["name"], "myfilter")
self.assertEqual(result["asset"][project_id][0]["is_shared"], False)
self.assertEqual(result["asset"][project_id][1]["name"], "props")
self.assertEqual(result["asset"][project_id][1]["is_shared"], True)
self.assertEqual(result["asset"][project_id][0]["name"], "team group")
self.assertEqual(result["asset"][project_id][0]["is_shared"], True)
self.assertEqual(result["asset"][project_id][1]["name"], "my group")
self.assertEqual(result["asset"][project_id][1]["is_shared"], False)

# Admin can update filter group
self.log_in_admin()
self.put(
"data/user/filter-groups/%s"
% result["asset"][project_id][0]["id"],
{"name": "updated", "is_shared": True},
{"name": "updated"},
)
result = self.get(path)
self.assertEqual(result["asset"][project_id][0]["is_shared"], False)
self.assertEqual(result["asset"][project_id][0]["is_shared"], False)
user_service.clear_filter_group_cache()
self.assertEqual(result["asset"][project_id][0]["name"], "updated")
self.assertEqual(result["asset"][project_id][0]["is_shared"], True)

# Artist cannot update admin's filter group
self.log_in_cg_artist()
self.put(
"data/user/filter-groups/%s"
% result["asset"][project_id][1]["id"],
% result["asset"][project_id][0]["id"],
{"name": "updated", "is_shared": True},
404,
)

# Admin can create a shared filter group for a department
self.log_in_admin()
filter_group_3 = {
"list_type": "asset",
"project_id": project_id,
"is_shared": True,
"name": "department group",
"color": "",
"department_id": self.department_animation.id,
}
filter_group_3 = self.post(path, filter_group_3)
result = self.get(path)
user_service.clear_filter_group_cache()
self.assertEqual(len(result["asset"][project_id]), 2)

# Artist can't see the department filter group
# because he is not in the department.
self.log_in_cg_artist()
result = self.get(path)
user_service.clear_filter_group_cache()
self.assertEqual(len(result["asset"][project_id]), 2)
self.assertEqual(result["asset"][project_id][0]["name"], "updated")
self.assertEqual(result["asset"][project_id][1]["name"], "my group")

# Filter group is shared with the artist's department
self.log_in_admin()
self.put(
"data/user/filter-groups/%s" % filter_group_3["id"],
{
"name": "department updated",
"is_shared": True,
"department_id": self.department.id
},
)
user_service.clear_filter_group_cache()
result = self.get(path)
self.assertEqual(len(result["asset"][project_id]), 2)
self.assertEqual(result["asset"][project_id][0]["name"], "department updated")
self.assertEqual(result["asset"][project_id][1]["name"], "updated")

# Now artist can see the department filter group
self.log_in_cg_artist()
user_service.clear_filter_group_cache()
result = self.get(path)
self.assertEqual(len(result["asset"][project_id]), 3)
self.assertEqual(
result["asset"][project_id][0]["name"], "department updated")
self.assertEqual(
result["asset"][project_id][1]["name"], "updated")
self.assertEqual(
result["asset"][project_id][2]["name"], "my group")

def create_test_folder(self):
return super().create_test_folder()
10 changes: 7 additions & 3 deletions zou/app/blueprints/index/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from zou.app import app, config
from zou.app.utils import permissions, shell, date_helpers
from zou.app.services import projects_service, stats_service
from zou.app.services import projects_service, stats_service, persons_service

from flask_jwt_extended import jwt_required

Expand Down Expand Up @@ -276,17 +276,21 @@ def get(self):
class ConfigResource(Resource):
def get(self):
"""
Get crisp token.
Get basic configuration for the current instance.
---
tags:
- Index
responses:
200:
description: Crisp token
description: Configuration object including self-hosted status,
Crisp token, indexer configuration, SAML status, and dark theme
status
"""
organisation = persons_service.get_organisation()
conf = {
"is_self_hosted": config.IS_SELF_HOSTED,
"crisp_token": config.CRISP_TOKEN,
"dark_theme_by_default": organisation["dark_theme_by_default"],
"indexer_configured": (
len(config.INDEXER["key"]) > 0
and config.INDEXER["key"] != "masterkey"
Expand Down
Loading
Loading