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

Count user defined js , adapt message when js exception #4776

Merged
merged 3 commits into from
Sep 24, 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
10 changes: 8 additions & 2 deletions assets/src/legacy/map.js
Original file line number Diff line number Diff line change
Expand Up @@ -3968,9 +3968,15 @@ window.lizMap = function() {
})
.catch((error) => {
console.error(error);
const errorMsg = `
let errorMsg = `
<p class="error-msg">${lizDict['startup.error']}
<br><a href="${globalThis['lizUrls'].basepath}">${lizDict['startup.goToProject']}</a></p>`;
<br><a href="${globalThis['lizUrls'].basepath}">${lizDict['startup.goToProject']}</a>`;
if (document.body.dataset.lizmapUserDefinedJsCount > 0 && document.body.dataset.lizmapAdminUser == 1) {
errorMsg += '<br>'+`${lizDict['startup.user_defined_js']}<br>
<a href="${globalThis['lizUrls'].repositoryAdmin}">${lizDict['startup.goToRepositoryAdmin']}</a><br>
<a href="`+ window.location+`&no_user_defined_js=1">${lizDict['startup.projectWithoutJSLink']}</a>`
}
errorMsg += `</p>`;
document.getElementById('header').insertAdjacentHTML('afterend', errorMsg);
})
.finally(() => {
Expand Down
3 changes: 3 additions & 0 deletions lizmap/modules/view/controllers/lizAjax.classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ function f($x)
$lizUrls['removeCache'] = jUrl::getFull('admin~maps:removeLayerCache');
}

if (jAcl2::check('lizmap.admin.access') || jAcl2::check('lizmap.admin.server.information.view')) {
$lizUrls['repositoryAdmin'] = jUrl::getFull('admin~maps:index');
}
$content = '<script type="text/javascript" src="'.jUrl::getFull('view~translate:index').'"/>'."\n";
$content .= '<script type="text/javascript">// <![CDATA['."\n";
$content .= 'var lizUrls = '.json_encode($lizUrls).";\n";
Expand Down
8 changes: 7 additions & 1 deletion lizmap/modules/view/controllers/lizMap.classic.php
Original file line number Diff line number Diff line change
Expand Up @@ -358,12 +358,13 @@ function f($x)
}
}

$countUserJs = 0;
// Override default theme by themes found in folder media/themes/...
// Theme name can be 'default' and apply to all projects in a repository
// or the project name and only apply to it
// Also if media/themes/default/css is found one directory above repositorie's one
// it will apply to all repositories
if ($lrep->allowUserDefinedThemes()) {
if ($lrep->allowUserDefinedThemes() && $this->param('no_user_defined_js') != '1') {
$repositoryPath = $lrep->getPath();
$cssArray = array('main', 'map', 'media');
$themeArray = array('default', $project);
Expand Down Expand Up @@ -439,8 +440,10 @@ function f($x)
);
if ($fileExtension == 'js') {
$jsUrls[] = $jsUrl;
++$countUserJs;
} elseif ($fileExtension == 'mjs') {
$mjsUrls[] = $jsUrl;
++$countUserJs;
} else {
$cssUrls[] = $jsUrl;
}
Expand All @@ -466,6 +469,7 @@ function f($x)
}
}
}
$rep->setBodyAttributes(array('data-lizmap-user-defined-js-count' => $countUserJs));

// optionally hide some tools
// header
Expand Down Expand Up @@ -562,6 +566,8 @@ function f($x)
} elseif ($lproj->projectCountCfgWarnings() >= 1) {
$rep->setBodyAttributes(array('data-lizmap-plugin-has-warnings-url' => jUrl::get('admin~qgis_projects:index')));
}
// add body attribute to tell if current user is admin
$rep->setBodyAttributes(array('data-lizmap-admin-user' => true));
}

$rep->body->assign($assign);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
startup.error=An error occurred while loading this map. Some necessary resources may temporarily be unavailable. Please try again later.
startup.user_defined_js=There's some user defined JavaScript scripts, that can be the cause of this message, try disabling them.
startup.goToProject=Go back to the home page.
startup.goToRepositoryAdmin=Go to maps management page
startup.projectWithoutJSLink=Project with user's scripts disabled

project.has.warnings=The project has some warnings in the QGIS desktop Lizmap plugin which must be fixed.
project.plugin.outdated.warning=The project has been recently updated in QGIS Desktop, but with an outdated version of the Lizmap plugin. You must upgrade your plugin in QGIS Desktop.
Expand Down
Loading