diff options
author | Alexander Lohnau <alexander.lohnau@gmx.de> | 2021-09-26 18:47:44 +0200 |
---|---|---|
committer | Alexander Lohnau <alexander.lohnau@gmx.de> | 2021-10-13 12:59:30 +0000 |
commit | b0a3e4276e8318475c39c2b7b4b5bc4040dcd19e (patch) | |
tree | 6eeea75d0b40a93ae590eb46095215ce6e26ba33 /src/core/kauthorized.h | |
parent | 9b44f490c8f5136571da34fcf28eb15e0f3bea6a (diff) | |
download | kconfig-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.h')
-rw-r--r-- | src/core/kauthorized.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/core/kauthorized.h b/src/core/kauthorized.h index a61e0927..b7fa4c97 100644 --- a/src/core/kauthorized.h +++ b/src/core/kauthorized.h @@ -10,7 +10,10 @@ #include <kconfigcore_export.h> +#include <QMetaEnum> +#include <QObject> #include <QStringList> +#include <QVariant> class QUrl; class QString; @@ -25,6 +28,39 @@ class QString; */ namespace KAuthorized { +Q_NAMESPACE_EXPORT(KCONFIGCORE_EXPORT); + +/** + * The enum values lower cased represent the action that is authorized + * For example the SHELL_ACCESS value is converted to the "shell_access" string. + * + * @since 5.88 + */ +enum GenericRestriction { + SHELL_ACCESS, // if the user is authorized to open a shell or execute shell commands + GHNS, /// if the collaborative data sharing framework KNewStuff is authorized + // GUI behavior + LINEEDIT_REVEAL_PASSWORD, /// if typed characters in password fields can be made visible + LINEEDIT_TEXT_COMPLETION, /// if line edits should be allowed to display completions + MOVABLE_TOOLBARS, /// if toolbars of of apps should be movable + RUN_DESKTOP_FILES, /// if .desktop files should be run as executables when clicked +}; +Q_ENUM_NS(GenericRestriction) + +/** + * + * @since 5.88 + */ +enum GenericAction { + OPEN_WITH, /// if the open-with menu should be shown for files etc. + EDITFILETYPE, /// if mime-type accociations are allowed to be configured + + OPTIONS_SHOW_TOOLBAR, /// if the toolbar should be displayed in apps + SWITCH_APPLICATION_LANGUAGE, /// if an action to switch the app language should be shown + BOOKMARKS, /// saving bookmarks is allowed +}; +Q_ENUM_NS(GenericAction) + /** * Returns whether the user is permitted to perform a certain action. * @@ -58,6 +94,16 @@ namespace KAuthorized KCONFIGCORE_EXPORT bool authorize(const QString &action); /** + * Returns whether the user is permitted to perform a common action. + * The enum values lower cased represent the action that is + * passed in to @p authorize(QString) + * + * @overload + * @since 5.88 + */ +KCONFIGCORE_EXPORT bool authorize(GenericRestriction action); + +/** * Returns whether the user is permitted to perform a certain action. * * This behaves like authorize(), except that "action/" is prepended to @@ -84,6 +130,14 @@ KCONFIGCORE_EXPORT bool authorize(const QString &action); */ KCONFIGCORE_EXPORT bool authorizeAction(const QString &action); +/** + * Overload to authorize common actions. + * + * @overload + * @since 5.88 + */ +KCONFIGCORE_EXPORT bool authorizeAction(GenericAction action); + #if KCONFIGCORE_ENABLE_DEPRECATED_SINCE(5, 24) /** * Returns whether the user is permitted to perform a certain action. |