From 4ef4c1f288938e8f281dbd238d853926941b570c Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Thu, 20 Jan 2011 02:34:28 +0000 Subject: - When saving user changes to the database, catch errors and display them in a single sheet for review. This fixes a number of isGroupRow crashes on any error. - Track a host row's original host to allow host edits - Update localisable strings --- Interfaces/English.lproj/UserManagerView.xib | 545 +++++++++++++++++++++++- Models/SPUserManager.xcdatamodel/elements | Bin 132168 -> 135130 bytes Models/SPUserManager.xcdatamodel/layout | Bin 9663 -> 9663 bytes Resources/English.lproj/DBView.strings | Bin 100436 -> 100462 bytes Resources/English.lproj/Localizable.strings | Bin 211178 -> 212828 bytes Resources/English.lproj/UserManagerView.strings | Bin 14802 -> 16228 bytes Source/SPUserManager.h | 7 + Source/SPUserManager.m | 74 +++- 8 files changed, 595 insertions(+), 31 deletions(-) diff --git a/Interfaces/English.lproj/UserManagerView.xib b/Interfaces/English.lproj/UserManagerView.xib index 795c247c..fbde0774 100644 --- a/Interfaces/English.lproj/UserManagerView.xib +++ b/Interfaces/English.lproj/UserManagerView.xib @@ -2,10 +2,10 @@ 1050 - 10F569 - 804 - 1038.29 - 461.00 + 10J567 + 788 + 1038.35 + 462.00 YES @@ -15,18 +15,19 @@ YES - 804 + 788 1.2.5 YES - + + YES - com.brandonwalkin.BWToolkit com.apple.InterfaceBuilder.CocoaPlugin + com.brandonwalkin.BWToolkit YES @@ -56,7 +57,7 @@ User Managment NSWindow - {3.40282e+38, 3.40282e+38} + {1.79769e+308, 1.79769e+308} {752, 506} @@ -148,7 +149,7 @@ controlBackgroundColor 3 - MC42NjY2NjY2ODY1AA + MC42NjY2NjY2NjY3AA @@ -2224,7 +2225,7 @@ {{0, 0}, {1680, 1028}} {752, 528} - {3.40282e+38, 3.40282e+38} + {1.79769e+308, 1.79769e+308} @@ -2430,6 +2431,201 @@ + + 9 + 2 + {{157, 20}, {480, 441}} + 1954022400 + Errors Sheet + NSWindow + + + + 256 + + YES + + + 268 + {{17, 327}, {446, 94}} + + YES + + 67239424 + 272891904 + RXJyb3JzIG9jY3VycmVkIHdoZW4gYXBwbHlpbmcgeW91ciBjaGFuZ2VzIHRvIHRoZSBzZXJ2ZXIuCgpT +b21lIGNoYW5nZXMgbWF5IGhhdmUgYWxyZWFkeSBiZWVuIGFwcGxpZWQ7IHBsZWFzZSByZXZpZXcgdGhl +IGVycm9ycyBiZWxvdyBiZWZvcmUgcHJvY2VlZGluZy4 + + LucidaGrande + 13 + 16 + + + + + + + + + 274 + + YES + + + 2304 + + YES + + + 2322 + {438, 25} + + + + + + + + + + + YES + + + 134 + + + + 438 + 1 + + + 11237 + 0 + + + + YES + + YES + NSBackgroundColor + NSColor + + + YES + + 6 + System + selectedTextBackgroundColor + + + + 6 + System + selectedTextColor + + + + + + + YES + + YES + NSColor + NSCursor + NSUnderline + + + YES + + 1 + MCAwIDEAA + + + {8, -8} + 13 + + + + + + + 6 + {463, 1e+07} + {223, 25} + + + + {{1, 1}, {438, 257}} + + + + + + {4, -5} + 1 + + 4 + + + + -2147483392 + {{424, 1}, {15, 257}} + + + _doScroller: + 1 + 0.85256409645080566 + + + + -2147483392 + {{-100, -100}, {87, 18}} + + 1 + + _doScroller: + 1 + 0.94565218687057495 + + + {{20, 60}, {440, 259}} + + + 562 + + + + + + + 268 + {{314, 12}, {152, 32}} + + YES + + 67239424 + 134217728 + OK + + + -2038284033 + 129 + + DQ + 200 + 25 + + + + {480, 441} + + + {{0, 0}, {1440, 878}} + {1.79769e+308, 1.79769e+308} + @@ -4145,6 +4341,30 @@ 982 + + + errorsSheet + + + + 993 + + + + errorsTextView + + + + 994 + + + + closeErrorsSheet: + + + + 998 + @@ -5411,6 +5631,80 @@ + + 983 + + + YES + + + + + + 984 + + + YES + + + + + + + + 985 + + + YES + + + + + + 986 + + + + + 987 + + + YES + + + + + + + + 988 + + + + + 989 + + + + + 990 + + + + + 995 + + + YES + + + + + + 996 + + + @@ -5594,6 +5888,19 @@ 973.IBNumberFormatterBehaviorMetadataKey 973.IBNumberFormatterLocalizesFormatMetadataKey 973.IBPluginDependency + 983.IBEditorWindowLastContentRect + 983.IBPluginDependency + 983.IBWindowTemplateEditedContentRect + 983.NSWindowTemplate.visibleAtLaunch + 984.IBPluginDependency + 985.IBPluginDependency + 986.IBPluginDependency + 987.IBPluginDependency + 988.IBPluginDependency + 989.IBPluginDependency + 990.IBPluginDependency + 995.IBPluginDependency + 996.IBPluginDependency YES @@ -5617,9 +5924,9 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{315, 326}, {815, 506}} + {{187, 326}, {815, 506}} com.apple.InterfaceBuilder.CocoaPlugin - {{315, 326}, {815, 506}} + {{187, 326}, {815, 506}} {752, 506} @@ -5795,6 +6102,19 @@ com.apple.InterfaceBuilder.CocoaPlugin + {{348, 393}, {480, 441}} + com.apple.InterfaceBuilder.CocoaPlugin + {{348, 393}, {480, 441}} + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -5813,7 +6133,7 @@ - 982 + 998 @@ -5833,10 +6153,10 @@ - NSObject + NSMenu IBProjectSource - Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h + Source/SPMenuAdditions.h @@ -5920,6 +6240,143 @@ Source/SPTablesList.h + + NSTextView + + YES + + YES + doDecomposedStringWithCanonicalMapping: + doDecomposedStringWithCompatibilityMapping: + doPrecomposedStringWithCanonicalMapping: + doPrecomposedStringWithCompatibilityMapping: + doRemoveDiacritics: + doSelectionLowerCase: + doSelectionTitleCase: + doSelectionUpperCase: + doTranspose: + executeBundleItemForInputField: + insertNULLvalue: + moveSelectionLineDown: + moveSelectionLineUp: + selectCurrentLine: + selectCurrentWord: + selectEnclosingBrackets: + + + YES + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + + + + YES + + YES + doDecomposedStringWithCanonicalMapping: + doDecomposedStringWithCompatibilityMapping: + doPrecomposedStringWithCanonicalMapping: + doPrecomposedStringWithCompatibilityMapping: + doRemoveDiacritics: + doSelectionLowerCase: + doSelectionTitleCase: + doSelectionUpperCase: + doTranspose: + executeBundleItemForInputField: + insertNULLvalue: + moveSelectionLineDown: + moveSelectionLineUp: + selectCurrentLine: + selectCurrentWord: + selectEnclosingBrackets: + + + YES + + doDecomposedStringWithCanonicalMapping: + id + + + doDecomposedStringWithCompatibilityMapping: + id + + + doPrecomposedStringWithCanonicalMapping: + id + + + doPrecomposedStringWithCompatibilityMapping: + id + + + doRemoveDiacritics: + id + + + doSelectionLowerCase: + id + + + doSelectionTitleCase: + id + + + doSelectionUpperCase: + id + + + doTranspose: + id + + + executeBundleItemForInputField: + id + + + insertNULLvalue: + id + + + moveSelectionLineDown: + id + + + moveSelectionLineUp: + id + + + selectCurrentLine: + id + + + selectCurrentWord: + id + + + selectEnclosingBrackets: + id + + + + + IBProjectSource + Source/SPTextViewAdditions.h + + NSWindow @@ -5946,6 +6403,7 @@ addSchemaPriv: addUser: checkAllPrivileges: + closeErrorsSheet: doApply: doCancel: refresh: @@ -5967,6 +6425,7 @@ id id id + id @@ -5977,6 +6436,7 @@ addSchemaPriv: addUser: checkAllPrivileges: + closeErrorsSheet: doApply: doCancel: refresh: @@ -6003,6 +6463,10 @@ checkAllPrivileges: id + + closeErrorsSheet: + id + doApply: id @@ -6040,6 +6504,8 @@ addSchemaPrivButton availableController availableTableView + errorsSheet + errorsTextView grantedController grantedTableView maxConnectionsTextField @@ -6060,6 +6526,8 @@ NSButton NSArrayController NSTableView + NSWindow + NSTextView NSArrayController NSTableView NSTextField @@ -6083,6 +6551,8 @@ addSchemaPrivButton availableController availableTableView + errorsSheet + errorsTextView grantedController grantedTableView maxConnectionsTextField @@ -6112,6 +6582,14 @@ availableTableView NSTableView + + errorsSheet + NSWindow + + + errorsTextView + NSTextView + grantedController NSArrayController @@ -6676,6 +7154,27 @@ PrintCore.framework/Headers/PDEPluginInterface.h + + NSObject + + IBFrameworkSource + ShortcutRecorder.framework/Headers/SRRecorderCell.h + + + + NSObject + + IBFrameworkSource + ShortcutRecorder.framework/Headers/SRRecorderControl.h + + + + NSObject + + IBFrameworkSource + ShortcutRecorder.framework/Headers/SRValidator.h + + NSObject @@ -6878,6 +7377,14 @@ NSControl + + NSText + NSView + + IBFrameworkSource + AppKit.framework/Headers/NSText.h + + NSTextField NSControl @@ -6894,6 +7401,14 @@ AppKit.framework/Headers/NSTextFieldCell.h + + NSTextView + NSText + + IBFrameworkSource + AppKit.framework/Headers/NSTextView.h + + NSTreeController NSObjectController diff --git a/Models/SPUserManager.xcdatamodel/elements b/Models/SPUserManager.xcdatamodel/elements index d9f1e943..01aa994f 100644 Binary files a/Models/SPUserManager.xcdatamodel/elements and b/Models/SPUserManager.xcdatamodel/elements differ diff --git a/Models/SPUserManager.xcdatamodel/layout b/Models/SPUserManager.xcdatamodel/layout index 7e8fd9cf..d177ace3 100644 Binary files a/Models/SPUserManager.xcdatamodel/layout and b/Models/SPUserManager.xcdatamodel/layout differ diff --git a/Resources/English.lproj/DBView.strings b/Resources/English.lproj/DBView.strings index f7096605..35f47990 100644 Binary files a/Resources/English.lproj/DBView.strings and b/Resources/English.lproj/DBView.strings differ diff --git a/Resources/English.lproj/Localizable.strings b/Resources/English.lproj/Localizable.strings index 345a08ee..101f45e3 100644 Binary files a/Resources/English.lproj/Localizable.strings and b/Resources/English.lproj/Localizable.strings differ diff --git a/Resources/English.lproj/UserManagerView.strings b/Resources/English.lproj/UserManagerView.strings index bf8bad55..9f31028f 100644 Binary files a/Resources/English.lproj/UserManagerView.strings and b/Resources/English.lproj/UserManagerView.strings differ diff --git a/Source/SPUserManager.h b/Source/SPUserManager.h index c4eff098..8bb4e4d2 100644 --- a/Source/SPUserManager.h +++ b/Source/SPUserManager.h @@ -59,6 +59,9 @@ IBOutlet NSTextField *userNameTextField; + IBOutlet NSWindow *errorsSheet; + IBOutlet NSTextView *errorsTextView; + IBOutlet BWAnchoredButtonBar *splitViewButtonBar; NSMutableArray *schemas; @@ -67,6 +70,9 @@ NSArray *treeSortDescriptors; NSSortDescriptor *treeSortDescriptor; + + BOOL isSaving; + NSMutableString *errorsString; } @property (nonatomic, retain) MCPConnection *mySqlConnection; @@ -93,6 +99,7 @@ - (IBAction)doApply:(id)sender; - (IBAction)checkAllPrivileges:(id)sender; - (IBAction)uncheckAllPrivileges:(id)sender; +- (IBAction)closeErrorsSheet:(id)sender; // Schema Privieges - (IBAction)addSchemaPriv:(id)sender; diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m index 87b01cdc..9118d8a9 100644 --- a/Source/SPUserManager.m +++ b/Source/SPUserManager.m @@ -91,6 +91,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; schemas = [[NSMutableArray alloc] init]; availablePrivs = [[NSMutableArray alloc] init]; grantedSchemaPrivs = [[NSMutableArray alloc] init]; + isSaving = NO; } return self; @@ -367,6 +368,10 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; { // Assumes that the child has already been initialized with values from the // global user table. + + // Set an originalhost key on the child to allow the tracking of edits + [child setPrimitiveValue:[child valueForKey:@"host"] forKey:@"originalhost"]; + // Select rows from the db table that contains schema privs for each user/host NSString *queryString = [NSString stringWithFormat:@"SELECT * from mysql.db d WHERE d.user = %@ and d.host = %@", [[[child parent] valueForKey:@"user"] tickQuotedString], [[child valueForKey:@"host"] tickQuotedString]]; @@ -601,21 +606,29 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; - (IBAction)doApply:(id)sender { NSError *error = nil; + errorsString = [[NSMutableString alloc] init]; //Change the first responder to end editing in any field [[self window] makeFirstResponder:self]; + isSaving = YES; [[self managedObjectContext] save:&error]; - - if (error != nil) { - [[NSApplication sharedApplication] presentError:error]; - } - else { - // Close sheet - [self.mySqlConnection queryString:@"FLUSH PRIVILEGES"]; - [NSApp endSheet:[self window] returnCode:0]; - [[self window] orderOut:self]; + isSaving = NO; + if (error != nil) [errorsString appendString:[error localizedDescription]]; + + [self.mySqlConnection queryString:@"FLUSH PRIVILEGES"]; + + // Display any errors + if ([errorsString length]) { + [errorsTextView setString:errorsString]; + [NSApp beginSheet:errorsSheet modalForWindow:[NSApp keyWindow] modalDelegate:nil didEndSelector:NULL contextInfo:nil]; + [errorsString release]; + return; } + + // Otherwise, close the sheet + [NSApp endSheet:[self window] returnCode:0]; + [[self window] orderOut:self]; } /** @@ -955,12 +968,25 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; } } +/** + * Closes the supplied sheet, before closing the master window. + */ +- (IBAction)closeErrorsSheet:(id)sender +{ + [NSApp endSheet:[sender window] returnCode:[sender tag]]; + [[sender window] orderOut:self]; + + // Close the window + [NSApp endSheet:[self window] returnCode:0]; + [[self window] orderOut:self]; +} + #pragma mark - #pragma mark Notifications /** * This notification is called when the managedObjectContext save happens. - * This takes the inserted, updated, and deleted arrays and applys them to + * This takes the inserted, updated, and deleted arrays and applies them to * the database. */ - (void)contextDidSave:(NSNotification *)notification @@ -1016,7 +1042,7 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; NSString *renameUserStatement = [NSString stringWithFormat: @"RENAME USER %@@%@ TO %@@%@", [[user valueForKey:@"originaluser"] tickQuotedString], - [[child host] tickQuotedString], + [([child valueForKey:@"originalhost"]?[child valueForKey:@"originalhost"]:[child host]) tickQuotedString], [[user valueForKey:@"user"] tickQuotedString], [[child host] tickQuotedString]]; @@ -1041,6 +1067,19 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; } } else { + + // If the hostname has changed, remane the detail before editing details. + if (![[user valueForKey:@"host"] isEqualToString:[user valueForKey:@"originalhost"]]) { + NSString *renameUserStatement = [NSString stringWithFormat: + @"RENAME USER %@@%@ TO %@@%@", + [[[user parent] valueForKey:@"originaluser"] tickQuotedString], + [[user valueForKey:@"originalhost"] tickQuotedString], + [[[user parent] valueForKey:@"user"] tickQuotedString], + [[user valueForKey:@"host"] tickQuotedString]]; + + [self.mySqlConnection queryString:renameUserStatement]; + } + if ([serverSupport supportsUserMaxVars]) [self updateResourcesForUser:user]; [self grantPrivilegesToUser:user]; @@ -1387,11 +1426,14 @@ static const NSString *SPTableViewNameColumnID = @"NameColumn"; - (BOOL)_checkAndDisplayMySqlError { if ([self.mySqlConnection queryErrored]) { - - SPBeginAlertSheet(NSLocalizedString(@"An error occurred", @"mysql error occurred message"), - NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occurred whilst trying to perform the operation.\n\nMySQL said: %@", @"mysql error occurred informative message"), [self.mySqlConnection getLastErrorMessage]]); - + if (isSaving) { + [errorsString appendFormat:@"%@\n", [self.mySqlConnection getLastErrorMessage]]; + } else { + SPBeginAlertSheet(NSLocalizedString(@"An error occurred", @"mysql error occurred message"), + NSLocalizedString(@"OK", @"OK button"), nil, nil, [self window], self, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"An error occurred whilst trying to perform the operation.\n\nMySQL said: %@", @"mysql error occurred informative message"), [self.mySqlConnection getLastErrorMessage]]); + } + return NO; } -- cgit v1.2.3