Commit 1bae06b2 authored by Florent Chehab's avatar Florent Chehab

Standardized serverModerationStatus in the backend

not perfect but will do the trick for now
parent 5b3e318f
......@@ -15,6 +15,8 @@ CLASSIC_MODELS = []
# Go through the API configuraion
for entry in api_config:
if "is_api_view" in entry and entry["is_api_view"]:
continue
if "model" in entry and entry["model"]:
model_obj = DotMap(entry)
if (not model_obj.requires_testing) and (not model_obj.ignore_in_admin):
......
from rest_framework.views import APIView
from rest_framework.response import Response
from backend_app.utils import get_viewset_permissions
from django.conf import settings
from django.http import HttpResponse
import json
from shared import OBJ_MODERATION_PERMISSIONS
def app_moderation_status(request):
return HttpResponse(
json.dumps(
class AppModerationStatusViewSet(APIView):
"""
"""
permission_classes = get_viewset_permissions("AppModerationStatusViewSet")
def get(self, request):
return Response(
{
"activated": settings.MODERATION_ACTIVATED,
"moderator_level": OBJ_MODERATION_PERMISSIONS["moderator"],
}
)
)
......@@ -10,6 +10,8 @@ ALL_VIEWSETS = {}
for model in api_config:
model = DotMap(model)
if "is_api_view" in model and model.is_api_view:
continue
if not model.requires_testing:
if model.viewset != "UserDataViewSet":
module = importlib.import_module(
......@@ -20,6 +22,8 @@ for model in api_config:
if settings.TESTING:
for model in api_config:
model = DotMap(model)
if "is_api_view" in model and model.is_api_view:
continue
if model.requires_testing:
if model.viewset != "UserDataViewSet":
module = importlib.import_module(
......
from django.conf import settings
from django.conf.urls import include, url
from django.urls import path
from rest_framework import routers
from rest_framework.documentation import include_docs_urls
from backend_app.permissions import DEFAULT_VIEWSET_PERMISSIONS
from shared import get_api_config
from . import views
from dotmap import DotMap
from .other_viewsets import AppModerationStatusViewSet
import importlib
......@@ -23,6 +22,8 @@ api_config = get_api_config()
for entry in api_config:
model_obj = DotMap(entry)
if "is_api_view" in model_obj and model_obj.is_api_view:
continue
if (not model_obj.requires_testing) or (
settings.TESTING and model_obj.requires_testing
):
......@@ -45,10 +46,10 @@ for entry in api_config:
router.register(str_url, Viewset)
# Add all the endpoints for the base api
urlpatterns += [url(r"^api/", include(router.urls))]
# Add some custom APIs
urlpatterns.append(path("api/serverModerationStatus/", views.app_moderation_status))
urlpatterns += [
url(r"^api/", include(router.urls)),
url(r"^api/serverModerationStatus/", AppModerationStatusViewSet.as_view()),
]
#######
# Models and Viewset checks
......
......@@ -5,6 +5,8 @@ def get_model_config(model):
api_config = get_api_config()
for obj in api_config:
if "is_api_view" in obj and obj["is_api_view"]:
continue
if obj["model"] == model:
tmp = {
"moderation_level": obj["moderation_level"],
......
......@@ -36,6 +36,11 @@
# - IsOwner : (or )
#
- viewset: AppModerationStatusViewSet
api_end_point: serverModerationStatus
read_only: true
is_api_view: true
- model: Country
viewset: CountryViewSet
import_location: country
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment