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

Retire la gestion des anciens smileys #6268

Merged
merged 2 commits into from
Mar 26, 2022
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
Binary file removed assets/smileys/old/ange.png
Binary file not shown.
Binary file removed assets/smileys/old/angry.gif
Binary file not shown.
Binary file removed assets/smileys/old/blink.gif
Binary file not shown.
Binary file removed assets/smileys/old/clin.png
Binary file not shown.
Binary file removed assets/smileys/old/cthulhu.png
Binary file not shown.
Binary file removed assets/smileys/old/diable.png
Binary file not shown.
Binary file removed assets/smileys/old/heureux.png
Binary file not shown.
Binary file removed assets/smileys/old/hihi.png
Binary file not shown.
Binary file removed assets/smileys/old/huh.png
Binary file not shown.
Binary file removed assets/smileys/old/langue.png
Binary file not shown.
Binary file removed assets/smileys/old/magicien.png
Binary file not shown.
Binary file removed assets/smileys/old/mechant.png
Binary file not shown.
Binary file removed assets/smileys/old/ninja.png
Binary file not shown.
Binary file removed assets/smileys/old/pinch.png
Binary file not shown.
Binary file removed assets/smileys/old/pirate.png
Binary file not shown.
Binary file removed assets/smileys/old/pleure.png
Binary file not shown.
Binary file removed assets/smileys/old/rire.gif
Binary file not shown.
Binary file removed assets/smileys/old/rouge.png
Binary file not shown.
Binary file removed assets/smileys/old/siffle.png
Binary file not shown.
Binary file removed assets/smileys/old/smile.png
Binary file not shown.
Binary file removed assets/smileys/old/soleil.png
Binary file not shown.
Binary file removed assets/smileys/old/triste.png
Binary file not shown.
Binary file removed assets/smileys/old/unsure.gif
Binary file not shown.
Binary file removed assets/smileys/old/waw.png
Binary file not shown.
Binary file removed assets/smileys/old/zorro.png
Binary file not shown.
5 changes: 0 additions & 5 deletions templates/pages/cookies.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ <h4>{% trans "Cookies techniques" %}</h4>
<dd>{% blocktrans %}Ce cookie est un identifiant unique qui permet de faire le lien entre votre session de navigation et les différentes pages que vous visitez. Il permet en particulier de vous connecter à {{ site_name }}. Il ne contient qu’une chaîne de caractères aléatoires.{% endblocktrans %}</dd>
<dt><tt>csrftoken</tt></dt>
<dd>{% blocktrans %}Ce cookie contient une chaîne de caractères aléatoires qui permet de se prémunir des attaques <a href="http://fr.wikipedia.org/wiki/Cross-Site_Request_Forgery">CSRF</a>. Composant indispensable de la sécurité du site, vous ne pourrez rien poster sans ce cookie.{% endblocktrans %}</dd>
{% if app.member.old_smileys_allowed %}
<dt><tt>{{ app.member.old_smileys_cookie_key }}</tt></dt>
{% url 'update-member' as update_member %}
<dd>{% blocktrans with url=update_member %}Ce cookie est utilisé pour afficher les "vieux" smileys en lieu et place des smileys Clem (auquel cas il prend la valeur <tt>True</tt>), si vous activez cette option <a href="{{ url }}">dans votre profil</a>.{% endblocktrans %}</dd>
{% endif %}
</dl>


Expand Down
6 changes: 0 additions & 6 deletions zds/member/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,9 +250,6 @@ def __init__(self, *args, **kwargs):
self.helper.form_class = "content-wrapper"
self.helper.form_method = "post"

if settings.ZDS_APP["member"]["old_smileys_allowed"]:
self.fields["options"].choices.insert(3, ("use_old_smileys", _("Utiliser les anciens smileys")))

# to get initial value form checkbox show email
initial = kwargs.get("initial", {})
self.fields["options"].initial = ""
Expand All @@ -266,9 +263,6 @@ def __init__(self, *args, **kwargs):
if "allow_temp_visual_changes" in initial and initial["allow_temp_visual_changes"]:
self.fields["options"].initial += "allow_temp_visual_changes"

