diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-05-09 10:42:44 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-06-13 18:16:05 +0200 |
commit | d829d11aec86a015d3898738ae9d73b5067bb865 (patch) | |
tree | 699c21e561d4335880985f39ccb68ecb678d2560 /ishtar_common/rest.py | |
parent | 5b0c5f805eb444269668e318082ec7809719ff8f (diff) | |
download | Ishtar-d829d11aec86a015d3898738ae9d73b5067bb865.tar.bz2 Ishtar-d829d11aec86a015d3898738ae9d73b5067bb865.zip |
✨ GIS API: get data sources list
Diffstat (limited to 'ishtar_common/rest.py')
-rw-r--r-- | ishtar_common/rest.py | 42 |
1 files changed, 41 insertions, 1 deletions
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 <etienne.loks at iggdrasil dot net> + +# 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 <http://www.gnu.org/licenses/>. + +# 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,) |