diff --git a/umap/models.py b/umap/models.py index c69b3f93..5efe3aba 100644 --- a/umap/models.py +++ b/umap/models.py @@ -251,6 +251,11 @@ class Map(NamedModel): path = reverse("map_anonymous_edit_url", kwargs={"signature": signature}) return settings.SITE_URL + path + def is_owner(self, user=None, request=None): + if user and self.owner == user: + return True + return self.is_anonymous_owner(request) + def is_anonymous_owner(self, request): if not request or self.owner: # edit cookies are only valid while the map doesn't have owner diff --git a/umap/static/umap/js/modules/global.js b/umap/static/umap/js/modules/global.js index 604cdb3d..dc08b4c1 100644 --- a/umap/static/umap/js/modules/global.js +++ b/umap/static/umap/js/modules/global.js @@ -22,7 +22,6 @@ window.U = { NOKError, Orderable, Panel, - Panel, Request, RequestError, SCHEMA, diff --git a/umap/static/umap/js/modules/sync/engine.js b/umap/static/umap/js/modules/sync/engine.js index 2fac3da8..62568f22 100644 --- a/umap/static/umap/js/modules/sync/engine.js +++ b/umap/static/umap/js/modules/sync/engine.js @@ -4,7 +4,7 @@ import { MarkerUpdater, PolygonUpdater, PolylineUpdater, - DatalayerUpdater, + DataLayerUpdater, } from './updaters.js' export class SyncEngine { @@ -43,7 +43,7 @@ export class MessagesDispatcher { marker: new MarkerUpdater(this.map), polyline: new PolylineUpdater(this.map), polygon: new PolygonUpdater(this.map), - datalayer: new DatalayerUpdater(this.map), + datalayer: new DataLayerUpdater(this.map), } } diff --git a/umap/static/umap/js/modules/sync/updaters.js b/umap/static/umap/js/modules/sync/updaters.js index 85741f8e..f3cce6d0 100644 --- a/umap/static/umap/js/modules/sync/updaters.js +++ b/umap/static/umap/js/modules/sync/updaters.js @@ -45,7 +45,7 @@ export class MapUpdater extends BaseUpdater { } } -export class DatalayerUpdater extends BaseUpdater { +export class DataLayerUpdater extends BaseUpdater { update({ key, metadata, value }) { const datalayer = this.getLayerFromID(metadata.id) console.log('datalayer', datalayer, key, value) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index da31c7d4..1584e6a4 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -246,7 +246,7 @@ U.Map = L.Map.extend({ this.on('click contextmenu.show', this.closeInplaceToolbar) this.sync = new U.SyncEngine(this) - Promise.resolve(this.initSyncEngine()) + this.initSyncEngine() }, initSyncEngine: async function () { @@ -1498,6 +1498,12 @@ U.Map = L.Map.extend({ slideshow.appendChild(slideshowBuilder.build()) }, + _editSync: function (container) { + const sync = L.DomUtil.createFieldset(container, L._('Real-time collaboration')) + const builder = new U.FormBuilder(this, ['options.syncEnabled']) + sync.appendChild(builder.build()) + }, + _advancedActions: function (container) { const advancedActions = L.DomUtil.createFieldset(container, L._('Advanced actions')) const advancedButtons = L.DomUtil.create('div', 'button-bar half', advancedActions) @@ -1546,10 +1552,6 @@ U.Map = L.Map.extend({ const container = L.DomUtil.create('div', 'umap-edit-container') const metadataFields = ['options.name', 'options.description'] - if (this.options.websocketEnabled) { - metadataFields.push('options.syncEnabled') - } - const title = L.DomUtil.create('h3', '', container) title.textContent = L._('Edit map details') const builder = new U.FormBuilder(this, metadataFields, { @@ -1584,6 +1586,9 @@ U.Map = L.Map.extend({ this._editOverlay(container) this._editBounds(container) this._editSlideshow(container) + if (this.options.websocketEnabled) { + this._editSync(container) + } this._advancedActions(container) this.editPanel.open({ content: container, className: 'dark' }) diff --git a/umap/views.py b/umap/views.py index f37d5423..34d41045 100644 --- a/umap/views.py +++ b/umap/views.py @@ -794,7 +794,7 @@ def get_websocket_auth_token(request, map_id, map_inst): if map_object.can_edit(request.user, request): permissions = ["edit"] - if map_object.can_delete(request.user, request): + if map_object.is_owner(request.user, request): permissions.append("owner") if request.user.is_authenticated: