Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Corrige la mauvaise permission sur les galeries lors de la désinscription #6693

Merged
merged 2 commits into from
Dec 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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