Merge "Remove per-type notify-type-availability (make it category-only)"

This commit is contained in:
jenkins-bot 2019-04-27 13:28:18 +00:00 committed by Gerrit Code Review
commit 6b8b45cbb6
6 changed files with 43 additions and 71 deletions

View file

@ -90,7 +90,6 @@
"echo-displaynotificationsconfiguration-sorting-by-section-legend": "Which section each notification type is sorted into",
"echo-displaynotificationsconfiguration-available-notification-methods-header": "Allowed notification methods",
"echo-displaynotificationsconfiguration-available-notification-methods-by-category-legend": "Which notification methods are supported for each category",
"echo-displaynotificationsconfiguration-available-notification-methods-by-type-legend": "Which notification methods are supported for each type; only applies to types within categories that are hidden from preferences",
"echo-displaynotificationsconfiguration-enabled-default-header": "Enabled by default",
"echo-displaynotificationsconfiguration-enabled-default-existing-users-legend": "Existing users",
"echo-displaynotificationsconfiguration-enabled-default-new-users-legend": "New users",

View file

@ -89,7 +89,6 @@
"echo-displaynotificationsconfiguration-sorting-by-section-legend": "Legend on DisplayNotificationsConfiguration for a table of which section (alert/message) each type is in",
"echo-displaynotificationsconfiguration-available-notification-methods-header": "Header on DisplayNotificationsConfiguration for section regarding methods the user can use to receive different kinds of notifications",
"echo-displaynotificationsconfiguration-available-notification-methods-by-category-legend": "Explanatory text on DisplayNotificationsConfiguration regarding which notification methods are available for each category",
"echo-displaynotificationsconfiguration-available-notification-methods-by-type-legend": "Explanatory text on DisplayNotificationsConfiguration regarding which notification methods are available for each type",
"echo-displaynotificationsconfiguration-enabled-default-header": "Header on DisplayNotificationsConfiguration for section about which categories are enabled by default",
"echo-displaynotificationsconfiguration-enabled-default-existing-users-legend": "Explanatory text on DisplayNotificationsConfiguration regarding which notification methods for each category are enabled by default, for existing users",
"echo-displaynotificationsconfiguration-enabled-default-new-users-legend": "Explanatory text on DisplayNotificationsConfiguration regarding which notification methods for each category are enabled by default, for new users\n{{Identical|New user}}",

View file

