Skip to Content.
Sympa Menu

grouper-users - [grouper-users] RE: How to delete direct memberships without touching subgroups and their members

Subject: Grouper Users - Open Discussion List

List archive

[grouper-users] RE: How to delete direct memberships without touching subgroups and their members


Chronological Thread 
  • From: "Redman, Chad" <>
  • To: Rory Larson <>, "" <>
  • Subject: [grouper-users] RE: How to delete direct memberships without touching subgroups and their members
  • Date: Sat, 10 Feb 2018 06:43:35 +0000
  • Accept-language: en-US
  • Authentication-results: spf=none (sender IP is ) ;
  • Ironport-phdr: 9a23:w9uurB0rurBhVzhAsmDT+DRfVm0co7zxezQtwd8ZseMWL/ad9pjvdHbS+e9qxAeQG9mDsrQc06L/iOPJYSQ4+5GPsXQPItRndiQuroEopTEmG9OPEkbhLfTnPGQQFcVGU0J5rTngaRAGUMnxaEfPrXKs8DUcBgvwNRZvJuTyB4Xek9m72/q99pHPfglEniaxba9vJxiqsAvdsdUbj5F/Iagr0BvJpXVIe+VSxWx2IF+Yggjx6MSt8pN96ipco/0u+dJOXqX8ZKQ4UKdXDC86PGAv5c3krgfMQA2S7XYBSGoWkx5IAw/Y7BHmW5r6ryX3uvZh1CScIMb7Vq4/Vyi84Kh3SR/okCYHOCA/8GHLkcx7kaZXrAu8qxBj34LYZYeYP+d8cKzAZ9MXXWpPUNhMWSxdDI2ybIUPAOgAPelEoIfyqEADrQenBQWwGO/j1iNEimHw0KYn0+ohCwbG3Ak4Et4ArHrbssj6NKIIXuCz1KXD0CvOb/NM1jjg5oTDbxcsru2MXb1qbMXe0VMvGB3YgVWVs4PlOSiY1vkLs2eH9eZvS/+gi3M+pgx3vzOhxd8sh5HUio4JxV3I7yp0zYQvKdC3VUJ3e9ypHIZIuyyYNoZ6WN4uTmJ2tCogxLALuIS3cDYFxZkowRPUduaJfJKS4h35UeacOTd4i2xheLK4nxu86VStxOrgWsS6yVpEoC1Ln9fVunAKzBPc9NKLSvxg/ke9wjmP0B3T6udZLkwujarbMZkhwqIumZUPrUTDHyj2mEPsgK+Ra0Uk5uyo6+PgYrXlvJOTK4h0igTmPqQvnMywH/g4PxATU2SH9umwzrLu8E/jTLhFk/E6iKvUvI3CKcQevKG5AgtV0og56xa4CjeryMgXnXkdI11YYB2HlZbmNEzLIP/iC/eymEmskDF3yPzcILLuH4jNImDZkLj9ZbZ991JcyA0rwNBQ/ZJUDawBIOrtVU/rrdDYEwQ5PBKuw+b8E9h90oIeWXmTAq+CLq/eq16I5uQzI+aSfo8VvijyK+Q76/L0k3A2hEIdLuGV2s4tb2qpVtBvOV6eZzK4mNMIC3wNuFMWUeruzlCOTGgXLzy9RaUh/jwhTZ+9AJ3YboGrnLGb2iqnRNtban0MQgSDC3D1b4ieHuoXZTiJCs5njjEeU7W9Ecks2Qz45yHgzL8yZNDZ9igRs9ar/9h866ebwRoy/DBDFcmR1miLZ3xylSUFSyJgj/M3mlB01lrWifswuPdfD9EGoqoRCgo=
  • Spamdiagnosticmetadata: NSPM
  • Spamdiagnosticoutput: 1:99

Hi Rory,

The Group class has methods for getImmediateMembers() and
getEffectiveMembers(), so the combination of those two would make it a
straightforward task. Here are two sample scripts. Depending on your GSH
version (original bsh or the newer groovy), you may need to fold the
multi-line blocks into a single line.


# (1) Print tab-separated summary of all group members, and flags for direct,
indirect, or both
# Depending on the results, you could use the data to create a scrutinized
list of Ids to delete, then import it and delete in a loop

me = SubjectFinder.findByIdentifierAndSource("my-username", "pid", true);
session = GrouperSession.start(me);
// OR: session = GrouperSession.startRootSession(True)

group = GroupFinder.findByName(session, "tmp:my:group", true);

effectiveMembers = group.getEffectiveMembers();
immediateMembers = group.getImmediateMembers();

System.out.println(String.join("\t", "id", "name", "Effective", "Immediate"));

for (Member m: group.getMembers()) {
System.out.print(m.getSubject().getId() + "\t" + m.getSubject().getName()
+ "\t");
System.out.print(effectiveMembers.contains(m).toString() + "\t");
System.out.println(immediateMembers.contains(m).toString() + "\t");
}



# (2) Get the immediate and effective members for a specific source ("pid" in
this example), intersect them to find the redundant ones
# This has a dryRun flag, so you can test first

sources = new HashSet<Source>()
sources.add(SourceManager.getInstance().getSource("pid"))

effectiveUsers = group.getEffectiveMembers(Group.getDefaultList(), sources,
null)
immediateUsers = group.getImmediateMembers(Group.getDefaultList(), sources,
null)

# use retainAll() to find the intersection; i.e., users both as effective and
immediate member
immediateUsers.retainAll(effectiveUsers)

System.out.println("There are " + immediateUsers.size() + " users having both
direct + indirect memberships");

dryRun = true

for (Member m: immediateUsers) {
if (dryRun) {
System.out.println("Ok to delete " + m.getSubject().getId());
} else {
System.out.println("Deleting " + m.getSubject().getId());
group.deleteMember(m, false);
}
}


Hope this helps!

Chad








-----Original Message-----
From:


[mailto:]
On Behalf Of Rory Larson
Sent: Friday, February 09, 2018 8:52 PM
To:

Subject: [grouper-users] How to delete direct memberships without touching
subgroups and their members

Hello,

I have a group with largely redundant membership. It was originally created
with direct memberships from one data source, and then given a few groups
from another data source that had most of the same people, in a process
intended to be a smooth transition. Now I would like to remove all the old
direct memberships from the group, leaving only the new subgroups with their
members.

When I try this through the Grouper New UI, marking all direct members on the
page for deletion, it grinds for a while, deletes a few members, and then
crashes with a pink error message telling me to start over. It works as
advertised for the few it does delete, but since I'm dealing with a
membership of over 7500, this route does not look promising.

I would like to handle this through gsh, but I'm having trouble figuring out
how to filter. The query I've been developing might look something like this:

$ for (mem : getMembers("my:group:name")) {System.out.println("deleting: " +
mem.getName()); mem.delete();}

But I'm queasy about using this, because I'm not sure what all I'm deleting,
and where. I don't want to delete my subgroups, and I don't want to delete
anybody inside those subgroups. I tried testing with an if statement to
check names against who shows up with direct and indirect memberships in the
New UI, and was disappointed to discover that getMembers() returns both
direct and indirect members.

Is there a method that will return only the direct members of a group, but
not member groups? Or is there a filter I could use to select only the ones
I want through an if statement?

Thanks,
Rory




Archive powered by MHonArc 2.6.19.

Top of Page