Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Get all project that use a group crowd

Salim Hammar
Contributor
April 15, 2022

Hi everyone 

I would like get all project use the groups 

Example : 

Groups Crow : test-administrators ; test-developers

Project used the groups test-administrators : Test1 and Test2

 

I to do this script but he don't work 

script_groups.png

 

Have you idea ?? 

 

Thanks in advance

 

2 answers

0 votes
Nic Brough -Adaptavist-
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.
April 23, 2022

Hmm, this one has thrown me a bit of a curveball.

My initial answer was going to boil down to "define 'use'", but I wanted to think about it a bit before answering, and it got complicated.

The "define 'use'" matters though - a project could be using a group in all sorts of ways.  The obvious one is the stuff around permissions that I think this question is about (possibly as simple as "what groups can see this project?"?), but there's more.  Do you have group-picker fields?  Have you used groups in the notifications scheme?  Or the security scheme?  Have you used groups in the workflows?

That's not the curveball though, it's just checking I am thinking about the right question.

Assuming it is about "groups who have permissions in the projects", then there is a complexity you'll need to think about.  Going back to "Can this group see the issues" as the simple example, then it is not a simple question because you could set up the "browse project" permission with:

  • Group X can see it.
  • Role Y can see it, and someone has added Group X to role Y
  • Custom field Z (a group-picker field) can see it and someone has selected group Z for some issues

So, the curveball is in @PD Sheehan 's code.  I do not know if that drills down into the three lines above.  It will either return

Where Group X has been used in the permission scheme

or

Where Group X has made its way into the permission scheme by being named directly, or by being added to a role or group-picker.

I really do hope the code there will literally return all the groups that have a permission, by whatever route, but I don't know.

Please, do let us know if it does!  I'd be very grateful to find out!

(Actually, the bit about the group-picker is a bit of a red-herring, I do know how that works, and you do not want the long boring essay that ends up with "just don't use group-pickers in permission schemes, it's probably not going to do what you expect")

PD Sheehan
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.
April 23, 2022

Yeah @Nic Brough -Adaptavist- I made some assumptions about where the OP was attempting to go based on some of the code they had already written.

Since the code was already attempting to get all the groups that have BROWSE permission, I just fixed the part of the code that was comparing the list for a given project against the group specified by the form/annotation.

But you were correct to be cautious... 

It turns out that permissionManager.getAllGroups() returns only the groups added directly to the permissions scheme.

It doesn't include roles granted access via project roles.

Like Nic Brough -Adaptavist- likes this
0 votes
PD Sheehan
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.
April 23, 2022

This is working for me:

import com.onresolve.scriptrunner.parameters.annotation.ShortTextInput
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.Permissions

@ShortTextInput(description = 'Select admin group to search for', label = 'Admin group')
String adminGroup
def group = ComponentAccessor.groupManager.getGroup(adminGroup)
assert group, "No group found by the name of $adminGroup"
def
projects = ComponentAccessor.projectManager.projectObjects
def projectsWithGroup = []
projects.each{
def listGroups = ComponentAccessor.permissionManager.getAllGroups(Permissions.BROWSE, it)
if(listGroups.contains(group)){
projectsWithGroup.add(it)
}
}
"Projects containing $group.name: <br>${projectsWithGroup.collect{"$it.name ($it.key)"}.join('<br>')}"

But you want to look for an alternative solution since the "com.atlassian.jira.security.Permissions" is deprecated. Strangely, they've not deprecated the permissionsManager.getAllGroups method. It's the only one that still requires the Permissions class and there is no replacement.

Salim Hammar
Contributor
May 11, 2022

Hello

Thank for your answer but i have the errors :

errorss.png

 

Have you idea for this errrors

 

Thanks in advance

Nic Brough -Adaptavist-
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.
May 11, 2022

Your code is structured incorrectly, but you have not shown us all of the code, so we can't see where the problem might be.

Salim Hammar
Contributor
May 11, 2022

Sorry is here : 

 2022-05-11 11_30_50-Script Editor.png

PD Sheehan
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.
May 11, 2022

What errors do you get when you execute that script?

Not all errors in the editor are real. Most "static type checking" errors are just warning that the editor in unable to confirm the type of the object in question (in this case "it" an element of the projectsWithGroup) and therefore can't confirm if the property or method being called (.name and .key) is valid.

If you really want to eliminate this error, you can add

import com.atlassian.jira.project.Project

Then define the projectsWithGroup using a typed declaration:

List<Project> projectsWithGroup= []

Suggest an answer

Log in or Sign up to answer