Skip to end of banner
Go to start of banner

Script - Show Page Watchers (groovy & beanshell)

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

The script is implemented as a macro, to show watchers of the current page (including space watchers). Two versions are provided here: groovy and beanshell. This was tested in Confluence 2.7.3, 2.10.3 and 3.0, so it should work for most versions.

Macro Name

watchers

Macro has a body

Unchecked

Output

Macro generates wiki markup

Groovy

#set ($title = "Notification List")
#if ($paramtitle)
  #set ($title = $paramtitle)
#end
##
{groovy}
import com.atlassian.confluence.util.GeneralUtil;
import com.atlassian.confluence.core.ContentEntityObject;
import com.atlassian.confluence.mail.notification.Notification;
import com.atlassian.confluence.mail.notification.NotificationManager;
import com.atlassian.spring.container.ContainerManager;
import com.atlassian.user.User;

// Get the default Notification Manager
NotificationManager nm = ( NotificationManager) ContainerManager.getComponent( "notificationManager" );

// Get the current page object
ContentEntityObject page = context.getEntity();

#if ($title.length() > 0)
  println("<h4>$!{title}</h4>");
#end

// Notifications for this page
for (Notification notif in nm.getNotificationsByPage(page)) {
  if (notif.getUserName()) {
    println(GeneralUtil.getUserAccessor().getUser(notif.getUserName()).getFullName() + "<br />");
  }
}
// Notifications for this space
for (Notification notif in nm.getNotificationsBySpace(page.getSpace())) {
  if (notif.getUserName()) {
    println(GeneralUtil.getUserAccessor().getUser(notif.getUserName()).getFullName() + " (<i class=smalltext>Watching this Space</i>)<br />");
  }
}
{groovy}

Beanshell

#set ($title = "Notification List")
#if ($paramtitle)
  #set ($title = $paramtitle)
#end
##
{beanshell}
import com.atlassian.confluence.util.GeneralUtil;
import com.atlassian.confluence.core.ContentEntityObject;
import com.atlassian.confluence.mail.notification.Notification;
import com.atlassian.confluence.mail.notification.NotificationManager;
import com.atlassian.spring.container.ContainerManager;
import com.atlassian.user.User;

// Get the default Notification Manager
NotificationManager nm = ( NotificationManager) ContainerManager.getComponent( "notificationManager" );

// Get the current page object
ContentEntityObject page = context.getEntity();

#if ($title.length() > 0)
  print("<h4>$!{title}</h4>");
#end

// Notifications for this page
for (Notification notif : nm.getNotificationsByPage(page)) {
  if (notif.getUserName() != null) {
    print(GeneralUtil.getUserAccessor().getUser(notif.getUserName()).getFullName() + "<br />");
  }
}
// Notifications for this space
for (Notification notif : nm.getNotificationsBySpace(page.getSpace())) {
  if (notif.getUserName() != null) {
    print(GeneralUtil.getUserAccessor().getUser(notif.getUserName()).getFullName() + " (<i class=smalltext>Watching this Space</i>)<br />");
  }
}
{beanshell}
  • No labels