I'm banging my head against this. I'm pretty sure it's simple but my MySQL is pretty rusty. What I'd like to do is return usernames, full name email address and group memeberships for users who are both in "jira-login" and in another one of a list of groups. Example:
davebloggs is in jira-login and client1 and his details should be in the results
fredbloggs is in client1 but not in jira-login his details should be excluded
joebloggs is in client2 and jira-login and his details should be returned
billbloggs is in jira-login only and his details should be excluded
Can anyone help?
Hi Graham, you can retrieve the list of members of a group with the following query:
select * from cwd_membership where parent_name = '<group_name>';
Then, you can run another query like this to return the user informtion:
select * from cwd_user where lower_user_name in (select child_name from cwd_membership where parent_name = '<group_name>')
I hope it helps.
Cheers
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you have "Nested Groups" enabled, this isn't going to be easy. However, if you do not mind getting only the direct members and that you will also get answers for disabled directories, I think you want something like this:
SELECT cu.user_name, cu.display_name, cu.email_address FROM cwd_user AS cu INNER JOIN cwd_membership AS cm ON cu.directory_id=cm.directory_id AND cu.lower_user_name=cm.lower_child_name AND cm.membership_type='GROUP_USER' WHERE cm.lower_parent_name='jira-login';
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry, that gets all of those in jira-login... rereading your requirements, add to this something like:
AND EXISTS ( SELECT 1 FROM cwd_membership x WHERE x.directory_id=cu.directory_id AND x.lower_child_name=cu.lower_user_name AND x.lower_parent_name <> 'jira-login' )
It's a bit gross, but should get you there.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks very much. One question though. If I want to return a list of users who are in both jira-login AND "client1" where do I define "client1"?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The last line would become
AND x.lower_parent_name = 'client1' )
to be more specific about the name of the second group.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Apologies for the late reply. I've tried this but it's returning users who are not in the group specified in "AND
x.lower_parent_name =
'client1'
)"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
How I can know that users are only included in a group?
Thanks!!
Eva
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.