aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2010-05-03 15:55:55 +0000
committerrowanbeentje <rowan@beent.je>2010-05-03 15:55:55 +0000
commit77afbf92a968609371a41c84f1114747bd0d9629 (patch)
treee49a8afac9be1e1c3a3e87074cba6f6cbc79942c
parentfcdc950e186d1f6e616b5386e6d304dcae681a8a (diff)
downloadsequelpro-77afbf92a968609371a41c84f1114747bd0d9629.tar.gz
sequelpro-77afbf92a968609371a41c84f1114747bd0d9629.tar.bz2
sequelpro-77afbf92a968609371a41c84f1114747bd0d9629.zip
- Fix quoting of various fields, including usernames and passwords
- Restore ability to edit passwords - Fix the "Refresh" gear menu item not being connected to the action - Add support in code for renaming users - previously interface changes weren't saved - Fix user deletion support, including non-existant hosts. This addresses Issue #653.
-rw-r--r--Interfaces/English.lproj/UserManagerView.xib43
-rw-r--r--Source/SPUserManager.m84
-rw-r--r--Source/SPUserManager.xcdatamodel/elementsbin127771 -> 131784 bytes
-rw-r--r--Source/SPUserManager.xcdatamodel/layoutbin9663 -> 9663 bytes
4 files changed, 81 insertions, 46 deletions
diff --git a/Interfaces/English.lproj/UserManagerView.xib b/Interfaces/English.lproj/UserManagerView.xib
index 3d4b9a1d..d28c0761 100644
--- a/Interfaces/English.lproj/UserManagerView.xib
+++ b/Interfaces/English.lproj/UserManagerView.xib
@@ -2,7 +2,7 @@
<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.10">
<data>
<int key="IBDocument.SystemTarget">1050</int>
- <string key="IBDocument.SystemVersion">10D573</string>
+ <string key="IBDocument.SystemVersion">10D2094</string>
<string key="IBDocument.InterfaceBuilderVersion">762</string>
<string key="IBDocument.AppKitVersion">1038.29</string>
<string key="IBDocument.HIToolboxVersion">460.00</string>
@@ -21,12 +21,11 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="27"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
- <string>com.brandonwalkin.BWToolkit</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.brandonwalkin.BWToolkit</string>
</object>
<object class="NSMutableDictionary" key="IBDocument.Metadata">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -56,10 +55,10 @@
<string key="NSWindowTitle">User Managment</string>
<string key="NSWindowClass">NSWindow</string>
<nil key="NSViewClass"/>
- <string key="NSWindowContentMaxSize">{3.40282e+38, 3.40282e+38}</string>
+ <string key="NSWindowContentMaxSize">{1.79769e+308, 1.79769e+308}</string>
<string key="NSWindowContentMinSize">{752, 506}</string>
<object class="NSView" key="NSWindowView" id="846307432">
- <reference key="NSNextResponder"/>
+ <nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -148,7 +147,7 @@
<string key="NSColorName">controlBackgroundColor</string>
<object class="NSColor" key="NSColor" id="246134814">
<int key="NSColorSpace">3</int>
- <bytes key="NSWhite">MC42NjY2NjY2ODY1AA</bytes>
+ <bytes key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
</object>
</object>
<object class="NSColor" key="NSTextColor" id="315534074">
@@ -204,7 +203,6 @@
</object>
<string key="NSFrame">{{0, 17}, {194, 467}}</string>
<reference key="NSSuperview" ref="848314643"/>
- <reference key="NSNextKeyView" ref="265138544"/>
<reference key="NSDocView" ref="265138544"/>
<reference key="NSBGColor" ref="898983655"/>
<int key="NScvFlags">4</int>
@@ -238,7 +236,6 @@
</object>
<string key="NSFrameSize">{194, 17}</string>
<reference key="NSSuperview" ref="848314643"/>
- <reference key="NSNextKeyView" ref="98886535"/>
<reference key="NSDocView" ref="98886535"/>
<reference key="NSBGColor" ref="898983655"/>
<int key="NScvFlags">4</int>
@@ -247,7 +244,6 @@
</object>
<string key="NSFrame">{{0, 22}, {194, 484}}</string>
<reference key="NSSuperview" ref="490248567"/>
- <reference key="NSNextKeyView" ref="310332121"/>
<int key="NSsFlags">560</int>
<reference key="NSVScroller" ref="710626046"/>
<reference key="NSHScroller" ref="851800246"/>
@@ -400,6 +396,7 @@
</object>
</object>
</object>
+ <int key="NSSelectedIndex">4</int>
<bool key="NSPullDown">YES</bool>
<int key="NSPreferredEdge">1</int>
<bool key="NSUsesItemFromMenu">YES</bool>
@@ -1479,7 +1476,6 @@
</object>
<string key="NSFrame">{{1, 17}, {130, 363}}</string>
<reference key="NSSuperview" ref="307214944"/>
- <reference key="NSNextKeyView" ref="280739950"/>
<reference key="NSDocView" ref="280739950"/>
<reference key="NSBGColor" ref="898983655"/>
<int key="NScvFlags">4</int>
@@ -1514,7 +1510,6 @@
</object>
<string key="NSFrame">{{1, 0}, {130, 17}}</string>
<reference key="NSSuperview" ref="307214944"/>
- <reference key="NSNextKeyView" ref="406943647"/>
<reference key="NSDocView" ref="406943647"/>
<reference key="NSBGColor" ref="898983655"/>
<int key="NScvFlags">4</int>
@@ -1523,7 +1518,6 @@
</object>
<string key="NSFrame">{{17, 17}, {132, 381}}</string>
<reference key="NSSuperview" ref="601698335"/>
- <reference key="NSNextKeyView" ref="380397569"/>
<int key="NSsFlags">562</int>
<reference key="NSVScroller" ref="304497597"/>
<reference key="NSHScroller" ref="1067950228"/>
@@ -1610,7 +1604,6 @@
</object>
<string key="NSFrame">{{1, 17}, {130, 363}}</string>
<reference key="NSSuperview" ref="728294866"/>
- <reference key="NSNextKeyView" ref="64638447"/>
<reference key="NSDocView" ref="64638447"/>
<reference key="NSBGColor" ref="898983655"/>
<int key="NScvFlags">4</int>
@@ -1644,7 +1637,6 @@
</object>
<string key="NSFrame">{{1, 0}, {130, 17}}</string>
<reference key="NSSuperview" ref="728294866"/>
- <reference key="NSNextKeyView" ref="599931188"/>
<reference key="NSDocView" ref="599931188"/>
<reference key="NSBGColor" ref="898983655"/>
<int key="NScvFlags">4</int>
@@ -1653,7 +1645,6 @@
</object>
<string key="NSFrame">{{157, 17}, {132, 381}}</string>
<reference key="NSSuperview" ref="601698335"/>
- <reference key="NSNextKeyView" ref="239762482"/>
<int key="NSsFlags">562</int>
<reference key="NSVScroller" ref="210192488"/>
<reference key="NSHScroller" ref="253008686"/>
@@ -1739,7 +1730,6 @@
</object>
<string key="NSFrame">{{1, 17}, {130, 363}}</string>
<reference key="NSSuperview" ref="898351365"/>
- <reference key="NSNextKeyView" ref="443904239"/>
<reference key="NSDocView" ref="443904239"/>
<reference key="NSBGColor" ref="898983655"/>
<int key="NScvFlags">4</int>
@@ -1774,7 +1764,6 @@
</object>
<string key="NSFrame">{{1, 0}, {130, 17}}</string>
<reference key="NSSuperview" ref="898351365"/>
- <reference key="NSNextKeyView" ref="120612996"/>
<reference key="NSDocView" ref="120612996"/>
<reference key="NSBGColor" ref="898983655"/>
<int key="NScvFlags">4</int>
@@ -1783,7 +1772,6 @@
</object>
<string key="NSFrame">{{362, 17}, {132, 381}}</string>
<reference key="NSSuperview" ref="601698335"/>
- <reference key="NSNextKeyView" ref="728383964"/>
<int key="NSsFlags">562</int>
<reference key="NSVScroller" ref="939829514"/>
<reference key="NSHScroller" ref="1063461866"/>
@@ -2183,11 +2171,10 @@
</object>
</object>
<string key="NSFrameSize">{752, 506}</string>
- <reference key="NSSuperview"/>
</object>
<string key="NSScreenRect">{{0, 0}, {1680, 1028}}</string>
<string key="NSMinSize">{752, 528}</string>
- <string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string>
+ <string key="NSMaxSize">{1.79769e+308, 1.79769e+308}</string>
</object>
<object class="NSTreeController" id="889422316">
<object class="NSMutableArray" key="NSDeclaredKeys">
@@ -4071,6 +4058,14 @@
</object>
<int key="connectionID">924</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">refresh:</string>
+ <reference key="source" ref="1001"/>
+ <reference key="destination" ref="587450306"/>
+ </object>
+ <int key="connectionID">925</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -5483,11 +5478,11 @@
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{145, 249}, {752, 506}}</string>
+ <string>{{152, 121}, {752, 506}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="NO"/>
<boolean value="NO"/>
- <string>{{145, 249}, {752, 506}}</string>
+ <string>{{152, 121}, {752, 506}}</string>
<boolean value="NO"/>
<boolean value="YES"/>
<string>{752, 506}</string>
@@ -5601,7 +5596,7 @@
<string>com.brandonwalkin.BWToolkit</string>
<string>com.brandonwalkin.BWToolkit</string>
<string>com.brandonwalkin.BWToolkit</string>
- <string>{{511, 95}, {130, 81}}</string>
+ <string>{{202, 63}, {130, 81}}</string>
<string>com.brandonwalkin.BWToolkit</string>
<string>com.brandonwalkin.BWToolkit</string>
<string>com.brandonwalkin.BWToolkit</string>
@@ -5666,7 +5661,7 @@
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">924</int>
+ <int key="maxID">925</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
diff --git a/Source/SPUserManager.m b/Source/SPUserManager.m
index 369cbbc7..6594d75f 100644
--- a/Source/SPUserManager.m
+++ b/Source/SPUserManager.m
@@ -181,7 +181,7 @@
* it's data from the SPUser Entity objects in the current managedObjectContext.
*/
- (void)_initializeTree:(NSArray *)items
-{
+{
// Go through each item that contains a dictionary of key-value pairs
// for each user currently in the database.
for(NSInteger i = 0; i < [items count]; i++)
@@ -208,9 +208,12 @@
NSManagedObject *parent = [self _createNewSPUser];
NSManagedObject *child = [self _createNewSPUser];
- // We only care about setting the user and password keys on the parent
+ // We only care about setting the user and password keys on the parent, together with their
+ // original values for comparison purposes
[parent setValue:username forKey:@"user"];
+ [parent setValue:username forKey:@"originaluser"];
[parent setValue:[item objectForKey:@"Password"] forKey:@"password"];
+ [parent setValue:[item objectForKey:@"Password"] forKey:@"originalpassword"];
[self _initializeChild:child withItem:item];
@@ -330,8 +333,8 @@
// Assumes that the child has already been initialized with values from the
// global user table.
// 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"], [child valueForKey:@"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]];
MCPResult *queryResults = [self.mySqlConnection queryString:queryString];
if ([queryResults numOfRows] > 0)
{
@@ -636,14 +639,20 @@
- (IBAction)removeUser:(id)sender
{
NSString *username = [[[treeController selectedObjects] objectAtIndex:0]
- valueForKey:@"user"];
+ valueForKey:@"originaluser"];
NSArray *children = [[[treeController selectedObjects] objectAtIndex:0]
valueForKey:@"children"];
+
+ // On all the children - host entries - set the username to be deleted,
+ // for later query contruction.
for(NSManagedObject *child in children)
{
[child setPrimitiveValue:username forKey:@"user"];
}
+ // Unset the host on the user, so that only the host entries are dropped
+ [[[treeController selectedObjects] objectAtIndex:0] setPrimitiveValue:nil forKey:@"host"];
+
[treeController remove:sender];
}
@@ -750,6 +759,19 @@
[grantedTableView reloadData];
[self _initializeAvailablePrivs];
[treeController fetch:nil];
+
+ // After the reset, ensure all original password and user values are up-to-date.
+ NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"SPUser"
+ inManagedObjectContext:self.managedObjectContext];
+ NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease];
+ [request setEntity:entityDescription];
+ NSArray *userArray = [self.managedObjectContext executeFetchRequest:request error:nil];
+ for (NSManagedObject *user in userArray) {
+ if (![user parent]) {
+ [user setValue:[user valueForKey:@"user"] forKey:@"originaluser"];
+ [user setValue:[user valueForKey:@"password"] forKey:@"originalpassword"];
+ }
+ }
}
- (void)_setSchemaPrivValues:(NSArray *)objects enabled:(BOOL)enabled
@@ -866,6 +888,7 @@
- (void)contextDidSave:(NSNotification *)notification
{
NSManagedObjectContext *notificationContext = (NSManagedObjectContext *)[notification object];
+
// If there are multiple user manager windows open, it's possible to get this
// notification from foreign windows. Ignore those notifications.
if (notificationContext != self.managedObjectContext) return;
@@ -907,22 +930,39 @@
if ([[[user entity] name] isEqualToString:@"Privileges"])
{
[self grantDbPrivilegesWithPrivilege:user];
+
+
+ // If the parent user has changed, either the username or password have been edited.
}
- else if (![user host])
+ else if (![user parent])
{
- // Just the user password was changed.
- // Change password to be the same on all hosts.
NSArray *hosts = [user valueForKey:@"children"];
-
- for(NSManagedObject *child in hosts)
- {
- NSString *changePasswordStatement = [NSString stringWithFormat:
- @"SET PASSWORD FOR %@@%@ = PASSWORD('%@')",
- [[user valueForKey:@"user"] tickQuotedString],
- [[child host] tickQuotedString],
- [user valueForKey:@"password"]];
- [self.mySqlConnection queryString:changePasswordStatement];
- [self checkAndDisplayMySqlError];
+
+ // If the user has been changed, update the username on all hosts. Don't check for errors, as some
+ // hosts may be new.
+ if (![[user valueForKey:@"user"] isEqualToString:[user valueForKey:@"originaluser"]]) {
+ for (NSManagedObject *child in hosts) {
+ NSString *renameUserStatement = [NSString stringWithFormat:
+ @"RENAME USER %@@%@ TO %@@%@",
+ [[user valueForKey:@"originaluser"] tickQuotedString],
+ [[child host] tickQuotedString],
+ [[user valueForKey:@"user"] tickQuotedString],
+ [[child host] tickQuotedString]];
+ [self.mySqlConnection queryString:renameUserStatement];
+ }
+ }
+
+ // If the password has been changed, use the same password on all hosts
+ if (![[user valueForKey:@"password"] isEqualToString:[user valueForKey:@"originalpassword"]]) {
+ for (NSManagedObject *child in hosts) {
+ NSString *changePasswordStatement = [NSString stringWithFormat:
+ @"SET PASSWORD FOR %@@%@ = PASSWORD(%@)",
+ [[user valueForKey:@"user"] tickQuotedString],
+ [[child host] tickQuotedString],
+ [[user valueForKey:@"password"] tickQuotedString]];
+ [self.mySqlConnection queryString:changePasswordStatement];
+ [self checkAndDisplayMySqlError];
+ }
}
} else {
[self grantPrivilegesToUser:user];
@@ -935,18 +975,18 @@
- (BOOL)deleteUsers:(NSArray *)deletedUsers
{
NSMutableString *droppedUsers = [NSMutableString string];
-
+
for (NSManagedObject *user in deletedUsers)
{
if (![[[user entity] name] isEqualToString:@"Privileges"] && [user valueForKey:@"host"] != nil)
{
[droppedUsers appendString:[NSString stringWithFormat:@"%@@%@, ",
- [[user valueForKey:@"user"] backtickQuotedString],
- [[user valueForKey:@"host"] backtickQuotedString]]];
+ [[user valueForKey:@"user"] tickQuotedString],
+ [[user valueForKey:@"host"] tickQuotedString]]];
}
}
-
+
droppedUsers = [[droppedUsers substringToIndex:[droppedUsers length]-2] mutableCopy];
[self.mySqlConnection queryString:[NSString stringWithFormat:@"DROP USER %@", droppedUsers]];
[droppedUsers release];
diff --git a/Source/SPUserManager.xcdatamodel/elements b/Source/SPUserManager.xcdatamodel/elements
index 33881efc..22c2c418 100644
--- a/Source/SPUserManager.xcdatamodel/elements
+++ b/Source/SPUserManager.xcdatamodel/elements
Binary files differ
diff --git a/Source/SPUserManager.xcdatamodel/layout b/Source/SPUserManager.xcdatamodel/layout
index 14b1545d..60630b61 100644
--- a/Source/SPUserManager.xcdatamodel/layout
+++ b/Source/SPUserManager.xcdatamodel/layout
Binary files differ