Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Julien Jerphanion
Rex Dri
Commits
1bae06b2
Commit
1bae06b2
authored
Mar 03, 2019
by
Florent Chehab
Browse files
Standardized serverModerationStatus in the backend
not perfect but will do the trick for now
parent
5b3e318f
Changes
6
Hide whitespace changes
Inline
Side-by-side
backend/backend_app/admin.py
View file @
1bae06b2
...
...
@@ -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
):
...
...
backend/backend_app/views.py
→
backend/backend_app/
other_
views
ets
.py
View file @
1bae06b2
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"
],
}
)
)
backend/backend_app/permissions/__list_user_post_permission.py
View file @
1bae06b2
...
...
@@ -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
(
...
...
backend/backend_app/urls.py
View file @
1bae06b2
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
...
...
backend/backend_app/utils/__get_model_config.py
View file @
1bae06b2
...
...
@@ -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"
],
...
...
shared/api_config.yml
View file @
1bae06b2
...
...
@@ -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
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment