Hi all,
we are using the following scripted field to get the date of the last unrestricted comment:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor
import java.util.Comparator;
def commentManager = ComponentAccessor.getCommentManager()
def commentList = commentManager.getComments(issue).sort{it.getCreated()}
Collections.reverse(commentList)
for (Comment comment : commentList) {
if (comment.getRoleLevelId() == null && comment.getGroupLevel() == null) {
return comment.getCreated()
}
}
return null
Additionally, we would like for this script to only return a date if the user who added the comment is in a certain group. Is this possible?
Thank you for your assistance.
Best regards
I'm not in a position to actually test the code at the moment, but it should be possible. Comment can return the ApplicationUser that authored the comment. Then you just need to create a GroupManager the same way you created the CommentManager. GroupManager has a function for determining if a user is in a group. It would look something like this:
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.comments.Comment
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.security.groups.GroupManager
import com.atlassian.jira.component.ComponentAccessor
import java.util.Comparator;
def commentManager = ComponentAccessor.getCommentManager()
def groupManager = ComponentAccessor.getGroupManager()
def commentList = commentManager.getComments(issue).sort{it.getCreated()}
Collections.reverse(commentList)
for (Comment comment : commentList) {
if (comment.getRoleLevelId() == null &&
comment.getGroupLevel() == null &&
groupManager.isUserInGroup(comment.getAuthorApplicationUser(), 'Group Name')) {
return comment.getCreated()
}
}
return null
Hope that helps!
Hi Wade,
please ignore the other notifications, I was able to resolve the other issues I had using the correct searcher for the field. In this case Date Time Range Picker.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For that, you will want to use GroupManager
[...]
def groupManager = ComponentAccessor.groupManager
def group = groupManager.getGroup("name of your group")
[...]
if (comment.getRoleLevelId() == null && comment.getGroupLevel() == null) {
if(groupManager.isUserInGroup(comment.authorApplicationUser, group)) {
return comment.getCreated()
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Found and corrected a typo
comment.authorApplicationUser was comment.authorApplicatioUser
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Also, the other signature of isUserInGroup(ApplicationUser, String groupName) as suggested by Wade will work.
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.