chenzhaoyang
2025-12-17 d3e5a4b7658ece4f845bbc0c4f95acf3fbdf8a61
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from django.utils.decorators import method_decorator
from drf_spectacular.utils import extend_schema
from rest_framework import generics
from rest_framework.permissions import IsAuthenticated
 
from .models import SessionTimeoutPolicy
from .serializers import SessionTimeoutPolicySerializer
 
 
@method_decorator(
    name='get',
    decorator=extend_schema(
        tags=['Session Policy'],
        summary='Retrieve Session Policy',
        description='Retrieve session timeout policy for the currently active organization.',
        responses={
            200: SessionTimeoutPolicySerializer,
        },
        extensions={
            'x-fern-sdk-group-name': 'session_policy',
            'x-fern-sdk-method-name': 'get',
            'x-fern-audiences': ['public'],
        },
    ),
)
@method_decorator(
    name='patch',
    decorator=extend_schema(
        tags=['Session Policy'],
        summary='Update Session Policy',
        description='Update session timeout policy for the currently active organization.',
        request=SessionTimeoutPolicySerializer,
        responses={
            200: SessionTimeoutPolicySerializer,
        },
        extensions={
            'x-fern-sdk-group-name': 'session_policy',
            'x-fern-sdk-method-name': 'update',
            'x-fern-audiences': ['public'],
        },
    ),
)
class SessionTimeoutPolicyView(generics.RetrieveUpdateAPIView):
    """
    API endpoint for retrieving and updating organization's session timeout policy
    """
 
    serializer_class = SessionTimeoutPolicySerializer
    permission_classes = [IsAuthenticated]
    http_method_names = ['get', 'patch']  # Explicitly specify allowed methods
 
    def get_object(self):
        # Get the organization from the request
        org = self.request.user.active_organization
        # Get or create the session policy for the organization
        policy, _ = SessionTimeoutPolicy.objects.get_or_create(organization=org)
        return policy