Created
February 18, 2014 22:22
-
-
Save jechlin/9081649 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package examples.usermgr | |
import com.atlassian.jira.component.ComponentAccessor | |
import com.atlassian.jira.issue.Issue | |
import com.opensymphony.workflow.InvalidInputException | |
/* CONFIGURABLE SECTION */ | |
// custom field names | |
final def userNameField = "Username" | |
final def passwordField = "Password" | |
final def displayNameField = "Display Name" | |
final def emailField = "E-Mail" | |
/* END CONFIGURABLE SECTION */ | |
def issue = issue as Issue | |
def customFieldManager = ComponentAccessor.getCustomFieldManager() | |
def customFields = customFieldManager.getCustomFieldObjects(issue) | |
[userNameField, passwordField, displayNameField, emailField].each {fieldName -> | |
def field = customFields.find { it.name == fieldName } | |
assert field // fields not found or not associated with issue | |
if (! issue.getCustomFieldValue(field)) { | |
throw new InvalidInputException("Please enter all of $userNameField, $passwordField, $displayNameField and $emailField") | |
} | |
} | |
def username = issue.getCustomFieldValue(customFields.find {it.name == userNameField}) as String | |
def userUtil = ComponentAccessor.getUserUtil() | |
if (userUtil.getUserByKey(username)) { | |
throw new InvalidInputException(userNameField, "User already exists with this key") | |
} | |
if (userUtil.getUserByName(username)) { | |
throw new InvalidInputException(userNameField, "User already exists with this user name") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment