Skip to content

Commit

Permalink
Corrige la mauvaise permission sur les galeries lors de la désinscrip…
Browse files Browse the repository at this point in the history
…tion (#6693)
  • Loading branch information
philippemilink authored Dec 25, 2024
1 parent 4096ebf commit b39c7fc
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
42 changes: 42 additions & 0 deletions zds/gallery/migrations/0008_normalize_user_gallery_mode.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Generated by Django 4.2.16 on 2024-11-21 22:39

"""
In production, the column `mode` of the table gallery_usergallery contains both
lower case 'w' and upper case 'W':
SELECT mode, COUNT(*) AS nb FROM gallery_usergallery GROUP BY BINARY mode;
+------+-------+
| mode | nb |
+------+-------+
| R | 10 |
| W | 22693 |
| w | 603 |
+------+-------+
while only the upper case 'W' is actually recognized (see value of
zds.gallery.models.GALLERY_WRITE). This comes probably from the the permission
modification of galleries when a member unregisters itself: the lower case 'w'
was hard-coded.
This migration changes 'w' to 'W'.
"""

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("gallery", "0007_auto_20191122_1154"),
]

operations = [
# This WHERE is actually case *in*sensitive, but it will not change
# the result (just modify more records which don't need it), but
# having a WHERE which is case-sensitive *and* compatible with both
# SQLite and MariaDB seems tricky...
migrations.RunSQL(
("UPDATE gallery_usergallery SET mode = 'W' WHERE mode = 'w';"),
),
]
4 changes: 2 additions & 2 deletions zds/member/views/register.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from django.views.generic import CreateView, FormView

from zds.forum.models import Topic
from zds.gallery.models import UserGallery
from zds.gallery.models import UserGallery, GALLERY_WRITE
from zds.member import NEW_ACCOUNT
from zds.member.commons import (
ProfileCreate,
Expand Down Expand Up @@ -242,7 +242,7 @@ def unregister(request):
if gallery.gallery.get_linked_users().count() == 1:
anonymous_gallery = UserGallery()
anonymous_gallery.user = external
anonymous_gallery.mode = "w"
anonymous_gallery.mode = GALLERY_WRITE
anonymous_gallery.gallery = gallery.gallery
anonymous_gallery.save()
galleries.delete()
Expand Down

0 comments on commit b39c7fc

Please sign in to comment.