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

Nouvelle page Utilisateurs #1954

Merged
merged 2 commits into from
Mar 10, 2023
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
1 change: 1 addition & 0 deletions app/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
path("contributions/", include("www.contributions.urls")),
path("glossary/", include("www.glossary.urls")),
path("activity/", include("www.activity.urls")),
path("users/", include("www.users.urls")),
path("admin/", include("www.admin.urls")),
)

Expand Down
6 changes: 2 additions & 4 deletions templates/admin/history.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ <h1>50 dernières modifications</h1>
</div>
</div>
<div class="row overflow-scroll">
<div class="row overflow-scroll">
<div class="col-12">
{% render_table table %}
</div>
<div class="col-12">
{% render_table table %}
</div>
</div>
</div>
Expand Down
5 changes: 4 additions & 1 deletion templates/includes/_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
<li class="nav-item">
<a class="nav-link" href="{% url 'glossary:list' %}">{% translate "Glossary" %}</a>
</li>
<li class="nav-item">
<a class="nav-link" href="{% url 'users:home' %}">{% translate "Users" %}</a>
</li>
{% if user.has_role_administrator %}
<span style="padding:0.5em">|</span>
<li class="nav-item">
Expand All @@ -45,7 +48,7 @@
{% endif %}
<span style="padding:0.5em">|</span>
<li class="nav-item">
<a class="nav-link" href="{% url 'pages:help_home' %}">🛟 {% translate "Help" %}</a>
<a class="nav-link" href="{% url 'pages:help' %}">🛟 {% translate "Help" %}</a>
</li>
{% endif %}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion templates/includes/_header_notice_beta.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

<div id="header-notice-beta" class="alert alert-info font-weight-bold text-center p-2 m-0">
<p class="mb-0">
{% translate "Website under construction. Feedback is gladly welcome (bugs, improvements...)" %} 🙏🏻👉 <a href="{% url 'pages:help_home' %}#contact">{% translate "contact us" %}</a>
{% translate "Website under construction. Feedback is gladly welcome (bugs, improvements...)" %} 🙏🏻👉 <a href="{% url 'pages:help' %}#contact">{% translate "contact us" %}</a>
</p>
</div>
2 changes: 1 addition & 1 deletion templates/pages/help.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ <h4 id="tuto">{% translate "How to use the administrator interface" %}</h4>

<h4 id="contact">{% translate "Contact an administrator" %}</h4>
<ul>
<li><a href="{% url 'pages:help_administrator_list' %}">{% translate "Administrator list" %}</a></li>
<li><a href="{% url 'users:administrator_list' %}">{% translate "Administrator list" %}</a></li>
<li>via <s>Slack</s> Discord : <a href="{{ DISCORD_INVITATION_LINK }}">{% translate "invitation link" %}</a></li>
<li><a href="mailto:{{ CONTACT_EMAIL }}">{{ CONTACT_EMAIL }}</a></li>
</ul>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{% url 'pages:home' %}">{% translate "Home" %}</a></li>
<li class="breadcrumb-item"><a href="{% url 'pages:help_home' %}">{% translate "Help" %}</a></li>
<li class="breadcrumb-item"><a href="{% url 'users:home' %}">{% translate "Users" %}</a></li>
<li class="breadcrumb-item active" aria-current="page">{% translate "Administrator list" %}</li>
</ol>
</nav>
Expand Down
48 changes: 48 additions & 0 deletions templates/users/home.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{% extends "layouts/base.html" %}
{% load i18n %}

{% block title %}{% translate "Users" %}{{ block.super }}{% endblock %}

{% block breadcrumbs %}
<div class="container">
<div class="row">
<div class="col-12 my-auto">
<nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
<ol class="breadcrumb">
<li class="breadcrumb-item"><a href="{% url 'pages:home' %}">{% translate "Home" %}</a></li>
<li class="breadcrumb-item active" aria-current="page">{% translate "Users" %}</li>
</ol>
</nav>
</div>
</div>
</div>
{% endblock %}

{% block content %}
<div class="container">
<div class="row mb-3">
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">{% translate "Contributors" %} <small class="text-muted">{{ contributor_count }}</small></h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">{% translate "Quiz authors" %} <small class="text-muted">{{ quiz_author_count }}</small></h5>
</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">
<h5 class="card-title">{% translate "Administrators" %} <small class="text-muted">{{ administrator_count }}</small></h5>
<a class="btn btn-primary" href="{% url 'users:administrator_list' %}">{% translate "View" %}</a>
</div>
</div>
</div>
</div>
</div>
{% endblock %}
14 changes: 3 additions & 11 deletions www/pages/urls.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
from django.urls import include, path
from django.urls import path
from django.views.generic import TemplateView

from www.pages.views import AdministratorListView, HelpView, HomeView
from www.pages.views import HelpView, HomeView


