Skip to content

Commit 776ffee

Browse files
authored
Merge pull request #182 from pneumaticapp/backend/template/45313__owner_has_access_all_templates
45313 backend [ templates ] Account owner has full access to all templates in the account
2 parents abf2298 + b89ec5d commit 776ffee

2 files changed

Lines changed: 71 additions & 11 deletions

File tree

backend/src/processes/queries.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
)
1414
from src.processes.enums import (
1515
DirectlyStatus,
16+
OwnerRole,
1617
OwnerType,
1718
TaskOrdering,
1819
TaskStatus,
@@ -2110,15 +2111,6 @@ def _get_filter_by_type(self):
21102111

21112112
def _get_accessible_templates(self):
21122113
"""Returns templates where user is owner or viewer"""
2113-
# Account owner has full access to all templates in the account
2114-
if self.user.is_account_owner:
2115-
return """
2116-
SELECT DISTINCT t.id AS template_id
2117-
FROM processes_template t
2118-
WHERE t.is_deleted IS FALSE
2119-
AND t.account_id = %(account_id)s
2120-
"""
2121-
# For other users (including admins), apply filtering logic
21222114
# Users can see templates where they are:
21232115
# 1. Template owners (user or via group)
21242116
# 2. Template viewers (user or via group)
@@ -2128,8 +2120,8 @@ def _get_accessible_templates(self):
21282120
self.params['owner_type_group'] = OwnerType.GROUP
21292121
self.params['viewer_type_user'] = OwnerType.USER
21302122
self.params['viewer_type_group'] = OwnerType.GROUP
2131-
self.params['owner_role'] = 'owner'
2132-
self.params['viewer_role'] = 'viewer'
2123+
self.params['owner_role'] = OwnerRole.OWNER
2124+
self.params['viewer_role'] = OwnerRole.VIEWER
21332125
return """
21342126
SELECT DISTINCT template_id
21352127
FROM (

backend/src/processes/tests/test_views/test_templates/test_titles_by_workflows.py

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from src.authentication.services.guest_auth import GuestJWTAuthService
44
from src.processes.enums import (
5+
OwnerRole,
56
OwnerType,
67
TemplateType,
78
WorkflowApiStatus,
@@ -284,6 +285,73 @@ def test_titles__user_not_template_owner__empty_result__ok(api_client):
284285
assert len(response.data) == 0
285286

286287

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+
287355
def test_titles__invited_user__unauthorized(api_client):
288356

289357
# arrange

0 commit comments

Comments
 (0)