What I'm trying to do: only allow myself to add myself as a watcher to issues in JIRA.
Since it seems way too complicated to prevent being added as a watcher by other people, I decided to make a scripted listener that undoes it whenever it happens. Instant global unwatch, basically.
I got this far:
import com.atlassian.jira.event.issue.IssueWatcherAddedEvent
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.component.ComponentAccessor
def watcherEvent = event as IssueWatcherAddedEvent
def eventIssue = watcherEvent.getIssue() as Issue
def watcherUser = watcherEvent.getApplicationUser() as ApplicationUser
def watcherManager = ComponentAccessor.getWatcherManager()
// make this point to a directory group to de-jank and open up
def immuneUsers = ["meLDAP","meAdmin"]
if (immuneUsers.contains(watcherUser.getName())) {
watcherManager.stopWatching(watcherUser, eventIssue)
}
This works a little too well though, and removes immuneUsers even if they add themselves.
The problem is, I can't figure out how to grab the event initiator user. All of the event parameters I can find only seem to return the watcher user.
With access to the initiating user, I could tweak this into only stopWatching() if watcherUser != initiatingUser. Atlassian's API docs almost make this look impossible, though, which it might be. But am I missing something super obvious...?
You can grab the event initiator like this
import com.atlassian.jira.component.ComponentAccessor
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.