Rename allowEdit in editMode

This commit is contained in:
Yohan Boniface 2023-09-12 17:02:18 +02:00
parent de7c693c7b
commit 24e4aed8d3
8 changed files with 38 additions and 28 deletions

View file

@ -366,7 +366,7 @@ class DataLayer(NamedModel):
} }
obj["id"] = self.pk obj["id"] = self.pk
obj["permissions"] = {"edit_status": self.edit_status} obj["permissions"] = {"edit_status": self.edit_status}
obj["allowEdit"] = self.can_edit(user, request) obj["editMode"] = "advanced" if self.can_edit(user, request) else 'disabled'
return obj return obj
def clone(self, map_inst=None): def clone(self, map_inst=None):

View file

@ -275,7 +275,7 @@ L.U.ContinueLineAction = L.U.BaseVertexAction.extend({
// Leaflet.Toolbar doesn't allow twice same toolbar class… // Leaflet.Toolbar doesn't allow twice same toolbar class…
L.U.SettingsToolbar = L.Toolbar.Control.extend({ L.U.SettingsToolbar = L.Toolbar.Control.extend({
addTo: function (map) { addTo: function (map) {
if (map.options.allowMapEdit === false) return if (map.options.editMode !== 'advanced') return
L.Toolbar.Control.prototype.addTo.call(this, map) L.Toolbar.Control.prototype.addTo.call(this, map)
}, },
}) })
@ -1467,7 +1467,7 @@ L.U.IframeExporter = L.Evented.extend({
miniMap: false, miniMap: false,
scrollWheelZoom: false, scrollWheelZoom: false,
zoomControl: true, zoomControl: true,
allowEdit: false, editMode: 'disabled',
moreControl: true, moreControl: true,
searchControl: null, searchControl: null,
tilelayersControl: null, tilelayersControl: null,

View file

@ -15,7 +15,7 @@ L.Map.mergeOptions({
default_interactive: true, default_interactive: true,
default_labelDirection: 'auto', default_labelDirection: 'auto',
attributionControl: false, attributionControl: false,
allowEdit: true, editMode: 'advanced',
embedControl: true, embedControl: true,
zoomControl: true, zoomControl: true,
datalayersControl: true, datalayersControl: true,
@ -103,7 +103,7 @@ L.U.Map.include({
L.Util.setBooleanFromQueryString(this.options, 'moreControl') L.Util.setBooleanFromQueryString(this.options, 'moreControl')
L.Util.setBooleanFromQueryString(this.options, 'scaleControl') L.Util.setBooleanFromQueryString(this.options, 'scaleControl')
L.Util.setBooleanFromQueryString(this.options, 'miniMap') L.Util.setBooleanFromQueryString(this.options, 'miniMap')
L.Util.setBooleanFromQueryString(this.options, 'allowEdit') L.Util.setBooleanFromQueryString(this.options, 'editMode')
L.Util.setBooleanFromQueryString(this.options, 'displayDataBrowserOnLoad') L.Util.setBooleanFromQueryString(this.options, 'displayDataBrowserOnLoad')
L.Util.setBooleanFromQueryString(this.options, 'displayCaptionOnLoad') L.Util.setBooleanFromQueryString(this.options, 'displayCaptionOnLoad')
L.Util.setBooleanFromQueryString(this.options, 'captionBar') L.Util.setBooleanFromQueryString(this.options, 'captionBar')
@ -122,7 +122,7 @@ L.U.Map.include({
if (this.datalayersOnLoad) if (this.datalayersOnLoad)
this.datalayersOnLoad = this.datalayersOnLoad.toString().split(',') this.datalayersOnLoad = this.datalayersOnLoad.toString().split(',')
if (L.Browser.ielt9) this.options.allowEdit = false // TODO include ie9 if (L.Browser.ielt9) this.options.editMode = 'disabled' // TODO include ie9
let editedFeature = null let editedFeature = null
const self = this const self = this
@ -235,7 +235,7 @@ L.U.Map.include({
this.isDirty = true this.isDirty = true
this._default_extent = true this._default_extent = true
this.options.name = L._('Untitled map') this.options.name = L._('Untitled map')
this.options.allowEdit = true this.options.editMode = 'advanced'
const datalayer = this.createDataLayer() const datalayer = this.createDataLayer()
datalayer.connectToMap() datalayer.connectToMap()
this.enableEdit() this.enableEdit()
@ -253,7 +253,7 @@ L.U.Map.include({
this.slideshow = new L.U.Slideshow(this, this.options.slideshow) this.slideshow = new L.U.Slideshow(this, this.options.slideshow)
this.permissions = new L.U.MapPermissions(this) this.permissions = new L.U.MapPermissions(this)
this.initCaptionBar() this.initCaptionBar()
if (this.options.allowEdit) { if (this.hasEditMode()) {
this.editTools = new L.U.Editable(this) this.editTools = new L.U.Editable(this)
this.ui.on( this.ui.on(
'panel:closed panel:open', 'panel:closed panel:open',
@ -292,7 +292,7 @@ L.U.Map.include({
this.helpMenuActions = {} this.helpMenuActions = {}
this._controls = {} this._controls = {}
if (this.options.allowEdit && !this.options.noControl) { if (this.hasEditMode() && !this.options.noControl) {
new L.U.EditControl(this).addTo(this) new L.U.EditControl(this).addTo(this)
new L.U.DrawToolbar({ map: this }).addTo(this) new L.U.DrawToolbar({ map: this }).addTo(this)
@ -511,7 +511,7 @@ L.U.Map.include({
else this.ui.closePanel() else this.ui.closePanel()
} }
if (!this.options.allowEdit) return if (!this.hasEditMode()) return
/* Edit mode only shortcuts */ /* Edit mode only shortcuts */
if (key === L.U.Keys.E && modifierKey && !this.editEnabled) { if (key === L.U.Keys.E && modifierKey && !this.editEnabled) {
@ -1790,6 +1790,11 @@ L.U.Map.include({
this.fire('edit:disabled') this.fire('edit:disabled')
}, },
hasEditMode: function () {
return this.options.editMode === 'simple' || this.options.editMode === 'advanced'
},
getDisplayName: function () { getDisplayName: function () {
return this.options.name || L._('Untitled map') return this.options.name || L._('Untitled map')
}, },
@ -1946,7 +1951,7 @@ L.U.Map.include({
items = items.concat(e.relatedTarget.getContextMenuItems(e)) items = items.concat(e.relatedTarget.getContextMenuItems(e))
} }
} }
if (this.options.allowEdit) { if (this.hasEditMode()) {
items.push('-') items.push('-')
if (this.editEnabled) { if (this.editEnabled) {
if (!this.hasDirty) { if (!this.hasDirty) {

View file

@ -356,7 +356,7 @@ L.U.DataLayer = L.Evented.extend({
// So do not let all options to be reset // So do not let all options to be reset
// Fix is a proper migration so all datalayers settings are // Fix is a proper migration so all datalayers settings are
// in DB, and we remove it from geojson flat files. // in DB, and we remove it from geojson flat files.
geojson['_umap_options']['allowEdit'] = this.options.allowEdit geojson['_umap_options']['editMode'] = this.options.editMode
this.fromUmapGeoJSON(geojson) this.fromUmapGeoJSON(geojson)
this.backupOptions() this.backupOptions()
this.fire('loaded') this.fire('loaded')
@ -496,7 +496,7 @@ L.U.DataLayer = L.Evented.extend({
}) })
// No browser cache for owners/editors. // No browser cache for owners/editors.
if (this.map.options.allowEdit) url = `${url}?${Date.now()}` if (this.map.hasEditMode()) url = `${url}?${Date.now()}`
return url return url
}, },
@ -1194,7 +1194,8 @@ L.U.DataLayer = L.Evented.extend({
}, },
isReadOnly: function () { isReadOnly: function () {
return this.options.allowEdit === false // isReadOnly must return true if unset
return this.options.editMode === 'disabled'
}, },
save: function () { save: function () {

View file

@ -190,7 +190,7 @@ function initMap(options) {
name: 'name of the map', name: 'name of the map',
description: 'The description of the map', description: 'The description of the map',
locale: 'en', locale: 'en',
allowEdit: true, editMode: 'advanced',
moreControl: true, moreControl: true,
scaleControl: true, scaleControl: true,
miniMap: false, miniMap: false,

View file

@ -37,7 +37,7 @@ def map_fragment(map_instance, **kwargs):
'datalayers': datalayer_data, 'datalayers': datalayer_data,
'urls': _urls_for_js(), 'urls': _urls_for_js(),
'STATIC_URL': settings.STATIC_URL, 'STATIC_URL': settings.STATIC_URL,
"allowEdit": False, "editMode": 'disabled',
'hash': False, 'hash': False,
'attributionControl': False, 'attributionControl': False,
'scrollWheelZoom': False, 'scrollWheelZoom': False,

View file

@ -127,9 +127,9 @@ def test_wrong_slug_should_redirect_to_canonical(client, map):
def test_wrong_slug_should_redirect_with_query_string(client, map): def test_wrong_slug_should_redirect_with_query_string(client, map):
url = reverse("map", kwargs={"map_id": map.pk, "slug": "wrong-slug"}) url = reverse("map", kwargs={"map_id": map.pk, "slug": "wrong-slug"})
url = "{}?allowEdit=0".format(url) url = "{}?editMode=simple".format(url)
canonical = reverse("map", kwargs={"map_id": map.pk, "slug": map.slug}) canonical = reverse("map", kwargs={"map_id": map.pk, "slug": map.slug})
canonical = "{}?allowEdit=0".format(canonical) canonical = "{}?editMode=simple".format(canonical)
response = client.get(url) response = client.get(url)
assert response.status_code == 301 assert response.status_code == 301
assert response["Location"] == canonical assert response["Location"] == canonical
@ -137,7 +137,7 @@ def test_wrong_slug_should_redirect_with_query_string(client, map):
def test_should_not_consider_the_query_string_for_canonical_check(client, map): def test_should_not_consider_the_query_string_for_canonical_check(client, map):
url = reverse("map", kwargs={"map_id": map.pk, "slug": map.slug}) url = reverse("map", kwargs={"map_id": map.pk, "slug": map.slug})
url = "{}?allowEdit=0".format(url) url = "{}?editMode=simple".format(url)
response = client.get(url) response = client.get(url)
assert response.status_code == 200 assert response.status_code == 200

View file

@ -449,10 +449,7 @@ class MapDetailMixin:
properties = { properties = {
"urls": _urls_for_js(), "urls": _urls_for_js(),
"tilelayers": TileLayer.get_list(), "tilelayers": TileLayer.get_list(),
"allowEdit": self.is_edit_allowed(), # showEditMode "editMode": self.edit_mode,
"allowMapEdit": self.object.can_edit(self.request.user, self.request)
if getattr(self, "object", None)
else True, # FIXME naming
"default_iconUrl": "%sumap/img/marker.png" % settings.STATIC_URL, # noqa "default_iconUrl": "%sumap/img/marker.png" % settings.STATIC_URL, # noqa
"umap_id": self.get_umap_id(), "umap_id": self.get_umap_id(),
"starred": self.is_starred(), "starred": self.is_starred(),
@ -500,8 +497,9 @@ class MapDetailMixin:
def get_datalayers(self): def get_datalayers(self):
return [] return []
def is_edit_allowed(self): @property
return True def edit_mode(self):
return "advanced"
def get_umap_id(self): def get_umap_id(self):
return None return None
@ -563,11 +561,17 @@ class MapView(MapDetailMixin, PermissionsMixin, DetailView):
for l in self.object.datalayer_set.all() for l in self.object.datalayer_set.all()
] ]
def is_edit_allowed(self): @property
return self.object.can_edit(self.request.user, self.request) or any( def edit_mode(self):
edit_mode = 'disabled'
if self.object.can_edit(self.request.user, self.request):
edit_mode = "advanced"
elif any(
d.can_edit(self.request.user, self.request) d.can_edit(self.request.user, self.request)
for d in self.object.datalayer_set.all() for d in self.object.datalayer_set.all()
) ):
edit_mode = "simple"
return edit_mode
def get_umap_id(self): def get_umap_id(self):
return self.object.pk return self.object.pk