Notification filter preferences remover

Last modified by slauriere on 2026/06/02 17:54

cogRemoves the page only notification filter preferences for a given user
Type
Category
Developed by

slauriere

Rating
0 Votes
LicenseGNU Lesser General Public License 2.1

Table of contents

Description

Warning

The snippet Clear all notifications settings for users should be used instead, since it removes more notification filters.

This snippet removes all the notification filters of a given user whose scope is "page only". It can be handy when a user has many page notification filters, which can slow down the wiki in some cases.

{{groovy}}
def notificationFilterPreferenceService = services.component.componentManager.getInstance(org.xwiki.notifications.filters.NotificationFilterPreferenceManager.class)
def userReference = services.model.createDocumentReference("xwiki", "XWiki", "jdoe")
def filters = notificationFilterPreferenceService.getFilterPreferences(userReference)
filters.eachWithIndex() {
  it, index ->
  if (it.pageOnly != null) {
    println "* #${index}: ${it.id}"
    notificationFilterPreferenceService.deleteFilterPreference(userReference, it.getId())
  }
}
{{/groovy}}

Get Connected