mirror of
https://github.com/ae-utbm/sith.git
synced 2026-04-08 19:55:31 +00:00
Compare commits
1 Commits
update_pyt
...
album_fix
| Author | SHA1 | Date | |
|---|---|---|---|
|
09f8d0fd6d
|
@@ -110,7 +110,7 @@ class Command(BaseCommand):
|
||||
p.save(force_lock=True)
|
||||
|
||||
club_root = SithFile.objects.create(name="clubs", owner=root)
|
||||
sas = SithFile.objects.create(name="SAS", owner=root)
|
||||
sas = Album.objects.create(name="SAS", owner=root)
|
||||
main_club = Club.objects.create(
|
||||
id=1, name="AE", address="6 Boulevard Anatole France, 90000 Belfort"
|
||||
)
|
||||
|
||||
@@ -56,12 +56,6 @@ Commencez par installer les dépendances système :
|
||||
sudo pacman -S postgresql nginx
|
||||
```
|
||||
|
||||
=== "Fedora/RHEL/AlmaLinux/Rocky"
|
||||
|
||||
```bash
|
||||
sudo dnf install postgresql libpq-devel nginx
|
||||
```
|
||||
|
||||
=== "macOS"
|
||||
|
||||
```bash
|
||||
@@ -106,11 +100,9 @@ PROCFILE_SERVICE=
|
||||
vous devez ouvrir une autre fenêtre de votre terminal
|
||||
et lancer la commande `npm run serve`
|
||||
|
||||
## Configurer Redis/Valkey en service externe
|
||||
## Configurer Redis en service externe
|
||||
|
||||
Redis est installé comme dépendance mais n'es pas lancé par défaut.
|
||||
|
||||
Si vous avez installé Valkey parce que Redis n'es pas disponible, remplacez juste `redis` par `valkey`.
|
||||
Redis est installé comme dépendance mais pas lancé par défaut.
|
||||
|
||||
En mode développement, le sith se charge de le démarrer mais
|
||||
pas en production !
|
||||
|
||||
@@ -79,29 +79,6 @@ cd /mnt/<la_lettre_du_disque>/vos/fichiers/comme/dhab
|
||||
sudo pacman -S uv gcc git gettext pkgconf npm valkey
|
||||
```
|
||||
|
||||
=== "Fedora"
|
||||
```bash
|
||||
sudo dnf update
|
||||
sudo dnf install epel-release
|
||||
sudo dnf install python-devel uv git gettext pkgconf npm redis @c-development @development-tools
|
||||
```
|
||||
|
||||
=== "RHEL/AlmaLinux/Rocky"
|
||||
```bash
|
||||
dnf update
|
||||
dnf install epel-release
|
||||
dnf install python-devel uv git gettext pkgconf npm valkey
|
||||
dnf group install "Development Tools"
|
||||
```
|
||||
|
||||
La couche de compatibilitée valkey/redis est un package Fedora.
|
||||
Il est nécessaire de faire un alias nous même:
|
||||
|
||||
```bash
|
||||
ln -s /usr/bin/valkey-server /usr/bin/redis-server
|
||||
```
|
||||
|
||||
|
||||
=== "macOS"
|
||||
|
||||
Pour installer les dépendances, il est fortement recommandé d'installer le gestionnaire de paquets `homebrew <https://brew.sh/index_fr>`_.
|
||||
@@ -121,7 +98,7 @@ cd /mnt/<la_lettre_du_disque>/vos/fichiers/comme/dhab
|
||||
!!!note
|
||||
|
||||
Python ne fait pas parti des dépendances puisqu'il est automatiquement
|
||||
installé par uv. Il est cependant parfois nécessaire d'installer les headers Python nécessaire à la compilation de certains paquets.
|
||||
installé par uv.
|
||||
|
||||
## Finaliser l'installation
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ authors = [
|
||||
license = { text = "GPL-3.0-only" }
|
||||
requires-python = "<4.0,>=3.12"
|
||||
dependencies = [
|
||||
"django>=5.2.13,<6.0.0",
|
||||
"django>=5.2.12,<6.0.0",
|
||||
"django-ninja>=1.5.3,<6.0.0",
|
||||
"django-ninja-extra>=0.31.0",
|
||||
"Pillow>=12.1.1,<13.0.0",
|
||||
@@ -30,7 +30,7 @@ dependencies = [
|
||||
"phonenumbers>=9.0.25,<10.0.0",
|
||||
"reportlab>=4.4.10,<5.0.0",
|
||||
"django-haystack<4.0.0,>=3.3.0",
|
||||
"xapian-haystack<3.1.0,<5.0.0",
|
||||
"xapian-haystack<4.0.0,>=3.1.0",
|
||||
"libsass<1.0.0,>=0.23.0",
|
||||
"django-ordered-model<4.0.0,>=3.7.4",
|
||||
"django-simple-captcha<1.0.0,>=0.6.3",
|
||||
@@ -45,7 +45,7 @@ dependencies = [
|
||||
"pydantic-extra-types>=2.11.0,<3.0.0",
|
||||
"ical>=11.1.0,<12",
|
||||
"redis[hiredis]>=5.3.0,<8.0.0",
|
||||
"environs[django]>=14.5.0,<16.0.0",
|
||||
"environs[django]>=14.5.0,<15.0.0",
|
||||
"requests>=2.32.5,<3.0.0",
|
||||
"honcho>=2.0.0",
|
||||
"psutil>=7.2.2,<8.0.0",
|
||||
|
||||
@@ -50,13 +50,15 @@ class AlbumEditForm(forms.ModelForm):
|
||||
model = Album
|
||||
fields = ["name", "date", "file", "parent", "edit_groups"]
|
||||
widgets = {
|
||||
"parent": AutoCompleteSelectAlbum,
|
||||
"edit_groups": AutoCompleteSelectMultipleGroup,
|
||||
}
|
||||
|
||||
name = forms.CharField(max_length=Album.NAME_MAX_LENGTH, label=_("file name"))
|
||||
date = forms.DateField(label=_("Date"), widget=SelectDate, required=True)
|
||||
recursive = forms.BooleanField(label=_("Apply rights recursively"), required=False)
|
||||
parent = forms.ModelChoiceField(
|
||||
Album.objects.all(), required=True, widget=AutoCompleteSelectAlbum
|
||||
)
|
||||
|
||||
|
||||
class PictureModerationRequestForm(forms.ModelForm):
|
||||
|
||||
@@ -205,7 +205,13 @@ class AlbumQuerySet(models.QuerySet):
|
||||
|
||||
class SASAlbumManager(models.Manager):
|
||||
def get_queryset(self):
|
||||
return super().get_queryset().filter(is_in_sas=True, is_folder=True)
|
||||
return (
|
||||
super()
|
||||
.get_queryset()
|
||||
.filter(
|
||||
Q(id=settings.SITH_SAS_ROOT_DIR_ID) | Q(is_in_sas=True, is_folder=True)
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class Album(SasFile):
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
# OR WITHIN THE LOCAL FILE "LICENSE"
|
||||
#
|
||||
#
|
||||
from datetime import date
|
||||
from typing import Callable
|
||||
|
||||
import pytest
|
||||
@@ -20,6 +21,7 @@ from django.conf import settings
|
||||
from django.core.cache import cache
|
||||
from django.test import Client, TestCase
|
||||
from django.urls import reverse
|
||||
from django.utils import timezone
|
||||
from model_bakery import baker
|
||||
from pytest_django.asserts import assertHTMLEqual, assertInHTML, assertRedirects
|
||||
|
||||
@@ -133,6 +135,180 @@ class TestAlbumUpload:
|
||||
assert not album.children.exists()
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
class TestAlbumEdit:
|
||||
@pytest.fixture
|
||||
def sas_root(self) -> Album:
|
||||
return Album.objects.get(id=settings.SITH_SAS_ROOT_DIR_ID)
|
||||
|
||||
@pytest.fixture
|
||||
def album(self, sas_root: Album) -> Album:
|
||||
return baker.make(Album, parent=sas_root, is_moderated=True)
|
||||
|
||||
@pytest.fixture
|
||||
def moderator(self) -> User:
|
||||
return baker.make(
|
||||
User, groups=[Group.objects.get(pk=settings.SITH_GROUP_SAS_ADMIN_ID)]
|
||||
)
|
||||
|
||||
@pytest.fixture
|
||||
def subscriber(self) -> User:
|
||||
return subscriber_user.make()
|
||||
|
||||
@pytest.fixture
|
||||
def root(self) -> User:
|
||||
return User.objects.get(username="root")
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"user",
|
||||
[
|
||||
None,
|
||||
"subscriber",
|
||||
],
|
||||
)
|
||||
def test_permission_denied(
|
||||
self,
|
||||
client: Client,
|
||||
album: Album,
|
||||
request: pytest.FixtureRequest,
|
||||
user: str | None,
|
||||
):
|
||||
if user:
|
||||
client.force_login(request.getfixturevalue(user))
|
||||
response = client.get(reverse("sas:album_edit", kwargs={"album_id": album.pk}))
|
||||
assert response.status_code == 403
|
||||
response = client.post(reverse("sas:album_edit", kwargs={"album_id": album.pk}))
|
||||
assert response.status_code == 403
|
||||
|
||||
def test_sas_root_read_only(self, client: Client, sas_root: Album, moderator: User):
|
||||
client.force_login(moderator)
|
||||
response = client.get(
|
||||
reverse("sas:album_edit", kwargs={"album_id": sas_root.pk})
|
||||
)
|
||||
assert response.status_code == 404
|
||||
response = client.post(
|
||||
reverse("sas:album_edit", kwargs={"album_id": sas_root.pk})
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"user",
|
||||
[
|
||||
"root",
|
||||
"moderator",
|
||||
],
|
||||
)
|
||||
def test_update(
|
||||
self,
|
||||
client: Client,
|
||||
album: Album,
|
||||
sas_root: Album,
|
||||
request: pytest.FixtureRequest,
|
||||
user: str,
|
||||
):
|
||||
client.force_login(request.getfixturevalue(user))
|
||||
response = client.get(reverse("sas:album_edit", kwargs={"album_id": album.pk}))
|
||||
assert response.status_code == 200
|
||||
|
||||
# Test no changes
|
||||
response = client.post(reverse("sas:album_edit", kwargs={"album_id": album.pk}))
|
||||
assert response.status_code == 200
|
||||
|
||||
updated_album = Album.objects.get(id=album.pk)
|
||||
assert album.name == updated_album.name
|
||||
assert album.date == updated_album.date
|
||||
assert album.parent == updated_album.parent
|
||||
assert album.edit_groups == updated_album.edit_groups
|
||||
|
||||
# Prepare a good payload
|
||||
payload = {
|
||||
"name": album.name[50],
|
||||
"parent": baker.make(Album, parent=sas_root, is_moderated=True).pk,
|
||||
"date": date.today().isoformat(),
|
||||
"recursive": False,
|
||||
}
|
||||
# Test missing parent
|
||||
payload_missing_parent = {**payload}
|
||||
del payload_missing_parent["parent"]
|
||||
response = client.post(
|
||||
reverse(
|
||||
"sas:album_edit",
|
||||
kwargs={"album_id": album.pk},
|
||||
),
|
||||
payload_missing_parent,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
updated_album = Album.objects.get(id=album.pk)
|
||||
assert updated_album.name == album.name
|
||||
assert updated_album.parent == album.parent
|
||||
assert updated_album.date == album.date
|
||||
|
||||
# Test missing date
|
||||
payload_missing_date = {**payload}
|
||||
del payload_missing_date["date"]
|
||||
response = client.post(
|
||||
reverse(
|
||||
"sas:album_edit",
|
||||
kwargs={"album_id": album.pk},
|
||||
),
|
||||
payload_missing_date,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
updated_album = Album.objects.get(id=album.pk)
|
||||
assert updated_album.name == album.name
|
||||
assert updated_album.parent == album.parent
|
||||
assert updated_album.date == album.date
|
||||
|
||||
# Test recursive parent
|
||||
payload_recursive_parent = {**payload}
|
||||
payload_recursive_parent["parent"] = album.pk
|
||||
response = client.post(
|
||||
reverse(
|
||||
"sas:album_edit",
|
||||
kwargs={"album_id": album.pk},
|
||||
),
|
||||
payload_recursive_parent,
|
||||
)
|
||||
assert response.status_code == 200
|
||||
updated_album = Album.objects.get(id=album.pk)
|
||||
assert updated_album.name == album.name
|
||||
assert updated_album.parent == album.parent
|
||||
assert updated_album.date == album.date
|
||||
|
||||
# Test successful update
|
||||
response = client.post(
|
||||
reverse(
|
||||
"sas:album_edit",
|
||||
kwargs={"album_id": album.pk},
|
||||
),
|
||||
payload,
|
||||
)
|
||||
assert response.status_code == 302
|
||||
updated_album = Album.objects.get(id=album.pk)
|
||||
assert updated_album.name == payload["name"]
|
||||
assert updated_album.parent.id == payload["parent"]
|
||||
assert timezone.localdate(updated_album.date) == date.fromisoformat(
|
||||
payload["date"]
|
||||
)
|
||||
|
||||
# Test root album can be used as parent
|
||||
payload["parent"] = sas_root.pk
|
||||
response = client.post(
|
||||
reverse(
|
||||
"sas:album_edit",
|
||||
kwargs={"album_id": album.pk},
|
||||
),
|
||||
payload,
|
||||
)
|
||||
assert response.status_code == 302
|
||||
updated_album = Album.objects.get(id=album.pk)
|
||||
assert updated_album.name == payload["name"]
|
||||
assert updated_album.parent.id == payload["parent"]
|
||||
assert timezone.localdate(updated_album.date) == date.fromisoformat(
|
||||
payload["date"]
|
||||
)
|
||||
|
||||
|
||||
class TestSasModeration(TestCase):
|
||||
@classmethod
|
||||
def setUpTestData(cls):
|
||||
|
||||
@@ -37,7 +37,7 @@ from sas.forms import (
|
||||
PictureModerationRequestForm,
|
||||
PictureUploadForm,
|
||||
)
|
||||
from sas.models import Album, PeoplePictureRelation, Picture
|
||||
from sas.models import Album, AlbumQuerySet, PeoplePictureRelation, Picture
|
||||
|
||||
|
||||
class AlbumCreateFragment(FragmentMixin, CreateView):
|
||||
@@ -266,6 +266,9 @@ class AlbumEditView(CanEditMixin, UpdateView):
|
||||
template_name = "core/edit.jinja"
|
||||
pk_url_kwarg = "album_id"
|
||||
|
||||
def get_queryset(self) -> AlbumQuerySet:
|
||||
return super().get_queryset().exclude(id=settings.SITH_SAS_ROOT_DIR_ID)
|
||||
|
||||
def form_valid(self, form):
|
||||
ret = super().form_valid(form)
|
||||
if form.cleaned_data["recursive"]:
|
||||
|
||||
Reference in New Issue
Block a user