mirror of https://github.com/MISP/PyMISP
fix: Event delegation was incorrect
parent
d47bf6fbdf
commit
daca32db36
|
@ -1779,25 +1779,12 @@ class ExpandedPyMISP(PyMISP):
|
|||
def accept_event_delegation(self, delegation: Union[MISPEventDelegation, int, str], pythonify: bool=False):
|
||||
delegation_id = self.__get_uuid_or_id_from_abstract_misp(delegation)
|
||||
delegation = self._prepare_request('POST', f'event_delegations/acceptDelegation/{delegation_id}')
|
||||
delegation = self._check_response(delegation, expect_json=True)
|
||||
if not (self.global_pythonify or pythonify) or 'errors' in delegation:
|
||||
return delegation
|
||||
e = MISPEvent()
|
||||
e.from_dict(**delegation)
|
||||
return e
|
||||
return self._check_response(delegation, expect_json=True)
|
||||
|
||||
def discard_event_delegation(self, delegation: Union[MISPEventDelegation, int, str], pythonify: bool=False):
|
||||
delegation_id = self.__get_uuid_or_id_from_abstract_misp(delegation)
|
||||
delegation = self._prepare_request('POST', f'event_delegations/deleteDelegation/{delegation_id}')
|
||||
delegation = self._check_response(delegation, expect_json=True)
|
||||
if self._old_misp((2, 4, 114), '2020-01-01', sys._getframe().f_code.co_name) and isinstance(delegation, list):
|
||||
# FIXME: https://github.com/MISP/MISP/issues/5056
|
||||
delegation = delegation[0]
|
||||
if not (self.global_pythonify or pythonify) or 'errors' in delegation:
|
||||
return delegation
|
||||
e = MISPEvent()
|
||||
e.from_dict(**delegation)
|
||||
return e
|
||||
return self._check_response(delegation, expect_json=True)
|
||||
|
||||
def delegate_event(self, event: Union[MISPEvent, int, str, UUID]=None,
|
||||
organisation: Union[MISPOrganisation, int, str, UUID]=None,
|
||||
|
|
|
@ -1884,7 +1884,9 @@ class TestComprehensive(unittest.TestCase):
|
|||
# Test delegation
|
||||
delegations = self.delegate_user_misp_connector.event_delegations()
|
||||
self.assertEqual(delegations[0].id, delegation.id)
|
||||
e = self.delegate_user_misp_connector.accept_event_delegation(delegation)
|
||||
r = self.delegate_user_misp_connector.accept_event_delegation(delegation)
|
||||
self.assertEqual(r['message'], 'Event ownership transferred.')
|
||||
e = self.delegate_user_misp_connector.get_event(e)
|
||||
self.assertTrue(isinstance(e, MISPEvent), e)
|
||||
self.assertEqual(e.info, 'Test Roles')
|
||||
self.assertEqual(e.org.name, 'Test Org - delegate')
|
||||
|
@ -1892,13 +1894,14 @@ class TestComprehensive(unittest.TestCase):
|
|||
self.assertEqual(r['message'], 'Event deleted.', r)
|
||||
e = test_roles_user_connector.add_event(base_event)
|
||||
delegation = test_roles_user_connector.delegate_event(e, self.test_org_delegate)
|
||||
e = test_roles_user_connector.discard_event_delegation(delegation.id)
|
||||
r = test_roles_user_connector.discard_event_delegation(delegation.id)
|
||||
self.assertEqual(r['message'], 'Delegation request deleted.')
|
||||
|
||||
e = test_roles_user_connector.get_event(e)
|
||||
self.assertTrue(isinstance(e, MISPEvent), e)
|
||||
self.assertEqual(e.info, 'Test Roles')
|
||||
self.assertEqual(e.org_id, int(self.test_org.id))
|
||||
finally:
|
||||
# time.sleep(200)
|
||||
# NOTE: When the delegation will work, we need to delete as site admin.
|
||||
self.user_misp_connector.delete_event(e)
|
||||
|
||||
# Publisher
|
||||
|
|
Loading…
Reference in New Issue