This repository has been archived by the owner on Mar 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #139 from scaleoutsystems/feature/STACKN-120
Feature/stackn 120
- Loading branch information
Showing
3 changed files
with
74 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from rest_framework.permissions import BasePermission | ||
from django.http import QueryDict | ||
from .serializers import Model, MLModelSerializer, Report, ReportSerializer, \ | ||
ReportGenerator, ReportGeneratorSerializer, Project, ProjectSerializer, \ | ||
DeploymentInstance, DeploymentInstanceSerializer, DeploymentDefinition, \ | ||
DeploymentDefinitionSerializer | ||
import modules.keycloak_lib as keylib | ||
|
||
|
||
class ProjectPermission(BasePermission): | ||
|
||
def has_permission(self, request, view): | ||
""" | ||
Should simply return, or raise a 403 response. | ||
""" | ||
|
||
project = Project.objects.get(pk=view.kwargs['project_pk']) | ||
|
||
project_rules = { | ||
'GET': ['guest', 'member', 'admin'], | ||
'POST': ['member', 'admin'], | ||
'PUT': ['member', 'admin'], | ||
'DELETE': ['admin'] | ||
} | ||
|
||
is_authorized = False | ||
if request.method in project_rules: | ||
is_authorized = keylib.keycloak_verify_user_role(request, project.slug, project_rules[request.method]) | ||
|
||
print('Is authorized: {}'.format(is_authorized)) | ||
return is_authorized |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,32 @@ | ||
from django.conf.urls import include | ||
from django.urls import path | ||
from rest_framework import routers | ||
import rest_framework.routers as drfrouters | ||
from .views import ModelList, ReportList, ReportGeneratorList, ProjectList, DeploymentInstanceList, DeploymentDefinitionList | ||
from rest_framework.authtoken.views import obtain_auth_token | ||
from rest_framework_nested import routers | ||
|
||
app_name = 'api' | ||
|
||
router = routers.DefaultRouter() | ||
router.register(r'models', ModelList, basename='model') | ||
router.register(r'reports', ReportList, basename='report') | ||
router.register(r'generators', ReportGeneratorList, basename='report_generator') | ||
router.register(r'projects', ProjectList, basename='project') | ||
router.register(r'deploymentInstances', DeploymentInstanceList, basename='deploymentInstance') | ||
router.register(r'deploymentDefinitions', DeploymentDefinitionList, basename='deploymentDefinition') | ||
router_drf = drfrouters.DefaultRouter() | ||
# router = routers.DefaultRouter() | ||
router = routers.SimpleRouter() | ||
|
||
router.register(r'reports', ReportList, base_name='report') | ||
router.register(r'generators', ReportGeneratorList, base_name='report_generator') | ||
router.register(r'projects', ProjectList, base_name='project') | ||
|
||
models_router = routers.NestedSimpleRouter(router, r'projects', lookup='project') | ||
models_router.register(r'models', ModelList, base_name='model') | ||
# router.register(r'models', ModelList, basename='model') | ||
router.register(r'deploymentInstances', DeploymentInstanceList, base_name='deploymentInstance') | ||
router.register(r'deploymentDefinitions', DeploymentDefinitionList, base_name='deploymentDefinition') | ||
# print(router.urls) | ||
print(models_router.urls) | ||
urlpatterns = [ | ||
path('', include(router_drf.urls)), | ||
path('', include(router.urls)), | ||
path('', include(models_router.urls)), | ||
path('api-token-auth', obtain_auth_token, name='api_token_auth'), | ||
] | ||
|
||
print(urlpatterns) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters