Hi,
I have developed JIRA custom field plugin(type : text) and i want it to be visible only for particular user .
How to check currently logged in user of JIRA in velocity template ?
Do i need to fetch loggedin user in my java file and then assign to varaible then it can be accessible to vm file
you can try with $authcontext.loggedInUser.name
or using javascript you can get current loggedin user details
try with this inside javascript,
AJS.params.loggedInUser
try with this idf you want check current user in specific group
${jiraUserUtils.getGroupNamesForUser($authcontext.loggedInUser.name).contains('jira-users')}
check this, it may help you
https://answers.atlassian.com/questions/31839/jira-api-check-if-user-is-in-group
if something helped then don't forgot to accept as a answer it will help to other users to choose right answer!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
Thanks lot :)
I ll explain my scenario :
I have developed one custom field plugin , wanted to display only for the user who belong to particular group.
I have used the below line of code in my edit.vm file and built a jar deployed in jira using admin role , then created new custom field using that JAR addedd to particular project and to the screen which the project is using.
After logeg in to jira as normal user still i'm not able to view that field when creating issue.
Could you pls help me
#if (${jiraUserUtils.getGroupNamesForUser($authcontext.loggedInUser.name).contains('Jira-users')})
#if($value)
<input type="text" name="$customField.id" value="$value" id="$customField.id" class="text"/>
#else
<input type="text" name="$customField.id" value="" id="$customField.id" class="text"/>
#end
#end
Still it is hidden only . Even if user in 'jira-user' group not able to view when creating issue .
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
which version of jira you are using?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
can you confirm what is the group name you used
jira-users or Jira-users ? check the first leter, it should be small leter
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi rambanam ,
great !!!!!! it's working fine. thanks a lot .
and one more doubt. field name should also be hidden . is it possible? because custom field name being created when creating new custom field
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Glad to hear it worked!!
where needs to hidden the field name?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In screen i want to hide label name of the custom field. (ex : when creating issue)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi ,
Is there any document where i could find how to use objects from JIRA-API class in velocity template?
For "jiraUserUtils" which is being used in velocity template. i am not able find any API document for further reference
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
already @Bharadwaj Jannu has given link to this document
https://developer.atlassian.com/display/JIRADEV/Custom+field+Velocity+context+unwrapped
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @rambanam prasad
Thanks for your immmediate respone for my queries .
In the above link i coudn't find "jiraUserUtils" object .The only thing i could see the object for velocity template
in this link
, but i want to know how the objects can be used in velocity template
EX : ${jiraUserUtils.getGroupNamesForUser($authcontext.loggedInUser.name).contains('jira-users')}
In the above example "$authcontext" object is used to find logged in user and i have checked the corresponding API class in the below link:
https://docs.atlassian.com/jira/latest/com/atlassian/jira/security/JiraAuthenticationContext.html
Here i couldn't find "loggedInUser" method instead "getLoggedInUser" is available anyhow i considered that "getLoggedInUser" can also be called as "$authcontext.loggedInUser
" ,but "name" is not available in that class.
from where it's being called.
Could you please explain ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi @rambanam prasad
Actually the field is displaying based on the user group but i also want to hide label name for the field . how to hide it ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
i am not much expertise in velocity files, i suggest gothrough the following document
http://velocity.apache.org/engine/devel/user-guide.html
you can find the "jiraUserUtils" Object here i think you can use UserUtils Object also to get user details
https://developer.atlassian.com/display/JIRADEV/Velocity%20Context%20for%20Email%20Templates
"$authcontext.loggedInUser
" will return the User Object in that getName() method is there so use the "$authcontext.loggedInUser.name"
How to hide label:
where you have declared label for your field?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@rambanam prasad
Actually i have build custom field jira plugin where it is visible only for "jira-users"
group .then i have uploaded to "Universal plugin manager" in JIRA
When creating new custom field ,Name for the field must be set and assigned that filed to screen which is used in "X" project.
when creating issue , field input box displaying to the user who belong to the "Jira-users" group, but when the other user creating the issue at that time filed is hidden but the name for the field is still displaying which has been set when the custom field is created.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
check i have added another answeer!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Augustin,
you can use $authcontext.getUser().getName()=='user1'
and follow link to know about velocity variables.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
appreciated if accept as an answer.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Augustin
i am not sure how to hide the custom field name in velocity file
i have another solution to hide a field to specific group/user with javascript, add the following script as webresource in a plugin
<script type="text/javascript"> jQuery(document).ready( function($) { JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function(e,context) { hideField(); }); hideField(); function hideField(){ var user=getCurrentUserName(); var statusText=$('#status-val').text(); if(isUserInGroup(user,'Developers') ){ //to hide field $("#customfield_10571").closest('div.field-group').hide(); }else { AJS.$("#customfield_10571").closest('div.field-group').show(); } } function getCurrentUserName() { var user; AJS.$.ajax({ url: "/rest/gadget/1.0/currentUser", type: 'get', dataType: 'json', async: false, success: function(data) { user = data.username; } }); return user; } function getGroups(user) { var groups; AJS.$.ajax({ url: "/rest/api/2/user?username="+user+"&expand=groups", type: 'get', dataType: 'json', async: false, success: function(data) { groups = data.groups.items; } }); return groups; } function isUserInGroup(user, group){ var groups = getGroups(user); for (i = 0; i < groups.length; i++){ if (groups[i].name == group){ return true; } } return false; } }); </script>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Bharadwaj,
I want to display the field only to the members who is belong to 'jira-users' group .
https://confluence.atlassian.com/display/JIRA040/How+to+create+a+new+Custom+Field+Type
I have tried this above refrence URL ,but it is not displaying field even the user belong to 'jira-users' group
In the above example i have used 'Jira-users' instaed of 'Jira-administrators'.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
check my answer i have updated!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.