def test_signals(self): received_signals = [] def hijack_started_receiver(sender, hijacker_id, hijacked_id, request, **kwargs): received_signals.append('hijack_started_%d_%d' % (hijacker_id, hijacked_id)) hijack_started.connect(hijack_started_receiver) def hijack_ended_receiver(sender, hijacker_id, hijacked_id, request, **kwargs): received_signals.append('hijack_ended_%d_%d' % (hijacker_id, hijacked_id)) hijack_ended.connect(hijack_ended_receiver) self.assertEqual(len(received_signals), 0) self._hijack(self.user) self.assertEqual(len(received_signals), 1) self.assertIn( 'hijack_started_%d_%d' % (self.superuser.id, self.user.id), received_signals) self._release_hijack() self.assertEqual(len(received_signals), 2) self.assertIn('hijack_ended_%d_%d' % (self.superuser.id, self.user.id), received_signals)
def test_signals(self): received_signals = [] def hijack_started_receiver(sender, hijacker_id, hijacked_id, request, **kwargs): received_signals.append('hijack_started_%d_%d' % (hijacker_id, hijacked_id)) hijack_started.connect(hijack_started_receiver) def hijack_ended_receiver(sender, hijacker_id, hijacked_id, request, **kwargs): received_signals.append('hijack_ended_%d_%d' % (hijacker_id, hijacked_id)) hijack_ended.connect(hijack_ended_receiver) self.assertEqual(len(received_signals), 0) self._hijack(self.user) self.assertEqual(len(received_signals), 1) self.assertIn('hijack_started_%d_%d' % (self.superuser.id, self.user.id), received_signals) self._release_hijack() self.assertEqual(len(received_signals), 2) self.assertIn('hijack_ended_%d_%d' % (self.superuser.id, self.user.id), received_signals)
"#users-needing-attention'><i class='fa fa-arrow-right' aria-hidden='true'></i> Jump to user</a>" )) return render(request, 'reserver/user_management/admin_users.html', {'users': users}) def log_hijack_started(sender, hijacker_id, hijacked_id, request, **kwargs): user = User.objects.get(id=hijacker_id) target_user = User.objects.get(id=hijacked_id) action = Action(user=user, target=str(target_user)) action.action = "took control of user" action.timestamp = timezone.now() action.save() hijack_started.connect(log_hijack_started) def log_hijack_ended(sender, hijacker_id, hijacked_id, request, **kwargs): user = User.objects.get(id=hijacker_id) target_user = User.objects.get(id=hijacked_id) action = Action(user=user, target=str(target_user)) action.action = "released control of user" action.timestamp = timezone.now() action.save() hijack_ended.connect(log_hijack_ended) class UserDataEditView(UpdateView):
'hijacked': _get_user_dict(kwargs['hijacked']) } requests.request(s['method'], s['url'], data=json.dumps(data), **s.get('kwargs', {})) except Exception: logging.exception("Could not notify of hijack-started") def notify_hijack_ended(sender, **kwargs): s = settings.PROLOGIN_HIJACK_NOTIFY if not s: return try: data = { 'event': 'end', 'hijacker': _get_user_dict(kwargs['hijacker']), 'hijacked': _get_user_dict(kwargs['hijacked']) } requests.request(s['method'], s['url'], data=json.dumps(data), **s.get('kwargs', {})) except Exception: logging.exception("Could not notify of hijack-ended") hijack_started.connect(notify_hijack_started) hijack_ended.connect(notify_hijack_ended)