How can i Restrict issue link create for current project

reza azad January 6, 2019

I am trying to Restrict issue link create only for current project

Many thanks in advance.

3 answers

1 accepted

1 vote
Answer accepted
Tomasz Bryła January 6, 2019

Hi,

You can use ScriptRunner Listener to delete link if linked issue is not from current project.

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent

def issueLinkManager = ComponentAccessor.getIssueLinkManager()
Issue currentIssue = event.getIssueLink().getSourceObject()
def currentProject = currentIssue.projectObject.name
def linkedIssue
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

issueLinkManager.getOutwardLinks(currentIssue.id).each { issueLink ->

     linkedIssue = issueLink.destinationObject

    if( linkedIssue.projectObject.name != currentProject )
{
   
    issueLinkManager.removeIssueLink(issueLink, user)
}
    
}
reza azad January 6, 2019

thanks,i want to write this code in listener and i have this error

unable to resole class "import com.atlassian.jira.event.issue.link.IssueLinkCreatedEvent"

Tomasz Bryła January 6, 2019

Did you used IssueLinkeCreatedEvent? I have to some errors, but listener work good.

obraz.png

Like reza azad likes this
reza azad January 6, 2019

i try this code and don't have any error but i have error in executelinkscript.png

Tomasz Bryła January 6, 2019

What version of Jira and Script Runner you have? Can you past here error?

reza azad January 6, 2019

jira version 7.1.4 linkscript2.png

Tomasz Bryła January 7, 2019

Unfortunately Issue Linked Event was add in Jira 7.5.

Like reza azad likes this
reza azad January 8, 2019

i resolved my problem with this code,thank you for your help

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.event.issue.EventUtils

Issue issuesou=event.issue;

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

Issue currentIssue = issuesou
def currentIssueId = issuesou.getId()
def currentProject = currentIssue.projectObject.name
def linkedIssue = issuesou
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

issueLinkManager.getOutwardLinks(currentIssueId).each { issueLink ->

linkedIssue = issueLink.getDestinationObject()

if(linkedIssue.projectObject.name != currentProject )
{

issueLinkManager.removeIssueLink(issueLink, user)
}

}

reza azad January 8, 2019

i resolved my problem with this code,thank you for your help

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.link.IssueLink
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.project.Project;
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.event.issue.EventUtils

Issue issuesou=event.issue;

def issueLinkManager = ComponentAccessor.getIssueLinkManager()

Issue currentIssue = issuesou
def currentIssueId = issuesou.getId()
def currentProject = currentIssue.projectObject.name
def linkedIssue = issuesou
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()

issueLinkManager.getOutwardLinks(currentIssueId).each { issueLink ->

linkedIssue = issueLink.getDestinationObject()

if(linkedIssue.projectObject.name != currentProject )
{

issueLinkManager.removeIssueLink(issueLink, user)
}

}

1 vote
Alexey Matveev
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 6, 2019
reza azad January 6, 2019

i want to my users cant link issue to another project and just can link to current issue project

0 votes
Bastian Stehmann
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
January 6, 2019

Hi @reza azad,

Welcome to the community. 

You can do this by editing the permission scheme for your project (You must be an Administrator to do that). You should make sure, that the permission scheme is used only in your project, otherwise create a copy, edit that and assign it to your project.

There is a permission for linking issues. If you remove all associated roles, users and groups, nobody can create an issue link anymore.

Suggest an answer

Log in or Sign up to answer