From 4b3924814a01d3743c26f9c9e8ab177fd111d1f9 Mon Sep 17 00:00:00 2001 From: DATVenancio Date: Wed, 11 Jun 2025 16:39:54 -0300 Subject: [PATCH 1/4] api: grant maintainer privileges to superusers --- patchwork/api/patch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py index dae4269b..b7a3991c 100644 --- a/patchwork/api/patch.py +++ b/patchwork/api/patch.py @@ -425,6 +425,7 @@ def partial_update(self, request, *args, **kwargs): req_user_id = request.user.id is_maintainer = request.user.is_authenticated and ( obj.project in request.user.profile.maintainer_projects.all() + or request.user.is_superuser ) if 'attention_set' in request.data and request.method in ('PATCH',): From b118494832e92b709ef0a5bf0464e7cbcb7225b1 Mon Sep 17 00:00:00 2001 From: DATVenancio Date: Wed, 11 Jun 2025 16:40:56 -0300 Subject: [PATCH 2/4] views: grant maintainer privileges to superusers --- patchwork/views/patch.py | 1 + 1 file changed, 1 insertion(+) diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index 6c0e90f7..f82c0a82 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -66,6 +66,7 @@ def patch_detail(request, project_id, msgid): is_maintainer = ( request.user.is_authenticated and project in request.user.profile.maintainer_projects.all() + or request.user.is_superuser ) form = None From 9fbcd31db87369ec489395c93c332cd1e4d45880 Mon Sep 17 00:00:00 2001 From: DATVenancio Date: Wed, 11 Jun 2025 16:48:57 -0300 Subject: [PATCH 3/4] views: fix include in attention set and review interest count --- patchwork/templatetags/patch.py | 2 +- patchwork/views/patch.py | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/patchwork/templatetags/patch.py b/patchwork/templatetags/patch.py index 26282d83..d19b2c35 100644 --- a/patchwork/templatetags/patch.py +++ b/patchwork/templatetags/patch.py @@ -79,7 +79,7 @@ def patch_commit_display(patch): @register.filter(name='patch_interest') def patch_interest(patch): - reviews = patch.attention_set.count() + reviews = patch.patchattentionset_set.filter(removed=False).count() review_title = ( f'has {reviews} interested reviewers' if reviews > 0 diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index f82c0a82..cbe71ba7 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -90,9 +90,7 @@ def patch_detail(request, project_id, msgid): elif action in ['add-interest', 'remove-interest']: if request.user.is_authenticated: if action == 'add-interest': - PatchAttentionSet.objects.get_or_create( - patch=patch, user=request.user - ) + PatchAttentionSet.objects.upsert(patch, [request.user.id]) message = ( 'You have declared interest in reviewing this patch' ) From 50710b16e30900e2d55c56e09ddb2b56c49f3da0 Mon Sep 17 00:00:00 2001 From: DATVenancio Date: Thu, 12 Jun 2025 10:54:20 -0300 Subject: [PATCH 4/4] api: allow non maintainers to update only attention set --- patchwork/api/patch.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/patchwork/api/patch.py b/patchwork/api/patch.py index b7a3991c..48085316 100644 --- a/patchwork/api/patch.py +++ b/patchwork/api/patch.py @@ -427,6 +427,14 @@ def partial_update(self, request, *args, **kwargs): obj.project in request.user.profile.maintainer_projects.all() or request.user.is_superuser ) + non_attention_set_keys = [ + key for key in request.data if key != 'attention_set' + ] + + if non_attention_set_keys and not is_maintainer: + raise PermissionDenied( + detail='You do not have permission to edit patch properties.' + ) if 'attention_set' in request.data and request.method in ('PATCH',): attention_set = request.data.get('attention_set', None)