if "use_old_smileys" in initial and initial["use_old_smileys"]:
self.fields["options"].initial += "use_old_smileys"

if "show_markdown_help" in initial and initial["show_markdown_help"]:
self.fields["options"].initial += "show_markdown_help"

Expand Down
17 changes: 17 additions & 0 deletions zds/member/migrations/0021_remove_profile_use_old_smileys.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Generated by Django 3.2.12 on 2022-03-24 18:57

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("member", "0020_auto_20201018_0841"),
]

operations = [
migrations.RemoveField(
model_name="profile",
name="use_old_smileys",
),
]
28 changes: 0 additions & 28 deletions zds/member/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class Meta:
can_write = models.BooleanField("Possibilité d'écrire", default=True)
end_ban_write = models.DateTimeField("Fin d'interdiction d'écrire", null=True, blank=True)
last_visit = models.DateTimeField("Date de dernière visite", null=True, blank=True)
use_old_smileys = models.BooleanField("Utilise les anciens smileys ?", default=False)
_permissions = {}
_groups = None
_cached_city = None
Expand Down Expand Up @@ -490,33 +489,6 @@ def remove_hats_linked_to_group(sender, instance, **kwargs):
instance.hats.remove(hat)


def remove_old_smileys_cookie(response):
"""Remove the Clem smileys cookie by immediate expiration

:param response: the HTTP response
:type: django.http.response.HttpResponse
"""

response.set_cookie(settings.ZDS_APP["member"]["old_smileys_cookie_key"], "", expires=0)


def set_old_smileys_cookie(response, profile):
"""Set the Clem smileys cookie according to profile (and if allowed)

:param response: the HTTP response
:type: django.http.response.HttpResponse
:param profile: the profile
:type profile: Profile
"""

if settings.ZDS_APP["member"]["old_smileys_allowed"]:
if profile.use_old_smileys:
# TODO: set max_age, expires and so all (see https://stackoverflow.com/a/1623910)
response.set_cookie(settings.ZDS_APP["member"]["old_smileys_cookie_key"], profile.use_old_smileys)
else:
remove_old_smileys_cookie(response)


