Ejemplo n.º 1
0
 def post(self, request, *args, **kwargs):
     days = int(request.POST.get('days_get', 0))
     models = []
     if request.POST.get('preprint_get', None):
         models.append(Preprint)
     if request.POST.get('node_get', None):
         models.append(Node)
     if request.POST.get('registration_get', None):
         models.append(Registration)
     regex = request.POST.get('regex_get', None)
     if not days:
         messages.error(
             request,
             'A number of days over 0 must be specified. Check your inputs and try again'
         )
         return redirect(reverse('management:commands'))
     if not models:
         messages.error(
             request,
             'At least one model must be specified. Check your inputs and try again'
         )
         return redirect(reverse('management:commands'))
     if not regex:
         messages.error(
             request,
             'A regular expression input must be specified. Check your inputs and try again'
         )
         return redirect(reverse('management:commands'))
     response = HttpResponse(content_type='text/csv')
     manage_spammy_content(regex, days, models, response_object=response)
     filename = 'spam_document.csv'
     response['Content-Disposition'] = f'attachment; filename={filename}'
     return response
Ejemplo n.º 2
0
 def test_ban_all_preprint_spam(self, user, user_two, kombat_preprint, preprint_two):
     manage_spammy_content('Kombat', models=[Preprint, ], ban=True)
     kombat_preprint.reload()
     preprint_two.reload()
     user.reload()
     user_two.reload()
     assert kombat_preprint.is_spam
     assert not preprint_two.is_spam
     assert user.is_disabled
     assert not user_two.is_disabled
Ejemplo n.º 3
0
 def test_ban_recent_spam(self, kombat_node, spam_node_but_old, user, user_two):
     manage_spammy_content('Kombat', models=[Node, ], ban=True)
     kombat_node.reload()
     spam_node_but_old.reload()
     user.reload()
     user_two.reload()
     assert kombat_node.is_spam
     assert not spam_node_but_old.is_spam
     assert user.is_disabled
     assert not user_two.is_disabled
Ejemplo n.º 4
0
 def test_ban_all_node_spam(self, user, user_two, kombat_node, node_two):
     manage_spammy_content('Kombat', models=[Node, ], ban=True)
     user.reload()
     kombat_node.reload()
     node_two.reload()
     user_two.reload()
     assert kombat_node.is_spam
     assert not node_two.is_spam
     assert user.is_disabled
     assert not user_two.is_disabled
Ejemplo n.º 5
0
 def test_ban_all_registration_spam(self, user, user_two, kombat_registration, registration_two):
     manage_spammy_content('Kombat', models=[Registration, ], ban=True)
     user.reload()
     user_two.reload()
     kombat_registration.reload()
     registration_two.reload()
     assert kombat_registration.is_spam
     assert not registration_two.is_spam
     assert user.is_disabled
     assert not user_two.is_disabled
Ejemplo n.º 6
0
 def post(self, request, *args, **kwargs):
     days = int(request.POST.get('days_ban', 0))
     models = []
     if request.POST.get('preprint_ban', None):
         models.append(Preprint)
     if request.POST.get('node_ban', None):
         models.append(Node)
     if request.POST.get('registration_ban', None):
         models.append(Registration)
     regex = request.POST.get('regex_ban', None)
     if not days:
         messages.error(
             request,
             'A number of days over 0 must be specified. Check your inputs and try again'
         )
         return redirect(reverse('management:commands'))
     if not models:
         messages.error(
             request,
             'At least one model must be specified. Check your inputs and try again'
         )
         return redirect(reverse('management:commands'))
     if not regex:
         messages.error(
             request,
             'A regular expression input must be specified. Check your inputs and try again'
         )
         return redirect(reverse('management:commands'))
     spam_ban_count = manage_spammy_content(regex, days, models, ban=True)
     messages.success(request, f'{spam_ban_count} users have been banned')
     return redirect(reverse('management:commands'))
Ejemplo n.º 7
0
 def test_get_recent_spam(self, kombat_node, spam_node_but_old):
     spam_data = manage_spammy_content('Kombat', models=[Node, ], return_csv=False)
     spam_guids = [spam['guid'] for spam in spam_data]
     assert kombat_node._id in spam_guids
     assert spam_node_but_old not in spam_guids
Ejemplo n.º 8
0
 def test_get_all_preprint_spam(self, kombat_preprint, preprint_two):
     spam_data = manage_spammy_content('Kombat', models=[Preprint, ], return_csv=False)
     spam_guids = [spam['guid'] for spam in spam_data]
     assert kombat_preprint._id in spam_guids
     assert preprint_two not in spam_guids
Ejemplo n.º 9
0
 def test_get_all_registration_spam(self, kombat_registration, registration_two):
     spam_data = manage_spammy_content('Kombat', models=[Registration, ], return_csv=False)
     spam_guids = [spam['guid'] for spam in spam_data]
     assert kombat_registration._id in spam_guids
     assert registration_two not in spam_guids
Ejemplo n.º 10
0
 def test_get_all_node_spam(self, kombat_node, node_two):
     spam_data = manage_spammy_content('Kombat', models=[Node, ], return_csv=False)
     spam_guids = [spam['guid'] for spam in spam_data]
     assert kombat_node._id in spam_guids
     assert node_two not in spam_guids