validating user properties in create issue transition

Hello,

I wanted to validate user's group while creating issue. We have a field GROUP which is in user property. I wanted to allow create issue permission to one particular group of users. 

I have a user property named GROUP with values G1,G2,G3,G4. Only G1 users can create issues. I wanted to restrict create issue access to other GROUP users.

I tried to add validator in Create transition using following script but no luck :

import com.atlassian.jira.component.ComponentAccessor

import com.atlassian.jira.user.UserPropertyManager

UserPropertyManager userPropertyManager = ComponentAccessor.getUserPropertyManager()

if (issue.reporter) {
userPropertyManager.getPropertySet("GROUP") != 'G1'
}

How can I achieve this?

Thanks in advance.

1 answer

This widget could not be displayed.

Why are you doing this?  You can achieve the same far more cleanly and better with simple group memberships.

Hello,

Could you please precise?

FYI we don't have any 'User GROUP'. These user categories are driven from external ED using scripts. This user details (G1,G2,G3,G4) are present only under 'User Properties' and yes also in Custom fields (using nfeed) but those values filled post creation of issue. 

 

But I need to validate while creating issue. If reporter is not in G1 then they cannot raise issues.

User Property Key : GROUP

Values : G1,G2,G3 and G4

Thanks.

I don't understand why you are doing it this way.  It's clumsy, frail and not transparent.  You're doing a lot of work to do something JIRA does off-the-shelf in a really simple way.

Put your users into groups.  Use the permissions to say "only users in group 1 can create issues".

I have nearly 20k users. All users belongs to these categories. So it is difficult to find them and group. Users will get added on a daily basis. it is difficult to find them everyday and add them in group.

 

So i found using 'User Property' value is simplest.

It's absolutely not the simplest way to do it.

You still have to identify your users and then set a property to do it.  Why not simply set a group instead? 

Also, this makes me suspect that you're setting the user properties in a way that is wrong, as there's no easy way to do it reliably, and if you were doing it the reliable way, you would not need help with this question!

I know I'm not being "helpful" here, but your approach to this is pretty much broken, and it is always worth questioning it when we see that.

If you insist on persuing it badly though, then the problem is in your line

getPropertySet("GROUP") != 'G1'

This "get" does not return a simple string, it returns a whole property set for the user's properties.  Even if you have only set one, it's still the whole set that comes back.  This is documented at https://developer.atlassian.com/static/javadoc/opensymphony-propertyset/1.5/reference/com/opensymphony/module/propertyset/PropertySet.html and you'll see you need to find your property within that and pull it out to be compared.

But that's what you should have used when you are setting the properties (which is why I'm worried about how you are setting them)

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted Tuesday in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

258 views 1 3
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you