from django.utils.translation import gettext as _ from rest_framework.response import Response from rest_framework.permissions import IsAuthenticated from rest_framework.exceptions import NotFound from pingcap_sso.api.base import Endpoint from pingcap_sso.lib.operation import DOT_NAMES, reddot_list, mark_reddot_as_read class RedDotListEndpoint(Endpoint): permission_classes = (IsAuthenticated, ) def get(self, request, *args, **kwargs): return Response({ 'detail': _('success'), 'data': reddot_list(request.user) }) class RedDotDetailEndpoint(Endpoint): permission_classes = (IsAuthenticated, ) def post(self, request, dot_name, *args, **kwargs): if dot_name not in DOT_NAMES: raise NotFound mark_reddot_as_read(request.user, dot_name) return Response({ 'detail': _('success') })