From e2919211f3c273675c765426cc937e8738f62ff5 Mon Sep 17 00:00:00 2001 From: Andre Klapper Date: Thu, 11 Jul 2024 12:07:28 +0200 Subject: [PATCH] Avoid PhabricatorApplicationTransactionStructureException on editors not supporting Mute Notifications Summary: Do not expose the "Mute Notifications" sidebar menu entry when the underlying Editor for that object type does not support muting notifications (means: creating a transaction of type "core:edge") at all. This avoids a disappointing `PhabricatorApplicationTransactionStructureException` after two clicks. Disabling the menu entry while still exposing it makes no sense here as the user could never get it enabled anyway. ``` EXCEPTION: (PhabricatorApplicationTransactionStructureException) Attempting to apply a transaction (of class "PhabricatorFileTransaction", with type "core:edge") which has not been constructed correctly: Transaction has type "core:edge", but that transaction type is not supported by this editor (PhabricatorFileEditor). at [/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php:1830] ``` ``` EXCEPTION: (PhabricatorApplicationTransactionStructureException) Attempting to apply a transaction (of class "LegalpadTransaction", with type "core:edge") which has not been constructed correctly: Transaction has type "core:edge", but that transaction type is not supported by this editor (LegalpadDocumentEditor). at [/src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php:1830] ``` Closes T15378 Test Plan: * Open various different object types: ** Files: http://phorge.localhost/F1 (not implemented) ** Legalpad: http://phorge.localhost/legalpad/view/1/ (not implemented) ** Maniphest: http://phorge.localhost/T1 (implemented) * Click "Subscribe" on these various types of objects. * Click "Mute Notifications" on these various types of objects, remember which objects throw an exception. * Apply this patch. * Check that "Mute Notifications" is not exposed for those types of objects that threw an exception. Reviewers: O1 Blessed Committers, valerio.bozzolan Reviewed By: O1 Blessed Committers, valerio.bozzolan Subscribers: tobiaswiese, valerio.bozzolan, Matthew, Cigaryno Maniphest Tasks: T15378 Differential Revision: https://we.phorge.it/D25730 --- ...habricatorSubscriptionsUIEventListener.php | 43 +++++++++++-------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/applications/subscriptions/events/PhabricatorSubscriptionsUIEventListener.php b/src/applications/subscriptions/events/PhabricatorSubscriptionsUIEventListener.php index 2077160b7c..3d43d972f6 100644 --- a/src/applications/subscriptions/events/PhabricatorSubscriptionsUIEventListener.php +++ b/src/applications/subscriptions/events/PhabricatorSubscriptionsUIEventListener.php @@ -94,26 +94,33 @@ final class PhabricatorSubscriptionsUIEventListener } } - $mute_action = id(new PhabricatorActionView()) - ->setWorkflow(true) - ->setHref('/subscriptions/mute/'.$object->getPHID().'/') - ->setDisabled(!$user_phid); - - if (!$is_muted) { - $mute_action - ->setName(pht('Mute Notifications')) - ->setIcon('fa-volume-up'); - } else { - $mute_action - ->setName(pht('Unmute Notifications')) - ->setIcon('fa-volume-off') - ->setColor(PhabricatorActionView::RED); - } - - $actions = $event->getValue('actions'); $actions[] = $sub_action; - $actions[] = $mute_action; + + // Hide "Mute Notifications" in sidebar if not supported by Editor - T15378 + $supported_editor_transaction_types = + array_fill_keys($object->getApplicationTransactionEditor() + ->getTransactionTypesForObject($object), true); + if (array_key_exists(PhabricatorTransactions::TYPE_EDGE, + $supported_editor_transaction_types)) { + $mute_action = id(new PhabricatorActionView()) + ->setWorkflow(true) + ->setHref('/subscriptions/mute/'.$object->getPHID().'/') + ->setDisabled(!$user_phid); + + if (!$is_muted) { + $mute_action + ->setName(pht('Mute Notifications')) + ->setIcon('fa-volume-up'); + } else { + $mute_action + ->setName(pht('Unmute Notifications')) + ->setIcon('fa-volume-off') + ->setColor(PhabricatorActionView::RED); + } + $actions[] = $mute_action; + } + $event->setValue('actions', $actions); }