Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script for automating space or blog watching?

Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

Hi everybody,

i have just started using Scriptrunner for Confluence.

A thing that i would like to do is to manage watchers of a space or blog centrally or to be able to add new users as watchers to spaces.

I had a look in Confluence API but i didn't manage to find something.

Thanx in advance for the help.

Kostas

4 answers

1 accepted

3 votes
Answer accepted
Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 19, 2014

Here is the script i have created for managing Space watchers. It has as inputs a group of users, the Space key and the content type.

import bucket.user.UserAccessor
//import com.atlassian.confluence.user
import com.atlassian.spring.container.ContainerManager;
import com.atlassian.confluence.mail.notification.NotificationManager;
import com.atlassian.confluence.user.DefaultUserDetailsManager;
import com.atlassian.confluence.spaces.SpaceManager;
import com.atlassian.confluence.search.service.ContentTypeEnum
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
def log = Logger.getLogger("com.onresolve.confluence.scripting.WatchSpace")
// Get the default Notification Manager
def notificationManager = (NotificationManager) ContainerManager.getComponent('notificationManager')
//def userDetailsManager = (DefaultUserDetailsManager) ContainerManager.getComponent('userDetailsManager')
// Get User Accessor
def userAccessor = (UserAccessor) ContainerManager.getComponent('userAccessor')
// Get Space Manager
def spaceManager = ContainerManager.getComponent("spaceManager") as SpaceManager
 
//def users = userAccessor.getUsers()
 
//define the group that you want to add as watchers
def group = userAccessor.getGroup('Add group here')
def users = userAccessor.getMemberNames(group)
 
 
//define the space that users will watch.
def space_for_watch = spaceManager.getSpace("Add space key here")
users.each{user->
  log.warn (user)
  def username = userAccessor.getUser(user)
  boolean isWatching = notificationManager.isUserWatchingPageOrSpace(username, space_for_watch, null)
  if (!isWatching) {
 
//Choose the content type of space that users will watch. Add BLOG  for watching Space Blogs, leave blank for watching entire content
  notificationManager.addSpaceNotification(username, space_for_watch, BLOG)
   
  }
}

1 vote
Nick Muldoon
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 2, 2015

Hi Kostas,

I know you got this sorted for your instance. If anyone stumbles on this and wants a turnkey solution I invite you to look at Better Blogs for Confluence. It is a paid add-on that allows Space Administrators to subscribe users and groups to email notifications of new blogs in a space.

At Twitter we needed this feature to ensure every member of our product, design and engineering organisation (>1,500 people) were notified of new blog posts in the Engineering space. The Engineering Blog enabled VP's to communicate one-to-many and teams to share details of the technology and features they were working on. It didn't make sense to ask every new employee to subscribe to the blog in that space, hence Better Blogs was born.

With Better Blogs you can keep everyone informed, and do so with ease. For those wishing to take advantage of early bird pricing use the promotion code HHYUWD before the end of October 2015.

If you have feedback on the Better Blogs for Confluence add-on contact me via nick@arijea.com or +1 415 568 7064.

Thanks Kostas, hope you don't mind me dropping this note here.

 

Cheers,
Nicholas Muldoon
Arijea

Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 7, 2015

Hi @Nick Muldoon, no problem at all. Thanks for the update on that. Indeed for large instances of Confluence, asking new users to subscribe to the blog doesn't make sense. Our instance has 90 users so far, so i use the script every time that a new user is added. I will take a look on Better Blogs. For any comment, feedback etc i will let you know. Cheers, Kostas

Nick Muldoon
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 7, 2015

Thanks Kostas

1 vote
Matthew J. Horn
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 7, 2014

It looks like you can do it with the RPC and SOAP APIs. Although I haven't used any of these, it looks like watching pages and spaces can be automated with the following services:

  • WikiSoapService
  • XhtmlSoapService
  • ConfluenceSoapService
  • NotificationsRpc
  • ConfluenceXmlRpcHandler

You can also do some automation by writing a user macro, although my success with page and space watching has been mixed with this approach.

Tsol
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 19, 2014

Hey Matthew thanks for the help. I managed to write a script for adding space watchers. Is listed in my answer below. Cheers

0 votes
Vera Henrichs
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 26, 2016

And how about this feature? https://jira.atlassian.com/browse/CONF-40582 Please vote!

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events