def test_protected_layers3(self): from c2cgeoportal_geoportal.lib.filter_capabilities import get_protected_layers pl = get_protected_layers(self.role3_id, [self.ogc_server_id]) self.assertEqual( {pl[l].name for l in pl}, {"testpoint_protected", "testpoint_protected_query_with_collect"} )
def get_report(self): self.layername = self.request.matchdict["layername"] layer_config = self.config["layers"].get(self.layername) multiple = layer_config.get("multiple", False) ids = self.request.matchdict["ids"] if multiple: ids = ids.split(",") if layer_config is None: raise HTTPBadRequest("Layer not found") features_ids = [self.layername + "." + id_ for id_ in ids] if multiple \ else [self.layername + "." + ids] if layer_config["check_credentials"]: # check user credentials role_id = None if self.request.user is None else self.request.user.role.id # FIXME: support of mapserver groups ogc_server_ids = [self.default_ogc_server.id] private_layers_object = get_private_layers(ogc_server_ids) private_layers_names = [ private_layers_object[oid].name for oid in private_layers_object ] protected_layers_object = get_protected_layers( role_id, ogc_server_ids) protected_layers_names = [ protected_layers_object[oid].name for oid in protected_layers_object ] if self.layername in private_layers_names and self.layername not in protected_layers_names: raise HTTPForbidden srs = layer_config["srs"] mapserv_url = self.request.route_url("mapserverproxy") vector_request_url = add_url_params( mapserv_url, { "service": "WFS", "version": "1.1.0", "outputformat": "gml3", "request": "GetFeature", "typeName": self.layername, "featureid": ",".join(features_ids), "srsName": "epsg:{}".format(srs) }) spec = layer_config["spec"] if spec is None: spec = { "layout": self.layername, "outputFormat": "pdf", "attributes": { "ids": [{ "id": id_ } for id_ in ids] } if multiple else { "id": id } } map_config = layer_config.get("map") if map_config is not None: spec["attributes"]["map"] = self._build_map( mapserv_url, vector_request_url, srs, map_config) maps_config = layer_config.get("maps") if maps_config is not None: spec["attributes"]["maps"] = [] for map_config in maps_config: spec["attributes"]["maps"].append( self._build_map(mapserv_url, vector_request_url, srs, map_config)) else: datasource = layer_config.get("datasource", True) if multiple and datasource: data = dumps(layer_config["data"]) datas = [ loads( data % { "layername": self.layername, "id": id_, "srs": srs, "mapserv_url": mapserv_url, "vector_request_url": vector_request_url, }) for id_ in ids ] self.walker(spec, "%(datasource)s", datas) spec = loads( dumps(spec) % { "layername": self.layername, "srs": srs, "mapserv_url": mapserv_url, "vector_request_url": vector_request_url, }) elif multiple: spec = loads( dumps(spec) % { "layername": self.layername, "ids": ",".join(ids), "srs": srs, "mapserv_url": mapserv_url, "vector_request_url": vector_request_url, }) else: spec = loads( dumps(spec) % { "layername": self.layername, "id": ids, "srs": srs, "mapserv_url": mapserv_url, "vector_request_url": vector_request_url, }) return self._do_print(spec)
def get_report(self): ids = self.request.matchdict["ids"].split(",") self.layername = self.request.matchdict["layername"] layer_config = self.config["layers"].get(self.layername) if layer_config is None: raise HTTPBadRequest("Layer not found") features_ids = [self.layername + "." + id_ for id_ in ids] if layer_config["check_credentials"]: # check user credentials role_id = None if self.request.user is None else \ self.request.user.role.id # FIXME: support of mapserver groups ogc_server_ids = [self.default_ogc_server.id] private_layers_object = get_private_layers(ogc_server_ids) private_layers_names = [ private_layers_object[oid].name for oid in private_layers_object ] protected_layers_object = get_protected_layers( role_id, ogc_server_ids) protected_layers_names = [ protected_layers_object[oid].name for oid in protected_layers_object ] if self.layername in private_layers_names and \ self.layername not in protected_layers_names: raise HTTPForbidden srs = layer_config["srs"] mapserv_url = self.request.route_url("mapserverproxy") vector_request_url = "{0!s}?{1!s}".format( mapserv_url, "&".join([ "{0!s}={1!s}".format(*i) for i in list({ "service": "WFS", "version": "1.1.0", "outputformat": "gml3", "request": "GetFeature", "typeName": self.layername, "featureid": ",".join(features_ids), "srsName": "epsg:" + str(srs) }.items()) ])) spec = layer_config["spec"] if spec is None: spec = { "layout": self.layername, "outputFormat": "pdf", "attributes": { "ids": ids } } map_config = layer_config.get("map") if map_config is not None: spec["attributes"]["map"] = self._build_map( mapserv_url, vector_request_url, srs, map_config) maps_config = layer_config.get("maps") if maps_config is not None: spec["attributes"]["maps"] = [] for map_config in maps_config: spec["attributes"]["maps"].append( self._build_map(mapserv_url, vector_request_url, srs, map_config)) else: spec = loads( dumps(spec) % { "layername": self.layername, "ids": dumps(ids), "srs": srs, "mapserv_url": mapserv_url, "vector_request_url": vector_request_url, }) return self._do_print(spec)
def get_report(self): self.layername = self.request.matchdict["layername"] layer_config = self.config["layers"].get(self.layername) multiple = layer_config.get("multiple", False) ids = self.request.matchdict["ids"] if multiple: ids = ids.split(",") if layer_config is None: raise HTTPBadRequest("Layer not found") features_ids = [self.layername + "." + id_ for id_ in ids] if multiple \ else [self.layername + "." + ids] if layer_config["check_credentials"]: # check user credentials role_id = None if self.request.user is None else self.request.user.role.id # FIXME: support of mapserver groups ogc_server_ids = [self.default_ogc_server.id] private_layers_object = get_private_layers(ogc_server_ids) private_layers_names = [private_layers_object[oid].name for oid in private_layers_object] protected_layers_object = get_protected_layers(role_id, ogc_server_ids) protected_layers_names = [protected_layers_object[oid].name for oid in protected_layers_object] if self.layername in private_layers_names and self.layername not in protected_layers_names: raise HTTPForbidden srs = layer_config["srs"] mapserv_url = self.request.route_url("mapserverproxy") vector_request_url = add_url_params( mapserv_url, { "service": "WFS", "version": "1.1.0", "outputformat": "gml3", "request": "GetFeature", "typeName": self.layername, "featureid": ",".join(features_ids), "srsName": "epsg:{}".format(srs) } ) spec = layer_config["spec"] if spec is None: spec = { "layout": self.layername, "outputFormat": "pdf", "attributes": { "ids": [{ "id": id_ } for id_ in ids] } if multiple else { "id": id } } map_config = layer_config.get("map") if map_config is not None: spec["attributes"]["map"] = self._build_map( mapserv_url, vector_request_url, srs, map_config ) maps_config = layer_config.get("maps") if maps_config is not None: spec["attributes"]["maps"] = [] for map_config in maps_config: spec["attributes"]["maps"].append(self._build_map( mapserv_url, vector_request_url, srs, map_config )) else: datasource = layer_config.get("datasource", True) if multiple and datasource: data = dumps(layer_config["data"]) datas = [ loads(data % { "layername": self.layername, "id": id_, "srs": srs, "mapserv_url": mapserv_url, "vector_request_url": vector_request_url, }) for id_ in ids] self.walker(spec, "%(datasource)s", datas) spec = loads(dumps(spec) % { "layername": self.layername, "srs": srs, "mapserv_url": mapserv_url, "vector_request_url": vector_request_url, }) elif multiple: spec = loads(dumps(spec) % { "layername": self.layername, "ids": ",".join(ids), "srs": srs, "mapserv_url": mapserv_url, "vector_request_url": vector_request_url, }) else: spec = loads(dumps(spec) % { "layername": self.layername, "id": ids, "srs": srs, "mapserv_url": mapserv_url, "vector_request_url": vector_request_url, }) return self._do_print(spec)