Tell us how you use Jira Service Desk and get a Starbucks gift card for this! Share your experience to help us design a new solution for efficient communication with customers!

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.config.IssueTypeManager
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.user.util.UserManager
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.onresolve.scriptrunner.runner.ScriptRunnerImpl
import com.onresolve.scriptrunner.runner.customisers.WithPlugin
import com.stiltsoft.jira.attachcategory.facade.SmartAttachmentsFacade
import com.stiltsoft.jira.attachcategory.facade.entity.config.AutoDistributionType

// Initializing the app components
@WithPlugin("com.stiltsoft.jira.smart-attachments")
SmartAttachmentsFacade facade = ScriptRunnerImpl.getPluginComponent(SmartAttachmentsFacade)
UserManager userManager = ComponentAccessor.getUserManager()
IssueTypeManager issueTypeManager = ComponentAccessor.getComponent(IssueTypeManager.class)
GroupManager groupManager = ComponentAccessor.getGroupManager()
ProjectRoleManager projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager.class)

// Specifying the user name and name of the scheme that will be updated
def currentUser = userManager.getUserByName("admin")
def optionalScheme = facade.getSchemeByName("New Scheme")

// Interrupting the script execution if the scheme with such name does not exist
if (!optionalScheme.isPresent()) {
    return
}

def scheme = optionalScheme.get()

// Specifying the category which configuration should be updated
def categoryDocuments = scheme.categories.find { category -> category.name.equalsIgnoreCase("Documents") }

// Specifying the issue type in which the category should be visible only
def taskIssueType = issueTypeManager.getIssueType("10100")
categoryDocuments.issueTypes.add(taskIssueType)

// Specifying user groups for access restrictions of the category
def softwareUserGroup = groupManager.getGroup("jira-software-users")
categoryDocuments.accessRestrictions.groups.add(softwareUserGroup)
categoryDocuments.accessRestrictions.users.add(currentUser)

// Specifying project roles for access restrictions of the category
def projectRole = projectRoleManager.getProjectRole("Administrators")
categoryDocuments.accessRestrictions.projectRoles.add(projectRole)

// Specifying the autodistribution rule that should be applied to the category
categoryDocuments.autoDistribution.type = AutoDistributionType.NAME_PATTERN
categoryDocuments.autoDistribution.value = ".doc, .pdf"

facade.updateScheme(scheme, currentUser)