validating user properties in create issue transition

Rajeswari Thangavel July 17, 2017

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

0 votes
Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 18, 2017

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

Rajeswari Thangavel July 18, 2017

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 19, 2017

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".

Rajeswari Thangavel July 19, 2017

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.

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 19, 2017

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!

Nic Brough -Adaptavist-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
July 19, 2017

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