From 21be2e4fd0398f19b9545fadf4d98f9cf00c83dc Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Fri, 4 Oct 2024 17:54:13 +0200 Subject: [PATCH] fix: hide "my profile" from dropdown menu if ALLOW_EDIT_PROFILE=False --- umap/static/umap/js/modules/urls.js | 6 +++++- umap/static/umap/js/umap.controls.js | 10 ++++++---- umap/tests/integration/test_basics.py | 2 +- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/umap/static/umap/js/modules/urls.js b/umap/static/umap/js/modules/urls.js index 171ca91b..c3cb8a2a 100644 --- a/umap/static/umap/js/modules/urls.js +++ b/umap/static/umap/js/modules/urls.js @@ -5,10 +5,14 @@ export default class URLs { this.urls = serverUrls } + has(urlName) { + return urlName in this.urls + } + get(urlName, params) { if (typeof this[urlName] === 'function') return this[urlName](params) - if (this.urls.hasOwnProperty(urlName)) { + if (this.has(urlName)) { return template(this.urls[urlName], params) } throw `Unable to find a URL for route ${urlName}` diff --git a/umap/static/umap/js/umap.controls.js b/umap/static/umap/js/umap.controls.js index 255aae91..555a85cc 100644 --- a/umap/static/umap/js/umap.controls.js +++ b/umap/static/umap/js/umap.controls.js @@ -654,10 +654,6 @@ const ControlsMixin = { label: L._('New map'), action: this.urls.get('map_new'), }, - { - label: L._('My profile'), - action: this.urls.get('user_profile'), - }, { label: L._('My maps'), action: this.urls.get('user_dashboard'), @@ -667,6 +663,12 @@ const ControlsMixin = { action: this.urls.get('user_teams'), }, ] + if (this.urls.has('user_profile')) { + actions.push({ + label: L._('My profile'), + action: this.urls.get('user_profile'), + }) + } button.addEventListener('click', () => { const x = button.offsetLeft const y = button.offsetTop + button.offsetHeight diff --git a/umap/tests/integration/test_basics.py b/umap/tests/integration/test_basics.py index c19c4a96..3ea7c2a7 100644 --- a/umap/tests/integration/test_basics.py +++ b/umap/tests/integration/test_basics.py @@ -94,4 +94,4 @@ def test_login_from_map_page(live_server, page, tilelayer, settings, user, conte # Save should have proceed assert Map.objects.count() == 1 # Use name should now appear on the header toolbar - expect(page.get_by_text("My Dashboard (Joe)")).to_be_visible() + expect(page.get_by_role("button", name="Joe")).to_be_visible()