From 0a32ed95fcaedf9637254f5b60d88ddc04010ffe Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 21 Jul 2025 15:10:19 +0200 Subject: ✨ GIS API: get data sources list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/rest.py | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'ishtar_common/rest.py') diff --git a/ishtar_common/rest.py b/ishtar_common/rest.py index 699440f15..3d0c90f04 100644 --- a/ishtar_common/rest.py +++ b/ishtar_common/rest.py @@ -1,14 +1,36 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright (C) 2021-2025 Étienne Loks + +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. + +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . + +# See the file COPYING for details. + +import datetime + from django.conf import settings from django.db.models import Q from django.http import HttpResponse from django.utils.translation import activate, deactivate -from rest_framework import authentication, permissions, generics +from rest_framework import authentication, exceptions, permissions, generics from rest_framework.response import Response from rest_framework.views import APIView from ishtar_common import models_rest from ishtar_common.models_common import GeneralType +from ishtar_common.utils import gettext_lazy as _ from ishtar_common.views_item import get_item @@ -253,3 +275,21 @@ class GetAPIView(generics.RetrieveAPIView): obj = q.all()[0] result = obj.full_serialize(search_model, request=request) return Response(result, content_type="json") + + +class GISAuthentication(authentication.TokenAuthentication): + model = models_rest.UserToken + + def authenticate_credentials(self, key): + """ + Manage date limit + """ + __, token = super().authenticate_credentials(key) + if token.limit_date and token.limit_date < datetime.date.today(): + raise exceptions.AuthenticationFailed(_("Access expired.")) + return (token.user, token) + + +class GISAPIView(APIView): + authentication_classes = (GISAuthentication,) + permission_classes = (permissions.IsAuthenticated,) -- cgit v1.2.3