From 65d8ed3e5b290ba0e8ea52ef1ebc976e0020d9a5 Mon Sep 17 00:00:00 2001 From: Philippe MILINK Date: Thu, 21 Nov 2024 23:00:21 +0100 Subject: [PATCH] =?UTF-8?q?Corrige=20la=20mauvaise=20permission=20sur=20le?= =?UTF-8?q?s=20galeries=20lors=20de=20la=20d=C3=A9sinscription?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../0008_normalize_user_gallery_mode.py | 42 +++++++++++++++++++ zds/member/views/register.py | 4 +- 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 zds/gallery/migrations/0008_normalize_user_gallery_mode.py diff --git a/zds/gallery/migrations/0008_normalize_user_gallery_mode.py b/zds/gallery/migrations/0008_normalize_user_gallery_mode.py new file mode 100644 index 0000000000..6b93efc5c8 --- /dev/null +++ b/zds/gallery/migrations/0008_normalize_user_gallery_mode.py @@ -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';"), + ), + ] diff --git a/zds/member/views/register.py b/zds/member/views/register.py index 5c312ba8c7..ab6ff35abd 100644 --- a/zds/member/views/register.py +++ b/zds/member/views/register.py @@ -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, @@ -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()