Identify offensive or inappropriate content in confluence page

Madhura Siddappagowda October 6, 2021

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

1 vote
Tiffany Wortham
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.
February 22, 2022

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. (:

Henry Brown March 18, 2022

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?

Tiffany Wortham
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.
March 22, 2022

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
Henry Brown March 23, 2022

Yes, this worked! Thank you very much

1 vote
James Conway
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 6, 2021

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 6, 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
AUG Leaders

Atlassian Community Events