Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Address review, export config string map as DOM element (eases editab…
…ility)
  • Loading branch information
nirvn committed May 13, 2021
1 parent a27c164 commit ad1c94c
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 9 deletions.
4 changes: 4 additions & 0 deletions python/core/auto_generated/auth/qgsauthmanager.sip.in
Expand Up @@ -307,6 +307,8 @@ Export authentication configurations to an XML file
:param filename: The file path to save the XML content to
:param authcfgs: The list of configuration IDs to export
:param password: A password string to encrypt the XML content

.. versionadded:: 3.20
%End

bool importAuthenticationConfigsFromXml( const QString &filename, const QString &password = QString() );
Expand All @@ -315,6 +317,8 @@ Import authentication configurations from an XML file

:param filename: The file path from which the XML content will be read
:param password: A password string to decrypt the XML content

.. versionadded:: 3.20
%End

bool removeAllAuthenticationConfigs();
Expand Down
2 changes: 2 additions & 0 deletions python/gui/auto_generated/auth/qgsauthconfigeditor.sip.in
Expand Up @@ -38,6 +38,8 @@ Hide the widget's title, e.g. when embedding
QStringList selectedAuthenticationConfigIds() const;
%Docstring
Returns the list of selected authentication configuration IDs

.. versionadded:: 3.20
%End

public slots:
Expand Down
24 changes: 20 additions & 4 deletions src/core/auth/qgsauthconfig.cpp
Expand Up @@ -15,6 +15,8 @@
***************************************************************************/

#include "qgsauthconfig.h"
#include "qgsauthcertutils.h"
#include "qgsxmlutils.h"

#include <QtCrypto>

Expand All @@ -23,8 +25,6 @@
#include <QCryptographicHash>
#include <QUrl>

#include "qgsauthcertutils.h"


//////////////////////////////////////////////
// QgsAuthMethodConfig
Expand Down Expand Up @@ -165,7 +165,16 @@ bool QgsAuthMethodConfig::writeXml( QDomElement &parentElement, QDomDocument &do
element.setAttribute( QStringLiteral( "name" ), mName );
element.setAttribute( QStringLiteral( "version" ), QString::number( mVersion ) );
element.setAttribute( QStringLiteral( "uri" ), mUri );
element.setAttribute( QStringLiteral( "config" ), configString() );

QDomElement configElements = document.createElement( QStringLiteral( "Config" ) );
QgsStringMap::const_iterator i = mConfigMap.constBegin();
while ( i != mConfigMap.constEnd() )
{
configElements.setAttribute( i.key(), i.value() );
++i;
}
element.appendChild( configElements );

parentElement.appendChild( element );
return true;
}
Expand All @@ -180,7 +189,14 @@ bool QgsAuthMethodConfig::readXml( const QDomElement &element )
mName = element.attribute( QStringLiteral( "name" ) );
mVersion = element.attribute( QStringLiteral( "version" ) ).toInt();
mUri = element.attribute( QStringLiteral( "uri" ) );
loadConfigString( element.attribute( QStringLiteral( "config" ) ) );

clearConfigMap();
QDomNamedNodeMap configAttributes = element.firstChildElement().attributes();
for ( int i = 0; i < configAttributes.length(); i++ )
{
QDomAttr configAttribute = configAttributes.item( i ).toAttr();
setConfig( configAttribute.name(), configAttribute.value() );
}

return true;
}
Expand Down
2 changes: 0 additions & 2 deletions src/core/auth/qgsauthmanager.cpp
Expand Up @@ -1428,8 +1428,6 @@ bool QgsAuthManager::importAuthenticationConfigsFromXml( const QString &filename
{
QgsAuthMethodConfig authMethodConfig;
authMethodConfig.readXml( configuration );
qDebug() << configuration.nodeName();
qDebug() << authMethodConfig.id();
storeAuthenticationConfig( authMethodConfig );

configuration = configuration.nextSiblingElement();
Expand Down
2 changes: 2 additions & 0 deletions src/core/auth/qgsauthmanager.h
Expand Up @@ -305,13 +305,15 @@ class CORE_EXPORT QgsAuthManager : public QObject
* \param filename The file path to save the XML content to
* \param authcfgs The list of configuration IDs to export
* \param password A password string to encrypt the XML content
* \since QGIS 3.20
*/
bool exportAuthenticationConfigsToXml( const QString &filename, const QStringList &authcfgs, const QString &password = QString() );

/**
* Import authentication configurations from an XML file
* \param filename The file path from which the XML content will be read
* \param password A password string to decrypt the XML content
* \since QGIS 3.20
*/
bool importAuthenticationConfigsFromXml( const QString &filename, const QString &password = QString() );

Expand Down
5 changes: 4 additions & 1 deletion src/gui/auth/qgsauthconfigeditor.h
Expand Up @@ -48,7 +48,10 @@ class GUI_EXPORT QgsAuthConfigEditor : public QWidget, private Ui::QgsAuthConfig
//! Hide the widget's title, e.g. when embedding
void toggleTitleVisibility( bool visible );

//! Returns the list of selected authentication configuration IDs
/**
* Returns the list of selected authentication configuration IDs
* \since QGIS 3.20
*/
QStringList selectedAuthenticationConfigIds() const;

public slots:
Expand Down
10 changes: 8 additions & 2 deletions src/gui/auth/qgsauthguiutils.h
Expand Up @@ -60,10 +60,16 @@ class GUI_EXPORT QgsAuthGuiUtils
//! Verify the authentication system is active, else notify user
static bool isDisabled( QgsMessageBar *msgbar );

//! Import authentication configurations from a XML file
/**
* Import authentication configurations from a XML file
* \since QGIS 3.20
*/
static void importAuthenticationConfigs( QgsMessageBar *msgbar );

//! Exports selected authentication configurations to a XML file
/**
* Exports selected authentication configurations to a XML file
* \since QGIS 3.20
*/
static void exportSelectedAuthenticationConfigs( QStringList authenticationConfigIds, QgsMessageBar *msgbar );

//! Sets the cached master password (and verifies it if its hash is in authentication database)
Expand Down

0 comments on commit ad1c94c

Please sign in to comment.