Skip to content

Commit

Permalink
Merge pull request #6287 from akatsoulas/aaq-waffle-flags
Browse files Browse the repository at this point in the history
Control the AAQ moderation flags through waffle
  • Loading branch information
akatsoulas authored Oct 10, 2024
2 parents 702645e + 760361e commit 4bdf529
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
22 changes: 12 additions & 10 deletions kitsune/questions/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import actstream
import actstream.actions
import waffle
from django.conf import settings
from django.contrib.auth.models import User
from django.contrib.contenttypes.fields import GenericForeignKey, GenericRelation
Expand Down Expand Up @@ -200,16 +201,17 @@ def save(self, update=False, *args, **kwargs):
# actstream
# Authors should automatically follow their own questions.
actstream.actions.follow(self.creator, self, send_action=False, actor_only=False)
# Add the question to the moderation queue to validate the topic
content_type = ContentType.objects.get_for_model(self)
FlaggedObject.objects.create(
content_type=content_type,
object_id=self.id,
creator=self.creator,
status=FlaggedObject.FLAG_PENDING,
reason="bug_support",
notes="New question, review topic",
)
if waffle.switch_is_active("flagit-spam-autoflag"):
# Add the question to the moderation queue to validate the topic
content_type = ContentType.objects.get_for_model(self)
FlaggedObject.objects.create(
content_type=content_type,
object_id=self.id,
creator=self.creator,
status=FlaggedObject.FLAG_PENDING,
reason="bug_support",
notes="New question, review topic",
)

def add_metadata(self, **kwargs):
"""Add (save to db) the passed in metadata.
Expand Down
6 changes: 4 additions & 2 deletions kitsune/questions/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
from datetime import datetime, timedelta
from unittest import mock

import waffle
from actstream.models import Action, Follow
from django.contrib.contenttypes.models import ContentType
from django.core.management import call_command
Expand Down Expand Up @@ -655,7 +655,9 @@ def test_question_solved_makes_action(self):
self.assertEqual(act.verb, "marked as a solution")
self.assertEqual(act.target, ans.question)

def test_create_question_creates_flag(self):
@mock.patch.object(waffle, "switch_is_active")
def test_create_question_creates_flag(self, switch_is_active):
"""Creating a question also creates a flag."""
switch_is_active.return_value = True
QuestionFactory(title="Test Question", content="Lorem Ipsum Dolor")
self.assertEqual(1, FlaggedObject.objects.filter(reason="bug_support").count())

0 comments on commit 4bdf529

Please sign in to comment.