Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How can I get ACTIVE notification when a project role has user or group added to it?

Mike Rathwell Community Leader Jan 03, 2019

Please don't get me started on the why I need this as that way lay madness. However, I have managed to get part of a requirement answered with a listener that actively notifies when a Jira group is updated and need to do the same thing when a project ROLE is updated.

The piece I have working (and need the same for project role changes) is when a user is added to a group using the "GroupMembershipCreatedEvent" event in a groovy script listener. The code below looks for additions to a SPECIFIC group (I only have been told to care about this particular one and have a separate one for when humans are REMOVED from the group).

import com.atlassian.crowd.event.group.GroupMembershipCreatedEvent
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.atlassian.mail.queue.SingleMailQueueItem

def event = event as GroupMembershipCreatedEvent
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

if (event.groupName == "GroupIcareAbout"){
def email = new Email("whoWantsToKnow@address.com"
email.setSubject("User added to the ${event.groupName} group")
email.setBody("User ${event.entityName} has been added to Jira's ${event.groupName} group by ${currentUser.displayName}" )
email.setMimeType("text/html")

SingleMailQueueItem item = new SingleMailQueueItem(email)
ComponentAccessor.getMailQueue().addItem(item)
}

How do I do the same thing but for project role changes? I tried, with trolling the API to use the seemingly equivalent "RoleMembershipCreatedEvent" event but no soap so far. Should I be using the "ProjectRoleUpdatedEvent" and root it out that way? Anyone with a script fragment or example that might be able to help?

1 answer

1 accepted

0 votes
Answer accepted

Hi MIke,

Yes, you can use ProjectRoleUpdatedEvent which has project field also with projectRole and originalRoleActors and roleActors which contain UserRoleActors or GroupRoleActors where parameter is String userKey or String groupName respectively.

So the analogue for ProjectRoleUpdatedEvent could be:

import com.atlassian.jira.event.role.ProjectRoleUpdatedEvent
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.mail.Email
import com.atlassian.mail.queue.SingleMailQueueItem

def event = event as ProjectRoleUpdatedEvent

def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def project = event.project
def role = event.projectRole

if (role.name == "RoleIcareAbout" && project.key == "ProjectIcareAbout"){
def email = new Email("whoWantsToKnow@address.com")

email.setSubject("Role ${role.name} has been updated for ${project.key} project")
def newUserKeys = event.roleActors.roleActors.stream().map{actor -> actor.parameter}.collect()
def oldUserKeys = event.originalRoleActors.roleActors.stream().map{actor -> actor.parameter}.collect()
email.setBody("Jira's ${role.name} role for ${project.key} project has been updated by ${currentUser.displayName}. Original user keys or group names: ${oldUserKeys}, new user keys or group names: ${newUserKeys}" )
email.setMimeType("text/html")

SingleMailQueueItem item = new SingleMailQueueItem(email)
ComponentAccessor.getMailQueue().addItem(item)
}
Mike Rathwell Community Leader Jan 07, 2019

Thanks @Aleksandr Zuevich. THAT gets me to the bit I couldn't get to. In the interim (and to get them at least partly off my back) I had come up with a subset of that which at least said that a role changed and who did it. This gets me the WHAT changed.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Apps & Integrations

🍻🍂Apptoberfest Update: Upcoming Virtual Events 🎉

Hello Community! I hope you've been enjoying the 🍂Apptoberfestivities🍂 (I know I have!) The event is heating up next week with a series of virtual events that we're calling the 🍻🍂Partner App ...

78 views 1 6
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