Hi all,
I am using JIRA 7.6.9 and ScriptRunner 5.5.5 and I need to restrict (make mandatory and after read only) the Fix Version/s field after a certain state for Users but editable for project Administrators. The field is available in the Edit and the View screen as well and JIRA instance is set ON for INLINE edit mode.
I created a behaviour and when I change the value of the Fix Version/s field in View screen the behaviour is not lauching the Edit screen hence I can modify the Value without any restriction.
Same applies for other custom fields :(
If I am opening the Edit screen the behaviour is working as expected.
Can someone help me why the behaviour not launching the Edit screen when I click to the field in View screen ?
Example:
Workflow:
NEW -> ANALYZED -> IMPLEMENTED -> RESOLVED
Code:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.security.roles.ProjectRoleManager;
//Read Only is False if user role is Administrator
def issue = underlyingIssue
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def projectRoleManager = ComponentAccessor.getComponentOfType(ProjectRoleManager)
def role = projectRoleManager.getProjectRole("Administrators")
def userIsAdmin = projectRoleManager.isUserInProjectRole(currentUser, role, issue.getProjectObject())
//Fix Version/s field value
def fixVersions = getFieldById("fixVersions")
//Current status of the issue
def issueStatus = underlyingIssue.getStatus().name
//IMPLEMENTED, RESOLVED state restricts the modification of the Fix Version/s if user role is not Administrator
if (!userIsAdmin){
if (issueStatus == "Implemented" || issueStatus == "Resolved"){
fixVersions.setReadOnly(true)
} else {
fixVersions.setRequired(true)
}
}
Was good to meet you in MetaInf conference.
So as we said the inline editing thing is indeed a bug and will be released in the week - please follow SRJIRA-3004 and SRJIRA-3462 in order to be up to date.
Now regarding the behaviour. The script should be an Initialiser and should look something like
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import static com.atlassian.jira.issue.IssueFieldConstants.*
@BaseScript FieldBehaviours fieldBehaviours
// if underlying issue is null means that we are trying to create a new issue - so do nothing
if (!underlyingIssue) {
return
}
def fixVersionField = getFieldById(FIX_FOR_VERSIONS)
def currentStatusName = underlyingIssue.status.name
def currentUser = ComponentAccessor.jiraAuthenticationContext.loggedInUser
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)
def projectRole = projectRoleManager.getProjectRole("Administrators")
def isAdminRole = projectRoleManager.isUserInProjectRole(currentUser, projectRole, underlyingIssue.projectObject)
// Fix Version/s is not mandatory in NEW and ANALYZED state
if (currentStatusName in ["New", "Analyzed"]) {
fixVersionField.setRequired(false)
}
// Fix Version is have to be set when it is moving to IMPLEMENTED sate
if (actionName == "Implemented") {
fixVersionField.setRequired(true)
}
// Fix Version/s is required (mandatory but can be changed) in IMPLEMENTED and RESOLVED state for Administrators
if (currentStatusName in ["Implemented", "Resolved"] && isAdminRole) {
fixVersionField.setRequired(true)
}
// Fix Version/s is read-only in IMPLEMENTED and RESOLVED state for other users
if (currentStatusName in ["Implemented", "Resolved"] && !isAdminRole) {
fixVersionField.setRequired(false)
fixVersionField.setReadOnly(true)
}
Please let me know if this does the trick.
Kind regards,
Thanos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am unable to get this to work as well. I have around 50 fields some of which are being made read only depending on the group a user belongs to. If he belongs to x group, he can edit otherwise he cannot. This functionality works perfectly fine in the edit screen but users are able to edit fields in view screen using inline edit.
This is a functionality we really need to get to work and disabling inline edit for the whole JIRA seems to be the only option we are left with (which is horrible) . Are there any other ways i can disable inline edit just for a single issuetype/ workflow. @Thanos Batagiannis [Adaptavist]
I tried using the setAllowInlineEdit(false) in the behaviour initializer. Does not work. Works only for field behaviours and adding more than 100 field behaviours would make jira super slow
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ferenc Ghido ,
I just tried it on my instance and the behaviour does not execute on view issue screen either. I would advise to take a look at this topic, maybe the JS will help, although I would agree that it is not ideal.
Antoine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Antoine Berry ,
Thank your for your suggestion. I saw that there are also a Bug opened for similar issue (not the same but similar): https://productsupport.adaptavist.com/browse/SRJIRA-3004
I still keep open my request if there are better solution.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.