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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,460,023
Community Members
 
Community Events
176
Community Groups

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

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)
}

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.

Hi @Aleksandr Zuevich 

Do you know how to change userkey to user display name in the output?

Thanks

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events