Skip to content

Commit

Permalink
Merge pull request #2809 from Geoportail-Luxembourg/GSLUX-434
Browse files Browse the repository at this point in the history
Update OpenLayers in API
  • Loading branch information
fredj authored Nov 5, 2021
2 parents d1cfa22 + e0a26d2 commit db31dd0
Show file tree
Hide file tree
Showing 86 changed files with 4,596 additions and 11,274 deletions.
13 changes: 3 additions & 10 deletions geoportal/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apt-get -y upgrade
RUN apt-get install -y ca-certificates
RUN mv /etc/apt/sources.list.d/nodesource.list.disabled /etc/apt/sources.list.d/nodesource.list
RUN apt update && apt-get install libgnutls30
RUN apt update && apt install openjdk-8-jdk-headless git -y && apt-get dist-upgrade -y
RUN apt update && apt install git -y && apt-get dist-upgrade -y
COPY package.json /app
RUN npm set progress=false && \
npm-packages --src=/app/package.json --dst=/tmp/npm-packages && \
Expand All @@ -28,18 +28,11 @@ RUN mv /app/geoportailv3_geoportal/static-ngeo/ngeo /usr/lib/node_modules/ngeo
COPY . /app

# jsapi generation
RUN mkdir /etc/apiv3
ADD ./jsapi /etc/apiv3/
WORKDIR /etc/apiv3
RUN node --version
RUN mkdir -p /etc/apiv3/.build/externs && mkdir -p /etc/apiv3/build
RUN curl -s https://raw.githubusercontent.com/google/closure-compiler/master/contrib/externs/angular-1.6.js -o /etc/apiv3/.build/externs/angular-1.6.js && \
curl -s https://raw.githubusercontent.com/google/closure-compiler/master/contrib/externs/angular-1.6-q_templated.js -o /etc/apiv3/.build/externs/angular-1.6-q_templated.js && \
curl -s https://raw.githubusercontent.com/google/closure-compiler/master/contrib/externs/angular-1.6-http-promise_templated.js -o /etc/apiv3/.build/externs/angular-1.6-http-promise_templated.js && \
curl -s https://raw.githubusercontent.com/google/closure-compiler/master/contrib/externs/jquery-1.9.js -o /etc/apiv3/.build/externs/jquery-1.9.js
COPY ./jsapi/package.json /etc/apiv3/
RUN npm install --no-optional && npm cache clear --force
ADD ./jsapi /etc/apiv3/jsapi
RUN /etc/apiv3/jsapi/rebuild_api.sh
RUN /etc/apiv3/rebuild_api.sh

