Navigation Menu

Skip to content

Commit

Permalink
Fix some oddities in server access control and bindings (refs #13919)
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jan 22, 2016
1 parent 752f6bd commit 69ce559
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 35 deletions.
15 changes: 6 additions & 9 deletions python/server/qgsaccesscontrolfilter.sip
Expand Up @@ -34,9 +34,6 @@ class QgsAccessControlFilter
{
%TypeHeaderCode
#include "qgsaccesscontrolfilter.h"
#include "qgsserverinterface.h"
#include "qgsfeature.h"
#include "qgsmaplayer.h"
%End

public:
Expand All @@ -60,18 +57,18 @@ class QgsAccessControlFilter
/** Return the QgsServerInterface instance*/
const QgsServerInterface* serverInterface() const;
/** Return an additional expression filter */
virtual const QString layerFilterExpression( const QgsVectorLayer* layer /Transfer/ ) const;
virtual QString layerFilterExpression( const QgsVectorLayer* layer ) const;
/** Return an additional the subset string (typically SQL) filter.
Faster than the layerFilterExpression but not supported on all the type of layer */
virtual const QString layerFilterSubsetString( const QgsVectorLayer* layer /Transfer/ ) const;
virtual QString layerFilterSubsetString( const QgsVectorLayer* layer ) const;
/** Return the layer permissions */
virtual const LayerPermissions layerPermissions( const QgsMapLayer* layer /Transfer/ ) const;
virtual LayerPermissions layerPermissions( const QgsMapLayer* layer ) const;
/** Return the authorized layer attributes */
virtual const QStringList* authorizedLayerAttributes( const QgsVectorLayer* layer /Transfer/, const QStringList& attributes ) const;
virtual QStringList authorizedLayerAttributes( const QgsVectorLayer* layer, const QStringList& attributes ) const;
/** Are we authorize to modify the following geometry */
virtual bool allowToEdit( const QgsVectorLayer* layer /Transfer/, const QgsFeature& feature /Transfer/ ) const;
virtual bool allowToEdit( const QgsVectorLayer* layer, const QgsFeature& feature ) const;
/** Cache key to used to create the capabilities cache, "" for no cache, shouldn't any contains "-", default to "" */
virtual const QString cacheKey() const;
virtual QString cacheKey() const;
};

typedef QMultiMap<int, QgsAccessControlFilter*> QgsAccessControlFilterMap;
14 changes: 5 additions & 9 deletions src/server/qgsaccesscontrol.cpp
Expand Up @@ -30,7 +30,7 @@ void QgsAccessControl::filterFeatures( const QgsVectorLayer* layer, QgsFeatureRe
QgsAccessControlFilterMap::const_iterator acIterator;
for ( acIterator = mPluginsAccessControls->constBegin(); acIterator != mPluginsAccessControls->constEnd(); ++acIterator )
{
const QString expression = acIterator.value()->layerFilterExpression( layer );
QString expression = acIterator.value()->layerFilterExpression( layer );
if ( !expression.isEmpty() )
{
expressions.append( expression );
Expand All @@ -49,13 +49,13 @@ QgsFeatureFilterProvider* QgsAccessControl::clone() const
}

/** Return an additional subset string (typically SQL) filter */
const QString QgsAccessControl::extraSubsetString( const QgsVectorLayer* layer ) const
QString QgsAccessControl::extraSubsetString( const QgsVectorLayer* layer ) const
{
QStringList sqls = QStringList();
QgsAccessControlFilterMap::const_iterator acIterator;
for ( acIterator = mPluginsAccessControls->constBegin(); acIterator != mPluginsAccessControls->constEnd(); ++acIterator )
{
const QString sql = acIterator.value()->layerFilterSubsetString( layer );
QString sql = acIterator.value()->layerFilterSubsetString( layer );
if ( !sql.isEmpty() )
{
sqls.append( sql );
Expand Down Expand Up @@ -121,17 +121,13 @@ bool QgsAccessControl::layerDeletePermission( const QgsVectorLayer* layer ) cons
}

/** Return the authorized layer attributes */
const QStringList QgsAccessControl::layerAttributes( const QgsVectorLayer* layer, const QStringList attributes ) const
QStringList QgsAccessControl::layerAttributes( const QgsVectorLayer* layer, const QStringList& attributes ) const
{
QStringList currentAttributes( attributes );
QgsAccessControlFilterMap::const_iterator acIterator;
for ( acIterator = mPluginsAccessControls->constBegin(); acIterator != mPluginsAccessControls->constEnd(); ++acIterator )
{
const QStringList* newAttributes = acIterator.value()->authorizedLayerAttributes( layer, currentAttributes );
if ( newAttributes )
{
currentAttributes = *newAttributes;
}
currentAttributes = acIterator.value()->authorizedLayerAttributes( layer, currentAttributes );
}
return currentAttributes;
}
Expand Down
4 changes: 2 additions & 2 deletions src/server/qgsaccesscontrol.h
Expand Up @@ -67,7 +67,7 @@ class SERVER_EXPORT QgsAccessControl : public QgsFeatureFilterProvider
* @param layer the layer to control
* @return the subset string to use
*/
const QString extraSubsetString( const QgsVectorLayer* layer ) const;
QString extraSubsetString( const QgsVectorLayer* layer ) const;

/** Return the layer read right
* @param layer the layer to control
Expand Down Expand Up @@ -98,7 +98,7 @@ class SERVER_EXPORT QgsAccessControl : public QgsFeatureFilterProvider
* @param attributes the list of attribute
* @return the list of visible attributes
*/
const QStringList layerAttributes( const QgsVectorLayer* layer, const QStringList attributes ) const;
QStringList layerAttributes( const QgsVectorLayer* layer, const QStringList& attributes ) const;

/** Are we authorized to modify the following geometry
* @param layer the layer to control
Expand Down
19 changes: 9 additions & 10 deletions src/server/qgsaccesscontrolfilter.cpp
Expand Up @@ -38,23 +38,23 @@ QgsAccessControlFilter::~QgsAccessControlFilter()
}

/** Return an additional layer expression filter */
const QString QgsAccessControlFilter::layerFilterExpression( const QgsVectorLayer* layer ) const
QString QgsAccessControlFilter::layerFilterExpression( const QgsVectorLayer* layer ) const
{
QgsMessageLog::logMessage( "QgsAccessControlFilter plugin default layerFilterExpression called", "AccessControlFilter", QgsMessageLog::INFO );
Q_UNUSED( layer );
return nullptr;
return QString();
}

/** Return an additional layer subset string (typically SQL) filter */
const QString QgsAccessControlFilter::layerFilterSubsetString( const QgsVectorLayer* layer ) const
QString QgsAccessControlFilter::layerFilterSubsetString( const QgsVectorLayer* layer ) const
{
QgsMessageLog::logMessage( "QgsAccessControlFilter plugin default layerFilterSQL called", "AccessControlFilter", QgsMessageLog::INFO );
Q_UNUSED( layer );
return nullptr;
return QString();
}

/** Return the layer permissions */
const QgsAccessControlFilter::LayerPermissions QgsAccessControlFilter::layerPermissions( const QgsMapLayer* layer ) const
QgsAccessControlFilter::LayerPermissions QgsAccessControlFilter::layerPermissions( const QgsMapLayer* layer ) const
{
QgsMessageLog::logMessage( "QgsAccessControlFilter plugin default layerPermissions called", "AccessControlFilter", QgsMessageLog::INFO );
Q_UNUSED( layer );
Expand All @@ -64,12 +64,11 @@ const QgsAccessControlFilter::LayerPermissions QgsAccessControlFilter::layerPerm
}

/** Return the authorized layer attributes */
const QStringList* QgsAccessControlFilter::authorizedLayerAttributes( const QgsVectorLayer* layer, const QStringList& attributes ) const
QStringList QgsAccessControlFilter::authorizedLayerAttributes( const QgsVectorLayer* layer, const QStringList& attributes ) const
{
Q_UNUSED( layer );
Q_UNUSED( attributes );
QgsMessageLog::logMessage( "QgsAccessControlFilter plugin default authorizedLayerAttributes called", "AccessControlFilter", QgsMessageLog::INFO );
return nullptr;
return attributes;
}

/** Are we authorized to modify the feature */
Expand All @@ -82,7 +81,7 @@ bool QgsAccessControlFilter::allowToEdit( const QgsVectorLayer* layer, const Qgs
}

/** Cache key to used to create the capabilities cache, "" for no cache */
const QString QgsAccessControlFilter::cacheKey() const
QString QgsAccessControlFilter::cacheKey() const
{
return "";
return QString();
}
10 changes: 5 additions & 5 deletions src/server/qgsaccesscontrolfilter.h
Expand Up @@ -69,26 +69,26 @@ class SERVER_EXPORT QgsAccessControlFilter
* @param layer the layer to control
* @return the filter expression
*/
virtual const QString layerFilterExpression( const QgsVectorLayer* layer ) const;
virtual QString layerFilterExpression( const QgsVectorLayer* layer ) const;

/** Return an additional subset string (typically SQL) filter
* @param layer the layer to control
* @return the subset string
*/
virtual const QString layerFilterSubsetString( const QgsVectorLayer* layer ) const;
virtual QString layerFilterSubsetString( const QgsVectorLayer* layer ) const;

/** Return the layer permissions
* @param layer the layer to control
* @return the permission to use on the layer
*/
virtual const LayerPermissions layerPermissions( const QgsMapLayer* layer ) const;
virtual LayerPermissions layerPermissions( const QgsMapLayer* layer ) const;

/** Return the authorized layer attributes
* @param layer the layer to control
* @param attributes the current list of visible attribute
* @return the new list of visible attributes
*/
virtual const QStringList* authorizedLayerAttributes( const QgsVectorLayer* layer, const QStringList& attributes ) const;
virtual QStringList authorizedLayerAttributes( const QgsVectorLayer* layer, const QStringList& attributes ) const;

/** Are we authorized to modify the following geometry
* @param layer the layer to control
Expand All @@ -100,7 +100,7 @@ class SERVER_EXPORT QgsAccessControlFilter
/** Cache key to used to create the capabilities cache
* @return the cache key, "" for no cache
*/
virtual const QString cacheKey() const;
virtual QString cacheKey() const;

private:

Expand Down

0 comments on commit 69ce559

Please sign in to comment.