You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
Hi
I want to check if the user is only in either Users and/or Watchers role .. I have this working but wondering if there is a more elegant way ?
if ( (remoteUsersRoles == ["Users"]) || ( remoteUsersRoles == ["Users","Watching"] ) || ( remoteUsersRoles == ["Watching", "Users"] ) )
Thanks in advance
Another approach to achieve what Nic suggested is:
def rolesToCheck = ['Users', 'Watching']
if( rolesToCheck.any{it in remoterUserRoles})
With 2 roles to check, it's not bad, but should you have a situation with a log more, having a bunch of OR groups would be tedious.
But if you desire to check if the user has some other roles or not, you can do it this way:
def rolesToCheck = ['Users', 'Watching']
def otherRoles = remoteUserRoles - rolesToCheck
if(remoteUserRoles && !otherRoles) {
//user has some roles, but no roles when you subtract both Users and Watching
} else if(remoteUserRoles && otherRoles) {
//user has remoteUsersRoles, and some other roles, you can inspect otherRoles to see what remains once you've removed users and watching
} else {
//remoteUserRoles was empty to start with, subtracting has no effect
}
I want to question the "watching" - do you genuinely have a project role of "watching" alongside the project roles like User, developer and administrator? (Assuming you've not removed the default project roles)
If you do, then I'd write your query as
if ("Users" in remoteUsersRoles || "Watching" in remoteUsersRoles )
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.