ensure creation file date
This commit is contained in:
parent
0eaff2266c
commit
8786f4b845
4 changed files with 46 additions and 5 deletions
24
core/files/migrations/0003_ensure_creation_date.py
Normal file
24
core/files/migrations/0003_ensure_creation_date.py
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# Generated by Django 4.2.7 on 2024-11-21 22:40
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
dependencies = [
|
||||||
|
('files', '0002_alter_file_file'),
|
||||||
|
]
|
||||||
|
|
||||||
|
def set_creation_date(apps, schema_editor):
|
||||||
|
File = apps.get_model('files', 'File')
|
||||||
|
for file in File.objects.all():
|
||||||
|
if file.created_at is None:
|
||||||
|
if not file.item.created_at is None:
|
||||||
|
file.created_at = file.item.created_at
|
||||||
|
else:
|
||||||
|
file.created_at = max(File.objects.filter(
|
||||||
|
id__lt=file.id, created_at__isnull=False).values_list('created_at', flat=True))
|
||||||
|
file.save()
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(set_creation_date),
|
||||||
|
]
|
|
@ -55,10 +55,10 @@ class EventTestCase(TestCase):
|
||||||
self.assertEqual(response.status_code, 204)
|
self.assertEqual(response.status_code, 204)
|
||||||
self.assertEqual(len(Event.objects.all()), 1)
|
self.assertEqual(len(Event.objects.all()), 1)
|
||||||
|
|
||||||
def test_items2(self):
|
def test_event_with_address(self):
|
||||||
from mail.models import EventAddress
|
from mail.models import EventAddress
|
||||||
event1 = Event.objects.create(slug='TEST1', name='Event')
|
event1 = Event.objects.create(slug='TEST1', name='Event')
|
||||||
EventAddress.objects.create(event=Event.objects.get(slug='TEST1'), address='foo@bar.baz')
|
EventAddress.objects.create(event=event1, address='foo@bar.baz')
|
||||||
response = self.client.get('/api/2/events/')
|
response = self.client.get('/api/2/events/')
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertEqual(1, len(response.json()))
|
self.assertEqual(1, len(response.json()))
|
||||||
|
|
|
@ -56,6 +56,23 @@ class ItemTestCase(TestCase):
|
||||||
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
||||||
self.assertEqual(len(response.json()[0]['related_issues']), 0)
|
self.assertEqual(len(response.json()[0]['related_issues']), 0)
|
||||||
|
|
||||||
|
def test_members_with_two_file(self):
|
||||||
|
import base64
|
||||||
|
item = Item.objects.create(container=self.box, event=self.event, description='1')
|
||||||
|
file1 = File.objects.create(item=item, data="data:text/plain;base64," + base64.b64encode(b"foo").decode('utf-8'))
|
||||||
|
file2 = File.objects.create(item=item, data="data:text/plain;base64," + base64.b64encode(b"bar").decode('utf-8'))
|
||||||
|
response = self.client.get(f'/api/2/{self.event.slug}/item/')
|
||||||
|
self.assertEqual(response.status_code, 200)
|
||||||
|
self.assertEqual(len(response.json()), 1)
|
||||||
|
self.assertEqual(response.json()[0]['id'], item.id)
|
||||||
|
self.assertEqual(response.json()[0]['description'], '1')
|
||||||
|
self.assertEqual(response.json()[0]['box'], 'BOX')
|
||||||
|
self.assertEqual(response.json()[0]['cid'], self.box.id)
|
||||||
|
self.assertEqual(response.json()[0]['file'], file2.hash)
|
||||||
|
self.assertEqual(response.json()[0]['returned'], False)
|
||||||
|
self.assertEqual(response.json()[0]['event'], self.event.slug)
|
||||||
|
self.assertEqual(len(response.json()[0]['related_issues']), 0)
|
||||||
|
|
||||||
def test_multi_members(self):
|
def test_multi_members(self):
|
||||||
Item.objects.create(container=self.box, event=self.event, description='1')
|
Item.objects.create(container=self.box, event=self.event, description='1')
|
||||||
Item.objects.create(container=self.box, event=self.event, description='2')
|
Item.objects.create(container=self.box, event=self.event, description='2')
|
||||||
|
|
|
@ -148,12 +148,12 @@ def filter_issues(issues, query):
|
||||||
|
|
||||||
|
|
||||||
@api_view(['GET'])
|
@api_view(['GET'])
|
||||||
@permission_classes([])
|
@permission_classes([IsAuthenticated])
|
||||||
# @permission_classes([IsAuthenticated])
|
|
||||||
# @permission_required('view_item', raise_exception=True)
|
|
||||||
def search_issues(request, event_slug, query):
|
def search_issues(request, event_slug, query):
|
||||||
try:
|
try:
|
||||||
event = Event.objects.get(slug=event_slug)
|
event = Event.objects.get(slug=event_slug)
|
||||||
|
if not request.user.has_event_perm(event, 'view_issuethread'):
|
||||||
|
return Response(status=403)
|
||||||
items = filter_issues(IssueThread.objects.filter(event=event), b64decode(query).decode('utf-8'))
|
items = filter_issues(IssueThread.objects.filter(event=event), b64decode(query).decode('utf-8'))
|
||||||
return Response(SearchResultSerializer(items, many=True).data)
|
return Response(SearchResultSerializer(items, many=True).data)
|
||||||
except Event.DoesNotExist:
|
except Event.DoesNotExist:
|
||||||
|
|
Loading…
Reference in a new issue