Skip to content

Commit

Permalink
Add option to lock parameters system scope (open-eid#1174)
Browse files Browse the repository at this point in the history
IB-7376

Signed-off-by: Raul Metsma <[email protected]>
  • Loading branch information
metsma authored Oct 25, 2023
1 parent d65d264 commit 55773df
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 22 deletions.
8 changes: 6 additions & 2 deletions client/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,14 @@ const Option<bool> Settings::MOBILEID_ORDER { QStringLiteral("MIDOrder"), true }
const Option<QString> Settings::SID_UUID { QStringLiteral("SIDUUID") };
const Option<QString> Settings::SID_NAME { QStringLiteral("SIDNAME"), QStringLiteral("RIA DigiDoc") };
const Option<QString, QString (*)()> Settings::SID_PROXY_URL { QStringLiteral("SID-PROXY-URL"), []{
return Application::confValue(QLatin1String("SIDV2-PROXY-URL")).toString(Application::confValue(QLatin1String("SID-PROXY-URL")).toString(QStringLiteral(SMARTID_URL)));
return Application::confValue(QLatin1String("SIDV2-PROXY-URL"))
.toString(Application::confValue(QLatin1String("SID-PROXY-URL"))
.toString(QStringLiteral(SMARTID_URL)));
}};
const Option<QString, QString (*)()> Settings::SID_SK_URL { QStringLiteral("SID-SK-URL"), []{
return Application::confValue(QLatin1String("SIDV2-SK-URL")).toString(Application::confValue(QLatin1String("SID-SK-URL")).toString(QStringLiteral(SMARTID_URL)));
return Application::confValue(QLatin1String("SIDV2-SK-URL"))
.toString(Application::confValue(QLatin1String("SID-SK-URL"))
.toString(QStringLiteral(SMARTID_URL)));
}};
const Option<bool, bool (*)()> Settings::SID_UUID_CUSTOM
{ QStringLiteral("SIDUUID-CUSTOM"), [] { return Settings::SID_UUID.isSet(); } };
Expand Down
18 changes: 16 additions & 2 deletions client/Settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

#pragma once

#include <QtCore/QCoreApplication>
#include <QtCore/QSettings>

template<typename T>
Expand All @@ -30,7 +31,7 @@ struct Settings
struct Option
{
operator QVariant() const {
return QSettings().value(KEY, defaultValue());
return settings().value(KEY, defaultValue());
}
operator T() const {
return operator QVariant().template value<T>();
Expand All @@ -52,11 +53,14 @@ struct Settings
void clear() const {
QSettings().remove(KEY);
}
bool isLocked() const {
return settings(QSettings::SystemScope).value(KEY + QLatin1String("_LOCK"), false).toBool();
}
bool isSet() const {
return QSettings().contains(KEY);
}
T value(const QVariant &def) const {
return QSettings().value(KEY, def).template value<T>();
return settings().value(KEY, def).template value<T>();
}
void setValue(const QVariant &value, const QVariant &def = {}) const {
if(bool valueIsNullOrEmpty = value.type() == QVariant::String ? value.toString().isEmpty() : value.isNull();
Expand All @@ -78,6 +82,16 @@ struct Settings
{
f = functor;
}
QSettings settings() const {
return settings(isLocked() ? QSettings::SystemScope : QSettings::UserScope);
}
static QSettings settings(QSettings::Scope scope) {
#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0)
return QSettings(scope);
#else
return QSettings(scope, QCoreApplication::organizationName(), QCoreApplication::applicationName());
#endif
}
const QString KEY;
const D DEFAULT {};
std::function<void (const T &value)> f;
Expand Down
50 changes: 33 additions & 17 deletions client/dialogs/SettingsDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -241,8 +241,7 @@ SettingsDialog::SettingsDialog(int page, QWidget *parent)
// remove certificates (having %ESTEID% text) from browsing history of Internet Explorer and/or Google Chrome, and do it for all users.
QList<TokenData> cache = qApp->signer()->cache();
CertStore s;
const QList<QSslCertificate> certificates = s.list();
for(const QSslCertificate &c: certificates)
for(const QSslCertificate &c: s.list())
{
if(std::any_of(cache.cbegin(), cache.cend(), [&](const TokenData &token) { return token.cert() == c; }))
continue;
Expand Down Expand Up @@ -418,16 +417,21 @@ void SettingsDialog::initFunctionality()
updateProxy();

// pageServices - TimeStamp
ui->rdTimeStampDefault->setDisabled(Settings::TSA_URL_CUSTOM.isLocked());
ui->rdTimeStampCustom->setEnabled(ui->rdTimeStampDefault->isEnabled());
ui->rdTimeStampCustom->setChecked(Settings::TSA_URL_CUSTOM);
ui->txtTimeStamp->setReadOnly(Settings::TSA_URL.isLocked());
ui->txtTimeStamp->setEnabled(ui->rdTimeStampCustom->isChecked());
ui->txtTimeStamp->setPlaceholderText(Application::confValue(Settings::TSA_URL.KEY).toString());
QString TSA_URL = Settings::TSA_URL.value(Application::confValue(Application::TSAUrl));
ui->txtTimeStamp->setText(ui->txtTimeStamp->placeholderText() == TSA_URL ? QString() : TSA_URL);
ui->wgtTSACert->setDisabled(Settings::TSA_CERT.isLocked());
ui->wgtTSACert->setVisible(ui->rdTimeStampCustom->isChecked());
connect(ui->rdTimeStampCustom, &QRadioButton::toggled, ui->txtTimeStamp, [this](bool checked) {
ui->txtTimeStamp->setEnabled(checked);
ui->wgtTSACert->setVisible(checked);
Settings::TSA_URL_CUSTOM = checked;
});
ui->rdTimeStampCustom->setChecked(Settings::TSA_URL_CUSTOM);
ui->wgtTSACert->setVisible(ui->rdTimeStampCustom->isChecked());
ui->txtTimeStamp->setPlaceholderText(Application::confValue(Settings::TSA_URL.KEY).toString());
QString TSA_URL = Settings::TSA_URL.value(Application::confValue(Application::TSAUrl));
ui->txtTimeStamp->setText(ui->txtTimeStamp->placeholderText() == TSA_URL ? QString() : TSA_URL);
connect(ui->txtTimeStamp, &QLineEdit::textChanged, this, [this](const QString &url) {
Application::setConfValue(Application::TSAUrl, url);
if(url.isEmpty())
Expand All @@ -450,13 +454,17 @@ void SettingsDialog::initFunctionality()
updateTSACert(QSslCertificate(QByteArray::fromBase64(Settings::TSA_CERT), QSsl::Der));

// pageServices - MID
ui->rdMIDUUIDDefault->setDisabled(Settings::MID_UUID_CUSTOM.isLocked());
ui->rdMIDUUIDCustom->setEnabled(ui->rdMIDUUIDDefault->isEnabled());
ui->rdMIDUUIDCustom->setChecked(Settings::MID_UUID_CUSTOM);
ui->txtMIDUUID->setReadOnly(Settings::MID_UUID.isLocked());
ui->txtMIDUUID->setEnabled(ui->rdMIDUUIDCustom->isChecked());
ui->txtMIDUUID->setText(Settings::MID_UUID);
connect(ui->rdMIDUUIDCustom, &QRadioButton::toggled, ui->txtMIDUUID, [=](bool checked) {
ui->txtMIDUUID->setEnabled(checked);
Settings::MID_UUID_CUSTOM = checked;
Settings::SID_UUID_CUSTOM = checked;
});
ui->rdMIDUUIDCustom->setChecked(Settings::MID_UUID_CUSTOM);
ui->txtMIDUUID->setText(Settings::MID_UUID);
connect(ui->txtMIDUUID, &QLineEdit::textChanged, this, [](const QString &text) {
Settings::MID_UUID = text;
Settings::SID_UUID = text;
Expand All @@ -466,16 +474,21 @@ void SettingsDialog::initFunctionality()
});

// pageValidation - SiVa
ui->rdSiVaDefault->setDisabled(Settings::SIVA_URL_CUSTOM.isLocked());
ui->rdSiVaCustom->setEnabled(ui->rdSiVaDefault->isEnabled());
ui->rdSiVaCustom->setChecked(Settings::SIVA_URL_CUSTOM);
ui->txtSiVa->setReadOnly(Settings::SIVA_URL.isLocked());
ui->txtSiVa->setEnabled(ui->rdSiVaCustom->isChecked());
ui->txtSiVa->setPlaceholderText(Application::confValue(Settings::SIVA_URL.KEY).toString());
QString SIVA_URL = Settings::SIVA_URL.value(Application::confValue(Application::SiVaUrl));
ui->txtSiVa->setText(ui->txtSiVa->placeholderText() == SIVA_URL ? QString() : SIVA_URL);
ui->wgtSiVaCert->setDisabled(Settings::SIVA_CERT.isLocked());
ui->wgtSiVaCert->setVisible(ui->rdSiVaCustom->isChecked());
connect(ui->rdSiVaCustom, &QRadioButton::toggled, ui->txtSiVa, [this](bool checked) {
ui->txtSiVa->setEnabled(checked);
ui->wgtSiVaCert->setVisible(checked);
Settings::SIVA_URL_CUSTOM = checked;
});
ui->rdSiVaCustom->setChecked(Settings::SIVA_URL_CUSTOM);
ui->wgtSiVaCert->setVisible(ui->rdSiVaCustom->isChecked());
ui->txtSiVa->setPlaceholderText(Application::confValue(Settings::SIVA_URL.KEY).toString());
QString SIVA_URL = Settings::SIVA_URL.value(Application::confValue(Application::SiVaUrl));
ui->txtSiVa->setText(ui->txtSiVa->placeholderText() == SIVA_URL ? QString() : SIVA_URL);
connect(ui->txtSiVa, &QLineEdit::textChanged, this, [this](const QString &url) {
Application::setConfValue(Application::SiVaUrl, url);
if(url.isEmpty())
Expand Down Expand Up @@ -689,9 +702,12 @@ void SettingsDialog::saveFile(const QString &name, const QString &path)

void SettingsDialog::saveFile(const QString &name, const QByteArray &content)
{
QString filename = FileDialog::getSaveFileName(this, tr("Save as"), QStringLiteral( "%1/%2_%3_%4")
.arg(QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation), QApplication::applicationName(), QApplication::applicationVersion(), name),
tr("Text files (*.txt)") );
QString filename = FileDialog::getSaveFileName(this, tr("Save as"), QStringLiteral( "%1/%2_%3_%4").arg(
QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation),
QApplication::applicationName(),
QApplication::applicationVersion(),
name),
tr("Text files (*.txt)"));
if( filename.isEmpty() )
return;
if(QFile f(filename); !f.open(QIODevice::WriteOnly|QIODevice::Text) || !f.write(content))
Expand Down
2 changes: 1 addition & 1 deletion client/dialogs/SettingsDialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ QCheckBox, QRadioButton {
min-height: 31px;
spacing: 5px;
}
QCheckBox:disabled {
QCheckBox:disabled, QRadioButton:disabled {
color: #727679;
}
QCheckBox::indicator, QRadioButton::indicator {
Expand Down

0 comments on commit 55773df

Please sign in to comment.