Skip to content

Commit

Permalink
Merge pull request #990 from thunderstore-io/minor-fixes
Browse files Browse the repository at this point in the history
Several smaller fixes
  • Loading branch information
MythicManiac authored Jan 5, 2024
2 parents 463470a + 8cf227c commit f3d8e4c
Show file tree
Hide file tree
Showing 11 changed files with 126 additions and 6 deletions.
1 change: 1 addition & 0 deletions django/thunderstore/repository/admin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
from .package import PackageAdmin
from .package_rating import PackageRatingAdmin
from .package_version import PackageVersionAdmin
from .submission import AsyncPackageSubmissionAdmin
from .team import TeamAdmin
35 changes: 35 additions & 0 deletions django/thunderstore/repository/admin/submission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from django.contrib import admin
from django.http import HttpRequest

from thunderstore.repository.models import AsyncPackageSubmission


@admin.register(AsyncPackageSubmission)
class AsyncPackageSubmissionAdmin(admin.ModelAdmin):
raw_id_fields = (
"owner",
"file",
)
list_select_related = (
"owner",
"file",
)
list_display = (
"owner",
"file",
"status",
"datetime_scheduled",
"datetime_polled",
"datetime_finished",
)
list_filter = ("status",)
search_fields = ("owner__username",)

def has_add_permission(self, request: HttpRequest, obj=None) -> bool:
return False

def has_change_permission(self, request: HttpRequest, obj=None) -> bool:
return False

def has_delete_permission(self, request: HttpRequest, obj=None) -> bool:
return False
36 changes: 36 additions & 0 deletions django/thunderstore/repository/admin/tests/test_submission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import pytest
from django.conf import settings
from django.test import Client

from thunderstore.repository.factories import AsyncPackageSubmissionFactory


@pytest.mark.django_db
def test_admin_asyncpackagesubmission_search(admin_client: Client) -> None:
username = AsyncPackageSubmissionFactory().owner.username
resp = admin_client.get(
path=f"/djangoadmin/repository/asyncpackagesubmission/?q={username}",
HTTP_HOST=settings.PRIMARY_HOST,
)
assert resp.status_code == 200


@pytest.mark.django_db
def test_admin_asyncpackagesubmission_list(admin_client: Client) -> None:
AsyncPackageSubmissionFactory()
resp = admin_client.get(
path="/djangoadmin/repository/asyncpackagesubmission/",
HTTP_HOST=settings.PRIMARY_HOST,
)
assert resp.status_code == 200


@pytest.mark.django_db
def test_admin_asyncpackagesubmission_detail(admin_client: Client) -> None:
pk = AsyncPackageSubmissionFactory().pk
path = f"/djangoadmin/repository/asyncpackagesubmission/{pk}/change/"
resp = admin_client.get(
path=path,
HTTP_HOST=settings.PRIMARY_HOST,
)
assert resp.status_code == 200
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
PackageSubmissionResult,
)
from thunderstore.repository.api.experimental.views.submit import get_usermedia_or_404
from thunderstore.repository.models.async_submission import AsyncPackageSubmission
from thunderstore.repository.models.submission import AsyncPackageSubmission


class PackageSubmissionStatusSerializer(serializers.Serializer):
Expand Down
2 changes: 1 addition & 1 deletion django/thunderstore/repository/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
from .async_submission import *
from .cache import *
from .discord_bot import *
from .namespace import *
from .package import *
from .package_download import *
from .package_rating import *
from .package_version import *
from .submission import *
from .team import *
from .wiki import *
2 changes: 1 addition & 1 deletion django/thunderstore/usermedia/cleanup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

def cleanup_expired_uploads():
client = get_s3_client()
for entry in UserMedia.objects.expired():
for entry in UserMedia.objects.expired().filter(async_package_submissions=None):
try:
cleanup_expired_upload(entry, client)
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 3.1.7 on 2024-01-04 15:48

import django.db.models.deletion
from django.conf import settings
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("usermedia", "0002_add_cleanup_schedule"),
]

operations = [
migrations.AlterField(
model_name="usermedia",
name="owner",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="usermedia",
to=settings.AUTH_USER_MODEL,
),
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.1.7 on 2024-01-04 15:59

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("usermedia", "0003_usermedia_owner_set_null"),
]

operations = [
migrations.AlterField(
model_name="usermedia",
name="size",
field=models.PositiveBigIntegerField(),
),
]
7 changes: 5 additions & 2 deletions django/thunderstore/usermedia/models/usermedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ class UserMedia(TimestampMixin, models.Model):
owner = models.ForeignKey(
settings.AUTH_USER_MODEL,
related_name="usermedia",
on_delete=models.PROTECT,
on_delete=models.SET_NULL,
blank=True,
null=True,
)
filename = models.CharField(max_length=1024)
key = models.CharField(max_length=2048)
size = models.PositiveIntegerField()
size = models.PositiveBigIntegerField()
uuid = models.UUIDField(default=ulid2.generate_ulid_as_uuid, primary_key=True)

# Prefix is the S3 storage bucket location prefix, only ever used for
Expand Down Expand Up @@ -127,6 +127,9 @@ def has_expired(self) -> bool:
def can_user_write(self, user: Optional[UserType]):
return user == self.owner

def __str__(self):
return self.filename

class Meta:
verbose_name = "user media"
verbose_name_plural = "user media"
2 changes: 1 addition & 1 deletion python-packages

0 comments on commit f3d8e4c

Please sign in to comment.