Skip to content

Commit

Permalink
Header - Add authenticated user organization in hidden fields
Browse files Browse the repository at this point in the history
This allows a JavaScript script to get the current user organization and use it in the editing form.
  • Loading branch information
mdouchin authored and Gustry committed Mar 5, 2025
1 parent 7f9a29e commit 1c9b794
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 4 deletions.
1 change: 1 addition & 0 deletions lizmap/modules/lizmap/templates/user_menu.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<span id="info-user-login" title="{$user->firstname} {$user->lastname}">{$user->login|eschtml}</span>
<span style="display:none" id="info-user-firstname">{$user->firstname}</span>
<span style="display:none" id="info-user-lastname">{$user->lastname}</span>
<span style="display:none" id="info-user-organization">{$user->organization}</span>
</span>
<span class="caret"></span>
</a>
Expand Down
57 changes: 57 additions & 0 deletions tests/end2end/playwright/header.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// @ts-check

Check failure on line 1 in tests/end2end/playwright/header.spec.js

View workflow job for this annotation

GitHub Actions / E2E QGIS 3.34 PG 14-3 PHP 8.1

Failed Test: Login info as user A on the landing page

Login info as user A on the landing page: Error: Timed out 5000ms waiting for expect(locator).toHaveClass(expected) Locator: locator('#info-user-firstname') Expected string: "hide" Received string: "" Call log: - expect.toHaveClass with timeout 5000ms - waiting for locator('#info-user-firstname') 9 × locator resolved to <span id="info-user-firstname">User A</span> - unexpected value "" - Error: Timed out 5000ms waiting for expect(locator).toHaveClass(expected) Locator: locator('#info-user-firstname') Expected string: "hide" Received string: "" Call log: - expect.toHaveClass with timeout 5000ms - waiting for locator('#info-user-firstname') 9 × locator resolved to <span id="info-user-firstname">User A</span> - unexpected value "" at /home/runner/work/lizmap-web-client/lizmap-web-client/tests/end2end/playwright/header.spec.js:19:60

Check failure on line 1 in tests/end2end/playwright/header.spec.js

View workflow job for this annotation

GitHub Actions / E2E QGIS 3.34 PG 14-3 PHP 8.1

Failed Test: Login info as user A on project page

Login info as user A on project page: Error: Timed out 5000ms waiting for expect(locator).toHaveClass(expected) Locator: locator('#info-user-firstname') Expected string: "hide" Received string: "" Call log: - expect.toHaveClass with timeout 5000ms - waiting for locator('#info-user-firstname') 9 × locator resolved to <span id="info-user-firstname">User A</span> - unexpected value "" - Error: Timed out 5000ms waiting for expect(locator).toHaveClass(expected) Locator: locator('#info-user-firstname') Expected string: "hide" Received string: "" Call log: - expect.toHaveClass with timeout 5000ms - waiting for locator('#info-user-firstname') 9 × locator resolved to <span id="info-user-firstname">User A</span> - unexpected value "" at /home/runner/work/lizmap-web-client/lizmap-web-client/tests/end2end/playwright/header.spec.js:37:64

Check failure on line 1 in tests/end2end/playwright/header.spec.js

View workflow job for this annotation

GitHub Actions / E2E QGIS 3.40 PG 17-3 PHP 8.3

Failed Test: Login info as user A on the landing page

Login info as user A on the landing page: Error: Timed out 5000ms waiting for expect(locator).toHaveClass(expected) Locator: locator('#info-user-firstname') Expected string: "hide" Received string: "" Call log: - expect.toHaveClass with timeout 5000ms - waiting for locator('#info-user-firstname') 9 × locator resolved to <span id="info-user-firstname">User A</span> - unexpected value "" - Error: Timed out 5000ms waiting for expect(locator).toHaveClass(expected) Locator: locator('#info-user-firstname') Expected string: "hide" Received string: "" Call log: - expect.toHaveClass with timeout 5000ms - waiting for locator('#info-user-firstname') 9 × locator resolved to <span id="info-user-firstname">User A</span> - unexpected value "" at /home/runner/work/lizmap-web-client/lizmap-web-client/tests/end2end/playwright/header.spec.js:19:60

Check failure on line 1 in tests/end2end/playwright/header.spec.js

View workflow job for this annotation

GitHub Actions / E2E QGIS 3.40 PG 17-3 PHP 8.3

Failed Test: Login info as user A on project page

Login info as user A on project page: Error: Timed out 5000ms waiting for expect(locator).toHaveClass(expected) Locator: locator('#info-user-firstname') Expected string: "hide" Received string: "" Call log: - expect.toHaveClass with timeout 5000ms - waiting for locator('#info-user-firstname') 9 × locator resolved to <span id="info-user-firstname">User A</span> - unexpected value "" - Error: Timed out 5000ms waiting for expect(locator).toHaveClass(expected) Locator: locator('#info-user-firstname') Expected string: "hide" Received string: "" Call log: - expect.toHaveClass with timeout 5000ms - waiting for locator('#info-user-firstname') 9 × locator resolved to <span id="info-user-firstname">User A</span> - unexpected value "" at /home/runner/work/lizmap-web-client/lizmap-web-client/tests/end2end/playwright/header.spec.js:37:64
import { test, expect } from '@playwright/test';
import {ProjectPage} from "./pages/project";

