From 6e6fcf8da80b5b6821837054ae51eaa19edc24b8 Mon Sep 17 00:00:00 2001 From: Felix Ernst Date: Mon, 22 Jul 2024 10:51:33 +0000 Subject: Notify users if authorization is required to proceed Previous to this commit entering a folder without read access would show the non-descriptive error message "Could not enter folder". If the user actually is not allowed to view the contents of the folder, this is indeed true and this commit will preserve this message as is. However, if an admin protocol is installed, users can actually view the contents of most folders after authorizing themselves as administrators. So this commit changes the error message in those specific circumstances to instead read "Authorization required to enter this folder." and provide a button to authorize themselves. This button is the "Act as Administrator" action. If no admin protocol is installed, this commit has no effect. The idea for this change came from Harald Sitter. I receive funding for changes like this by the Next Generation Internet Initiative, which (as I understand it) will no longer provide funds for future projects like this if the current EU draft budget goes through as it is. --- src/dolphinviewcontainer.cpp | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'src/dolphinviewcontainer.cpp') diff --git a/src/dolphinviewcontainer.cpp b/src/dolphinviewcontainer.cpp index 27f845fa7..3fedef6fc 100644 --- a/src/dolphinviewcontainer.cpp +++ b/src/dolphinviewcontainer.cpp @@ -7,6 +7,7 @@ #include "dolphinviewcontainer.h" #include "admin/bar.h" +#include "admin/workerintegration.h" #include "dolphin_compactmodesettings.h" #include "dolphin_contentdisplaysettings.h" #include "dolphin_detailsmodesettings.h" @@ -62,6 +63,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent) , m_searchBox(nullptr) , m_searchModeEnabled(false) , m_adminBar{nullptr} + , m_authorizeToEnterFolderAction{nullptr} , m_messageWidget(nullptr) , m_selectionModeTopBar{nullptr} , m_view(nullptr) @@ -139,7 +141,7 @@ DolphinViewContainer::DolphinViewContainer(const QUrl &url, QWidget *parent) connect(m_view, &DolphinView::directoryLoadingCanceled, this, &DolphinViewContainer::slotDirectoryLoadingCanceled); connect(m_view, &DolphinView::itemCountChanged, this, &DolphinViewContainer::delayedStatusBarUpdate); connect(m_view, &DolphinView::selectionChanged, this, &DolphinViewContainer::delayedStatusBarUpdate); - connect(m_view, &DolphinView::errorMessage, this, &DolphinViewContainer::showErrorMessage); + connect(m_view, &DolphinView::errorMessage, this, &DolphinViewContainer::slotErrorMessageFromView); connect(m_view, &DolphinView::urlIsFileError, this, &DolphinViewContainer::slotUrlIsFileError); connect(m_view, &DolphinView::activated, this, &DolphinViewContainer::activate); connect(m_view, &DolphinView::hiddenFilesShownChanged, this, &DolphinViewContainer::slotHiddenFilesShownChanged); @@ -897,6 +899,28 @@ void DolphinViewContainer::slotStatusBarZoomLevelChanged(int zoomLevel) m_view->setZoomLevel(zoomLevel); } +void DolphinViewContainer::slotErrorMessageFromView(const QString &message, const int kioErrorCode) +{ + if (kioErrorCode == KIO::ERR_CANNOT_ENTER_DIRECTORY && m_view->url().scheme() == QStringLiteral("file") + && KProtocolInfo::isKnownProtocol(QStringLiteral("admin")) && !rootItem().isReadable()) { + // Explain to users that they need authentication to see the folder contents. + if (!m_authorizeToEnterFolderAction) { // This code is similar to parts of Admin::Bar::hideTheNextTimeAuthorizationExpires(). + // We should not simply use the actAsAdminAction() itself here because that one always refers to the active view instead of this->m_view. + auto actAsAdminAction = Admin::WorkerIntegration::FriendAccess::actAsAdminAction(); + m_authorizeToEnterFolderAction = new QAction{actAsAdminAction->icon(), actAsAdminAction->text(), this}; + m_authorizeToEnterFolderAction->setToolTip(actAsAdminAction->toolTip()); + m_authorizeToEnterFolderAction->setWhatsThis(actAsAdminAction->whatsThis()); + connect(m_authorizeToEnterFolderAction, &QAction::triggered, this, [this, actAsAdminAction]() { + setActive(true); + actAsAdminAction->trigger(); + }); + } + showMessage(i18nc("@info", "Authorization required to enter this folder."), KMessageWidget::Error, {m_authorizeToEnterFolderAction}); + return; + } + Q_EMIT showErrorMessage(message); +} + void DolphinViewContainer::showErrorMessage(const QString &message) { showMessage(message, KMessageWidget::Error); -- cgit v1.3