Skip to content
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
1 change: 1 addition & 0 deletions QUICKSTART.md
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,7 @@ The React app will be available at `http://localhost:5173`.
| `SHOTGRID_URL` | Yes\* | - | ShotGrid site URL (required when using ShotGrid) |
| `SHOTGRID_API_KEY` | Yes\* | - | ShotGrid API key (required when using ShotGrid) |
| `SHOTGRID_SCRIPT_NAME` | Yes\* | - | ShotGrid script name (required when using ShotGrid) |
| `PROJECT_ALLOWED_TYPES` | No | - | Comma-separated list of allowed ShotGrid project types (`sg_type`) to return for users. When unset or empty, projects are not filtered by type. |
| `PRODTRACK_PROVIDER` | No | `shotgrid` | `shotgrid` or `mock`; set to `mock` to use the read-only mock DB without ShotGrid |
| `SESSION_PROVIDER` | No | `none` | `none` or `mock`. `none` makes session routes return 404. `mock` serves in-memory sessions for local development |
| `MONGODB_URL` | No | `mongodb://mongo:27017` | MongoDB connection string |
Expand Down
18 changes: 16 additions & 2 deletions backend/src/dna/prodtrack_providers/shotgrid.py
Original file line number Diff line number Diff line change
Expand Up @@ -772,17 +772,31 @@ def get_projects_for_user(self, user_email: str) -> list[Project]:
if not user:
raise ValueError(f"User not found: {user_email}")

filters = [["users", "is", user]]

allowed_types = [
t.strip()
for t in os.getenv("PROJECT_ALLOWED_TYPES", "").split(",")
if t.strip()
]

if allowed_types:
filters.append(["sg_type", "in", allowed_types])

# Find projects where this user is in the users list
sg_projects = self._sg.find(
"Project",
filters=[["users", "is", user]],
filters=filters,
fields=["id", "name"],
)

entity_mapping = FIELD_MAPPING["project"]
return [
self._convert_sg_entity_to_dna_entity(
sg_project, entity_mapping, "project", resolve_links=False
sg_project,
entity_mapping,
"project",
resolve_links=False,
)
for sg_project in sg_projects
]
Expand Down
88 changes: 88 additions & 0 deletions backend/tests/providers/test_shotgrid_provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,94 @@ def test_get_projects_for_user_returns_empty_list_when_no_projects(

assert results == []

def test_get_projects_for_user_no_allowed_types_filter(
self, shotgrid_provider, monkeypatch
):
"""Test that when PROJECT_ALLOWED_TYPES is not set, find() is called with only the user filter."""
monkeypatch.delenv("PROJECT_ALLOWED_TYPES", raising=False)

user_data = {"id": 42, "email": "test@example.com", "name": "Test User"}
shotgrid_provider.sg.find_one.return_value = user_data
shotgrid_provider.sg.find.return_value = []

shotgrid_provider.get_projects_for_user("test@example.com")

shotgrid_provider.sg.find.assert_called_once_with(
"Project",
filters=[["users", "is", user_data]],
fields=["id", "name"],
)

def test_get_projects_for_user_single_allowed_type(
self, shotgrid_provider, monkeypatch
):
"""Adds a single allowed project type filter."""
monkeypatch.setenv("PROJECT_ALLOWED_TYPES", "Commercial")

user_data = {"id": 42, "email": "test@example.com", "name": "Test User"}
shotgrid_provider.sg.find_one.return_value = user_data
shotgrid_provider.sg.find.return_value = []

shotgrid_provider.get_projects_for_user("test@example.com")

shotgrid_provider.sg.find.assert_called_once_with(
"Project",
filters=[
["users", "is", user_data],
["sg_type", "in", ["Commercial"]],
],
fields=["id", "name"],
)

def test_get_projects_for_user_multiple_allowed_types(
self, shotgrid_provider, monkeypatch
):
"""Test that when PROJECT_ALLOWED_TYPES=Commercial,Feature, find() includes both types."""
monkeypatch.setenv("PROJECT_ALLOWED_TYPES", "Commercial,Feature")

user_data = {"id": 42, "email": "test@example.com", "name": "Test User"}
shotgrid_provider.sg.find_one.return_value = user_data
shotgrid_provider.sg.find.return_value = []

shotgrid_provider.get_projects_for_user("test@example.com")

shotgrid_provider.sg.find.assert_called_once_with(
"Project",
filters=[
["users", "is", user_data],
["sg_type", "in", ["Commercial", "Feature"]],
],
fields=["id", "name"],
)

def test_get_projects_for_user_allowed_types_trims_whitespace(
self, shotgrid_provider, monkeypatch
):
"""Test that PROJECT_ALLOWED_TYPES trims whitespace and ignores empty entries."""
monkeypatch.setenv(
"PROJECT_ALLOWED_TYPES",
" Commercial , Feature , , ",
)

user_data = {
"id": 42,
"email": "test@example.com",
"name": "Test User",
}
shotgrid_provider.sg.find_one.return_value = user_data
shotgrid_provider.sg.find.return_value = []

shotgrid_provider.get_projects_for_user("test@example.com")

shotgrid_provider.sg.find.assert_called_once_with(
"Project",
filters=[
["users", "is", user_data],
["sg_type", "in", ["Commercial", "Feature"]],
],
fields=["id", "name"],
)


# ============================================================================
# ShotGrid get_playlists_for_project tests
Expand Down
Loading