userRestrictedModule.py 1004 Bytes
Newer Older
Florent Chehab's avatar
Florent Chehab committed
1
2
3
from django.db import models
from rest_framework import serializers
from django.contrib.auth.models import User
4
from backend.models.abstract.my_model import MyModel, MyModelSerializer, MyModelViewSet
Florent Chehab's avatar
Florent Chehab committed
5
6


7
class UserRestrictedModule(MyModel):
8
9
10
    """
    TODO move to abstract folder ?
    """
Florent Chehab's avatar
Florent Chehab committed
11
    # RGPD made easy with CASCADE
12
    owner = models.ForeignKey(User, on_delete=models.CASCADE)
Florent Chehab's avatar
Florent Chehab committed
13

14
15
16
17
18
19
    # User is anonymised
    is_anonymous = models.BooleanField(default=True)

    # To be seen by others than the user, is public needs to be set to True
    is_public = models.BooleanField(default=False)

Florent Chehab's avatar
Florent Chehab committed
20
21
22
23
    class Meta:
        abstract = True


24
25
class UserRestrictedModuleSerializer(MyModelSerializer):
    owner = serializers.HiddenField(
Florent Chehab's avatar
Florent Chehab committed
26
27
28
29
30
31
        default=serializers.CurrentUserDefault(),
    )  # TODO check that this works

    class Meta:
        model = UserRestrictedModule
        fields = '__all__'
32
33
34
35


class UserRestrictedModuleViewSet(MyModelViewSet):
    serializer_class = UserRestrictedModuleSerializer