Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,300,881
Community Members
 
Community Events
165
Community Groups

Identify offensive or inappropriate content in confluence page

As part of the Inclusivity Initiative from our company, we are looking into identify the non-inclusive(restricted) words like master, slave etc., in the confluence page and restrict user from using it.
We are evaluating the script runner for Confluence for the same. We are using event listener functionality to achieve it.
We were able to add the comment after we publish if the restricted words are found in the page but It does not block the user from publishing it.
We want to block the user from publishing the page if restricted words are found in the page.
Is there a way to identify this in draft page and block user from publishing the page until restricted words are replaced?

3 answers

Hey @Madhura Siddappagowda !

I have an approach for this that involves censoring the content you want to restricted. You'd create a ScriptRunner custom event listener, and have it listen for the 'PageCreateEvent' and 'PageUpdateEvent'. This would be your script:

import com.atlassian.confluence.core.Modification
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator

def page = event.page as Page
def body = page.bodyContent.body
def restrictedWords = ['fizz', 'buzz', 'foo', 'bar']
def containsRestrictedWord = restrictedWords.findAll() { word -> body.contains(word) }

if (containsRestrictedWord) {

containsRestrictedWord.each { word ->
body = body.replace(word, '<span style="color: rgb(255,0,0);">[REDACTED]</span>')
}

def pageManager = ComponentLocator.getComponent(PageManager)

pageManager.saveNewVersion(page, { Page pageObject ->
pageObject.setBodyAsString(body)
} as Modification<Page>)
}

Any time a user creates or edits a page and uses a restricted word, it'll be replaced with styled text that makes it easier for the user to spot, and know they have to replace. I hope this is helpful. (:

Hi, I have a similar use case to this. I am trying to add content to a page after the edit using the PageUpdateEvent listener. However, the issue I am having is that, because I am using the PageUpdateEvent listener, having code that edits the page in the script will cause the script to fire off multiple times until it times out.

The script listens for page edit, then the script edits the page, which then fires off the script again. Do you have this issue with this code?

Hi Henry!

Thank you for pointing this out! This can be fixed by adding a SaveContext which suppresses events (the last parameter you pass in when creating a new save context is the one that determines if events are suppressed):

import com.atlassian.confluence.core.DefaultSaveContext
import com.atlassian.confluence.core.Modification
import com.atlassian.confluence.pages.Page
import com.atlassian.confluence.pages.PageManager
import com.atlassian.sal.api.component.ComponentLocator

def page = event.page as Page
def body = page.bodyContent.body
def restrictedWords = ['fizz', 'buzz', 'foo', 'bar']
def containsRestrictedWord = restrictedWords.findAll() { word -> body.contains(word) }

if (containsRestrictedWord) {

containsRestrictedWord.each { word ->
body = body.replace(word, '<span style="color: rgb(255,0,0);">[REDACTED]</span>')
}

def pageManager = ComponentLocator.getComponent(PageManager)

pageManager.saveNewVersion(page, { Page pageObject ->
pageObject.setBodyAsString(body)
} as Modification<Page>, new DefaultSaveContext(true, true, true))
}

Let me know if this works for you! 

Like Henry Brown likes this

Yes, this worked! Thank you very much

Hello @Fabian Lim , thank you for recommending Comala Document Management (link)!

Hello @Madhura Siddappagowda,

Comala Document Management enables customers to build a customised review process that could form part of your solution here, for example Comala Document Management can add and remove restrictions as you move through your process. Currently the app does not have the ability to check for restricted words, but you can integrate ScriptRunner with Comala Document Management, see here (link = https://docs.adaptavist.com/sr4c/latest/features/event-listeners/custom-event-listener/comala-document-management) for an example (different use case).

Keep in mind that Comala Document Management does not block pages from being saved, but applies controls to pages that have been saved.

Note that ScriptRunner also provides the ability to add / remove page restrictions. 

I hope that helps

James

0 votes
Fabian Lim Community Leader Oct 06, 2021

Hi @Madhura Siddappagowda

Based on your requirements, I would consider an app such as comala workflows that allows to have a workflow on pages before they get published.  Approvers get notified to do the review.

The are other apps as well, but the one above is the one we use. 

Regards

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

An update on Confluence Cloud customer feedback – June 2022

Hi everyone, We’re always looking at how to improve Confluence and customer feedback plays an important role in making sure we're investing in the areas that will bring the most value to the most c...

391 views 2 13
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you