import os from flasgger import swag_from from flask import jsonify, request from app.blueprints.layers.routings import mod_layers from app.blueprints.layers.tags.models import LayerTag, Tag from app.db.general import token_required from app.docs import path_by @mod_layers.route("/tags") @swag_from(path_by(__file__, 'docs/tags.get.yml'), methods=['GET']) @token_required def tags_get(): query = Tag.select().order_by(Tag.id) result = list(query.dicts()) return jsonify({"data": result}) @mod_layers.route("/tags", methods=["POST"]) @swag_from(path_by(__file__, 'docs/tags.post.yml'), methods=['POST']) @token_required def tags_post(): payload = request.get_json(force=True) required_attributes = ("name", "color") if set(payload.keys()) != set(required_attributes): return jsonify({ "error":
from flask import Blueprint, jsonify, request from flasgger import swag_from from app.blueprints.layers.layers_attachments import LayerAttachmentsManager from app.db.database import database from app.docs import path_by from app.db.general import token_required, layer_decorator from app.helpers.layer import Layer, TYPES from shapely.geometry import shape mod_features = Blueprint("features", __name__) @mod_features.route('/layers/<lid>/features', methods=['POST']) @swag_from(path_by(__file__, 'docs.features.post.yml'), methods=['POST']) @token_required @layer_decorator(permission="write") def features_post(layer, lid): data = request.get_json(force=True) geometry = 'SRID=4326;{}'.format(shape(data['geometry']).wkt) columns = ['geometry'] values = [geometry] columns_with_types = layer.columns(with_types=True) for k, v in data['properties'].items(): if k in list(columns_with_types.keys()): columns.append(k) values.append(v) try: feature = layer.add_feature(columns, values, columns_with_types) except ValueError as e:
# -*- coding: utf-8 -*- from flask import Blueprint, jsonify, request from app.db.general import token_required, layer_decorator, user_exists, admin_only from app.helpers.cloud import PERMISSIONS from flasgger import swag_from from app.docs import path_by from os import environ from app.helpers.cloud import cloud_decorator from app.helpers.users import is_admin mod_permissions = Blueprint("permissions", __name__) @mod_permissions.route('/permissions') @swag_from(path_by(__file__, 'docs.permissions.get.yml')) @token_required @cloud_decorator def permissions(cloud): admin = True if request.user == environ.get('DEFAULT_USER') else False return jsonify(cloud.get_permissions(grantor=admin)) @mod_permissions.route('/permissions/<lid>', methods=['PUT']) @swag_from(path_by(__file__, 'docs.permissions.id.put.yml'), methods=['PUT']) @token_required @layer_decorator(permission="owner") def permissions_by_layer_id(layer, lid): data = request.get_json(force=True) user = data.get("user", "")
from flask import Blueprint, jsonify, request, send_file from flasgger import swag_from from app.blueprints.layers.utils import ATTACHMENTS_COLUMN_NAME from app.blueprints.rdos.analysis.distance_analysis import get_xlsx from app.blueprints.rdos.analysis.intersection_analysis import get_intersecting_features_ids from app.docs import path_by from app.db.general import token_required, layer_decorator, admin_only from app.helpers.layer import get_features_as_xlsx from app.blueprints.rdos.analysis.models import Settings mod_analysis = Blueprint("analysis", __name__) @mod_analysis.route('/analysis/settings', methods=['GET', 'PUT']) @swag_from(path_by(__file__, 'docs.settings.get.yml'), methods=['GET']) @swag_from(path_by(__file__, 'docs.settings.put.yml'), methods=['PUT']) @token_required def settings(): if request.method == 'GET': return jsonify({"settings": Settings.get_settings()}) elif request.method == 'PUT': @admin_only def put(): Settings.update_settings(request.get_json(force=True)) return jsonify({"settings": Settings.get_settings()}) return put()
#!/usr/bin/python # -*- coding: utf-8 -*- from flask import Blueprint, jsonify, request from flasgger import swag_from from app.docs import path_by from app.db.general import token_required from app.helpers.cloud import cloud_decorator from app.blueprints.rdos.services.models import Service import os mod_services = Blueprint("services", __name__) @mod_services.route('/services/<sid>', methods=['DELETE']) @swag_from(path_by(__file__, 'docs.services.delete.yml'), methods=['DELETE']) @token_required @cloud_decorator def service_delete(cloud, sid): if request.method == 'DELETE': """ Delete service Returns service id """ def delete(sid=sid): error, code = Service.check_permission(sid, cloud.get_user_group()) if error: return jsonify({"error": error}), code return jsonify({"sid": Service.delete_service(sid)}) return delete(sid=sid)
#!/usr/bin/python # -*- coding: utf-8 -*- from flask import Blueprint, jsonify, request, current_app, send_from_directory from flasgger import swag_from from app.docs import path_by from app.db.general import user_exists, create_user, authenticate_user, create_token, token_required, delete_user, admin_only import os from app.helpers.cloud import cloud_decorator mod_auth = Blueprint("auth", __name__) @mod_auth.route('/login', methods=['POST']) @swag_from(path_by(__file__, 'docs.login.post.yml'), methods=['POST']) def login(): payload = request.get_json(force=True) user = payload.get("user") if not user: return jsonify({"error": "user required"}), 400 password = payload.get("password") if not password: return jsonify({"error": "password required"}), 400 if not authenticate_user(user, password): return jsonify({"error": "invalid credentials"}), 403 token = create_token(user) return jsonify({"token": token}) @mod_auth.route('/check_token', methods=['GET'])
from flask import Blueprint, jsonify, request from flasgger import swag_from from app.docs import path_by from app.db.general import token_required, layer_decorator from app.helpers.layer import Layer from app.blueprints.rdos.attachments.models import Attachment import os mod_attachments = Blueprint("attachments", __name__) @mod_attachments.route( '/layers/<lid>/features/<int:fid>/attachments/<int:aid>', methods=['DELETE']) @swag_from(path_by(__file__, 'docs.attachments.delete.yml'), methods=['DELETE']) @token_required def attachment_delete(lid, fid, aid): if request.method == 'DELETE': """ Delete attachment for feature Returns attachments list """ @layer_decorator(permission="owner") def delete(layer, lid=lid, fid=fid, aid=None): return jsonify( {"aid": Attachment.delete_attachment(lid, fid, aid)}) return delete(lid=lid, fid=fid, aid=aid)
mod_layers = Blueprint("layers", __name__) from app.blueprints.layers.tags import routings GDAL_TO_PG = { "String": "character varying", "Integer": "integer", "Real": "real", "DateTime": "timestamp without time zone", "Date": "timestamp without time zone", "Integer64": "integer" } @mod_layers.route("/layers/max_name_length") @swag_from(path_by(__file__, 'docs.layers.max_name_length.get.yml')) @token_required def layers_max_name_length(): return jsonify({"data": MAX_LAYER_NAME_LENGTH}) @mod_layers.route('/layers', methods=['GET', 'POST']) @swag_from(path_by(__file__, 'docs.layers.post.yml'), methods=['POST']) @swag_from(path_by(__file__, 'docs.layers.get.yml'), methods=['GET']) @token_required @cloud_decorator def layers(cloud): if request.method == 'GET': return jsonify({"layers": cloud.get_layers()}) elif request.method == 'POST': files = [request.files[f] for f in request.files]