Skip to content

Commit

Permalink
more mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
xavfernandez committed Dec 3, 2024
1 parent 8deac73 commit d8d8806
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 55 deletions.
2 changes: 1 addition & 1 deletion config/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
# Override allauth `account_login` URL.
# /accounts/login/ <=> account_login
# Customized login pages per user type are handled by login.urls.
re_path(r"^accounts/login/$", login_not_required(login_views.ItouLoginView.as_view())),
re_path(r"^accounts/login/$", login_views.ItouLoginView.as_view()),
# --------------------------------------------------------------------------------------
# Override allauth `account_change_password` URL.
# /accounts/password/change/ <=> account_change_password
Expand Down
3 changes: 2 additions & 1 deletion itou/api/applicants_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
from itou.job_applications.models import JobApplication
from itou.users.enums import UserKind
from itou.users.models import User
from itou.utils.auth import LoginNotRequiredMixin

from .perms import ApplicantsAPIPermission
from .serializers import APIParametersSerializer, ApplicantSerializer


class ApplicantsView(generics.ListAPIView):
class ApplicantsView(LoginNotRequiredMixin, generics.ListAPIView):
authentication_classes = (
authentication.TokenAuthentication,
authentication.SessionAuthentication,
Expand Down
3 changes: 2 additions & 1 deletion itou/api/c4_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from itou.api.c4_api.serializers import C4CompanySerializer
from itou.companies.enums import COMPANY_KIND_RESERVED
from itou.companies.models import Company, CompanyMembership
from itou.utils.auth import LoginNotRequiredMixin


class C4APIUser(AnonymousUser):
Expand All @@ -27,7 +28,7 @@ def authenticate_credentials(self, key):
return C4APIUser(), None


class C4CompanyView(generics.ListAPIView):
class C4CompanyView(LoginNotRequiredMixin, generics.ListAPIView):
"""API pour le Marché de l'inclusion"""

authentication_classes = [C4Authentication]
Expand Down
3 changes: 2 additions & 1 deletion itou/api/data_inclusion_api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from itou.api.data_inclusion_api import enums, serializers
from itou.companies.models import Company
from itou.prescribers.models import PrescriberOrganization
from itou.utils.auth import LoginNotRequiredMixin


@extend_schema(
Expand All @@ -18,7 +19,7 @@
many=True,
)
)
class DataInclusionStructureView(generics.ListAPIView):
class DataInclusionStructureView(LoginNotRequiredMixin, generics.ListAPIView):
"""
# API au format data.inclusion
Expand Down
3 changes: 2 additions & 1 deletion itou/api/geiq/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from itou.companies.models import Company
from itou.job_applications.enums import JobApplicationState, Prequalification, ProfessionalSituationExperience
from itou.job_applications.models import JobApplication, PriorAction
from itou.utils.auth import LoginNotRequiredMixin
from itou.utils.validators import validate_siren

from .serializers import GeiqJobApplicationSerializer
Expand Down Expand Up @@ -41,7 +42,7 @@ class InvalidSirenError(exceptions.APIException):
status_code = status.HTTP_400_BAD_REQUEST


class GeiqJobApplicationListView(generics.ListAPIView):
class GeiqJobApplicationListView(LoginNotRequiredMixin, generics.ListAPIView):
authentication_classes = (
GeiqApiAuthentication,
authentication.SessionAuthentication,
Expand Down
4 changes: 3 additions & 1 deletion itou/api/redoc_views.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from django.templatetags.static import static
from drf_spectacular.views import SpectacularRedocView

from itou.utils.auth import LoginNotRequiredMixin

class ItouSpectacularRedocView(SpectacularRedocView):

class ItouSpectacularRedocView(LoginNotRequiredMixin, SpectacularRedocView):
@staticmethod
def _redoc_standalone():
return static("vendor/redoc/redoc.standalone.js")
10 changes: 5 additions & 5 deletions itou/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
path("token-auth/", ObtainAuthToken.as_view(), name="token-auth"),
# Needed for Browsable API (dev)
path("api-auth/", include("rest_framework.urls", namespace="rest_framework")),
path("embauches-geiq/", login_not_required(GeiqJobApplicationListView.as_view()), name="geiq_jobapplication_list"),
path("embauches-geiq/", GeiqJobApplicationListView.as_view(), name="geiq_jobapplication_list"),
# OpenAPI
# See: https://www.django-rest-framework.org/topics/documenting-your-api/
# OAS 3 YAML schema (downloadable)
Expand All @@ -47,15 +47,15 @@
),
path(
"redoc/",
login_not_required(ItouSpectacularRedocView.as_view(url_name="v1:openapi_schema")),
ItouSpectacularRedocView.as_view(url_name="v1:openapi_schema"),
name="redoc",
),
]

urlpatterns += router.urls

urlpatterns += [
path("structures/", login_not_required(DataInclusionStructureView.as_view()), name="structures-list"),
path("candidats/", login_not_required(ApplicantsView.as_view()), name="applicants-list"),
path("marche/", login_not_required(C4CompanyView.as_view()), name="marche-company-list"),
path("structures/", DataInclusionStructureView.as_view(), name="structures-list"),
path("candidats/", ApplicantsView.as_view(), name="applicants-list"),
path("marche/", C4CompanyView.as_view(), name="marche-company-list"),
]
8 changes: 2 additions & 6 deletions itou/www/announcements/views.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
from django.contrib.auth.decorators import login_not_required
from django.db.models import Count, Prefetch, Q
from django.urls import reverse
from django.utils import timezone
from django.views.generic import TemplateView

from itou.communications.models import AnnouncementCampaign, AnnouncementItem
from itou.users.enums import UserKind
from itou.utils.auth import LoginNotRequiredMixin
from itou.utils.pagination import pager
from itou.utils.urls import get_safe_url


class NewsView(TemplateView):
class NewsView(LoginNotRequiredMixin, TemplateView):
template_name = "announcements/news.html"

@login_not_required
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

def get_context_data(self):
items = AnnouncementItem.objects.all()
if self.request.user.is_authenticated and self.request.user.kind == UserKind.JOB_SEEKER:
Expand Down
13 changes: 3 additions & 10 deletions itou/www/companies_views/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from itou.utils import constants as global_constants
from itou.utils.apis.data_inclusion import DataInclusionApiClient, DataInclusionApiException
from itou.utils.apis.exceptions import GeocodingDataError
from itou.utils.auth import LoginNotRequiredMixin
from itou.utils.pagination import pager
from itou.utils.perms.company import get_current_company_or_404
from itou.utils.urls import add_url_params, get_absolute_url, get_safe_url
Expand Down Expand Up @@ -109,13 +110,9 @@ def report_tally_url(user, company, job_description=None):
### Job description views


class JobDescriptionCardView(ApplyForJobSeekerMixin, TemplateView):
class JobDescriptionCardView(LoginNotRequiredMixin, ApplyForJobSeekerMixin, TemplateView):
template_name = "companies/job_description_card.html"

@login_not_required
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

def setup(self, request, job_description_id, *args, **kwargs):
super().setup(request, *args, **kwargs)
self.job_description = get_object_or_404(
Expand Down Expand Up @@ -449,13 +446,9 @@ def select_financial_annex(request, template_name="companies/select_financial_an
### Company CRUD views


class CompanyCardView(ApplyForJobSeekerMixin, TemplateView):
class CompanyCardView(LoginNotRequiredMixin, ApplyForJobSeekerMixin, TemplateView):
template_name = "companies/card.html"

@login_not_required
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

def setup(self, request, siae_id, *args, **kwargs):
super().setup(request, *args, **kwargs)
self.company = get_object_or_404(Company.objects.with_has_active_members(), pk=siae_id)
Expand Down
5 changes: 2 additions & 3 deletions itou/www/login/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@
from allauth.account.views import LoginView
from django.conf import settings
from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import login_not_required
from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404
from django.urls import reverse

from itou.openid_connect.inclusion_connect.enums import InclusionConnectChannel
from itou.users.enums import MATOMO_ACCOUNT_TYPE, IdentityProvider, UserKind
from itou.users.models import User
from itou.utils.auth import LoginNotRequiredMixin
from itou.utils.urls import add_url_params, get_safe_url, get_url_param_value
from itou.www.login.forms import ItouLoginForm


class ItouLoginView(LoginView):
class ItouLoginView(LoginNotRequiredMixin, LoginView):
"""
Generic authentication entry point.
This view is used only in one case:
Expand Down Expand Up @@ -75,7 +75,6 @@ def get_context_data(self, **kwargs):
}
return context | extra_context

