I was able to write a condition for a UI item within Jira fairly easily:
def user = Users.getLoggedInUser()user.isMemberOfGroup("name-of-group")
Hi, @Miranda
Welcome to Atlassian Community!In Confluence Java API has methods, which differ from Jira.Code, which makes the same in Confluence, looks like:
import com.atlassian.crowd.embedded.api.CrowdServiceimport com.atlassian.sal.api.component.ComponentLocatordef crowdService = ComponentLocator.getComponent(CrowdService)crowdService.isUserMemberOfGroup(context.currentUser?.name, "confluence-administrators")
It's in example scripts, you can check it by yourself, and find many other useful examples:
@Evgenii thank you so much for your help!
Sorry, I should have mentioned this in my original post, I tried the example script but am receiving an error:
[Statis type checking] - Cannot find matching method .com.atlassian.crowd.embedded.api.CrowdService#isUserMemberOfGroup(java.lang.Object, java.lang.String). Please check if the declared type is correct and if the method exists.
[Static type checking] - No such property: name for class: java.lang.Object
This is in a dev environment, I haven't tried it in a Prod environment. I don't know if that could cause an issue?
This ended up working for me, I'm not sure why the example script didn't or why this one does...
import com.atlassian.crowd.embedded.api.CrowdServiceimport com.atlassian.sal.api.component.ComponentLocatordef user = Users.getLoggedInUser().namedef crowdService = ComponentLocator.getComponent(CrowdService)crowdService.isUserMemberOfGroup(user, "confluence-administrators")
It looks like you're new here. Sign in or register to get started.