diff --git a/bin/populate_wtsi_irods_groups.pl b/bin/populate_wtsi_irods_groups.pl index ca1c0d32..f76648fa 100755 --- a/bin/populate_wtsi_irods_groups.pl +++ b/bin/populate_wtsi_irods_groups.pl @@ -44,6 +44,11 @@ sequencing tracked in the ML warehouse, the iRODS group will be left empty (except for the iRODS groupadmin user). +Studies which are marked as have samples contaminated with human which +should be removed will have an ss__human iRODS group created +when they do not exist - population of this group is performed outside +this process and should be tracked in an auditable manner by a ticket. + Script runs to perform such updates when no arguments are given. Options: @@ -72,7 +77,7 @@ exit 0; }, 'logconf=s' => \$log4perl_config, - 'study=i' => \@study_ids, + 'study_id=i' => \@study_ids, 'verbose' => \$verbose) or die "\n$what_on_earth\n"; if ($log4perl_config) { @@ -141,7 +146,7 @@ sub _uid_to_irods_uid { my $studies = $mlwh->resultset('Study')->search($query, {order_by => 'id_study_lims'}); -my ($group_count, $altered_count) = (0, 0); +my ($group_count, $altered_count, $altered_human_count) = (0, 0, 0); while (my $study = $studies->next){ my $study_id = $study->id_study_lims; my $dag_str = $study->data_access_group || q(); @@ -172,14 +177,21 @@ sub _uid_to_irods_uid { $altered_count++; } + if ($study->contaminated_human_dna) { + $altered_human_count += $iga->ensure_group_exists("ss_$study_id".'_human'); + } + $group_count++; } $log->debug("Altered $altered_count groups"); +$log->debug("Created $altered_human_count _human groups"); $log->info("When considering $group_count Sequencescape studies, ", - "$altered_count iRODS groups were created or their ", - 'membership altered (by ', $iga->_user, ')'); + $altered_count.' iRODS "ss_*" groups were created or their ', + 'membership altered, and '.$altered_human_count, + ' "ss_?????_human" groups were created (by ', + $iga->_user, ')'); # Find both gid and member uids for each group sub find_group_ids { diff --git a/lib/WTSI/NPG/iRODS/GroupAdmin.pm b/lib/WTSI/NPG/iRODS/GroupAdmin.pm index e5522d45..640fa282 100644 --- a/lib/WTSI/NPG/iRODS/GroupAdmin.pm +++ b/lib/WTSI/NPG/iRODS/GroupAdmin.pm @@ -191,15 +191,22 @@ sub _op_g_u { return; } -sub _ensure_existence_of_group { +=head2 ensure_group_exists + +Given a group ensure that it exists in iRODS by making it if it does not, and adding this admin user to it to ensure admin rights on it are retained. Return true if a group is created. + +=cut + +sub ensure_group_exists { my($self,$group)=@_; $self->__croak_on_bad_group_name($group); if ( any {$group eq $_} $self->lg){ return;} if ($self->dry_run) { - $self->info("Dry run: mkgroup '$group'"); + $self->info("Dry run: mkgroup '$group' and then atg..."); } else { $self->_push_pump_trim_split(qq(mkgroup "$group"\n)); + $self->_op_g_u('atg',$group, $self->_user); #add this user to empty group (first) so admin rights to operate on it are retained } return 1; #return true if we make a group } @@ -212,7 +219,7 @@ Given a group and list of members will ensure that the group exists and contains sub set_group_membership { my($self,$group,@members)=@_; - my $altered = $self->_ensure_existence_of_group($group); + my $altered = $self->ensure_group_exists($group); my @orig_members = $self->lg($group); $self->debug("Members of $group: ", join q(, ), @orig_members); if (@orig_members){ diff --git a/t/lib/WTSI/NPG/iRODS/GroupAdminTest.pm b/t/lib/WTSI/NPG/iRODS/GroupAdminTest.pm index 6f2b61a8..e560c4d0 100644 --- a/t/lib/WTSI/NPG/iRODS/GroupAdminTest.pm +++ b/t/lib/WTSI/NPG/iRODS/GroupAdminTest.pm @@ -44,7 +44,7 @@ sub setup_test : Test(setup) { sub teardown_test : Test(teardown) { my ($self) = @_; - $self->remove_irods_groups($test_irods, @irods_groups); + $self->remove_irods_groups($test_irods, @irods_groups, q(ss_newempty)); if ($self->have_admin_rights) { foreach my $user (@irods_users) { @@ -93,6 +93,45 @@ sub lg : Test(5) { 'Empty string group throw'; } +sub ensure_group_exists: Test(6) { + my ($self) = @_; + + my $irods = WTSI::NPG::iRODS->new(environment => \%ENV, + strict_baton_version => 0); + SKIP: { + if (not $self->have_admin_rights) { + skip 'No admin rights to create test groups', 5; + } + + my $zone = $irods->find_zone_name($irods->working_collection); + my $user = $irods->get_irods_user; + + my $iga = WTSI::NPG::iRODS::GroupAdmin->new; + + throws_ok { $iga->lg('ss_newempty') } qr/does not exist/sm, + 'Non-existent group throw for ss_newempty'; + + my$created=0; + lives_ok { + $created=$iga->ensure_group_exists('ss_newempty'); + } 'Create new group ss_newempty'; + ok($created, "Reports that group has been created"); + + my @observed_members = sort $iga->lg('ss_newempty'); + my @expected_members = ("$user#$zone"); + is_deeply(\@observed_members, \@expected_members, + 'Has expected admin user automatically added') or + diag explain \@observed_members; + + $created=1; + lives_ok { + $created=$iga->ensure_group_exists('ss_newempty'); + } 'Safe to run on existing group'; + + ok(!$created, "Reports that group has not been created"); + } +} + sub set_group_membership : Test(5) { my ($self) = @_;