extensions-website/reviewers/models.py
Anna Sirota 729ce453ac Fix deletion task, protect more account-linked data
Account deletion task had a bug in it: its was skipping all accounts
that were deactivated, but accounts are deactivated as soon as
date_deletion_requested is received via webhook, so no
deletion/anonymisation would have happened.

In addition to fixing that (now the task will exclude all account records
that look like they were already anonymized), this also changes several on-delete properties:

  * abuse reports about a deleted account are deleted along with it;
  * abuse reports made by a deleted account remain;
  * ratings made by a deleted account remain;
  * approval activity protects against deletion: account cannot be deleted if it authored any approval activity;

This change also makes sure that API tokens and OAuth info/tokens
are deleted when account deleted or anonymized.
2024-06-05 13:20:51 +02:00

56 lines
1.9 KiB
Python

from django.contrib.auth import get_user_model
from django.db import models
from django.utils.translation import gettext_lazy as _
import common.help_texts
from common.model_mixins import CreatedModifiedMixin, RecordDeletionMixin
from constants.base import EXTENSION_TYPE_CHOICES
from constants.reviewers import CANNED_RESPONSE_CATEGORY_CHOICES
User = get_user_model()
class CannedResponse(CreatedModifiedMixin, models.Model):
TYPES = EXTENSION_TYPE_CHOICES
CATEGORIES = CANNED_RESPONSE_CATEGORY_CHOICES
name = models.CharField(max_length=255)
response = models.TextField()
sort_group = models.CharField(max_length=255)
type = models.PositiveIntegerField(choices=TYPES, db_index=True, default=TYPES.BPY)
# Category is used only by code-manager
category = models.PositiveIntegerField(choices=CATEGORIES, default=CATEGORIES.OTHER)
def __str__(self):
return str(self.name)
class ApprovalActivity(CreatedModifiedMixin, RecordDeletionMixin, models.Model):
class ActivityType(models.TextChoices):
COMMENT = "COM", _("Comment")
APPROVED = "APR", _("Approved")
AWAITING_CHANGES = "AWC", _("Awaiting Changes")
AWAITING_REVIEW = "AWR", _("Awaiting Review")
UPLOADED_NEW_VERSION = "UNV", _("Uploaded New Version")
user = models.ForeignKey(User, on_delete=models.PROTECT, blank=True, null=True)
extension = models.ForeignKey(
'extensions.Extension',
on_delete=models.CASCADE,
related_name='review_activity',
)
type = models.CharField(
max_length=3,
choices=ActivityType.choices,
default=ActivityType.COMMENT,
)
message = models.TextField(help_text=common.help_texts.markdown, blank=False, null=False)
class Meta:
verbose_name_plural = "Review activity"
def __str__(self):
return f"{self.extension.name}: {self.get_type_display()}"