Commit graph

470 commits

Author SHA1 Message Date
Jeena Huneidi 596729d852 Make AttributeManager a service
Adds AttributeManager to EchoServices so that dependencies of
AttributeManager can be injected.

Bug: T275148
Change-Id: I4fa5084d72914d16b6d218e7dd3521f5a1919b80
2021-02-26 12:58:23 -08:00
jenkins-bot fd61cf3082 Merge "Replace use of newMutableRevisionFromArray within new MutableRevisionRecord" 2021-02-03 22:52:56 +00:00
jenkins-bot a517f9ed2a Merge "Use monitored getTestUser() in tests if possible" 2021-02-03 14:37:30 +00:00
Peter Ovchyn f352b3406c Replace use of newMutableRevisionFromArray within new MutableRevisionRecord
Bug: T272560
Change-Id: I171537c3346a7dd4aeb4fc612d7dd9fba5d64679
2021-02-02 22:42:06 +02:00
Ed Sanders bb1bd02bd6 eslint: Fix warnings
* Load wikimedia/jsduck rules
* Add inline disables for compat
* Fix shadowed variables

Change-Id: I42234ab74f5007c16ff3960309335e715da76c1c
2021-02-01 21:02:46 +00:00
Thiemo Kreuz df6d65a6cf Use monitored getTestUser() in tests if possible
Change-Id: I584d8883f14b2651927890d353b738a02771abea
2021-01-29 18:00:57 +00:00
Thiemo Kreuz 0f954929a7 Remove comments that literally repeat the code
This also fixes a remaining `var` that should be `private`.

Change-Id: Ifa37a097a9d60bd22a16bc626d4b4271b8df2da7
2021-01-29 13:55:41 +01:00
Umherirrender fba5bcec19 Improve function and property documentation in tests
Change-Id: I90a0c9e7b1ac17edeed5f706a8f968f6d67df56f
2021-01-23 12:54:27 +01:00
jenkins-bot 2f15134088 Merge "push: die with error if providertokens param is empty" 2020-11-10 18:24:46 +00:00
mbsantos 86d45a66ca push: die with error if providertokens param is empty
Bug: T267263
Change-Id: Icf98189726602dd8e43e1f9daf19e3f73efb91b0
2020-11-10 16:50:37 +01:00
jenkins-bot 6135c62518 Merge "Avoid enqueueing delayed jobs if not supported." 2020-11-02 16:52:31 +00:00
jgiannelos 4f4786c62c Avoid enqueueing delayed jobs if not supported.
Change-Id: Ibb065f77a67bf47daafb6caaf8a338d0bcd479e7
2020-11-02 16:06:09 +01:00
libraryupgrader f5ff16571e build: Updating mediawiki/mediawiki-codesniffer to 32.0.0
The following sniffs are failing and were disabled:
* MediaWiki.Commenting.FunctionComment.ObjectTypeHintParam
* MediaWiki.Commenting.PropertyDocumentation.MissingDocumentationPrivate
* MediaWiki.Commenting.PropertyDocumentation.MissingDocumentationProtected
* MediaWiki.Commenting.PropertyDocumentation.MissingVar
* MediaWiki.Usage.ExtendClassUsage.FunctionConfigUsage

Additional changes:
* Dropped .inc files from .phpcs.xml (T200956).

Change-Id: I46e3dacb3da1266ff52d614003ad911feeb7504e
2020-10-29 14:24:24 +00:00
jenkins-bot cf0e87d18e Merge "Fix DiscussionParser failing in certain languages" 2020-10-29 00:16:32 +00:00
jgiannelos c97b8e6851 Implement delayed echo notifications
* EchoEvent now supports `extra` params for job delay and deduplication
* When Echo identifies this type of param it creates a
  DelayedEchoNotificationJob that will be executed after `delay` seconds

Change-Id: Ib0c6789dfe42e9703a67835909e5932c0054089f
2020-10-28 12:11:15 +01:00
Thiemo Kreuz 8880df4123 Fix DiscussionParser failing in certain languages
It appears like the initial \h in this non-Unicode regular
expression matches parts of an UTF-8 character, destroying it.
This makes the final preg_match() in this method fail, when
$output is going to be used as a pattern.

Bug: T264922
Change-Id: Iaf240bc2e0808c2f57c1f8bab2589d3207915afe
2020-10-27 20:03:18 +01:00
DannyS712 b708ba2462 UserNotificationGatewayTest: Mock User objects
Since its a unit test, the use of User::newFromId
prevents attempts in core to migrate to
the UserFactory.

