Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display a warning box when the CFG contains warnings #4270

Merged
merged 2 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions lizmap/modules/view/controllers/lizMap.classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,24 @@ function f($x)
$assign['googleAnalyticsID'] = $lser->googleAnalyticsID;
}

$serverInfoAccess = (\jAcl2::check('lizmap.admin.access') || \jAcl2::check('lizmap.admin.server.information.view'));
if ($serverInfoAccess && $lproj->projectCountCfgWarnings() >= 1) {
$jsWarning = "
lizMap.events.on(
{
'uicreated':function(evt){
var message = lizDict['project.has.warnings'];
message += '<br><a href=\"".jUrl::get('admin~qgis_projects:index')."\">';
message += lizDict['project.has.warnings.link'];
message += '</a>'
lizMap.addMessage(message, 'warning', true).attr('id','lizmap-warning-message');
}
}
);
";
$rep->addJSCode($jsWarning);
}

$rep->body->assign($assign);

// Log
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
startup.error=An error occurred while loading this map. Some necessary resource may temporarily be unavailable. Please try again later.
startup.goToProject=Go back to the home page.

project.has.warnings=The project has some warnings in the QGIS desktop Lizmap plugin which must be fixed. Only administrators or publishers can see this message.
project.has.warnings.link=Visit the QGIS project page in the administration panel.

tree.button.checkbox=Display/Hide
tree.button.link=Open documentation
tree.button.removeCache=Remove cache server for this layer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// @ts-check
const { defineConfig } = require('@playwright/test');
import { defineConfig } from '@playwright/test';

module.exports = defineConfig({
export default defineConfig({
testDir: './playwright',
/* Maximum time one test can run for. */
timeout: 30 * 1000,
Expand Down Expand Up @@ -40,25 +39,32 @@ module.exports = defineConfig({

/* Configure projects for major browsers */
projects: [
{
name: 'setup',
testMatch: 'auth.setup.ts',
},
{
name: 'chromium',
use: {
browserName: 'chromium',
},
dependencies: ['setup'],
},

{
name: 'firefox',
use: {
browserName: 'firefox',
},
dependencies: ['setup'],
},

{
name: 'webkit',
use: {
browserName: 'webkit',
},
dependencies: ['setup'],
},

{
Expand Down
39 changes: 39 additions & 0 deletions tests/end2end/playwright/auth.setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { test as setup } from '@playwright/test';

const user_in_group_aFile = 'playwright/.auth/user_in_group_a.json';

setup('authenticate as user_in_group_a', async ({ page }) => {
// Perform authentication steps. Replace these actions with your own.
await page.goto('http://localhost:8130/admin.php/auth/login?auth_url_return=%2Findex.php');
await page.locator('#jforms_jcommunity_login_auth_login').fill('user_in_group_a');
await page.locator('#jforms_jcommunity_login_auth_password').fill('admin');
await page.getByRole('button', { name: 'Sign in' }).click();
// Wait until the page receives the cookies.
//
// Sometimes login flow sets cookies in the process of several redirects.
// Wait for the final URL to ensure that the cookies are actually set.
await page.waitForURL('http://localhost:8130/index.php');

// End of authentication steps.

await page.context().storageState({ path: user_in_group_aFile });
});

const adminFile = 'playwright/.auth/admin.json';

setup('authenticate as admin', async ({ page }) => {
// Perform authentication steps. Replace these actions with your own.
await page.goto('http://localhost:8130/admin.php/auth/login?auth_url_return=%2Findex.php');
await page.locator('#jforms_jcommunity_login_auth_login').fill('admin');
await page.locator('#jforms_jcommunity_login_auth_password').fill('admin');
await page.getByRole('button', { name: 'Sign in' }).click();
// Wait until the page receives the cookies.
//
// Sometimes login flow sets cookies in the process of several redirects.
// Wait for the final URL to ensure that the cookies are actually set.
await page.waitForURL('http://localhost:8130/index.php');

// End of authentication steps.

await page.context().storageState({ path: adminFile });
});
24 changes: 24 additions & 0 deletions tests/end2end/playwright/project_load_warning.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { test, expect } from '@playwright/test';

test.describe('Project warnings in CFG as admin', () => {
test.use({ storageState: 'playwright/.auth/admin.json' });

test('Visit map with a warning', async ({ page }) => {
const url = '/index.php/view/map?repository=testsrepository&project=project_cfg_warnings';
await page.goto(url, { waitUntil: 'networkidle' });

await expect(page.locator("#lizmap-warning-message")).toBeVisible();
});

});

test.describe('Project warnings in CFG as anonymous', () => {

test('Visit map without a warning', async ({ page }) => {
const url = '/index.php/view/map?repository=testsrepository&project=project_cfg_warnings';
await page.goto(url, { waitUntil: 'networkidle' });

await expect(page.locator("#lizmap-warning-message")).toHaveCount(0);
});

});
Loading
Loading