test.describe('Header',
{
tag: ['@readonly'],
},
() => {

test('Login info as user A on the landing page', async ({ browser }) => {
const userA = await browser.newContext({ storageState: 'playwright/.auth/user_in_group_a.json' });
const page = await userA.newPage();
await page.goto('index.php');

// Fixme, class "hide" but visible ?
await expect(page.locator("#info-user-login")).toHaveText("user_in_group_a");
await expect(page.locator("#info-user-firstname")).toHaveText("User A");
await expect(page.locator("#info-user-firstname")).toHaveClass("hide");
await expect(page.locator("#info-user-firstname")).toBeVisible();
await expect(page.locator("#info-user-lastname")).toHaveText("Testadiferro");
await expect(page.locator("#info-user-lastname")).toHaveClass("hide");
await expect(page.locator("#info-user-lastname")).toBeVisible();
await expect(page.locator("#info-user-organization")).toHaveText("Make it KISS");
await expect(page.locator("#info-user-organization")).toHaveClass("hide");
await expect(page.locator("#info-user-organization")).toBeVisible();
});

test('Login info as user A on project page', async ({ browser }) => {
const userA = await browser.newContext({ storageState: 'playwright/.auth/user_in_group_a.json' });
const userPage = await userA.newPage();
const projectPage = new ProjectPage(userPage, 'world-3857');
await projectPage.open();

await expect(userPage.locator("#info-user-login")).toHaveText("user_in_group_a");
await expect(userPage.locator("#info-user-firstname")).toHaveText("User A");
await expect(userPage.locator("#info-user-firstname")).toHaveClass("hide");
await expect(userPage.locator("#info-user-firstname")).not.toBeVisible();
await expect(userPage.locator("#info-user-lastname")).toHaveText("Testadiferro");
await expect(userPage.locator("#info-user-lastname")).toHaveClass("hide");
await expect(userPage.locator("#info-user-lastname")).not.toBeVisible();
await expect(userPage.locator("#info-user-organization")).toHaveText("Make it KISS");
await expect(userPage.locator("#info-user-organization")).toHaveClass("hide");
await expect(userPage.locator("#info-user-organization")).not.toBeVisible();
});

test('Login info as anonymous on the landing page', async ({ page }) => {
await page.goto('index.php');
await expect(page.locator("#headermenu .login")).toHaveText("Connect");
});

test('Login info as anonymous on project page', async ({ page }) => {
const projectPage = new ProjectPage(page, 'world-3857');
await projectPage.open();
await expect(page.locator("#headermenu .login")).toHaveText("Connect");
});
});
8 changes: 4 additions & 4 deletions tests/qgis-projects/tests/set_tests_respository_rights.sql
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ INSERT INTO lizmap.jacl2_group(

-- Users
INSERT INTO lizmap.jlx_user(
usr_login, usr_email, usr_password, status, create_date)
usr_login, usr_email, usr_password, status, create_date, firstname, lastname, organization)
VALUES
('user_in_group_a', '[email protected]', '$2y$10$d2KZfxeYJP0l3YbNyDMZYe2vGSA3JWa8kFJSdecmSEIqInjnunTJ.', 1, NOW()),
('user_in_group_b', '[email protected]', '$2y$10$d2KZfxeYJP0l3YbNyDMZYe2vGSA3JWa8kFJSdecmSEIqInjnunTJ.', 1, NOW()),
('publisher', '[email protected]', '$2y$10$d2KZfxeYJP0l3YbNyDMZYe2vGSA3JWa8kFJSdecmSEIqInjnunTJ.', 1, NOW())
('user_in_group_a', '[email protected]', '$2y$10$d2KZfxeYJP0l3YbNyDMZYe2vGSA3JWa8kFJSdecmSEIqInjnunTJ.', 1, NOW(), 'User A', 'Testadiferro', 'Make it KISS'),
('user_in_group_b', '[email protected]', '$2y$10$d2KZfxeYJP0l3YbNyDMZYe2vGSA3JWa8kFJSdecmSEIqInjnunTJ.', 1, NOW(), 'User B', 'Testillano', 'Make it KISS'),
('publisher', '[email protected]', '$2y$10$d2KZfxeYJP0l3YbNyDMZYe2vGSA3JWa8kFJSdecmSEIqInjnunTJ.', 1, NOW(), 'Publisher', 'Testla', 'Make it KISS')
ON CONFLICT DO NOTHING
;

Expand Down

0 comments on commit 1c9b794

Please sign in to comment.