mirror of
https://github.com/ae-utbm/sith.git
synced 2025-02-26 01:17:13 +00:00
Move all user picture logic to sas
This commit is contained in:
parent
ba21738bd9
commit
e46cba7a06
@ -64,40 +64,6 @@ class TestImageAccess:
|
|||||||
assert not picture.is_owned_by(user)
|
assert not picture.is_owned_by(user)
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
|
||||||
class TestUserPicture:
|
|
||||||
def test_anonymous_user_unauthorized(self, client):
|
|
||||||
"""An anonymous user shouldn't have access to an user's photo page."""
|
|
||||||
response = client.get(
|
|
||||||
reverse(
|
|
||||||
"core:user_pictures",
|
|
||||||
kwargs={"user_id": User.objects.get(username="sli").pk},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
assert response.status_code == 403
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
|
||||||
("username", "status"),
|
|
||||||
[
|
|
||||||
("guy", 403),
|
|
||||||
("root", 200),
|
|
||||||
("skia", 200),
|
|
||||||
("sli", 200),
|
|
||||||
],
|
|
||||||
)
|
|
||||||
def test_page_is_working(self, client, username, status):
|
|
||||||
"""Only user that subscribed (or admins) should be able to see the page."""
|
|
||||||
# Test for simple user
|
|
||||||
client.force_login(User.objects.get(username=username))
|
|
||||||
response = client.get(
|
|
||||||
reverse(
|
|
||||||
"core:user_pictures",
|
|
||||||
kwargs={"user_id": User.objects.get(username="sli").pk},
|
|
||||||
)
|
|
||||||
)
|
|
||||||
assert response.status_code == status
|
|
||||||
|
|
||||||
|
|
||||||
# TODO: many tests on the pages:
|
# TODO: many tests on the pages:
|
||||||
# - renaming a page
|
# - renaming a page
|
||||||
# - changing a page's parent --> check that page's children's full_name
|
# - changing a page's parent --> check that page's children's full_name
|
||||||
|
@ -68,7 +68,6 @@ from core.views import (
|
|||||||
UserGodfathersView,
|
UserGodfathersView,
|
||||||
UserListView,
|
UserListView,
|
||||||
UserMiniView,
|
UserMiniView,
|
||||||
UserPicturesView,
|
|
||||||
UserPreferencesView,
|
UserPreferencesView,
|
||||||
UserStatsView,
|
UserStatsView,
|
||||||
UserToolsView,
|
UserToolsView,
|
||||||
@ -143,9 +142,6 @@ urlpatterns = [
|
|||||||
path("user/", UserListView.as_view(), name="user_list"),
|
path("user/", UserListView.as_view(), name="user_list"),
|
||||||
path("user/<int:user_id>/mini/", UserMiniView.as_view(), name="user_profile_mini"),
|
path("user/<int:user_id>/mini/", UserMiniView.as_view(), name="user_profile_mini"),
|
||||||
path("user/<int:user_id>/", UserView.as_view(), name="user_profile"),
|
path("user/<int:user_id>/", UserView.as_view(), name="user_profile"),
|
||||||
path(
|
|
||||||
"user/<int:user_id>/pictures/", UserPicturesView.as_view(), name="user_pictures"
|
|
||||||
),
|
|
||||||
path(
|
path(
|
||||||
"user/<int:user_id>/godfathers/",
|
"user/<int:user_id>/godfathers/",
|
||||||
UserGodfathersView.as_view(),
|
UserGodfathersView.as_view(),
|
||||||
|
@ -200,7 +200,7 @@ class UserTabsMixin(TabedViewMixin):
|
|||||||
"name": _("Family"),
|
"name": _("Family"),
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"url": reverse("core:user_pictures", kwargs={"user_id": user.id}),
|
"url": reverse("sas:user_pictures", kwargs={"user_id": user.id}),
|
||||||
"slug": "pictures",
|
"slug": "pictures",
|
||||||
"name": _("Pictures"),
|
"name": _("Pictures"),
|
||||||
},
|
},
|
||||||
@ -297,16 +297,6 @@ class UserView(UserTabsMixin, CanViewMixin, DetailView):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class UserPicturesView(UserTabsMixin, CanViewMixin, DetailView):
|
|
||||||
"""Display a user's pictures."""
|
|
||||||
|
|
||||||
model = User
|
|
||||||
pk_url_kwarg = "user_id"
|
|
||||||
context_object_name = "profile"
|
|
||||||
template_name = "core/user_pictures.jinja"
|
|
||||||
current_tab = "pictures"
|
|
||||||
|
|
||||||
|
|
||||||
def delete_user_godfather(request, user_id, godfather_id, is_father):
|
def delete_user_godfather(request, user_id, godfather_id, is_father):
|
||||||
user_is_admin = request.user.is_root or request.user.is_board_member
|
user_is_admin = request.user.is_root or request.user.is_board_member
|
||||||
if user_id != request.user.id and not user_is_admin:
|
if user_id != request.user.id and not user_is_admin:
|
||||||
|
@ -104,7 +104,7 @@ class PicturesController(ControllerBase):
|
|||||||
viewed=False,
|
viewed=False,
|
||||||
type="NEW_PICTURES",
|
type="NEW_PICTURES",
|
||||||
defaults={
|
defaults={
|
||||||
"url": reverse("core:user_pictures", kwargs={"user_id": u.id})
|
"url": reverse("sas:user_pictures", kwargs={"user_id": u.id})
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
{% extends "core/base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
{% from 'core/macros.jinja' import paginate_alpine %}
|
{% from 'core/macros.jinja' import paginate_alpine %}
|
||||||
{% from "core/download_pictures.jinja" import download_button %}
|
{% from "sas/download_pictures.jinja" import download_button %}
|
||||||
|
|
||||||
{%- block additional_css -%}
|
{%- block additional_css -%}
|
||||||
<link rel="stylesheet" href="{{ static('sas/css/album.scss') }}">
|
<link rel="stylesheet" href="{{ static('sas/css/album.scss') }}">
|
||||||
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
{%- block additional_js -%}
|
{%- block additional_js -%}
|
||||||
<script type="module" src="{{ static('bundled/sas/album-index.js') }}"></script>
|
<script type="module" src="{{ static('bundled/sas/album-index.js') }}"></script>
|
||||||
<script type="module" src="{{ static('bundled/user/pictures-index.ts') }}"></script>
|
<script type="module" src="{{ static('bundled/sas/user/pictures-index.ts') }}"></script>
|
||||||
{%- endblock -%}
|
{%- endblock -%}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
{% extends "core/base.jinja" %}
|
{% extends "core/base.jinja" %}
|
||||||
{% from "core/download_pictures.jinja" import download_button %}
|
{% from "sas/download_pictures.jinja" import download_button %}
|
||||||
|
|
||||||
{%- block additional_css -%}
|
{%- block additional_css -%}
|
||||||
<link rel="stylesheet" href="{{ static('sas/css/album.scss') }}">
|
<link rel="stylesheet" href="{{ static('sas/css/album.scss') }}">
|
||||||
{%- endblock -%}
|
{%- endblock -%}
|
||||||
|
|
||||||
{% block additional_js %}
|
{% block additional_js %}
|
||||||
<script type="module" src="{{ static('bundled/user/pictures-index.ts') }}"></script>
|
<script type="module" src="{{ static('bundled/sas/user/pictures-index.ts') }}"></script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% block title %}
|
{% block title %}
|
@ -171,3 +171,37 @@ class TestSasModeration(TestCase):
|
|||||||
"Vous avez déjà déposé une demande de retrait pour cette photo.</li></ul>",
|
"Vous avez déjà déposé une demande de retrait pour cette photo.</li></ul>",
|
||||||
res.content.decode(),
|
res.content.decode(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.django_db
|
||||||
|
class TestUserPicture:
|
||||||
|
def test_anonymous_user_unauthorized(self, client):
|
||||||
|
"""An anonymous user shouldn't have access to an user's photo page."""
|
||||||
|
response = client.get(
|
||||||
|
reverse(
|
||||||
|
"sas:user_pictures",
|
||||||
|
kwargs={"user_id": User.objects.get(username="sli").pk},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assert response.status_code == 403
|
||||||
|
|
||||||
|
@pytest.mark.parametrize(
|
||||||
|
("username", "status"),
|
||||||
|
[
|
||||||
|
("guy", 403),
|
||||||
|
("root", 200),
|
||||||
|
("skia", 200),
|
||||||
|
("sli", 200),
|
||||||
|
],
|
||||||
|
)
|
||||||
|
def test_page_is_working(self, client, username, status):
|
||||||
|
"""Only user that subscribed (or admins) should be able to see the page."""
|
||||||
|
# Test for simple user
|
||||||
|
client.force_login(User.objects.get(username=username))
|
||||||
|
response = client.get(
|
||||||
|
reverse(
|
||||||
|
"sas:user_pictures",
|
||||||
|
kwargs={"user_id": User.objects.get(username="sli").pk},
|
||||||
|
)
|
||||||
|
)
|
||||||
|
assert response.status_code == status
|
||||||
|
@ -24,6 +24,7 @@ from sas.views import (
|
|||||||
PictureEditView,
|
PictureEditView,
|
||||||
PictureView,
|
PictureView,
|
||||||
SASMainView,
|
SASMainView,
|
||||||
|
UserPicturesView,
|
||||||
send_album,
|
send_album,
|
||||||
send_compressed,
|
send_compressed,
|
||||||
send_pict,
|
send_pict,
|
||||||
@ -55,4 +56,7 @@ urlpatterns = [
|
|||||||
name="download_compressed",
|
name="download_compressed",
|
||||||
),
|
),
|
||||||
path("picture/<int:picture_id>/download/thumb/", send_thumb, name="download_thumb"),
|
path("picture/<int:picture_id>/download/thumb/", send_thumb, name="download_thumb"),
|
||||||
|
path(
|
||||||
|
"user/<int:user_id>/pictures/", UserPicturesView.as_view(), name="user_pictures"
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
11
sas/views.py
11
sas/views.py
@ -26,6 +26,7 @@ from django.views.generic.edit import FormMixin, FormView, UpdateView
|
|||||||
from core.auth.mixins import CanEditMixin, CanViewMixin
|
from core.auth.mixins import CanEditMixin, CanViewMixin
|
||||||
from core.models import SithFile, User
|
from core.models import SithFile, User
|
||||||
from core.views.files import FileView, send_file
|
from core.views.files import FileView, send_file
|
||||||
|
from core.views.user import UserTabsMixin
|
||||||
from sas.forms import (
|
from sas.forms import (
|
||||||
AlbumEditForm,
|
AlbumEditForm,
|
||||||
PictureEditForm,
|
PictureEditForm,
|
||||||
@ -193,6 +194,16 @@ class AlbumView(CanViewMixin, DetailView, FormMixin):
|
|||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
|
class UserPicturesView(UserTabsMixin, CanViewMixin, DetailView):
|
||||||
|
"""Display a user's pictures."""
|
||||||
|
|
||||||
|
model = User
|
||||||
|
pk_url_kwarg = "user_id"
|
||||||
|
context_object_name = "profile"
|
||||||
|
template_name = "sas/user_pictures.jinja"
|
||||||
|
current_tab = "pictures"
|
||||||
|
|
||||||
|
|
||||||
# Admin views
|
# Admin views
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user