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 = [] ...@@ -15,6 +15,8 @@ CLASSIC_MODELS = []
# Go through the API configuraion # Go through the API configuraion
for entry in api_config: for entry in api_config:
if "is_api_view" in entry and entry["is_api_view"]:
continue
if "model" in entry and entry["model"]: if "model" in entry and entry["model"]:
model_obj = DotMap(entry) model_obj = DotMap(entry)
if (not model_obj.requires_testing) and (not model_obj.ignore_in_admin): 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.conf import settings
from django.http import HttpResponse
import json
from shared import OBJ_MODERATION_PERMISSIONS from shared import OBJ_MODERATION_PERMISSIONS
def app_moderation_status(request): class AppModerationStatusViewSet(APIView):
return HttpResponse( """
json.dumps( """
permission_classes = get_viewset_permissions("AppModerationStatusViewSet")
def get(self, request):
return Response(
{ {
"activated": settings.MODERATION_ACTIVATED, "activated": settings.MODERATION_ACTIVATED,
"moderator_level": OBJ_MODERATION_PERMISSIONS["moderator"], "moderator_level": OBJ_MODERATION_PERMISSIONS["moderator"],
} }
) )
)
...@@ -10,6 +10,8 @@ ALL_VIEWSETS = {} ...@@ -10,6 +10,8 @@ ALL_VIEWSETS = {}
for model in api_config: for model in api_config:
model = DotMap(model) model = DotMap(model)
if "is_api_view" in model and model.is_api_view:
continue
if not model.requires_testing: if not model.requires_testing:
if model.viewset != "UserDataViewSet": if model.viewset != "UserDataViewSet":
module = importlib.import_module( module = importlib.import_module(
...@@ -20,6 +22,8 @@ for model in api_config: ...@@ -20,6 +22,8 @@ for model in api_config:
if settings.TESTING: if settings.TESTING:
for model in api_config: for model in api_config:
model = DotMap(model) model = DotMap(model)
if "is_api_view" in model and model.is_api_view:
continue
if model.requires_testing: if model.requires_testing:
if model.viewset != "UserDataViewSet": if model.viewset != "UserDataViewSet":
module = importlib.import_module( module = importlib.import_module(
......
from django.conf import settings from django.conf import settings
from django.conf.urls import include, url from django.conf.urls import include, url
from django.urls import path
from rest_framework import routers from rest_framework import routers
from rest_framework.documentation import include_docs_urls from rest_framework.documentation import include_docs_urls
from backend_app.permissions import DEFAULT_VIEWSET_PERMISSIONS from backend_app.permissions import DEFAULT_VIEWSET_PERMISSIONS
from shared import get_api_config from shared import get_api_config
from . import views
from dotmap import DotMap from dotmap import DotMap
from .other_viewsets import AppModerationStatusViewSet
import importlib import importlib
...@@ -23,6 +22,8 @@ api_config = get_api_config() ...@@ -23,6 +22,8 @@ api_config = get_api_config()
for entry in api_config: for entry in api_config:
model_obj = DotMap(entry) 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 ( if (not model_obj.requires_testing) or (
settings.TESTING and model_obj.requires_testing settings.TESTING and model_obj.requires_testing
): ):
...@@ -45,10 +46,10 @@ for entry in api_config: ...@@ -45,10 +46,10 @@ for entry in api_config:
router.register(str_url, Viewset) router.register(str_url, Viewset)
# Add all the endpoints for the base api # Add all the endpoints for the base api
urlpatterns += [url(r"^api/", include(router.urls))] urlpatterns += [
url(r"^api/", include(router.urls)),
# Add some custom APIs url(r"^api/serverModerationStatus/", AppModerationStatusViewSet.as_view()),
urlpatterns.append(path("api/serverModerationStatus/", views.app_moderation_status)) ]
####### #######
# Models and Viewset checks # Models and Viewset checks
......
...@@ -5,6 +5,8 @@ def get_model_config(model): ...@@ -5,6 +5,8 @@ def get_model_config(model):
api_config = get_api_config() api_config = get_api_config()
for obj in api_config: for obj in api_config:
if "is_api_view" in obj and obj["is_api_view"]:
continue
if obj["model"] == model: if obj["model"] == model:
tmp = { tmp = {
"moderation_level": obj["moderation_level"], "moderation_level": obj["moderation_level"],
......
...@@ -36,6 +36,11 @@ ...@@ -36,6 +36,11 @@
# - IsOwner : (or ) # - IsOwner : (or )
# #
- viewset: AppModerationStatusViewSet
api_end_point: serverModerationStatus
read_only: true
is_api_view: true
- model: Country - model: Country
viewset: CountryViewSet viewset: CountryViewSet
import_location: country 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