From ef680d8a9881be860547e6df11164a3a385152b5 Mon Sep 17 00:00:00 2001 From: cristian-ungureanu Date: Tue, 29 Aug 2023 18:18:36 +0300 Subject: [PATCH] fix: allow access to dashboard for admins on multisite [#4036] --- .../dashboard/src/Components/Notification.js | 72 +++++--- .../src/Components/Plugin/InstallActivate.js | 47 +++++- .../dashboard/src/Components/PluginCard.js | 154 +++++++++++------- .../src/scss/components/_notification.scss | 3 +- .../dashboard/src/scss/content/_plugins.scss | 3 +- inc/admin/dashboard/main.php | 4 +- inc/admin/dashboard/plugin_helper.php | 2 +- 7 files changed, 193 insertions(+), 92 deletions(-) diff --git a/assets/apps/dashboard/src/Components/Notification.js b/assets/apps/dashboard/src/Components/Notification.js index 6ee4edefde..ef775e4548 100644 --- a/assets/apps/dashboard/src/Components/Notification.js +++ b/assets/apps/dashboard/src/Components/Notification.js @@ -1,15 +1,16 @@ /* global neveDash */ import classnames from 'classnames'; -import { __ } from '@wordpress/i18n'; +import { sprintf, __ } from '@wordpress/i18n'; import { useState } from '@wordpress/element'; import { external } from '@wordpress/icons'; -import { Button, Dashicon, Icon } from '@wordpress/components'; +import { Button, Dashicon, Icon, Tooltip } from '@wordpress/components'; const Notification = ({ data, slug }) => { // eslint-disable-next-line no-unused-vars const [hidden, setHidden] = useState(false); const { text, cta, type, update, url, targetBlank } = data; + const { canInstallPlugins } = neveDash; const [inProgress, setInProgress] = useState(false); const [done, setDone] = useState(false); const [errorMessage, setErrorMessage] = useState(null); @@ -112,6 +113,51 @@ const Notification = ({ data, slug }) => { }); }; + const ctaContent = () => { + if (!cta || done) { + return null; + } + return ( + + ); + }; + + const wrappedButtonContent = !canInstallPlugins ? ( + + {ctaContent()} + + ) : ( + ctaContent() + ); + const UpdateNotification = () => { return (
@@ -132,27 +178,7 @@ const Notification = ({ data, slug }) => { )}

)} - {cta && !done && ( - - )} + {wrappedButtonContent}
); }; diff --git a/assets/apps/dashboard/src/Components/Plugin/InstallActivate.js b/assets/apps/dashboard/src/Components/Plugin/InstallActivate.js index d86ef2ba55..f6cb7479b4 100644 --- a/assets/apps/dashboard/src/Components/Plugin/InstallActivate.js +++ b/assets/apps/dashboard/src/Components/Plugin/InstallActivate.js @@ -1,8 +1,8 @@ /* global neveDash */ import { get } from '../../utils/rest'; -import { __ } from '@wordpress/i18n'; +import { sprintf, __ } from '@wordpress/i18n'; import { useState, useEffect } from '@wordpress/element'; -import { Button } from '@wordpress/components'; +import { Button, Tooltip } from '@wordpress/components'; const InstallActivate = ({ labels = {}, @@ -12,8 +12,8 @@ const InstallActivate = ({ smallButton = false, description, }) => { - const { slug, pluginState, activateURL } = pluginData; - const { getPluginStateBaseURL, pluginsURL } = neveDash; + const { slug, pluginState, activateURL, pluginBasename } = pluginData; + const { getPluginStateBaseURL, pluginsURL, canInstallPlugins, canActivatePlugins } = neveDash; const [progress, setProgress] = useState(false); // const [updating, setUpdating] = useState(false); @@ -129,11 +129,24 @@ const InstallActivate = ({ const isProgress = (type) => progress === type; + const isButtonDisabled = () => { + if (progress) { + return true; + } + if (isProgress('installing')) { + return !canInstallPlugins; + } + if (isProgress('activating')) { + return !canActivatePlugins; + } + return false; + }; + const renderNoticeContent = () => { const buttonMap = { install: ( + ); + }; + + const showTooltip = + (!canInstallPlugins && action === 'install') || + (!canActivatePlugins && action === 'activate'); + + const wrappedButtonContent = showTooltip ? ( + + {ctaContent()} + + ) : ( + ctaContent() + ); + return (
@@ -42,61 +136,7 @@ const Card = ({ slug, data, setPluginState }) => { {version && v{version} | } {author && {author}}
- - {action !== 'external' && ( - - )} - + {wrappedButtonContent} {action === 'external' && ( {stringMap[action]} diff --git a/assets/apps/dashboard/src/scss/components/_notification.scss b/assets/apps/dashboard/src/scss/components/_notification.scss index af59dbd109..7f433b9109 100644 --- a/assets/apps/dashboard/src/scss/components/_notification.scss +++ b/assets/apps/dashboard/src/scss/components/_notification.scss @@ -110,7 +110,8 @@ &[disabled] { text-shadow: none; - opacity: .5; + color: rgba( 54, 54, 54, .5 ); + border-color: rgba( 54, 54, 54, .5 ); } } diff --git a/assets/apps/dashboard/src/scss/content/_plugins.scss b/assets/apps/dashboard/src/scss/content/_plugins.scss index 710c8e6cb9..96a38dbb48 100644 --- a/assets/apps/dashboard/src/scss/content/_plugins.scss +++ b/assets/apps/dashboard/src/scss/content/_plugins.scss @@ -24,7 +24,8 @@ padding: 20px 15px 20px 20px; display: flex; align-items: center; - margin-top: auto; + margin-top: auto; + justify-content: space-between; .plugin-data { font-size: 14px; diff --git a/inc/admin/dashboard/main.php b/inc/admin/dashboard/main.php index a9daccea54..379db01277 100755 --- a/inc/admin/dashboard/main.php +++ b/inc/admin/dashboard/main.php @@ -176,7 +176,7 @@ public function register() { } $neve_icon = apply_filters( 'neve_menu_icon', $icon ); $priority = apply_filters( 'neve_menu_priority', 59 ); // The position of the menu item, 60 is the position of the Appearance menu. - $capability = 'activate_plugins'; + $capability = 'manage_options'; // Place a theme page in the Appearance menu, for older versions of Neve Pro or TPC. to maintain backwards compatibility. if ( @@ -374,6 +374,8 @@ private function get_localization() { 'tpcAdminURL' => admin_url( 'admin.php?page=tiob-starter-sites' ), 'pluginsURL' => esc_url( admin_url( 'plugins.php' ) ), 'getPluginStateBaseURL' => esc_url( rest_url( '/nv/v1/dashboard/plugin-state/' ) ), + 'canInstallPlugins' => current_user_can( 'install_plugins' ), + 'canActivatePlugins' => current_user_can( 'activate_plugins' ), ]; if ( defined( 'NEVE_PRO_PATH' ) ) { diff --git a/inc/admin/dashboard/plugin_helper.php b/inc/admin/dashboard/plugin_helper.php index 1c1f145fe9..2cf5ce9868 100644 --- a/inc/admin/dashboard/plugin_helper.php +++ b/inc/admin/dashboard/plugin_helper.php @@ -115,7 +115,7 @@ public function get_plugin_action_link( $slug, $action = 'activate' ) { 'paged' => '1', '_wpnonce' => wp_create_nonce( $action . '-plugin_' . $this->get_plugin_path( $slug ) ), ), - esc_url( network_admin_url( 'plugins.php' ) ) + esc_url( 'plugins.php' ) ); }