[Rt-commit] rt branch, unique-group-names, updated. rt-3.9.4-531-gd477e02

Thomas Sibley trs at bestpractical.com
Fri Nov 19 11:36:49 EST 2010


The branch, unique-group-names has been updated
       via  d477e02f12a787e244181b02f17b1a79e95f5212 (commit)
      from  84b68b3784bddb2d30fe342e86308d6e570eed0d (commit)

Summary of changes:
 sbin/rt-validator.in |   22 ++++++++++++++++++++++
 1 files changed, 22 insertions(+), 0 deletions(-)

- Log -----------------------------------------------------------------
commit d477e02f12a787e244181b02f17b1a79e95f5212
Author: Thomas Sibley <trs at bestpractical.com>
Date:   Fri Nov 19 11:36:05 2010 -0500

    Check for non-unique UserDefined group names in rt-validator
    
    Automatically resolve the conflicts by appending the id.

diff --git a/sbin/rt-validator.in b/sbin/rt-validator.in
index bb8ca4a..194924d 100644
--- a/sbin/rt-validator.in
+++ b/sbin/rt-validator.in
@@ -179,6 +179,9 @@ $redo_on{'Create'} = {
     GroupMembers => [ 'CGM vs. GM' ],
     CachedGroupMembers => [ 'CGM vs. GM' ],
 };
+$redo_on{'Update'} = {
+    Groups => ['User Defined Group Name uniqueness'],
+};
 
 my %describe_cb;
 %describe_cb = (
@@ -355,6 +358,24 @@ push @CHECKS, 'Role Groups (Instance, Type) uniqueness' => sub {
     );
 };
 
+# CHECK that user defined group names are unique
+push @CHECKS, 'User Defined Group Name uniqueness' => sub {
+    check_uniqueness(
+        'Groups',
+        columns     => ['Name'],
+        condition   => '.Domain = ?',
+        bind_values => [ 'UserDefined' ],
+        action      => sub {
+            return unless prompt(
+                'Rename', "Found a user defined group with a non-unique Name."
+            );
+
+            my $id = shift;
+            my %cols = @_;
+            update_records('Groups', { id => $id }, { Name => join('-', $cols{'Name'}, $id) });
+        },
+    );
+};
 
 push @CHECKS, 'GMs -> Groups, Members' => sub {
     my $msg = "A record in GroupMembers references an object that doesn't exist."
@@ -990,6 +1011,7 @@ sub check_uniqueness {
         for ( my $i = 0; $i < @columns; $i++ ) {
             print STDERR "\t$columns[$i] => '$set[$i]'\n";
         }
+        $args{'action'}->( $tid, map { $columns[$_] => $set[$_] } (0 .. (@columns-1)) ) if $args{'action'};
     }
 }
 

-----------------------------------------------------------------------


More information about the Rt-commit mailing list