aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPUserManagerDelegate.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2013-03-09 23:22:03 +0000
committerrowanbeentje <rowan@beent.je>2013-03-09 23:22:03 +0000
commit5f3881c0f03e6d103bb09a4fb8da525b761b40dc (patch)
tree73e424b2607d01025ed7673f12f6ee794f6ffe92 /Source/SPUserManagerDelegate.m
parentc51d93d760b6ad47ac4256bdf564688cb9a5d2f8 (diff)
downloadsequelpro-5f3881c0f03e6d103bb09a4fb8da525b761b40dc.tar.gz
sequelpro-5f3881c0f03e6d103bb09a4fb8da525b761b40dc.tar.bz2
sequelpro-5f3881c0f03e6d103bb09a4fb8da525b761b40dc.zip
Tweak and improve the User Manager:
- Rework how data to populate the user manager is retrieved from the server, speeding up display of lots of users by a large factor - Fix support for schema permissions for the Anonymous user, and add support for '%' and '' hostnames (only showing if already set once), fixing Issue #1620 - Highlight databases in the user manager that have permissions set for the selected user - Switch to using the centrally provided database list to reduce queries and remove the information_schema and performance_schema "databases" - Speed up a number of operations by tweaking the logic and queries used
Diffstat (limited to 'Source/SPUserManagerDelegate.m')
-rw-r--r--Source/SPUserManagerDelegate.m54
1 files changed, 42 insertions, 12 deletions
diff --git a/Source/SPUserManagerDelegate.m b/Source/SPUserManagerDelegate.m
index 8fa2b980..c00abba3 100644
--- a/Source/SPUserManagerDelegate.m
+++ b/Source/SPUserManagerDelegate.m
@@ -42,7 +42,6 @@ static NSString *SPSchemaPrivilegesTabIdentifier = @"Schema Privileges";
@interface SPUserManager (DeclaredAPI)
-- (void)_initializeSchemaPrivs;
- (void)_initializeAvailablePrivs;
- (void)_selectParentFromSelection;
- (void)_selectFirstChildOfParentNode;
@@ -64,15 +63,15 @@ static NSString *SPSchemaPrivilegesTabIdentifier = @"Schema Privileges";
if (object == schemasTableView) {
[grantedSchemaPrivs removeAllObjects];
[grantedTableView reloadData];
-
+
[self _initializeAvailablePrivs];
-
- if ([[treeController selectedObjects] count] > 0 && [[schemaController selectedObjects] count] > 0) {
+
+ if ([[treeController selectedObjects] count] > 0 && [[schemasTableView selectedRowIndexes] count] > 0) {
NSManagedObject *user = [[treeController selectedObjects] objectAtIndex:0];
// Check to see if the user host node was selected
if ([user valueForKey:@"host"]) {
- NSString *selectedSchema = [[schemaController selectedObjects] objectAtIndex:0];
+ NSString *selectedSchema = [schemas objectAtIndex:[schemasTableView selectedRow]];
NSArray *results = [self _fetchPrivsWithUser:[[user parent] valueForKey:@"user"]
schema:[selectedSchema stringByReplacingOccurrencesOfString:@"_" withString:@"\\_"]
@@ -116,6 +115,43 @@ static NSString *SPSchemaPrivilegesTabIdentifier = @"Schema Privileges";
}
}
+- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)rowIndex
+{
+ if (tableView == schemasTableView) {
+ NSString *schemaName = [schemas objectAtIndex:rowIndex];
+
+ // Gray out the "all database" entries
+ if ([schemaName isEqualToString:@""] || [schemaName isEqualToString:@"%"]) {
+ [cell setTextColor:[NSColor lightGrayColor]];
+ } else {
+ [cell setTextColor:[NSColor blackColor]];
+ }
+
+ // If the schema has permissions set, highlight with a yellow background
+ BOOL enabledPermissions = NO;
+ NSManagedObject *user = [[treeController selectedObjects] objectAtIndex:0];
+ NSArray *results = [self _fetchPrivsWithUser:[[user parent] valueForKey:@"user"]
+ schema:[schemaName stringByReplacingOccurrencesOfString:@"_" withString:@"\\_"]
+ host:[user valueForKey:@"host"]];
+ if ([results count]) {
+ NSManagedObject *schemaPrivs = [results objectAtIndex:0];
+ for (NSString *itemKey in [[[schemaPrivs entity] attributesByName] allKeys]) {
+ if ([itemKey hasSuffix:@"_priv"] && [[schemaPrivs valueForKey:itemKey] boolValue]) {
+ enabledPermissions = YES;
+ break;
+ }
+ }
+ }
+
+ if (enabledPermissions) {
+ [cell setDrawsBackground:YES];
+ [cell setBackgroundColor:[NSColor colorWithDeviceRed:1.f green:1.f blue:0.f alpha:0.2]];
+ } else {
+ [cell setDrawsBackground:NO];
+ }
+ }
+}
+
#pragma mark -
#pragma mark Tab View Delegate methods
@@ -191,13 +227,6 @@ static NSString *SPSchemaPrivilegesTabIdentifier = @"Schema Privileges";
}
}
-- (void)tabView:(NSTabView *)usersTabView willSelectTabViewItem:(NSTabViewItem *)tabViewItem
-{
- if ([[tabViewItem identifier] isEqualToString:SPSchemaPrivilegesTabIdentifier]) {
- [self _initializeSchemaPrivs];
- }
-}
-
#pragma mark -
#pragma mark Outline view Delegate Methods
@@ -252,6 +281,7 @@ static NSString *SPSchemaPrivilegesTabIdentifier = @"Schema Privileges";
}
[schemasTableView deselectAll:nil];
+ [schemasTableView setNeedsDisplay:YES];
[grantedTableView deselectAll:nil];
[availableTableView deselectAll:nil];
}