WORKDIR /app
# sad fix, to allow webpack's file-loader to find files with query string & hash added
Expand Down
4 changes: 2 additions & 2 deletions geoportal/geoportailv3_geoportal/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ def main(global_config, **settings):
# jsapi routes
config.add_route(
'jsapiloader',
'/apiv3loader.js'
'/apiv4loader.js'
)
config.add_route(
'jsapiexample',
Expand Down Expand Up @@ -488,7 +488,7 @@ def main(global_config, **settings):
'/geoportailv3.appcache'
)
config.include("pyramid_assetviews")
config.add_asset_views("/etc/static-ngeo/build/", filenames=['apiv3-full-async.js', 'apiv3.css'])
config.add_asset_views("/etc/static-ngeo/build/", filenames=['apiv4.js', 'apiv4.css'])
# ldap
from geoportailv3_geoportal.views.authentication import ldap_user_validator, \
get_user_from_request
Expand Down
19 changes: 15 additions & 4 deletions geoportal/geoportailv3_geoportal/static-ngeo/js/UserManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,8 @@ exports.prototype.authenticate = function(username, password) {
response.data['mail'],
response.data['sn'],
response.data['mymaps_role'],
response.data['is_admin']
response.data['is_admin'],
response.data['typeUtilisateur']
);
this.$rootScope.$broadcast('authenticated');
var msg = this.gettextCatalog.getString(
Expand Down Expand Up @@ -211,7 +212,8 @@ exports.prototype.getUserInfo = function() {
response.data['mail'],
response.data['sn'],
response.data['mymaps_role'],
response.data['is_admin']
response.data['is_admin'],
response.data['typeUtilisateur']
);
this.$rootScope.$broadcast('authenticated');
} else {
Expand Down Expand Up @@ -248,7 +250,7 @@ exports.prototype.isAuthenticated = function() {
* of error.
*/
exports.prototype.clearUserInfo = function() {
this.setUserInfo('', undefined, null, undefined, undefined, null, false);
this.setUserInfo('', undefined, null, undefined, undefined, null, false, 'prive');
};


Expand All @@ -260,9 +262,10 @@ exports.prototype.clearUserInfo = function() {
* @param {string|undefined} name Name.
* @param {?number} mymapsRole The role used by mymaps.
* @param {boolean} isAdmin True if is a mymaps admin.
* @param {string|undefined} typeUtilisateur type of user.
*/
exports.prototype.setUserInfo = function(
username, role, roleId, mail, name, mymapsRole, isAdmin) {
username, role, roleId, mail, name, mymapsRole, isAdmin, typeUtilisateur) {
if (username !== undefined) {
this.username = username;
this.role = role;
Expand All @@ -271,6 +274,7 @@ exports.prototype.setUserInfo = function(
this.name = name;
this.mymapsRole = mymapsRole;
this.isMymapsAdmin = isAdmin;
this.typeUtilisateur = typeUtilisateur;
} else {
this.clearUserInfo();
}
Expand All @@ -290,6 +294,13 @@ exports.prototype.getEmail = function() {
return this.email;
};

/**
* @return {string|undefined} The user type.
*/
exports.prototype.getUserType = function() {
return this.typeUtilisateur;
};

/**
* @return {?number} The Role Id.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {intersects} from 'ol/extent.js';
* @param {angular.$sce} $sce Angular $sce service.
* @param {app.locationinfo.LocationInfoOverlay} appLocationInfoOverlay The overlay.
* @param {app.Activetool} appActivetool The activetool service.
* @param {app.UserManager} appUserManager
* @ngInject
*/
const exports = function(
Expand All @@ -51,7 +52,14 @@ const exports = function(
qrServiceUrl, appLocationinfoTemplateUrl, appSelectedFeatures,
appGeocoding, appGetDevice, ngeoLocation, appThemes,
appGetLayerForCatalogNode, bboxLidar, bboxSrsLidar, lidarDemoUrl,
appRouting, $sce, appLocationInfoOverlay, appActivetool) {
appRouting, $sce, appLocationInfoOverlay, appActivetool,
appUserManager) {
/**
* @type {app.UserManager}
* @private
*/
this.appUserManager_ = appUserManager;

/**
* @type {app.Activetool}
* @private
Expand Down Expand Up @@ -532,6 +540,33 @@ exports.prototype.getLidarUrl = function() {
return '';
};


/**
* @return {boolean} True if we want to show cyclomedia button.
* @export
*/
exports.prototype.isCyclomediaAvailable = function() {
if (this.appUserManager_.getUserType() == 'etat' ||
this.appUserManager_.getUserType() == 'commune') {
return true;
}
return false;
};


/**
* @return {string} The cyclomedia url.
* @export
*/
exports.prototype.getCyclomediaUrl = function() {
if (this.clickCoordinateLuref_ !== undefined) {
return 'http://streetsmart.cyclomedia.com/streetsmart?q=' +
this.clickCoordinateLuref_[0] + ';' +
this.clickCoordinateLuref_[1];
}
return undefined;
};

/**
* @param {string} dest The destination parameter .
* @return {*} The url to mobility from field.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,10 @@ <h3 translate>Location Coordinates</h3>
<tr>
<th translate>Distance approximative</th> <td>{{ ctrl.distance }} <span translate> mètres</span></td>
</tr>
<tr class="no-print" ng-if="ctrl.isInBoxOfLidar">
<td colspan="2"><a class="fid-link" href="{{ctrl.getLidarUrl()}}" target="_blank" translate>Lien vers la démo lidar</a></td>
</tr>
<tr class="no-print">
<td><a class="fid-link" ng-href="{{ctrl.getMobilityUrl('SID')}}" target="_blank" translate>Itinéraire mobilitéit.lu depuis ici</a></td>
<td><a class="fid-link" ng-href="{{ctrl.getMobilityUrl('ZID')}}" target="_blank" translate>Itinéraire mobilitéit.lu vers ici</a></td>
<td colspan="2"><a ng-if="ctrl.isInBoxOfLidar" class="btn btn-default no-print" href="{{ctrl.getLidarUrl()}}" target="_geoportal_ext" translate>Lien vers la démo lidar</a>
<a ng-if="ctrl.isCyclomediaAvailable()" class="btn btn-default no-print" href="{{ctrl.getCyclomediaUrl()}}" target="_geoportal_ext" translate>Lien vers Cyclomédia</a>
</td>
</tr>
<tr class="no-print">
<td colspan="2">
Expand Down
39 changes: 0 additions & 39 deletions geoportal/geoportailv3_geoportal/templates/api/apiv3loader.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div id="map" style="height: 400px"></div>
<div id="layerManager"></div>

<script src="/apiv3loader.js"></script>
<script src="/apiv4loader.js"></script>
<script>
var map = new lux.Map({
target: 'map',
Expand Down
25 changes: 25 additions & 0 deletions geoportal/geoportailv3_geoportal/templates/api/apiv4loader.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## -*- coding: utf-8 -*-
<%
settings = request.registry.settings
proxy_wms_url = settings.get('proxy_wms_url')
hasSC = ('sc' in request.params)
%>\

(function() {
function writeScript(src) {
document.write('<script src="' + src + '"></script>');
}

document.write('<link rel="stylesheet" type="text/css" href="'
+ "${request.static_url('geoportailv3_geoportal:static-ngeo/build/apiv4.css')}" + '" />');
writeScript("${request.static_url('geoportailv3_geoportal:static-ngeo/build/apiv4.js')}");

document.write('<script type="text/javascript">'
+ "lux.setBaseUrl('${request.route_url('base')}', '${request.scheme}');" + '</script>');
document.write('<script type="text/javascript">'
+ "lux.setI18nUrl('${request.static_url('geoportailv3_geoportal:static-ngeo/build/fr.json')}');" + '</script>');
% if hasSC:
document.write('<script type="text/javascript">'
+ "lux.setWmtsCrossOrigin(null);" + '</script>');
% endif
})();
18 changes: 18 additions & 0 deletions geoportal/geoportailv3_geoportal/views/authentication.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import ldap3 as ldap
import logging
from pyramid.httpexceptions import HTTPFound, HTTPUnauthorized, HTTPBadRequest
from sqlalchemy import func

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -70,6 +71,9 @@ def get_user_from_request(request):
if username is not None:
return get_user(request, username)

def get_compte_pere(username):
return DBSession.query(func.lower(func.geov3.getMainAccount(username))).one()[0]

def get_user(request, username):
from c2cgeoportal_commons.models import DBSession
from c2cgeoportal_commons.models.main import Role
Expand All @@ -87,6 +91,7 @@ class O(object):
user.sn = None
user.is_password_changed = None
user.role_name = None
user.typeUtilisateur = "prive"
connector = get_ldap_connector(request)
cm = connector.manager

Expand Down Expand Up @@ -122,6 +127,16 @@ class O(object):
if 'roleOGC' in obj:
# This role is used by the print proxy and internal WMS proxy.
user.ogc_role = int(obj['roleOGC'][0])
if 'typeUtilisateur' in obj:
user.typeUtilisateur = obj['typeUtilisateur'][0].lower().decode()

login_pere = get_compte_pere(username)
# If an ascendant user exist, use his user type
if login_pere != username:
user_pere = get_user(request, login_pere)
if 'typeUtilisateur' in obj:
user.typeUtilisateur = user_pere.typeUtilisateur

conn.unbind()
try:
# Loading the plain c2cgeoportal role used for authentication.
Expand Down Expand Up @@ -156,6 +171,9 @@ def get_user_info(self):
"sn": getattr(
self.request.user, 'sn',
self.request.user.username),
"typeUtilisateur": getattr(
self.request.user, 'typeUtilisateur',
self.request.user.typeUtilisateur),
"is_admin": getattr(self.request.user, 'is_mymaps_admin', False)}
return {}

Expand Down
48 changes: 8 additions & 40 deletions geoportal/geoportailv3_geoportal/views/getfeatureinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from shapely.ops import transform
from shapely.wkt import loads as wkt_loads
from functools import partial
from arcgis2geojson import arcgis2geojson

from geoportailv3_geoportal.lib.esri_authentication import ESRITokenException
from geoportailv3_geoportal.lib.esri_authentication import get_arcgis_token, read_request_with_token
Expand Down Expand Up @@ -1308,7 +1309,10 @@ def _get_external_data(self, layer_id, url, id_column='objectid',
try:
url_request = urllib.request.Request(query_count)
result = read_request_with_token(url_request, self.request, log)
self.content_count = geojson_loads(result.data)['count']
geojson_res = geojson_loads(result.data)
self.content_count = 0
if 'count' in geojson_res:
self.content_count = geojson_res['count']
except ESRITokenException as e:
log.exception(e)
log.error(url)
Expand Down Expand Up @@ -1340,45 +1344,9 @@ def _get_external_data(self, layer_id, url, id_column='objectid',
'coordinates': [[
[x1, y1], [x2, y1], [x2, y2], [x1, y2], [x1, y1]
]]}
elif (rawfeature['geometry'] and
'x' in rawfeature['geometry'] and
'y' in rawfeature['geometry']):
geometry = {'type': 'Point',
'coordinates': [rawfeature['geometry']['x'],
rawfeature['geometry']['y']]}
elif (rawfeature['geometry'] and
'x' in rawfeature['geometry'] and
'Y' in rawfeature['geometry']):
geometry = {'type': 'Point',
'coordinates': [rawfeature['geometry']['x'],
rawfeature['geometry']['Y']]}
elif (rawfeature['geometry'] and
'paths' in rawfeature['geometry'] and
len(rawfeature['geometry']['paths']) > 0):
geometry = {'type': 'MultiLineString',
'coordinates': rawfeature['geometry']['paths']}
elif (rawfeature['geometry'] and
'rings' in rawfeature['geometry'] and
len(rawfeature['geometry']['rings']) > 0):
if len(rawfeature['geometry']['rings']) == 1:
geometry = {'type': 'Polygon',
'coordinates':
rawfeature['geometry']['rings']}
else:
coordinates = []
curpolygon = []
for ring in rawfeature['geometry']['rings']:
if not LinearRing(ring).is_ccw:
if len(curpolygon) > 0:
coordinates.append(curpolygon)
curpolygon = []
curpolygon.append(ring)

if len(curpolygon) > 0:
coordinates.append(curpolygon)

geometry = {'type': 'MultiPolygon',
'coordinates': coordinates}
else:
geojsonrawfeature = arcgis2geojson(rawfeature)
geometry = geojsonrawfeature['geometry']

if geometry != '':
alias = {}
Expand Down
Loading

0 comments on commit db31dd0

Please sign in to comment.