Skip to content

Commit 3b2b73c

Browse files
committed
patchwork/api/check.py: better handle add checks permission
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
1 parent 1455a92 commit 3b2b73c

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

‎patchwork/api/check.py‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,23 @@ class CheckListCreate(CheckMixin, ListCreateAPIView):
108108
lookup_url_kwarg = 'patch_id'
109109
ordering = 'id'
110110

111+
def is_editable(self, user):
112+
if not user.is_authenticated:
113+
return False
114+
115+
# Only users with add_check permission can do it.
116+
# Notice that this is a global permission: it allows
117+
# adding checks to any project inside Patchwork.
118+
if user.has_perm('patchwork.add_check'):
119+
patch._edited_by = user
120+
return True
121+
122+
# Being maintainer doesn't grant rights to create checks.
123+
return False
124+
111125
def create(self, request, patch_id, *args, **kwargs):
112126
p = get_object_or_404(Patch, id=patch_id)
113-
if not p.is_editable(request.user):
127+
if not self.is_editable(request.user):
114128
raise PermissionDenied()
115129
request.patch = p
116130
return super(CheckListCreate, self).create(request, *args, **kwargs)

0 commit comments

Comments
 (0)