/src/main/resources/com/onresolve/jira/groovy/canned/workflow/postfunctions/AddWatcher.groovy
Groovy | 79 lines | 62 code | 16 blank | 1 comment | 5 complexity | 37a0d89f5c891b489313c49c7024d75a MD5 | raw file
- package com.onresolve.jira.groovy.canned.workflow.postfunctions
-
- import com.atlassian.jira.ComponentManager
- import com.atlassian.jira.issue.MutableIssue
- import com.atlassian.jira.issue.watchers.WatcherManager
- import com.atlassian.jira.util.ErrorCollection
- import com.onresolve.jira.groovy.canned.CannedScript
- import com.onresolve.jira.groovy.canned.utils.ConditionUtils
- import org.apache.log4j.Category
- import com.atlassian.crowd.embedded.api.User
-
- class AddWatcher implements CannedScript {
-
- Category log = Category.getInstance(AddWatcher.class)
-
- String getName() {
- "Adds the current user as a watcher"
- }
-
- public String getHelpUrl() {
- "https://studio.plugins.atlassian.com/wiki/display/GRV/Listeners#Listeners-AddWatcher"
- }
-
- String getDescription() {
- "Adds the user performing the action as a watcher, if condition applies"
- }
-
- List getCategories() {
- ["Function", "Listener"]
- }
-
- List getParameters(Map params) {
- [
- ConditionUtils.getConditionParameter()
- ]
- }
-
- ErrorCollection doValidate(Map params, boolean forPreview) {
- null
- }
-
- Map doScript(Map params) {
- MutableIssue issue = params['issue'] as MutableIssue
-
- Boolean doIt = ConditionUtils.processCondition(params[ConditionUtils.FIELD_CONDITION] as String, issue, false, params)
- if (! doIt) {
- return [:]
- }
-
- ComponentManager componentManager = ComponentManager.getInstance()
- WatcherManager watcherManager = componentManager.getWatcherManager()
-
- User user = componentManager.getJiraAuthenticationContext().getUser()
- if (user) {
- // doesn't matter if they're already watching
- watcherManager.startWatching(user, issue.genericValue)
- }
- else {
- log.debug("Anonymous user, not adding as a watcher")
- }
-
- params
- }
-
- String getDescription(Map params, boolean forPreview) {
- StringBuffer sb = new StringBuffer()
- sb << "Current user will be added to watcher list of issue"
- if (params[ConditionUtils.FIELD_CONDITION]) {
- sb << " if this condition is true:<br><pre>${params[ConditionUtils.FIELD_CONDITION]}</pre>"
- }
- else {
- sb << "."
- }
- }
-
- Boolean isFinalParamsPage(Map params) {
- true
- }
- }