diff --git a/umap/static/umap/js/modules/schema.js b/umap/static/umap/js/modules/schema.js index b7f5080f..07e520bb 100644 --- a/umap/static/umap/js/modules/schema.js +++ b/umap/static/umap/js/modules/schema.js @@ -313,7 +313,7 @@ export const SCHEMA = { }, outlink: { type: String, - impacts: ['data'], + impacts: [], label: translate('Link to…'), helpEntries: 'outlink', placeholder: 'http://...', @@ -321,7 +321,7 @@ export const SCHEMA = { }, outlinkTarget: { type: String, - impacts: ['data'], + impacts: [], label: translate('Open link in…'), inheritable: true, default: 'blank', @@ -511,6 +511,7 @@ export const SCHEMA = { label: translate('Default zoom level'), inheritable: true, }, + // FIXME This is an internal Leaflet property, we might want to do this differently. _latlng: { type: Object, impacts: ['data'], diff --git a/umap/static/umap/js/modules/sync/engine.js b/umap/static/umap/js/modules/sync/engine.js index 7de5f662..70cc974c 100644 --- a/umap/static/umap/js/modules/sync/engine.js +++ b/umap/static/umap/js/modules/sync/engine.js @@ -4,7 +4,7 @@ import { MapUpdater, DataLayerUpdater, FeatureUpdater } from './updaters.js' export class SyncEngine { constructor(map) { this.map = map - this.receiver = new MessagesDispatcher(this.map) + this.dispatcher = new MessagesDispatcher(this.map) this._initialize() } _initialize() { @@ -22,7 +22,7 @@ export class SyncEngine { } start(webSocketURI, authToken) { - this.transport = new WebSocketTransport(webSocketURI, authToken, this.receiver) + this.transport = new WebSocketTransport(webSocketURI, authToken, this.dispatcher) this.sender = new MessagesSender(this.transport) this.upsert = this.sender.upsert.bind(this.sender) this.update = this.sender.update.bind(this.sender) diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js index b3c5abe1..2d5729e3 100644 --- a/umap/static/umap/js/modules/sync/updaters.js +++ b/umap/static/umap/js/modules/sync/updaters.js @@ -51,6 +51,7 @@ export class DataLayerUpdater extends BaseUpdater { upsert({ value }) { // Inserts does not happen (we use multiple updates instead). this.map.createDataLayer(value, false) + this.map.render() } update({ key, metadata, value }) { @@ -60,14 +61,6 @@ export class DataLayerUpdater extends BaseUpdater { } } -/** - * This is an abstract base class - * And needs to be subclassed to be used. - * - * The child classes need to expose: - * - `featureClass`: the name of the class to create the feature - * - `featureArgument`: an object with the properties to pass to the class when bulding it. - **/ export class FeatureUpdater extends BaseUpdater { getFeatureFromMetadata({ id, layerId }) { const datalayer = this.getDataLayerFromID(layerId) @@ -79,16 +72,14 @@ export class FeatureUpdater extends BaseUpdater { let { id, layerId } = metadata const datalayer = this.getDataLayerFromID(layerId) let feature = this.getFeatureFromMetadata(metadata, value) - if (feature === undefined) { - console.log(`Unable to find feature with id = ${metadata.id}. Creating a new one`) - } + feature = datalayer.geometryToFeature({ geometry: value.geometry, geojson: value, id, feature, }) - feature.addTo(datalayer) + datalayer.addLayer(feature) } // Update a property of an object @@ -103,9 +94,9 @@ export class FeatureUpdater extends BaseUpdater { datalayer.geometryToFeature({ geometry: value, id: metadata.id, feature }) default: this.updateObjectValue(feature, key, value) + feature.datalayer.indexProperties(feature) } - feature.datalayer.indexProperties(feature) feature.render([key]) } diff --git a/umap/views.py b/umap/views.py index 2819d410..d3046281 100644 --- a/umap/views.py +++ b/umap/views.py @@ -792,23 +792,18 @@ def get_websocket_auth_token(request, map_id, map_inst): """ map_object: Map = Map.objects.get(pk=map_id) - if map_object.can_edit(request.user, request): - permissions = ["edit"] - if map_object.is_owner(request.user, request): - permissions.append("owner") + permissions = ["edit"] + if map_object.is_owner(request.user, request): + permissions.append("owner") - if request.user.is_authenticated: - user = request.user.pk - else: - user = "anonymous" - signed_token = TimestampSigner().sign_object( - {"user": user, "map_id": map_id, "permissions": permissions} - ) - return simple_json_response(token=signed_token) + if request.user.is_authenticated: + user = request.user.pk else: - return HttpResponseForbidden( - _("You cannot edit this map with your current permissions.") - ) + user = "anonymous" + signed_token = TimestampSigner().sign_object( + {"user": user, "map_id": map_id, "permissions": permissions} + ) + return simple_json_response(token=signed_token) class MapUpdate(FormLessEditMixin, PermissionsMixin, UpdateView):