aboutsummaryrefslogtreecommitdiff
path: root/src/core/kauthorized.cpp
diff options
context:
space:
mode:
authorAlexander Lohnau <alexander.lohnau@gmx.de>2021-09-26 18:47:44 +0200
committerAlexander Lohnau <alexander.lohnau@gmx.de>2021-10-13 12:59:30 +0000
commitb0a3e4276e8318475c39c2b7b4b5bc4040dcd19e (patch)
tree6eeea75d0b40a93ae590eb46095215ce6e26ba33 /src/core/kauthorized.cpp
parent9b44f490c8f5136571da34fcf28eb15e0f3bea6a (diff)
downloadkconfig-b0a3e4276e8318475c39c2b7b4b5bc4040dcd19e.tar.gz
kconfig-b0a3e4276e8318475c39c2b7b4b5bc4040dcd19e.tar.bz2
Create enum to to authorize common keys
By using an enum we have a central place to provide docs for the most common actions/restrictions. Also consumers can pass in type-safe enum values instead of potentially undocumented strings that might contain typos. Also it is better documents is a value is supposed to be authorized using KAuthorized::authorize or KAuthorized::authorizeAction, in the case of "shell_access" this was mixed up from time to time. Considering that we do not want the parameter for the methods to become too long I have deliberately decided against using `enum class`. Also we don't have and usecases for the binary operators in combination with the newly added enums. Task: https://phabricator.kde.org/T11948
Diffstat (limited to 'src/core/kauthorized.cpp')
-rw-r--r--src/core/kauthorized.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/core/kauthorized.cpp b/src/core/kauthorized.cpp
index 3c0941d5..0c8beef9 100644
--- a/src/core/kauthorized.cpp
+++ b/src/core/kauthorized.cpp
@@ -218,6 +218,15 @@ bool KAuthorized::authorize(const QString &genericAction)
return cg.readEntry(genericAction, true);
}
+bool KAuthorized::authorize(KAuthorized::GenericRestriction action)
+{
+ const QMetaEnum metaEnum = QMetaEnum::fromType<KAuthorized::GenericRestriction>();
+ if (metaEnum.isValid()) {
+ return KAuthorized::authorize(QString::fromLatin1(metaEnum.valueToKey(action)).toLower());
+ }
+ return false;
+}
+
bool KAuthorized::authorizeAction(const QString &action)
{
MY_D if (d->blockEverything)
@@ -231,6 +240,15 @@ bool KAuthorized::authorizeAction(const QString &action)
return authorize(QLatin1String("action/") + action);
}
+bool KAuthorized::authorizeAction(KAuthorized::GenericAction action)
+{
+ const QMetaEnum metaEnum = QMetaEnum::fromType<KAuthorized::GenericAction>();
+ if (metaEnum.isValid()) {
+ return KAuthorized::authorizeAction(QString::fromLatin1(metaEnum.valueToKey(action)).toLower());
+ }
+ return false;
+}
+
#if KCONFIGCORE_BUILD_DEPRECATED_SINCE(5, 24)
bool KAuthorized::authorizeKAction(const QString &action)
{