Skip to content
Permalink
Browse files

Add settings to projectsFromUri method

  • Loading branch information
pblottiere committed Aug 27, 2020
1 parent bc37078 commit ccb72fb499699d545024a5efa8a2d545a1fa1c68
@@ -241,6 +241,18 @@ void QgsServerSettings::initSettings()
};

mSettings[ sApiWfs3MaxLimit.envVar ] = sApiWfs3MaxLimit;

// projects directory for landing page service
const Setting sProjectsDirectories = { QgsServerSettingsEnv::QGIS_SERVER_PROJECTS_DIRECTORIES,
QgsServerSettingsEnv::DEFAULT_VALUE,
QStringLiteral( "Directories used by the landing page service to find .qgs and .qgz projects" ),
QStringLiteral( "/qgis/server_projects_directories" ),
QVariant::String,
QVariant( "" ),
QVariant()
};

mSettings[ sProjectsDirectories.envVar ] = sProjectsDirectories;
}

void QgsServerSettings::load()
@@ -70,7 +70,7 @@ class SERVER_EXPORT QgsServerSettingsEnv : public QObject
QGIS_SERVER_API_WFS3_MAX_LIMIT, //!< Maximum value for "limit" in a features request, defaults to 10000 (since QGIS 3.10).
QGIS_SERVER_TRUST_LAYER_METADATA, //!< Trust layer metadata. Improves project read time. (since QGIS 3.16).
QGIS_SERVER_DISABLE_GETPRINT //!< Disabled WMS GetPrint request and don't load layouts. Improves project read time. (since QGIS 3.16).
QGIS_SERVER_PROJECTS_DIRECTORIES, //!< Directory used by the landing page service to find .qgs and .qgz projects (since QGIS 3.16)
QGIS_SERVER_PROJECTS_DIRECTORIES, //!< Directories used by the landing page service to find .qgs and .qgz projects (since QGIS 3.16)
QGIS_SERVER_PROJECTS_PG_CONNECTIONS //!< PostgreSQL connection string used by the landing page service to find projects (since QGIS 3.16)
};
Q_ENUM( EnvVar )
@@ -77,7 +77,7 @@ class QgsProjectLoaderFilter: public QgsServerFilter
const auto handler { serverInterface()->requestHandler() };
if ( handler->path().startsWith( QStringLiteral( "/project/" ) ) )
{
const QString projectPath { QgsLandingPageUtils::projectUriFromUrl( handler->url() ) };
const QString projectPath { QgsLandingPageUtils::projectUriFromUrl( handler->url(), *serverInterface()->serverSettings() ) };
if ( ! projectPath.isEmpty() )
{
qputenv( "QGIS_PROJECT_FILE", projectPath.toUtf8() );
@@ -110,7 +110,7 @@ class QgsLandingPageModule: public QgsServiceModule
// Register handlers
landingPageApi->registerHandler<QgsServerStaticHandler>( QStringLiteral( "/(?<staticFilePath>((css|js)/.*)|favicon.ico)$" ), QStringLiteral( "landingpage" ) );
landingPageApi->registerHandler<QgsLandingPageHandler>( serverIface->serverSettings() );
landingPageApi->registerHandler<QgsLandingPageMapHandler>();
landingPageApi->registerHandler<QgsLandingPageMapHandler>( serverIface->serverSettings() );

// Register API
registry.registerApi( landingPageApi );
@@ -76,7 +76,8 @@ json QgsLandingPageHandler::projectsData() const
}


QgsLandingPageMapHandler::QgsLandingPageMapHandler()
QgsLandingPageMapHandler::QgsLandingPageMapHandler( const QgsServerSettings *settings )
: mSettings( settings )
{
setContentTypes( { QgsServerOgcApi::ContentType::JSON } );
}
@@ -85,7 +86,7 @@ void QgsLandingPageMapHandler::handleRequest( const QgsServerApiContext &context
{
json data;
data[ "links" ] = json::array();
const QString projectPath { QgsLandingPageUtils::projectUriFromUrl( context.request()->url().path() ) };
const QString projectPath { QgsLandingPageUtils::projectUriFromUrl( context.request()->url().path(), *mSettings ) };
if ( projectPath.isEmpty() )
{
throw QgsServerApiNotFoundError( QStringLiteral( "Requested project hash not found!" ) );
@@ -69,7 +69,7 @@ class QgsLandingPageMapHandler: public QgsServerOgcApiHandler
{
public:

QgsLandingPageMapHandler( );
QgsLandingPageMapHandler( const QgsServerSettings *settings );

void handleRequest( const QgsServerApiContext &context ) const override;

@@ -87,6 +87,10 @@ class QgsLandingPageMapHandler: public QgsServerOgcApiHandler
}
std::string linkTitle() const override { return "Map Viewer"; }
QgsServerOgcApi::Rel linkType() const override { return QgsServerOgcApi::Rel::self; }

private:

const QgsServerSettings *mSettings = nullptr;
};

#endif // QGS_LANDINGPAGE_HANDLERS_H
@@ -55,6 +55,7 @@ QMap<QString, QString> QgsLandingPageUtils::projects( const QgsServerSettings &s


const QString projectDir { settings.projectsDirectories() };
QgsMessageLog::logMessage( QStringLiteral( "PROJECTS: %1" ).arg( projectDir ), QStringLiteral( "Landing Page" ), Qgis::MessageLevel::Info );

// Clear cache if QGIS_SERVER_PROJECTS_DIRECTORIES has changed
if ( projectDir != QGIS_SERVER_PROJECTS_DIRECTORIES )
@@ -639,12 +640,12 @@ json QgsLandingPageUtils::layerTree( const QgsProject &project, const QStringLis
return harvest( project.layerTreeRoot(), QString() );
}

QString QgsLandingPageUtils::projectUriFromUrl( const QString &url )
QString QgsLandingPageUtils::projectUriFromUrl( const QString &url, const QgsServerSettings &settings )
{
const auto match { QgsLandingPageUtils::PROJECT_HASH_RE.match( url ) };
if ( match.hasMatch() )
{
const auto availableProjects { QgsLandingPageUtils::projects() };
const auto availableProjects { QgsLandingPageUtils::projects( settings ) };
return availableProjects.value( match.captured( QStringLiteral( "projectHash" ) ), QString() );
}
return QString();
@@ -77,7 +77,7 @@ struct QgsLandingPageUtils
* Extracts and returns the (possibly empty) project URI from the \a url path
* by examining the project hash.
*/
static QString projectUriFromUrl( const QString &url );
static QString projectUriFromUrl( const QString &url, const QgsServerSettings &settings );

};

0 comments on commit ccb72fb

Please sign in to comment.
You can’t perform that action at this time.