From 9903700d95e23ad908ba3b3185e6a56a1206f659 Mon Sep 17 00:00:00 2001 From: mltownsend Date: Thu, 4 Feb 2010 18:21:45 +0000 Subject: Fix for issue #560. Still needs validation on hitting Apply, but fixes the initial problem. --- Source/SPUserManager.m | 58 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) (limited to 'Source/SPUserManager.m') diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m index 09d26f1f..b91a019b 100644 --- a/Source/SPUserManager.m +++ b/Source/SPUserManager.m @@ -474,11 +474,60 @@ } } + if ([selectedObject parent] != nil && [selectedObject host] == nil) + { + [selectedObject setValue:@"%" forKey:@"host"]; + [outlineView reloadItem:selectedObject]; + } [schemasTableView deselectAll:nil]; [grantedTableView deselectAll:nil]; [availableTableView deselectAll:nil]; } +-(BOOL)selectionShouldChangeInOutlineView:(NSOutlineView *)outlineView +{ + if ([[treeController selectedObjects] count] > 0) + { + id selectedObject = [[treeController selectedObjects] objectAtIndex:0]; + // Check parents + if ([selectedObject valueForKey:@"parent"] == nil) + { + NSString *name = [selectedObject valueForKey:@"user"]; + NSArray *results = [self _fetchUserWithUserName:name]; + if ([results count] > 1) + { + NSAlert *alert = [NSAlert alertWithMessageText:@"Duplicate User" + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:@"A user with that name already exists"]; + [alert runModal]; + return NO; + } + } + else + { + NSArray *children = [selectedObject valueForKeyPath:@"parent.children"]; + NSString *host = [selectedObject valueForKey:@"host"]; + for (NSManagedObject *child in children) + { + if (![selectedObject isEqual:child] && [[child valueForKey:@"host"] isEqualToString:host]) + { + NSAlert *alert = [NSAlert alertWithMessageText:@"Duplicate Host" + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:@"A user with that host already exists"]; + [alert runModal]; + return NO; + } + } + } + + } + return YES; +} + - (NSArray *)treeSortDescriptors { NSSortDescriptor *descriptor = [[[NSSortDescriptor alloc] initWithKey:@"displayName" ascending:YES] autorelease]; @@ -635,8 +684,7 @@ { if ([self.managedObjectContext hasChanges]) { - //NSAlert *alert = [[[NSAlert alloc] init] autorelease]; - NSAlert *alert = [NSAlert alertWithMessageText:@"Window has changes. All changes will be lost!" + NSAlert *alert = [NSAlert alertWithMessageText:@"Warning!" defaultButton:NSLocalizedString(@"Continue", @"Continue") alternateButton:NSLocalizedString(@"Cancel",@"Cancel") otherButton:nil @@ -1050,7 +1098,11 @@ - (BOOL)checkAndDisplayMySqlError { if (![[self.mySqlConnection getLastErrorMessage] isEqualToString:@""]) { - NSAlert *alert = [NSAlert alertWithMessageText:@"MySQL Error" defaultButton:@"OK" alternateButton:nil otherButton:nil informativeTextWithFormat:[self.mySqlConnection getLastErrorMessage]]; + NSAlert *alert = [NSAlert alertWithMessageText:@"MySQL Error" + defaultButton:NSLocalizedString(@"OK", @"OK button") + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[self.mySqlConnection getLastErrorMessage]]; [alert runModal]; return NO; -- cgit v1.2.3