@ -302,6 +302,22 @@ class EchoAttributeManager {
return $eventsByCategory;
}
/**
* Get notify type availability for all notify types for a given category.
*
* This means whether users *can* turn notifications for this category and format
* on, regardless of the default or a particular user's preferences.
*
* @param string $category Category name
* @return array [ 'web' => bool, 'email' => bool ]
*/
public function getNotifyTypeAvailabilityForCategory( $category ) {
return array_merge(
$this->defaultNotifyTypeAvailability,
$this->notifyTypeAvailabilityByCategory[$category] ?? []
);
}
/**
* Checks whether the specified notify type is available for the specified
* category.
@ -314,11 +330,7 @@ class EchoAttributeManager {
* @return bool
*/
public function isNotifyTypeAvailableForCategory( $category, $notifyType ) {
if ( isset( $this->notifyTypeAvailabilityByCategory[$category][$notifyType] ) ) {
return $this->notifyTypeAvailabilityByCategory[$category][$notifyType];
}
return $this->defaultNotifyTypeAvailability[$notifyType];
return $this->getNotifyTypeAvailabilityForCategory( $category )[$notifyType];
}
/**

View file

@ -187,30 +187,13 @@ class EchoNotificationController {
* this event type
*/
public static function getEventNotifyTypes( $eventType ) {
global $wgDefaultNotifyTypeAvailability,
$wgEchoNotifications;
$attributeManager = EchoAttributeManager::newFromGlobalVars();
$category = $attributeManager->getNotificationCategory( $eventType );
// If the category is displayed in preferences, we should go by that, rather
// than overrides that are inconsistent with what the user saw in preferences.
$isTypeSpecificConsidered = !$attributeManager->isCategoryDisplayedInPreferences(
$category
);
$notifyTypes = $wgDefaultNotifyTypeAvailability;
if ( $isTypeSpecificConsidered && isset( $wgEchoNotifications[$eventType]['notify-type-availability'] ) ) {
$notifyTypes = array_merge(
$notifyTypes,
$wgEchoNotifications[$eventType]['notify-type-availability']
);
}
// Category settings for availability are considered in EchoNotifier
return array_keys( array_filter( $notifyTypes ) );
return array_keys( array_filter(
$attributeManager->getNotifyTypeAvailabilityForCategory( $category )
) );
}
/**

View file

@ -218,8 +218,6 @@ class SpecialDisplayNotificationsConfiguration extends UnlistedSpecialPage {
* Output which notify types are available for each category
*/
protected function outputAvailability() {
global $wgEchoNotifications;
$this->getOutput()->addHTML( Html::element(
'h2',
[ 'id' => 'mw-echo-displaynotificationsconfiguration-available-notification-methods' ],
@ -243,27 +241,6 @@ class SpecialDisplayNotificationsConfiguration extends UnlistedSpecialPage {
$this->flippedNotifyTypes,
$byCategoryValue
);
$byTypeValue = [];
$specialNotificationTypes = array_keys( array_filter( $wgEchoNotifications, function ( $val ) {
return isset( $val['notify-type-availability'] );
} ) );
foreach ( $specialNotificationTypes as $notificationType ) {
$allowedNotifyTypes = $this->notificationController->getEventNotifyTypes( $notificationType );
foreach ( $allowedNotifyTypes as $notifyType ) {
$byTypeValue[] = "$notifyType-$notificationType";
}
}
// No user-friendly label for rows yet
$this->outputCheckMatrix(
'availability-by-type',
'echo-displaynotificationsconfiguration-available-notification-methods-by-type-legend',
array_combine( $specialNotificationTypes, $specialNotificationTypes ),
$this->flippedNotifyTypes,
$byTypeValue
);
}
/**

View file

@ -197,45 +197,43 @@ class NotificationControllerTest extends MediaWikiTestCase {
'bar',
// default notification types configuration
[ 'web' => true ],
// type-specific
// per-category notification type availability
[
'f' => [ 'email' => true ]
],
// event types
[
'foo' => [
'notify-type-availability' => [ 'email' => true ],
'category' => 'f',
],
'bar' => [
'category' => 'b',
]
],
],
[
'Overrides `all` configuration with event type configuration',
'Overrides `all` configuration with event category configuration',
// expected result
[ 'web' ],
// event type
'foo',
// default notification types configuration
[ 'web' => true, 'email' => true ],
// type-specific
// per-category notification type availability
[
'f' => [ 'email' => false ],
'b' => [ 'sms' => true ],
],
// event types
[
'foo' => [
'notify-type-availability' => [ 'email' => false ],
'category' => 'f',
],
'bar' => [
'notify-type-availability' => [ 'sms' => true ],
'category' => 'b',
],
],
],
[
'Uses all configuration when notify-type-availability not set at all',
// expected result
[ 'web', 'email' ],
// event type
'baz',
// default notification types configuration
[ 'web' => true, 'email' => true ],
// type-specific
[
'baz' => [],
],
]
];
}
@ -243,10 +241,14 @@ class NotificationControllerTest extends MediaWikiTestCase {
/**
* @dataProvider getEventNotifyTypesProvider
*/
public function testGetEventNotifyTypes( $message, $expect, $type, array $defaultNotifyTypeAvailability, array $notifications ) {
public function testGetEventNotifyTypes(
$message, $expect, $type, array $defaultNotifyTypeAvailability, array $notifyTypeAvailabilityByCategory, array $notifications
) {
$this->setMwGlobals( [
'wgDefaultNotifyTypeAvailability' => $defaultNotifyTypeAvailability,
'wgNotifyTypeAvailabilityByCategory' => $notifyTypeAvailabilityByCategory,
'wgEchoNotifications' => $notifications,
'wgEchoNotificationCategories' => array_fill_keys( array_keys( $notifyTypeAvailabilityByCategory ), [ 'priority' => 4 ] ),
] );
$result = EchoNotificationController::getEventNotifyTypes( $type );
$this->assertEquals( $expect, $result, $message );