how to judge current login user belongs to a specified project role or not programmingly in behaviours plugin?

fabby June 4, 2012

what i want to implement is that,if current login user doesn't belong to the project role "PDM",then he can not choose "Duplicate" as resolution.

so at first,i shall judge current login user belonging to a specified project role or not.

i searched jira api,and found "isUserInProjecRole" mehod."boolean isUserInProjectRole(User user, ProjectRole projectRole, Project project) "

the first parameter is User object.i guess "User(String name, ProviderAccessor providerAccessor, com.atlassian.crowd.embedded.api.CrowdService crowdService) " can create the User object.but i don't know how to use the constructor.the parameter "providerAccessor" i can not understand.

anyone knows how to implement it? or can share full code about implement approach

my jira version is 4.4.1

8 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Augustin atto September 10, 2013

Hi ,

I have develped custom field , the field should be visible to particular user at the time of creating issue .

How it could be possible ?

Can you help me ?

0 votes
fabby June 4, 2012

i find "ProjectRole getProjectRole(String name)" in jira 5.0.1 api,its interface is ProjectRoleManager.i think this method can get project role object.but i don't know how to get ProjectRoleManager object.

0 votes
fabby June 4, 2012

oh..yes,i make a stupid mistake!

0 votes
Mizan
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.
June 4, 2012

There is a spelling mistake, fabby :)

String curruesr=user.getFullName()

0 votes
fabby June 4, 2012

hi Mizan,

i modify the script to,

import com.opensymphony.user.User
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.ComponentManager

FormField formField = getFieldById("resolution")
FormField comField = getFieldById("comment")

ComponentManager componentManager=ComponentManager.getInstance()
User user = componentManager.getJiraAuthenticationContext().getUser()
String curruesr=user.getFullName()
comField.setFormValue("current user is :"+curruser)

field "comment" returns nothing,and found error in log file

2012-06-05 15:42:22,997 http-8079-7 ERROR jirauser 942x2244x1 17twilp 127.0.0.1 /rest/com.onresolve.jira.plugin.Behaviours/1.0/behaviours/runvalidator.json [onresolve.jira.groovy.BehaviourManagerImpl] Found class but could not find method run
groovy.lang.MissingPropertyException: No such property: curruser for class: Script1

0 votes
Mizan
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.
June 4, 2012

Try this

User currentUser = componentManager.getJiraAuthenticationContext().getUser()

Even add some logging in your script .

And i am not sure but this user object cant be an argument in this method

isUserInProjectRole(User user, ProjectRole projectRole, Project project)

0 votes
fabby June 4, 2012
import com.opensymphony.user.User
import com.atlassian.jira.security.JiraAuthenticationContext
import com.atlassian.jira.component.ComponentAccessor.*

FormField formField = getFieldById("resolution")
FormField comField = getFieldById("comment")
 
com.atlassian.crowd.embedded.api.User user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def curruesr=user.getFullName()
comField.setFormValue("current user is :"+curruser)

i try to use the script above ,but the filed "comment" returnes nothing.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events