@login_not_required
def dispatch(self, request, *args, **kwargs):
if next_url := request.GET.get("next"):
if get_url_param_value(next_url, "channel") == InclusionConnectChannel.MAP_CONSEILLER:
Expand Down
31 changes: 6 additions & 25 deletions itou/www/signup/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from itou.users.adapter import UserAdapter
from itou.users.enums import KIND_EMPLOYER, KIND_PRESCRIBER, MATOMO_ACCOUNT_TYPE, UserKind
from itou.utils import constants as global_constants
from itou.utils.auth import LoginNotRequiredMixin
from itou.utils.nav_history import get_prev_url_from_history, push_url_in_history
from itou.utils.tokens import company_signup_token_generator
from itou.utils.urls import get_safe_url
Expand Down Expand Up @@ -94,14 +95,10 @@ def signup(request, template_name="signup/signup.html"):
return render(request, template_name, context)


class ChooseUserKindSignupView(FormView):
class ChooseUserKindSignupView(LoginNotRequiredMixin, FormView):
template_name = "signup/choose_user_kind.html"
form_class = forms.ChooseUserKindSignupForm

@login_not_required
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

def form_valid(self, form):
urls = {
UserKind.JOB_SEEKER: reverse("signup:job_seeker_situation"),
Expand All @@ -111,14 +108,10 @@ def form_valid(self, form):
return HttpResponseRedirect(urls[form.cleaned_data["kind"]])


class JobSeekerSignupView(SignupView):
class JobSeekerSignupView(LoginNotRequiredMixin, SignupView):
form_class = forms.JobSeekerSignupForm
template_name = "signup/job_seeker_signup.html"

@login_not_required
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context["show_france_connect"] = bool(settings.FRANCE_CONNECT_BASE_URL)
Expand Down Expand Up @@ -269,7 +262,7 @@ def dispatch(self, request, *args, company_id, **kwargs):
return super().dispatch(request, *args, **kwargs)


class CompanyUserView(CompanyBaseView, TemplateView):
class CompanyUserView(LoginNotRequiredMixin, CompanyBaseView, TemplateView):
"""
Display Inclusion Connect button.
This page is also shown if an error is detected during
Expand All @@ -278,10 +271,6 @@ class CompanyUserView(CompanyBaseView, TemplateView):

template_name = "signup/employer.html"

@login_not_required
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

def get_context_data(self, **kwargs):
params = {
"user_kind": KIND_EMPLOYER,
Expand Down Expand Up @@ -860,7 +849,7 @@ def facilitator_search(request, template_name="signup/facilitator_search.html"):
return render(request, template_name, context)


class FacilitatorUserView(FacilitatorBaseMixin, TemplateView):
class FacilitatorUserView(LoginNotRequiredMixin, FacilitatorBaseMixin, TemplateView):
"""
Display Inclusion Connect button.
This page is also shown if an error is detected during
Expand All @@ -869,10 +858,6 @@ class FacilitatorUserView(FacilitatorBaseMixin, TemplateView):

template_name = "signup/employer.html"

@login_not_required
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

def get_context_data(self, **kwargs):
params = {
"user_kind": KIND_EMPLOYER,
Expand All @@ -895,11 +880,7 @@ def get_context_data(self, **kwargs):
}


class FacilitatorJoinView(FacilitatorBaseMixin, View):
@login_not_required
def dispatch(self, request, *args, **kwargs):
return super().dispatch(request, *args, **kwargs)

class FacilitatorJoinView(LoginNotRequiredMixin, FacilitatorBaseMixin, View):
def get(self, request, *args, **kwargs):
self.company_to_create.auth_email = request.user.email
self.company_to_create.created_by = request.user
Expand Down

0 comments on commit d8d8806

Please sign in to comment.