From d0fb716108641d3a8c197ef12041bf46b14e7294 Mon Sep 17 00:00:00 2001 From: mltownsend Date: Tue, 9 Feb 2010 20:28:33 +0000 Subject: Fixed some issues with the drop user/drop host commands in the user manager --- Source/SPUserMO.m | 1 - Source/SPUserManager.m | 34 ++++++++++++++++++++++++------ Source/SPUserManager.xcdatamodel/elements | Bin 127988 -> 127762 bytes Source/SPUserManager.xcdatamodel/layout | Bin 9663 -> 9663 bytes 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/Source/SPUserMO.m b/Source/SPUserMO.m index c4980391..061f4658 100644 --- a/Source/SPUserMO.m +++ b/Source/SPUserMO.m @@ -66,5 +66,4 @@ [changedObjects release]; } - @end diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m index a65de9ee..e81ca2a2 100644 --- a/Source/SPUserManager.m +++ b/Source/SPUserManager.m @@ -497,7 +497,7 @@ if ([results count] > 1) { NSAlert *alert = [NSAlert alertWithMessageText:@"Duplicate User" - defaultButton:NSLocalizedString(@"OK", @"OK button") + defaultButton:NSLocalizedString(@"OK", @"OK") alternateButton:nil otherButton:nil informativeTextWithFormat:@"A user with that name already exists"]; @@ -514,7 +514,7 @@ if (![selectedObject isEqual:child] && [[child valueForKey:@"host"] isEqualToString:host]) { NSAlert *alert = [NSAlert alertWithMessageText:@"Duplicate Host" - defaultButton:NSLocalizedString(@"OK", @"OK button") + defaultButton:NSLocalizedString(@"OK", @"OK") alternateButton:nil otherButton:nil informativeTextWithFormat:@"A user with that host already exists"]; @@ -634,6 +634,14 @@ - (IBAction)removeUser:(id)sender { + NSString *username = [[[treeController selectedObjects] objectAtIndex:0] + valueForKey:@"user"]; + NSArray *children = [[[treeController selectedObjects] objectAtIndex:0] + valueForKey:@"children"]; + for(NSManagedObject *child in children) + { + [child setPrimitiveValue:username forKey:@"user"]; + } [treeController remove:sender]; } @@ -661,7 +669,21 @@ - (IBAction)removeHost:(id)sender { + // Set the username on the child so that it's accessabile when building + // the drop sql command + NSManagedObject *child = [[treeController selectedObjects] objectAtIndex:0]; + NSManagedObject *parent = [child valueForKey:@"parent"]; + [child setPrimitiveValue:[[child valueForKey:@"parent"] valueForKey:@"user"] forKey:@"user"]; [treeController remove:sender]; + if ([[parent valueForKey:@"children"] count] == 0) + { + NSAlert *alert = [NSAlert alertWithMessageText:@"User doesn't have any hosts." + defaultButton:NSLocalizedString(@"OK", @"OK") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:@"This user doesn't have any hosts associated with it. User will be deleted unless one is added"]; + [alert runModal]; + } } - (IBAction)addSchemaPriv:(id)sender @@ -690,8 +712,8 @@ if ([self.managedObjectContext hasChanges]) { NSAlert *alert = [NSAlert alertWithMessageText:@"Warning!" - defaultButton:NSLocalizedString(@"Continue", @"continue button") - alternateButton:NSLocalizedString(@"Cancel",@"cancel button") + defaultButton:NSLocalizedString(@"Continue", @"Continue") + alternateButton:NSLocalizedString(@"Cancel",@"Cancel") otherButton:nil informativeTextWithFormat:@"Window has changes. All changes will be lost!"]; [alert setAlertStyle:NSWarningAlertStyle]; @@ -889,7 +911,7 @@ NSMutableString *droppedUsers = [NSMutableString string]; for (NSManagedObject *user in deletedUsers) { - if ([user host] != nil) + if (![[[user entity] name] isEqualToString:@"Privileges"] && [user valueForKey:@"host"] != nil) { [droppedUsers appendString:[NSString stringWithFormat:@"%@@%@, ", [[user valueForKey:@"user"] backtickQuotedString], @@ -1115,7 +1137,7 @@ { if (![[self.mySqlConnection getLastErrorMessage] isEqualToString:@""]) { NSAlert *alert = [NSAlert alertWithMessageText:@"MySQL Error" - defaultButton:NSLocalizedString(@"OK", @"OK button") + defaultButton:NSLocalizedString(@"OK", @"OK") alternateButton:nil otherButton:nil informativeTextWithFormat:[self.mySqlConnection getLastErrorMessage]]; diff --git a/Source/SPUserManager.xcdatamodel/elements b/Source/SPUserManager.xcdatamodel/elements index b651569a..66ebccfc 100644 Binary files a/Source/SPUserManager.xcdatamodel/elements and b/Source/SPUserManager.xcdatamodel/elements differ diff --git a/Source/SPUserManager.xcdatamodel/layout b/Source/SPUserManager.xcdatamodel/layout index f55e70d0..44b16b93 100644 Binary files a/Source/SPUserManager.xcdatamodel/layout and b/Source/SPUserManager.xcdatamodel/layout differ -- cgit v1.2.3