Change-Id: If5e76f2ae570ef4ae58cb77b5281c4446a1cadff
2020-10-02 03:44:07 +00:00
Matthias Mullie a969c6d312 Make tests match actual expected format for user-locators
EchoAttributeManager::getUserCallable casts to array,
which means that even a non-array value (e.g. a simple callback)
becomes an array and NotificationController::evaluateUserCallable
will handle it just fine. But tests seemed to thing it was wrong.

Change-Id: Ia1e1e4015ebbc4d79bba5274e802911f222692c0
2020-09-30 15:54:54 +00:00
daniel 7170b0f35f Use MockHttpTrait
Use the mock HTTP request, in preparation for I1702c11928f87

Depends-On: I8ce17da7315b87b8dd0e502e601b9ac488089456
Needed-By: I1702c11928f8760bb41b41f4c7c04d7af03f62e2
Bug: T262443
Change-Id: I390856b4609635cee22253071f21ce63ff716791
2020-09-29 09:05:50 +00:00
DannyS712 357c8224ae NotificationsTest: No need to set $wgUser
Bug: T243732
Change-Id: I85e25ebc636a1cfce8a06614adad8d7afb68965f
2020-09-15 01:01:11 +00:00
jgiannelos 4abfbd3c96 Normalize eps_topic
* DB changes
 - Create a table for push topics NameTableStore
 - Add a foreign key on subscriptions to normalize push topics

* Implement NameTableStore to normalize topics
* Update DB query joins to include topic from foreignkey
* Adapt code to use IDs instead of the actual topic

Bug: T261756
Change-Id: Ia7589f4a607993352d45b2dd3bcb3867d12d6e97
2020-09-14 15:52:23 -04:00
Ostrzyciel a585ad635a Explicitly provide sysop user in unit tests that need it
Currently Echo assumes the default user used when ->editPage() is
called to be a sysop user… which is kind of the case? It passed null
to WikiPage::doEditContent() which in turn falls back to the default
user (127.0.0.1). In a test that relies on the user to be a sysop, it's
better to provide the user explicitly to avoid confusion.

This is to clean up the confusion introduced by ->editPage()'s doc
block, see: I9f77474f40e0f6901aa2c6f846e471b822636aa5

Change-Id: I7a79e0eaa1617e4d87a8d615a5391723c0e30b6a
2020-09-13 08:16:45 +00:00
Michael Holloway 3513c642dd Create push subscription manager group/right to clean up dead subs
Creates a new push-subscription-manager group and an associated
right, manage-all-push-subscriptions. The purpose of this is to
allow privileged accounts to purge expired subscriptions from the
database on behalf of other users. A user with this right will be
permitted to delete any subscription from the DB based on the token
alone. For all other users, deletion requests will be limited to
those associated with the requesting user's central ID.

This right will be granted to a bot account on Metawiki associated
with the Wikimedia push notifications service, and the push
notifications service account will make push subscription delete
requests to the API for subscriptions for which vendor APIs return bad
subscription responses.

Additionally, the providertoken parameter to ApiPushSubscriptionDelete
is updated to allow multiple providertoken values.

Bug: T259148
Change-Id: Ia6c17588ee94e6be74e5e3a75eb33e38f172fc93
2020-08-20 17:08:48 -04:00
Mateus Santos c188dac23f push: send apns topic when present
1) send apns topic when present in subscription metadata
2) check if subscription metadata is a valid JSON string
3) make epp_id column at echo_push_provider table auto_increment,
otherwise it will fail when trying to add a second row in the table

Bug: T259394
Change-Id: I785435e9f2d4ba9c14977d431d271f0fa2d0c795
2020-08-18 13:21:20 +00:00
jenkins-bot aa1f1801e4 Merge "Create and enforce a config setting for max subscriptions per user" 2020-08-13 17:03:05 +00:00
Thiemo Kreuz e5fead8b42 Use more canonical (object)[] instead of new stdClass
Both styles create the exact same object. Casting an array to an
object creates an stdClass object as well. The main benefit of this
syntax is that there is much less repetition. Everything is one
token instead of individual lines, where each line might contain a
typo.

Change-Id: Id43fa2c4b6bd5d9dbc60008427d4a9e14ae3811c
2020-08-13 09:58:14 +00:00
Michael Holloway 15d48278be Create and enforce a config setting for max subscriptions per user
Creates a EchoPushMaxSubscriptionsPerUser config setting (default: 0)
that controls the maximum number of subscriptions a user may associate
with the user's central user ID.

The setting is enforced in EchoPush\SubscriptionManager::create().

To allow creating push subscriptions for development, set
$wgEchoPushMaxSubscriptionsPerUser to a positive integer value in
LocalSettings.php:

 $wgEchoPushMaxSubscriptionsPerUser = 10;

