mirror of
https://github.com/pacnpal/thrillwiki_django_no_react.git
synced 2025-12-21 09:51:09 -05:00
Add OWASP compliance mapping and security test case templates, and document version control implementation phases
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
from django.db import models
|
||||
from django.urls import reverse
|
||||
from django.contrib.contenttypes.fields import GenericForeignKey
|
||||
from django.contrib.contenttypes.models import ContentType
|
||||
from django.core.validators import MinValueValidator, MaxValueValidator
|
||||
from history_tracking.models import HistoricalModel, VersionBranch, ChangeSet
|
||||
from history_tracking.signals import get_current_branch, ChangesetContextManager
|
||||
|
||||
class Review(models.Model):
|
||||
class Review(HistoricalModel):
|
||||
# Generic relation to allow reviews on different types (rides, parks)
|
||||
content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
|
||||
object_id = models.PositiveIntegerField()
|
||||
@@ -47,6 +50,58 @@ class Review(models.Model):
|
||||
def __str__(self):
|
||||
return f"Review of {self.content_object} by {self.user.username}"
|
||||
|
||||
def save(self, *args, **kwargs) -> None:
|
||||
# Get the branch from context or use default
|
||||
current_branch = get_current_branch()
|
||||
|
||||
if current_branch:
|
||||
# Save in the context of the current branch
|
||||
super().save(*args, **kwargs)
|
||||
else:
|
||||
# If no branch context, save in main branch
|
||||
main_branch, _ = VersionBranch.objects.get_or_create(
|
||||
name='main',
|
||||
defaults={'metadata': {'type': 'default_branch'}}
|
||||
)
|
||||
|
||||
with ChangesetContextManager(branch=main_branch):
|
||||
super().save(*args, **kwargs)
|
||||
|
||||
def get_version_info(self) -> dict:
|
||||
"""Get version control information for this review and its reviewed object"""
|
||||
content_type = ContentType.objects.get_for_model(self)
|
||||
latest_changes = ChangeSet.objects.filter(
|
||||
content_type=content_type,
|
||||
object_id=self.pk,
|
||||
status='applied'
|
||||
).order_by('-created_at')[:5]
|
||||
|
||||
active_branches = VersionBranch.objects.filter(
|
||||
changesets__content_type=content_type,
|
||||
changesets__object_id=self.pk,
|
||||
is_active=True
|
||||
).distinct()
|
||||
|
||||
# Get version info for the reviewed object if it's version controlled
|
||||
reviewed_object_branch = None
|
||||
if hasattr(self.content_object, 'get_version_info'):
|
||||
reviewed_object_branch = self.content_object.get_version_info().get('current_branch')
|
||||
|
||||
return {
|
||||
'latest_changes': latest_changes,
|
||||
'active_branches': active_branches,
|
||||
'current_branch': get_current_branch(),
|
||||
'total_changes': latest_changes.count(),
|
||||
'reviewed_object_branch': reviewed_object_branch
|
||||
}
|
||||
|
||||
def get_absolute_url(self) -> str:
|
||||
"""Get the absolute URL for this review"""
|
||||
if hasattr(self.content_object, 'get_absolute_url'):
|
||||
base_url = self.content_object.get_absolute_url()
|
||||
return f"{base_url}#review-{self.pk}"
|
||||
return reverse('reviews:review_detail', kwargs={'pk': self.pk})
|
||||
|
||||
class ReviewImage(models.Model):
|
||||
review = models.ForeignKey(
|
||||
Review,
|
||||
|
||||
Reference in New Issue
Block a user