🔧(backend) disable contact/teams/mail in prod

We don't want to make these features available for everyone.
This commit is contained in:
Quentin BEY
2024-11-06 17:30:25 +01:00
committed by BEY Quentin
parent ac853299d3
commit 6be1b63277
4 changed files with 37 additions and 7 deletions

View File

@@ -85,16 +85,23 @@ class SerializerPerActionMixin:
This mixin is useful to avoid to define a serializer class for each action in the
`get_serializer_class` method.
"""
serializer_classes: dict[str, type] = {}
default_serializer_class: type = None
Example:
```
class MyViewSet(SerializerPerActionMixin, viewsets.GenericViewSet):
serializer_class = MySerializer
list_serializer_class = MyListSerializer
retrieve_serializer_class = MyRetrieveSerializer
```
"""
def get_serializer_class(self):
"""
Return the serializer class to use depending on the action.
"""
return self.serializer_classes.get(self.action, self.default_serializer_class)
if serializer_class := getattr(self, f"{self.action}_serializer_class", None):
return serializer_class
return super().get_serializer_class()
class Pagination(pagination.PageNumberPagination):
@@ -176,7 +183,10 @@ class ContactViewSet(
class UserViewSet(
mixins.UpdateModelMixin, viewsets.GenericViewSet, mixins.ListModelMixin
SerializerPerActionMixin,
mixins.UpdateModelMixin,
viewsets.GenericViewSet,
mixins.ListModelMixin,
):
"""
User viewset for all interactions with user infos and teams.

View File

@@ -20,7 +20,13 @@ def test_api_config_anonymous():
assert response.status_code == HTTP_200_OK
assert response.json() == {
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"]],
"FEATURES": {"TEAMS": True},
"FEATURES": {
"CONTACTS_DISPLAY": True,
"CONTACTS_CREATE": True,
"MAILBOXES_CREATE": True,
"TEAMS": True,
"TEAMS_CREATE": True,
},
"RELEASE": "NA",
}
@@ -36,6 +42,12 @@ def test_api_config_authenticated():
assert response.status_code == HTTP_200_OK
assert response.json() == {
"LANGUAGES": [["en-us", "English"], ["fr-fr", "French"]],
"FEATURES": {"TEAMS": True},
"FEATURES": {
"CONTACTS_DISPLAY": True,
"CONTACTS_CREATE": True,
"MAILBOXES_CREATE": True,
"TEAMS": True,
"TEAMS_CREATE": True,
},
"RELEASE": "NA",
}

View File

@@ -101,6 +101,10 @@ backend:
name: backend
key: MAIL_PROVISIONING_API_CREDENTIALS
FEATURE_TEAMS: False
FEATURE_CONTACTS_DISPLAY: False
FEATURE_CONTACTS_CREATE: False
FEATURE_TEAMS_CREATE: False
FEATURE_MAILBOXES_CREATE: False
SENTRY_DSN: "https://b72746c73d669421e7a8ccd3fab0fad2@sentry.incubateur.net/171"
createsuperuser:

View File

@@ -101,6 +101,10 @@ backend:
name: backend
key: MAIL_PROVISIONING_API_CREDENTIALS
FEATURE_TEAMS: False
FEATURE_CONTACTS_DISPLAY: False
FEATURE_CONTACTS_CREATE: False
FEATURE_TEAMS_CREATE: False
FEATURE_MAILBOXES_CREATE: False
SENTRY_DSN: "https://b72746c73d669421e7a8ccd3fab0fad2@sentry.incubateur.net/171"
createsuperuser: