Hi jira community,
I need to change security level for specific issue type for once jira project. I found this script and I tried using it.
*************************
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.ManagerFactory
import com.atlassian.jira.issue.security.IssueSecurityLevelManager
import com.atlassian.jira.issue.security.IssueSecuritySchemeManager
import com.opensymphony.user.User
import org.apache.log4j.Category
import org.ofbiz.core.entity.GenericValue
log = Category.getInstance("com.onresolve.jira.groovy.PostFunction")
log.debug ("PostFunction function running")
// Set the following according to what you want to be private
def secLevelString = "Internal"
def privateIssueTypes = ["Risk", "Bug"]
if (privateIssueTypes.contains(issue.issueTypeObject.name)) {
ComponentManager componentManager = ComponentManager.getInstance()
IssueSecurityLevelManager securityLevelManager = componentManager.getComponentInstanceOfType(com.atlassian.jira.issue.security.IssueSecurityLevelManager)
IssueSecuritySchemeManager issueSecuritySchemeManager = ManagerFactory.getIssueSecuritySchemeManager()
IssueSecurityLevelManager issueSecurityLevelManager = ManagerFactory.getIssueSecurityLevelManager()
GenericValue srcProjectGV = issue.getProject()
def issueSecurityScheme = issueSecuritySchemeManager.getSchemes(srcProjectGV).size() == 0 ? null : issueSecuritySchemeManager.getSchemes(srcProjectGV)[0]
User currentUser = componentManager.getJiraAuthenticationContext().getUser()
def secLevelGv = issueSecurityLevelManager.getUsersSecurityLevels(issue.getGenericValue(), currentUser).find ({
it.get("name") == secLevelString
});
if (secLevelGv) {
log.debug ("Set ${issue.getKey()} to $secLevelString")
issue.setSecurityLevel (secLevelGv)
issue.store()
}
else {
log.error ("Could not find security level for $secLevelString")
}
}
log4j.category.com.onresolve.jira.groovy = DEBUG, console, filelog
log4j.additivity.com.onresolve.jira.groovy = false
*****************************************************
I've added that script in the "create event" so that the script will run during issue creation.
I tried creating an issue but it does not change the security level. I checked the logs and I found this:
***************************************************
/secure/CreateIssueDetails.jspa [onresolve.jira.groovy.PostFunction] Could not find security level for Internal
***************************************************
I changed the value of "secLevelString" to "Private" but the same issue exist. It just changed Internal to private.
I tried to open the Database of Jira and I found this table "schemeissuesecuritylevels" and I found the corresponding "ID" for security level "Internal". I changed the value of "secLevelString" to corresponding ID number I found in the database but the same issue exist.
May I know what is missing in my script? Do you have suggestion/s to resolve this issue.
Thanks,
GV