Allow to hide advanced edit buttons

This only deals with showing or hidding those buttons, but does
not deal with real persmission behind (which are handled by the
back-end).

There is at least one workaround possible for users (apart
from using the JS console): clicking the "pencil" near to the
map name in the edit bar will open the map settings. Not sure
how much we want to block this.

cf #930
This commit is contained in:
Yohan Boniface 2023-06-20 23:07:00 +02:00
parent 1620c0567b
commit 16e776b96f
3 changed files with 16 additions and 3 deletions

View file

@ -272,8 +272,13 @@ L.U.ContinueLineAction = L.U.BaseVertexAction.extend({
}, },
}) })
// 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) {
if (map.options.advancedEditControl === false && !map.permissions.isOwner()) return
L.Toolbar.Control.prototype.addTo.call(this, map)
}
})
L.U.DrawToolbar = L.Toolbar.Control.extend({ L.U.DrawToolbar = L.Toolbar.Control.extend({
initialize: function (options) { initialize: function (options) {
L.Toolbar.Control.prototype.initialize.call(this, options) L.Toolbar.Control.prototype.initialize.call(this, options)

View file

@ -1081,6 +1081,10 @@ L.U.FormBuilder = L.FormBuilder.extend({
handler: 'DataLayersControl', handler: 'DataLayersControl',
label: L._('Display the data layers control'), label: L._('Display the data layers control'),
}, },
advancedEditControl: {
handler: 'Switch',
label: L._('Show advanced edit buttons to other editors'),
},
starControl: { starControl: {
handler: 'ControlChoice', handler: 'ControlChoice',
label: L._('Display the star map button'), label: L._('Display the star map button'),

View file

@ -25,6 +25,7 @@ L.Map.mergeOptions({
editInOSMControl: false, editInOSMControl: false,
editInOSMControlOptions: false, editInOSMControlOptions: false,
scaleControl: true, scaleControl: true,
advancedEditControl: true,
noControl: false, // Do not render any control. noControl: false, // Do not render any control.
miniMap: false, miniMap: false,
name: '', name: '',
@ -161,6 +162,8 @@ L.U.Map.include({
) )
this.options.slideshow.active = true this.options.slideshow.active = true
this.permissions = new L.U.MapPermissions(this)
this.initControls() this.initControls()
// create datalayers // create datalayers
@ -233,7 +236,6 @@ L.U.Map.include({
this.help = new L.U.Help(this) this.help = new L.U.Help(this)
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.initCaptionBar() this.initCaptionBar()
if (this.options.allowEdit) { if (this.options.allowEdit) {
this.editTools = new L.U.Editable(this) this.editTools = new L.U.Editable(this)
@ -1209,6 +1211,7 @@ L.U.Map.include({
'measureControl', 'measureControl',
'tilelayersControl', 'tilelayersControl',
'starControl', 'starControl',
'advancedEditControl',
'easing', 'easing',
], ],
@ -1444,6 +1447,7 @@ L.U.Map.include({
'options.captionBar', 'options.captionBar',
'options.captionMenus', 'options.captionMenus',
]) ])
if (!this.permissions.isAnonymousMap()) UIFields.push('options.advancedEditControl')
builder = new L.U.FormBuilder(this, UIFields, { builder = new L.U.FormBuilder(this, UIFields, {
callback: function () { callback: function () {
this.renderControls() this.renderControls()