fix(maps): let users and admins enter a CARTO API key (#2060)

CARTO stamps an "API KEY REQUIRED" watermark onto every basemap tile
fetched without a key since 26.08.2026, and both CartoDB presets plus the
built-in fallback are CARTO. The key is free and needs no account, so add
it as a setting rather than dropping the provider.

carto_api_key sits next to mapbox_access_token: per user in Settings/Map,
instance-wide under Admin/User Defaults, encrypted at rest, injected from
CARTO_API_KEY on managed instances. Unlike Mapbox it never switches the
map provider, since a raster key says nothing about the renderer.

The key is appended as ?key= at render time instead of being stored in the
template, so a saved URL stays portable and survives a rotation. That is
also what reaches the four maps that pinned CARTO and ignored the user's
tile setting: atlas, collections, the public trip share and the public
journey. The two share pages read it from their token-gated payload, the
same way baseCurrency already travels.

Also lifts the release notice above page chrome. Its overlay sat at
z-index 50, under the Vacay mode toolbar at 61, so the dialog was neither
on top nor modal. Adds a six-step layer scale to index.css and moves the
three notice shells onto it.

Closes #2054
Closes #2052
This commit is contained in:
Maurice
2026-08-27 12:06:55 +02:00
committed by GitHub
parent 521e52c853
commit 1f66ef1d32
99 changed files with 1258 additions and 67 deletions
@@ -1,4 +1,4 @@
// FE-MOB-MDUS-001 to FE-MOB-MDUS-024
// FE-MOB-MDUS-001 to FE-MOB-MDUS-027
import { describe, it, expect, beforeEach, vi } from 'vitest';
import { render, screen, waitFor, within, fireEvent } from '../../../helpers/render';
import userEvent from '@testing-library/user-event';
@@ -48,6 +48,11 @@ function resetLink(label: string): HTMLElement {
return within(holder).getByRole('button', { name: 'reset' });
}
/** The CARTO key input sits under its label inside the field's own wrapper. */
function cartoInput(): HTMLInputElement {
return within(screen.getByText('Shared CARTO key').parentElement as HTMLElement).getByRole('textbox');
}
describe('MAdminDefaultUserSettings', () => {
beforeEach(() => {
resetAllStores();
@@ -376,4 +381,41 @@ describe('MAdminDefaultUserSettings', () => {
expect(screen.queryByText('Reset to built-in default')).not.toBeInTheDocument();
expect(screen.getByRole('tab', { name: '°C Celsius' })).toHaveAttribute('aria-selected', 'true');
});
it('FE-MOB-MDUS-025: the shared CARTO key is stored on blur and cleared by its reset link', async () => {
const user = userEvent.setup();
const { puts } = stubDefaults({ carto_api_key: 'ck.old' });
render(<MAdminDefaultUserSettings />);
await screen.findByText('Shared CARTO key');
const input = cartoInput();
expect(input).toHaveValue('ck.old');
await user.clear(input);
await user.type(input, 'ck.new');
input.blur();
await waitFor(() => expect(puts).toEqual([{ carto_api_key: 'ck.new' }]));
await user.click(resetLink('Shared CARTO key'));
await waitFor(() => expect(puts).toHaveLength(2));
expect(puts[1]).toEqual({ carto_api_key: null });
await waitFor(() => expect(cartoInput()).toHaveValue(''));
});
it('FE-MOB-MDUS-026: a managed instance brings its own CARTO key and hides the field', async () => {
seedStore(useAuthStore, { isAuthenticated: true, user: buildAdmin(), managed: true });
stubDefaults({ carto_api_key: 'ck.hoster' });
render(<MAdminDefaultUserSettings />);
await screen.findByText('Default User Settings');
expect(screen.queryByText('Shared CARTO key')).not.toBeInTheDocument();
});
it('FE-MOB-MDUS-027: a managed instance hides the shared Mapbox token as well', async () => {
seedStore(useAuthStore, { isAuthenticated: true, user: buildAdmin(), managed: true });
stubDefaults({ map_provider: 'mapbox-gl', mapbox_access_token: 'pk.hoster' });
render(<MAdminDefaultUserSettings />);
await screen.findByText('Map style');
expect(screen.queryByText('Shared Mapbox token')).not.toBeInTheDocument();
});
});
@@ -5,6 +5,7 @@ import { render, screen, waitFor } from '../../../helpers/render';
import { resetAllStores, seedStore } from '../../../helpers/store';
import { buildSettings } from '../../../helpers/factories';
import { useSettingsStore } from '../../../../src/store/settingsStore';
import { useAuthStore } from '../../../../src/store/authStore';
import { ToastContainer } from '../../../../src/components/shared/Toast';
import type { Settings } from '../../../../src/types';
import MSettingsMap from '../../../../src/mobile/screens/settings/MSettingsMap';
@@ -30,6 +31,7 @@ vi.mock('../../../../src/components/Settings/MapboxPreview', () => ({
}));
const OSM_URL = 'https://tile.openstreetmap.org/{z}/{x}/{y}.png';
const CARTO_DARK_TILES = 'https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png';
function seedMap(over: Partial<Settings> = {}, updateSettings = vi.fn().mockResolvedValue(undefined)) {
seedStore(useSettingsStore, {
@@ -39,6 +41,11 @@ function seedMap(over: Partial<Settings> = {}, updateSettings = vi.fn().mockReso
return updateSettings;
}
/** The CARTO key input follows its eyebrow label in the card's flat layout. */
function cartoInput(): HTMLInputElement {
return screen.getByText('CARTO API key').nextElementSibling as HTMLInputElement;
}
function renderMap() {
return render(
<>
@@ -188,6 +195,7 @@ describe('MSettingsMap', () => {
map_provider: 'leaflet',
map_tile_url: OSM_URL,
mapbox_access_token: '',
carto_api_key: '',
mapbox_style: 'mapbox://styles/mapbox/dark-v11',
mapbox_3d_enabled: true,
mapbox_quality_mode: false,
@@ -272,4 +280,54 @@ describe('MSettingsMap', () => {
expect(await screen.findByTestId('gl-preview')).toHaveAttribute('data-style', 'https://tiles.openfreemap.org/styles/liberty');
});
it('FE-MOB-SETMAP-020: the Leaflet branch offers the CARTO key field', async () => {
const user = userEvent.setup();
renderMap();
expect(screen.getByText('CARTO API key')).toBeInTheDocument();
await user.click(screen.getByText('Mapbox GL'));
expect(screen.queryByText('CARTO API key')).not.toBeInTheDocument();
});
it('FE-MOB-SETMAP-021: a managed instance brings its own key and hides the field', () => {
seedStore(useAuthStore, { managed: true });
renderMap();
expect(screen.queryByText('CARTO API key')).not.toBeInTheDocument();
});
it('FE-MOB-SETMAP-022: a managed instance hides the Mapbox token field too', () => {
seedStore(useAuthStore, { managed: true });
seedMap({ map_provider: 'mapbox-gl' });
renderMap();
expect(screen.queryByPlaceholderText('pk.eyJ1Ijoi...')).not.toBeInTheDocument();
expect(screen.getByText('Mapbox Standard')).toBeInTheDocument();
});
it('FE-MOB-SETMAP-023: the typed CARTO key reaches the save payload', async () => {
const user = userEvent.setup();
const updateSettings = seedMap();
renderMap();
await user.type(cartoInput(), 'demo-key');
await user.click(screen.getByRole('button', { name: 'Save Map' }));
expect(updateSettings).toHaveBeenCalledWith(expect.objectContaining({ carto_api_key: 'demo-key' }));
});
it('FE-MOB-SETMAP-024: a CARTO template without a key explains the watermark until one is typed', async () => {
const user = userEvent.setup();
seedMap({ map_tile_url: CARTO_DARK_TILES });
renderMap();
expect(screen.getByText(/API KEY REQUIRED/)).toBeInTheDocument();
await user.type(cartoInput(), 'demo-key');
expect(screen.queryByText(/API KEY REQUIRED/)).not.toBeInTheDocument();
});
});