-
Notifications
You must be signed in to change notification settings - Fork 0
Feat(Auth): Display map data according to user #188
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
2578193
43cc58a
74fede0
939463e
143108c
801d0fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,100 @@ | ||
| { | ||
| "layers": [ | ||
| { | ||
| "id": "satellite", | ||
| "type": "xyzservices", | ||
| "provider": "Esri.WorldImagery" | ||
| }, | ||
| { | ||
| "id": "villages", | ||
| "type": "openmaptiles", | ||
| "layer": "place", | ||
| "filters": { | ||
| "class": "village" | ||
| } | ||
| }, | ||
| { | ||
| "id": "towns", | ||
| "type": "openmaptiles", | ||
| "layer": "place", | ||
| "filters": { | ||
| "class": "town" | ||
| } | ||
| }, | ||
| { | ||
| "id": "boundaries", | ||
| "type": "openmaptiles", | ||
| "layer": "boundary", | ||
| "filters": { | ||
| "admin_level": 2 | ||
| }, | ||
| "style": { | ||
| "paint": { | ||
| "line-color": "hsl(248,7%,66%)" | ||
| } | ||
| } | ||
| }, | ||
| { | ||
| "id": "seed", | ||
| "type": "datapackage", | ||
| "path": "../catalog/seed/datapackage.json", | ||
| "resource": "survey", | ||
| "minzoom": 13, | ||
| "columns": { | ||
| "geom": "geom", | ||
| "id": "OGC_FID", | ||
| "orga": "votre_orga", | ||
| "responsable": "nom_du_res", | ||
| "date_plantation": "date_de_pl", | ||
| "type_plant": "type_de_pl", | ||
| "prelevement_mangrove": "trace_de_p", | ||
| "test": "round(random() * 4 ) + 1" | ||
| }, | ||
| "paint": { | ||
| "fill-color": [ | ||
| "interpolate", | ||
| ["linear"], | ||
| ["number", ["get", "test"]], | ||
| 1, | ||
| "#2DC4B2", | ||
| 2, | ||
| "#3BB3C3", | ||
| 3, | ||
| "#669EC4", | ||
| 4, | ||
| "#A2719B", | ||
| 5, | ||
| "#AA5E79" | ||
| ], | ||
| "fill-opacity": 0.8 | ||
| }, | ||
| "popup": { | ||
| "trigger": "click" | ||
| } | ||
| }, | ||
| { | ||
| "id": "seed_point", | ||
| "type": "datapackage", | ||
| "path": "../catalog/seed/datapackage.json", | ||
| "resource": "survey", | ||
| "columns": { | ||
| "geom": "centroid(geom)" | ||
| }, | ||
| "maxzoom": 13 | ||
| } | ||
| ], | ||
| "controls": [ | ||
| { | ||
| "type": "compass", | ||
| "position": "top-left" | ||
| }, | ||
| { | ||
| "type": "layer", | ||
| "position": "top-right" | ||
| }, | ||
| { | ||
| "type": "scale", | ||
| "position": "bottom-left" | ||
| } | ||
| ] | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,30 +2,37 @@ | |
| from django.conf import settings | ||
| from django.http import JsonResponse | ||
| from django.contrib.auth.decorators import permission_required | ||
| from rest_framework.decorators import api_view, permission_classes | ||
| from rest_framework.decorators import api_view, permission_classes, authentication_classes | ||
| from rest_framework.permissions import IsAuthenticated | ||
| from rest_framework.response import Response | ||
| from rest_framework import status | ||
| from rest_framework_simplejwt.authentication import JWTAuthentication | ||
|
|
||
| from users.models import ADMIN_PROJECT | ||
| from copy import copy | ||
| from . import stats | ||
| from .datapackage_manager import DatapackageManager | ||
|
|
||
| config_path = settings.BASE_DIR / "configs" / "config.json" | ||
| map = Map.from_file(config_path) | ||
| ALL4TREES_LAYERS = ['inventaire_for', 'enquete'] | ||
|
|
||
| config_path = settings.BASE_DIR / "configs" / "all4trees_config.json" | ||
| map = Map.from_file(config_path) | ||
|
|
||
| @api_view(['GET', 'POST']) | ||
|
david-bretaud-dev marked this conversation as resolved.
|
||
| @authentication_classes([JWTAuthentication]) | ||
| def my_map_view(request, subpath): | ||
| return JsonResponse( | ||
| map.handle_request( | ||
|
|
||
| return JsonResponse(get_map(request.user).handle_request( | ||
| request.method, | ||
| subpath, | ||
| request.body, | ||
| ) | ||
| ) | ||
| )) | ||
|
|
||
|
|
||
| @api_view(['GET']) | ||
| @authentication_classes([JWTAuthentication]) | ||
| def dashboard_view(request, layer_id): | ||
| data = map.handle_request( | ||
| data = get_map(request.user).handle_request( | ||
| 'POST', | ||
| layer_id, | ||
| request.body) | ||
|
|
@@ -39,7 +46,6 @@ def dashboard_view(request, layer_id): | |
| }, status=status.HTTP_501_NOT_IMPLEMENTED) | ||
|
|
||
|
|
||
|
|
||
| @api_view(["POST"]) | ||
| @permission_classes([IsAuthenticated]) | ||
| @permission_required("users.add_data") | ||
|
|
@@ -97,4 +103,17 @@ def remove_foreign_key_view(request): | |
| """ | ||
| View for adding a foreign key to a DataPackage. | ||
| """ | ||
| return DatapackageManager(request).remove_foreign_key() | ||
| return DatapackageManager(request).remove_foreign_key() | ||
|
|
||
|
|
||
| def get_map(user): | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This makes the endpoint definitely "all4trees only", maybe let's reflect in the naming of the methods (
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, that's why I separated seed and all4trees. |
||
| user_map = copy(map) | ||
| if user.is_authenticated: | ||
| project = user.project | ||
| if (project.lower() != ADMIN_PROJECT): | ||
|
david-bretaud-dev marked this conversation as resolved.
|
||
| filter = f"proj = '{project}' or conf = 1" | ||
| else: | ||
| filter = 'conf = 1' | ||
|
|
||
| user_map.set_filters(ALL4TREES_LAYERS, filter) | ||
| return user_map | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we remove from
config.jsonthe seed layers then ?And rename
config.jsontoall4trees_config.json?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seed layers have already been removed because there is now a bug when importing seed data in coordo