|
2 | 2 |
|
3 | 3 | from src.authentication.services.guest_auth import GuestJWTAuthService |
4 | 4 | from src.processes.enums import ( |
| 5 | + OwnerRole, |
5 | 6 | OwnerType, |
6 | 7 | TemplateType, |
7 | 8 | WorkflowApiStatus, |
@@ -284,6 +285,73 @@ def test_titles__user_not_template_owner__empty_result__ok(api_client): |
284 | 285 | assert len(response.data) == 0 |
285 | 286 |
|
286 | 287 |
|
| 288 | +def test_titles__account_owner_not_template_owner__empty_result__ok( |
| 289 | + api_client, |
| 290 | +): |
| 291 | + |
| 292 | + """Account owner should only see templates where they are |
| 293 | + an owner or viewer, not all templates in the account.""" |
| 294 | + |
| 295 | + # arrange |
| 296 | + account = create_test_account() |
| 297 | + account_owner = create_test_owner(account=account) |
| 298 | + admin = create_test_admin(account=account) |
| 299 | + template = create_test_template( |
| 300 | + user=admin, |
| 301 | + is_active=True, |
| 302 | + tasks_count=1, |
| 303 | + ) |
| 304 | + create_test_workflow( |
| 305 | + user=admin, |
| 306 | + template=template, |
| 307 | + ) |
| 308 | + api_client.token_authenticate(account_owner) |
| 309 | + |
| 310 | + # act |
| 311 | + response = api_client.get('/templates/titles-by-workflows') |
| 312 | + |
| 313 | + # assert |
| 314 | + assert response.status_code == 200 |
| 315 | + assert len(response.data) == 0 |
| 316 | + |
| 317 | + |
| 318 | +def test_titles__account_owner_is_viewer__ok(api_client): |
| 319 | + |
| 320 | + """Account owner with viewer role should see the template.""" |
| 321 | + |
| 322 | + # arrange |
| 323 | + account = create_test_account() |
| 324 | + account_owner = create_test_owner(account=account) |
| 325 | + admin = create_test_admin(account=account) |
| 326 | + template = create_test_template( |
| 327 | + user=admin, |
| 328 | + is_active=True, |
| 329 | + tasks_count=1, |
| 330 | + ) |
| 331 | + create_test_workflow( |
| 332 | + user=admin, |
| 333 | + template=template, |
| 334 | + ) |
| 335 | + TemplateOwner.objects.create( |
| 336 | + template=template, |
| 337 | + account=account, |
| 338 | + user_id=account_owner.id, |
| 339 | + type=OwnerType.USER, |
| 340 | + role=OwnerRole.VIEWER, |
| 341 | + ) |
| 342 | + api_client.token_authenticate(account_owner) |
| 343 | + |
| 344 | + # act |
| 345 | + response = api_client.get('/templates/titles-by-workflows') |
| 346 | + |
| 347 | + # assert |
| 348 | + assert response.status_code == 200 |
| 349 | + assert len(response.data) == 1 |
| 350 | + assert response.data[0]['id'] == template.id |
| 351 | + assert response.data[0]['name'] == template.name |
| 352 | + assert response.data[0]['count'] == 1 |
| 353 | + |
| 354 | + |
287 | 355 | def test_titles__invited_user__unauthorized(api_client): |
288 | 356 |
|
289 | 357 | # arrange |
|
0 commit comments