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?
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.