Bug: T259150
Change-Id: Ib97b6b6cbb8161dd75dad92c54b4fe4fff80c421
2020-08-12 17:58:11 -04:00
Thiemo Kreuz 9d988e50b4 Use more specific PHPUnit assertions for type checks
Change-Id: I22d3cddfb5d3d3f2ac49d075e885a3241b8360bc
2020-08-10 12:54:10 +02:00
Amir Sarabadani 532fdbf294 Stop using ResourceLoaderTestModules hook
This hook is deprecated and we should use QUnitTestModule in extension.json instead

Bug: T232875
Change-Id: I7b3e22856adc64ee36e0b696e2371bb9673e4899
2020-08-03 13:18:29 +02:00
Roan Kattouw c87cae39d7 Make Echo QUnit tests run again
The automatic registration for these was broken, because
$wgResourceModules no longer contains Echo's modules (since they are now
registered in extension.json).

Instead, add the test files in tests/qunit/model/ explicitly in
onResourceLoaderTestModules. The tests in tests/qunit/mobile/ are
already added through QUnitTestModule in extension.json.

Delete the ext.echo.overlay tests, they were testing code that was
removed years ago.

Bug: T258818
Change-Id: I7b996dc8631a86033830cf532f1b8e85251788ad
2020-07-24 13:26:34 -07:00
Ed Sanders 1b40b69481 Make default snippet length (150) a constant
Change-Id: Idb53b226618fa0d625c7e4713c780538bd6a76ea
2020-07-23 13:00:44 +01:00
jenkins-bot a2c6b21925 Merge "Update hooks to use PageSaveComplete" 2020-06-30 10:40:51 +00:00
Umherirrender 3c53d6acb9 phpcs: Break long lines
Use the codesniffer default of length = 120

Change-Id: Ifbfd56b20432e54805d3a9bce22cda888c1fc74d
2020-06-27 12:05:03 +02:00
DannyS712 28a5eafe8c Update hooks to use PageSaveComplete
Extension requires MW 1.35+, always available

Bug: T250566
Change-Id: I1131a50f03002337d6b6eac18fdcb6adaaa896ce
2020-06-26 15:59:04 +00:00
vidhi-mody f25ed7e705 Selenium: Update to WebdriverIO v5
Update NPM packages: webdriverio, wdio-mediawiki.

Replace NPM packages:
- wdio-mocha-framework with @wdio/mocha-framework.
- wdio-spec-reporter with @wdio/spec-reporter.

New NPM packages: @wdio/cli, @wdio/local-runner, @wdio/sync.

Replace:
- `browser.element` with `$`.
- `chromeOptions` with `'goog:chromeOptions'`.
- `password` with `mwPwd`.
- `username` with `mwUser`.
- `waitForVisible()` with `waitForDisplayed()`.

Bug: T250610
Change-Id: If7a5ee9588f082be18f27ee45a051ae956c688f5
2020-06-22 15:54:30 +00:00
jenkins-bot 8fe5e47b76 Merge "Push: Add additional job params for logging" 2020-06-18 10:55:37 +00:00
Michael Holloway a2412732f6 Push: Add additional job params for logging
Adds additional job parameters to help diagnose the apparent issue of
jobs being performed twice on Beta.

Bug: T255068
Change-Id: Ib257a24056539487e1110fe286fa4535c3fec94a
2020-06-17 17:58:21 -04:00
Ed Sanders ffe3363d09 build: Update eslint-config-wikimedia to 0.16.1
Change-Id: I2ce14429f9440e69e36fa349847f58fb32862f2a
2020-06-15 16:19:00 +01:00
Michael Holloway 1d31fd753a Push: Submit requests to configured service endpoint
Finishes the implementation of the stubbed NotificationServiceClient.
Sends push notification request messages to the endpoint configured in
the EchoPushServiceBaseUrl setting. For example, to send messages to an
instance of mediawiki/services/push-notifications running on the host
machine while running MediaWiki in Docker, add the following line to
LocalSettings.php:

 $wgEchoPushServiceBaseUrl = 'http://172.17.0.1:8900/v1/message';

Bug: T252899
Change-Id: Icab7825e9080d6b1a4cfc5e12fed1da221ce4610
2020-06-08 13:37:24 +00:00
Michael Holloway a5bcc65504 Fix push subscription retrieval
Updates the push subscription query to retrieve a provider string rather
than only its numeric internal ID.

Change-Id: I910173409e48e8b6a6739d3122165c40b0d52b7f
2020-06-08 13:58:42 +02:00
Michael Holloway ce7a46f7ed Add push notifier
Provides a basic push notifier implementation. Since the push service is
not yet in place, all it does for now is log debug output when a
notification is to be sent.

