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)
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): model = UserData template_name = 'reserver/user/userdata_edit_form.html' form_class = AdminUserDataForm def get_success_url(self): return reverse_lazy('admin-users') def set_as_admin(request, pk): user = get_object_or_404(User, pk=pk) if request.user.is_superuser: user.is_staff = True
'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)