app_name = "pages"

urlpatterns = [
path("", HomeView.as_view(), name="home"),
path(
"help/",
include(
[
path("", HelpView.as_view(), name="help_home"),
path("administrators", AdministratorListView.as_view(), name="help_administrator_list"),
]
),
),
path("help/", HelpView.as_view(), name="help"),
path("403/", TemplateView.as_view(template_name="403.html"), name="403"),
path("404/", TemplateView.as_view(template_name="404.html"), name="404"),
path("500/", TemplateView.as_view(template_name="500.html"), name="500"),
Expand Down
18 changes: 1 addition & 17 deletions www/pages/views.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
from django.http import HttpResponseRedirect
from django.urls import reverse_lazy
from django.views.generic import TemplateView
from django_tables2.views import SingleTableView

from activity.models import Event
from core.mixins import ContributorUserRequiredMixin
from users.models import User
from users.tables import AdministratorTable


class HomeView(TemplateView):
class HomeView(TemplateView): # ContributorUserRequiredMixin ?
template_name = "pages/home.html"

def get(self, request, *args, **kwargs):
Expand All @@ -27,16 +24,3 @@ def get_context_data(self, **kwargs):

class HelpView(ContributorUserRequiredMixin, TemplateView):
template_name = "pages/help.html"


class AdministratorListView(ContributorUserRequiredMixin, SingleTableView):
model = User
template_name = "pages/administrator_list.html"
context_object_name = "administrators"
table_class = AdministratorTable

def get_queryset(self):
qs = super().get_queryset()
qs = qs.all_administrators()
qs = qs.order_by("created")
return qs
2 changes: 1 addition & 1 deletion www/profile/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setUpTestData(cls):
cls.user_super_contributor = UserFactory(roles=[constants.USER_ROLE_SUPER_CONTRIBUTOR])
cls.user_admin = UserFactory(roles=[constants.USER_ROLE_ADMINISTRATOR])

def test_only_contributor_can_access_profile(self):
def test_only_contributor_can_access_profile_home(self):
# anonymous
response = self.client.get(self.url)
self.assertEqual(response.status_code, 302)
Expand Down
Empty file added www/users/__init__.py
Empty file.
38 changes: 38 additions & 0 deletions www/users/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from django.test import TestCase
from django.urls import reverse

from users import constants
from users.factories import DEFAULT_PASSWORD, UserFactory


USER_URLS = ["users:home", "users:administrator_list"]


class UserViewTest(TestCase):
@classmethod
def setUpTestData(cls):
cls.user = UserFactory(roles=[])
cls.user_contributor = UserFactory()
cls.user_super_contributor = UserFactory(roles=[constants.USER_ROLE_SUPER_CONTRIBUTOR])
cls.user_admin = UserFactory(roles=[constants.USER_ROLE_ADMINISTRATOR])

def test_anonymous_user_cannot_access_user_pages(self):
for user_url in USER_URLS:
url = reverse(user_url)
response = self.client.get(url)
self.assertEqual(response.status_code, 302)
self.assertIn("/accounts/login/?next=", response.url)

def test_simple_user_cannot_access_user_pages(self):
self.client.login(email=self.user.email, password=DEFAULT_PASSWORD)
for user_url in USER_URLS:
url = reverse(user_url)
response = self.client.get(url)
self.assertEqual(response.status_code, 302)

def test_contributor_can_access_users_pages(self):
self.client.login(email=self.user_contributor.email, password=DEFAULT_PASSWORD)
for user_url in USER_URLS:
url = reverse(user_url)
response = self.client.get(url)
self.assertEqual(response.status_code, 200)
11 changes: 11 additions & 0 deletions www/users/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from django.urls import path

from www.users.views import AdministratorListView, UserHomeView


app_name = "users"

urlpatterns = [
path("", UserHomeView.as_view(), name="home"),
path("administrators/", AdministratorListView.as_view(), name="administrator_list"),
]
30 changes: 30 additions & 0 deletions www/users/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
from django.views.generic import TemplateView
from django_tables2.views import SingleTableView

from core.mixins import ContributorUserRequiredMixin
from users.models import User
from users.tables import AdministratorTable


class UserHomeView(ContributorUserRequiredMixin, TemplateView):
template_name = "users/home.html"

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["contributor_count"] = User.objects.all_contributors().count()
context["quiz_author_count"] = User.objects.has_public_quiz().count()
context["administrator_count"] = User.objects.all_administrators().count()
return context


class AdministratorListView(ContributorUserRequiredMixin, SingleTableView):
model = User
template_name = "users/administrator_list.html"
context_object_name = "administrators"
table_class = AdministratorTable

def get_queryset(self):
qs = super().get_queryset()
qs = qs.all_administrators()
qs = qs.order_by("created")
return qs