To register the push notifier, add the following configuration to
LocalSettings.php:

 $wgEchoNotifiers['push'] = [ 'EchoPush\\PushNotifier', 'notifyWithPush' ];
 $wgDefaultNotifyTypeAvailability['push'] = true;
 $wgNotifyTypeAvailabilityByCategory['system']['push'] = false;
 $wgNotifyTypeAvailabilityByCategory['system-noemail']['push'] = false;

We'll register the notifier in configuration for now, rather than
hard-coding the default in extension.json, in order to have control over
when and where it rolls out (beta vs. prod, as well as which wikis).

Since the push notifier implementation depends on jobs being processed
by the job queue, I also recommend adding the following configuration
setting to ensure that all pending jobs are processed at the end of each
web request:

 // ensure all pending jobs are processed when a web request completes
 $wgJobRunRate = PHP_INT_MAX;

Bug: T252899
Change-Id: Ie7f222443045d30620ff297b006104ef18a074a8
2020-06-02 13:40:04 -04:00
Michael Holloway a3674974f1 Add push subscription management
Adds DB tables for storing push subscriptions, some DB interaction code
for retrieving them within MediaWiki, and a set of API modules for
managing them from the outside world.

When testing this patch, be sure to run maintenance/update.php to create
the new tables, and set $wgEchoEnablePush = true in LocalSettings.php
to enable the API new API module.

N.B. The current DB schema is centered on app push subscriptions. Web
push subscriptions require slightly different handling, since they are
provided by browsers as a JSON blob rather than a token string. How to
handle web push subscriptions is a question we can defer until the time
comes to add web push support.

Subscription data is stored in the echo_push_subscription table, with
provider names normalized into the echo_push_provider table. We expect to
be looking up subscriptions by central user ID, so that column is indexed.
The subscription data also includes a column to store SHA256 digests of
the subscriber tokens. This is for use as a unique key constraint, since
we expect every push token to be univerally unique, and the token values
themselves may be too large to reasonably index in MySQL.

Bug: T252899
Change-Id: I3928761b3fba12e54ff4850e9a05c68ec7772f62
2020-06-02 13:40:00 -04:00
Roan Kattouw 28f432b150
Add dynamic secondary action to mute/unmute page-linked notifications
Also adds an API module for muting and unmuting pages (and users).

Bug: T46787
Bug: T115264
Change-Id: Icf4e4bfa9fd7fa27b4c40892e3d5ce000eb22d5a
2020-05-27 15:20:08 +02:00
Kosta Harlan 1560528dc7 Add page linked event title muted list
* Add a section on the preference form to allow users to mute articles
  from generating "page linked" notices
* The preference will save the article title as an article ID

Depends-On: Ia0ddf78646ec4c8ae0b84b6d5b46ef5e51c8e8c1
Bug: T46787
Change-Id: I67f751eae5fdc5bccff7fe3047227d432c1cb8d5
2020-05-06 12:38:55 +02:00
Daimona Eaytoy 1be7adf0a8 tests: Avoid calling Title::__construct
Change-Id: Icfe39e0835b4779bf538c2aea9a15cacbdcd6ff5
2020-03-14 18:41:08 +00:00
Umherirrender a933412ea5 Use MediaWikiServices::getMessageCache
This required MediaWiki 1.34 (already set in extension.json)

Change-Id: Ib9f9fe6581c3019fa32dff53acf33edb4266e44d
2020-03-14 14:04:32 +01:00
DannyS712 72f30649d5 Pass a user when creating a new ParserOptions
Bug: T246861
Change-Id: Ie6b6504d3b78a33ecb89a5c431bc225622d715c2
2020-03-04 21:53:33 +00:00
Daimona Eaytoy c256faf968 Remove hack for PHPUnit's Stub interface
This partly reverts commit c19c88567b.

Bug: T192167
Depends-On: Ia12658554c94497a204b7f65f1a6f7b1fa0310ac
Change-Id: I4ef736d87d05f74920ce88f57b0ad824986adb26
2020-01-23 12:34:48 +00:00
Daimona Eaytoy 07ff3debe5 Stop using PHPUnit deprecated methods
Change-Id: I77eefbd6f8b76620257c68be1c299868b5f5ff88
2020-01-14 15:59:46 +00:00
libraryupgrader ff43e1ecf2 build: Updating mediawiki/mediawiki-codesniffer to 29.0.0
The following sniffs are failing and were disabled:
* MediaWiki.Commenting.FunctionComment.MissingDocumentationPrivate
* MediaWiki.Commenting.FunctionComment.MissingReturn
* MediaWiki.Usage.ForbiddenFunctions.isset
* MediaWiki.Usage.PHPUnitDeprecatedMethods.AssertInternalTypeGeneric

Additional changes:
* Also sorted "composer fix" command to run phpcbf last.

Change-Id: I29416247ff3736799543926813beaf4afd569a6e
2020-01-14 05:09:44 +00:00