I am looking for help in the completing some custom code to uncheck the “Show changed content” box in the Email Settings for a subset of users. These users have access to sensitive information, and it should not be sent through email.
I am stuck at the end of the process.
EditEmailSettingsAction emailSettings = new EditEmailSettingsAction()
emailSettings.setShowDiffInEmailNotifications(true)
emailSettings.execute()
Error:
2024-04-16 13:20:14,174 ERROR [common.UserScriptEndpoint]: Script console script failed:
java.lang.NullPointerException
at com.atlassian.confluence.user.actions.EditEmailSettingsAction.updateUser(EditEmailSettingsAction.java:68)
at com.atlassian.confluence.user.actions.EditEmailSettingsAction.execute(EditEmailSettingsAction.java:30)
at com.opensymphony.xwork.Action$execute.call(Unknown Source)
at Script46.run(Script46.groovy:51)
Unfortunately not. I left this up to see if someone might get curious and have a breakthrough.
Even with the help of scriptrunner support, I was not able to get this functional.
Our work around was to do a DB change to up date the bulk. Then, we set up a job that would notify us when a user had the setting active. We would manually update the users settings. This approach worked for us, since we only got a few users at a time.
If you have any code snippets that would be helpful and I can see if i can get this working. Your approach wouldnt work in my case as we want this to be instance wide so it will affect all users on the server so a manual process wouldnt be feasible (but if you have the code of the job too that could be helpful).
I don’t have much. I gave up about a month after making this post. Here is something to get you started. It should take the current logged in user and attempt to disable the “Show changed content” email setting for the user.
You can see that it doesn’t make the change, despite code setting the value. I suspect this is because it is only changing the value in the local memory and not running the necessary command to save it to the database.
Progress has been made and big help from the atlassian support team below is the updated code which works on my instance. Please accept the answer if it helps you out.
import com.atlassian.confluence.user.AuthenticatedUserThreadLocal
import com.atlassian.confluence.user.UserPreferencesAccessor
import com.atlassian.confluence.user.UserAccessor
import com.atlassian.sal.api.component.ComponentLocator
def userAccessor = ComponentLocator.getComponent(UserAccessor)
def userPreferenceAssessor = ComponentLocator.getComponent(UserPreferencesAccessor)
def currentUser = AuthenticatedUserThreadLocal.get()
log.warn(currentUser)
//What is the starting value of the "Show Difference in Email"
def prefs = userPreferenceAssessor.getConfluenceUserPreferences(currentUser)
log.warn(prefs.showDifferencesInNotificationEmails)
prefs.getWrappedPreferences().setBoolean("confluence.prefs.email.show.diff", false)
log.warn(userPreferenceAssessor.getConfluenceUserPreferences(currentUser).showDifferencesInNotificationEmails)