未验证 提交 a6768625 编写于 作者: B bseres99 提交者: GitHub

Fix stage and state modification permission (#4324)

Co-authored-by: NMatyesz12 <turi.mate12@gmail.com>
上级 2f1e89cc
...@@ -357,7 +357,7 @@ class JobUpdateAPITestCase(APITestCase): ...@@ -357,7 +357,7 @@ class JobUpdateAPITestCase(APITestCase):
def test_api_v2_jobs_id_annotator(self): def test_api_v2_jobs_id_annotator(self):
data = {"stage": StageChoice.ANNOTATION, "assignee": self.annotator.id} data = {"stage": StageChoice.ANNOTATION, "assignee": self.annotator.id}
response = self._run_api_v2_jobs_id(self.job.id, self.annotator, data) response = self._run_api_v2_jobs_id(self.job.id, self.annotator, data)
self._check_request(response, data) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
response = self._run_api_v2_jobs_id(self.job.id + 10, self.annotator, data) response = self._run_api_v2_jobs_id(self.job.id + 10, self.annotator, data)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
...@@ -391,8 +391,8 @@ class JobPartialUpdateAPITestCase(JobUpdateAPITestCase): ...@@ -391,8 +391,8 @@ class JobPartialUpdateAPITestCase(JobUpdateAPITestCase):
def test_api_v2_jobs_id_annotator_partial(self): def test_api_v2_jobs_id_annotator_partial(self):
data = {"stage": StageChoice.ANNOTATION} data = {"stage": StageChoice.ANNOTATION}
response = self._run_api_v2_jobs_id(self.job.id, self.owner, data) response = self._run_api_v2_jobs_id(self.job.id, self.annotator, data)
self._check_request(response, data) self.assertEquals(response.status_code, status.HTTP_403_FORBIDDEN, response)
def test_api_v2_jobs_id_admin_partial(self): def test_api_v2_jobs_id_admin_partial(self):
data = {"assignee_id": self.user.id} data = {"assignee_id": self.user.id}
......
...@@ -788,6 +788,10 @@ class JobPermission(OpenPolicyAgentPermission): ...@@ -788,6 +788,10 @@ class JobPermission(OpenPolicyAgentPermission):
project_id = request.data.get('project_id') or request.data.get('project') project_id = request.data.get('project_id') or request.data.get('project')
if project_id != getattr(obj.project, 'id', None): if project_id != getattr(obj.project, 'id', None):
scopes.append(scope + ':project') scopes.append(scope + ':project')
if 'stage' in request.data:
scopes.append(scope + ':stage')
if 'state' in request.data:
scopes.append(scope + ':state')
if any(k in request.data for k in ('name', 'labels', 'bug_tracker', 'subset')): if any(k in request.data for k in ('name', 'labels', 'bug_tracker', 'subset')):
scopes.append(scope + ':desc') scopes.append(scope + ':desc')
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册