class TokenForgotPassword(models.Model):
"""
When a user forgot its password, the website sends it an email with a token (embedded in a URL).
Expand Down
66 changes: 0 additions & 66 deletions zds/member/tests/views/tests_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,69 +254,3 @@ def test_markdown_help_settings(self):
user.profile.save()
result = self.client.get(reverse("pages-index"), follow=False)
self.assertContains(result, 'data-show-markdown-help="false"')

def test_old_smileys(self):
"""Test the cookie"""

# NOTE: we have to use the "real" login and logout pages here
cookie_key = settings.ZDS_APP["member"]["old_smileys_cookie_key"]

profile_without_clem = ProfileFactory()
profile_without_clem = Profile.objects.get(pk=profile_without_clem.pk)
self.assertFalse(profile_without_clem.use_old_smileys)

user_without_clem = profile_without_clem.user
profile_with_clem = ProfileFactory()
profile_with_clem.use_old_smileys = True
profile_with_clem.save()
user_with_clem = profile_with_clem.user

settings.ZDS_APP["member"]["old_smileys_allowed"] = True

# test that the cookie is set when connection
result = self.client.post(
reverse("member-login"),
{"username": user_with_clem.username, "password": "hostel77", "remember": "remember"},
follow=False,
)
self.assertEqual(result.status_code, 302)
self.client.get(reverse("homepage"))

self.assertIn(cookie_key, self.client.cookies)
self.assertNotEqual(self.client.cookies[cookie_key]["expires"], 0)

# test that logout set the cookies expiration to 0 (= no more cookie)
self.client.post(reverse("member-logout"), follow=True)
self.client.get(reverse("homepage"))
self.assertEqual(self.client.cookies[cookie_key]["expires"], 0)

# test that user without the setting have the cookie with expiration 0 (= no cookie)
result = self.client.post(
reverse("member-login"),
{"username": user_without_clem.username, "password": "hostel77", "remember": "remember"},
follow=False,
)

self.assertEqual(result.status_code, 302)
self.assertEqual(self.client.cookies[cookie_key]["expires"], 0)

# setting use_smileys sets the cookie
self.client.post(
reverse("update-member"),
{"biography": "", "site": "", "avatar_url": "", "sign": "", "options": ["use_old_smileys"]},
)
self.client.get(reverse("homepage"))

profile_without_clem = Profile.objects.get(pk=profile_without_clem.pk)
self.assertTrue(profile_without_clem.use_old_smileys)
self.assertNotEqual(self.client.cookies[cookie_key]["expires"], 0)

# ... and that not setting it removes the cookie
self.client.post(
reverse("update-member"), {"biography": "", "site": "", "avatar_url": "", "sign": "", "options": []}
)
self.client.get(reverse("homepage"))

profile_without_clem = Profile.objects.get(pk=profile_without_clem.pk)
self.assertFalse(profile_without_clem.use_old_smileys)
self.assertEqual(self.client.cookies[cookie_key]["expires"], 0)
5 changes: 1 addition & 4 deletions zds/member/views/login.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from django.views.decorators.http import require_POST

from zds.member.forms import LoginForm
from zds.member.models import Profile, set_old_smileys_cookie, remove_old_smileys_cookie
from zds.member.models import Profile
from zds.member.views import get_client_ip
from zds.utils.tokens import generate_token

Expand Down Expand Up @@ -94,7 +94,6 @@ def login_view(request):
response = redirect(next_page)
except Resolver404:
response = redirect(reverse("homepage"))
set_old_smileys_cookie(response, profile)
return response

if next_page is not None:
Expand All @@ -112,6 +111,4 @@ def logout_view(request):
logout(request)
request.session.clear()
response = redirect(reverse("homepage"))
# disable Clem smileys:
remove_old_smileys_cookie(response)
return response
4 changes: 0 additions & 4 deletions zds/member/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
KarmaNote,
Ban,
NewEmailProvider,
set_old_smileys_cookie,
)
from zds.notification.models import TopicAnswerSubscription, NewPublicationSubscription
from zds.tutorialv2.models import CONTENT_TYPES
Expand Down Expand Up @@ -215,7 +214,6 @@ def get_form(self, form_class=ProfileForm):
"avatar_url": profile.avatar_url,
"show_sign": profile.show_sign,
"is_hover_enabled": profile.is_hover_enabled,
"use_old_smileys": profile.use_old_smileys,
"allow_temp_visual_changes": profile.allow_temp_visual_changes,
"show_markdown_help": profile.show_markdown_help,
"email_for_answer": profile.email_for_answer,
Expand Down Expand Up @@ -245,7 +243,6 @@ def form_valid(self, form):
self.save_profile(profile)

response = redirect(self.get_success_url())
set_old_smileys_cookie(response, profile)
return response

def update_profile(self, profile, form):
Expand All @@ -254,7 +251,6 @@ def update_profile(self, profile, form):
profile.site = form.data["site"]
profile.show_sign = "show_sign" in cleaned_data_options
profile.is_hover_enabled = "is_hover_enabled" in cleaned_data_options
profile.use_old_smileys = "use_old_smileys" in cleaned_data_options
profile.allow_temp_visual_changes = "allow_temp_visual_changes" in cleaned_data_options
profile.show_markdown_help = "show_markdown_help" in cleaned_data_options
profile.email_for_answer = "email_for_answer" in cleaned_data_options
Expand Down
2 changes: 0 additions & 2 deletions zds/settings/abstract_base/zds.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,6 @@
"users_in_hats_list": 5,
"requested_hats_per_page": 100,
"update_last_visit_interval": 600, # seconds
"old_smileys_allowed": False,
"old_smileys_cookie_key": "use_old_smileys",
},
"hats": {
"moderation": "Staff",
Expand Down