Permalink
Browse files

Change the behavior of user manager to only update values that actual…

…ly changed when editing users (part of #2229)

(This also removes an additional db roundtrip when updating per-db user privileges that previously was needed to differentiate between user actions „Only removing privileges from user“ and „Backtracking on adding privileges to user“. Since we now only update changed values and the latter one would be an empty changeset this is no longer needed)
  • Loading branch information...
dmoagx committed Dec 7, 2016
1 parent 9eab47a commit 56badea5971212fbeb168111cd4ead2d9a9e69b0
Showing with 10 additions and 9 deletions.
  1. +10 −9 Source/SPUserManager.m
View
@@ -1156,27 +1156,23 @@ - (BOOL)grantDbPrivilegesWithPrivilege:(SPPrivilegesMO *)schemaPriv skippingRevo
NSString *dbName = [schemaPriv valueForKey:@"db"];
dbName = [dbName stringByReplacingOccurrencesOfString:@"_" withString:@"\\_"];
NSString *statement = [NSString stringWithFormat:@"SELECT USER, HOST FROM mysql.db WHERE USER = %@ AND HOST = %@ AND DB = %@",
[[schemaPriv valueForKeyPath:@"user.parent.user"] tickQuotedString],
[[schemaPriv valueForKeyPath:@"user.host"] tickQuotedString],
[dbName tickQuotedString]];
NSArray *matchingUsers = [connection getAllRowsFromQuery:statement];
NSArray *changedKeys = [[schemaPriv changedValues] allKeys];
for (NSString *key in [self privsSupportedByServer])
{
if (![key hasSuffix:@"_priv"]) continue;
//ignore anything that we didn't change
if (![changedKeys containsObject:key]) continue;
NSString *privilege = [key stringByReplacingOccurrencesOfString:@"_priv" withString:@""];
NS_DURING
if ([[schemaPriv valueForKey:key] boolValue] == YES) {
[grantPrivileges addObject:[privilege replaceUnderscoreWithSpace]];
}
else {
if ([matchingUsers count] || [grantPrivileges count] > 0) {
[revokePrivileges addObject:[privilege replaceUnderscoreWithSpace]];
}
[revokePrivileges addObject:[privilege replaceUnderscoreWithSpace]];
}
NS_HANDLER
NS_ENDHANDLER
@@ -1236,10 +1232,15 @@ - (BOOL)grantPrivilegesToUser:(SPUserMO *)user skippingRevoke:(BOOL)skipRevoke
NSMutableArray *grantPrivileges = [NSMutableArray array];
NSMutableArray *revokePrivileges = [NSMutableArray array];
NSArray *changedKeys = [[user changedValues] allKeys];
for (NSString *key in [self privsSupportedByServer])
{
if (![key hasSuffix:@"_priv"]) continue;
//ignore anything that we didn't change
if (![changedKeys containsObject:key]) continue;
NSString *privilege = [key stringByReplacingOccurrencesOfString:@"_priv" withString:@""];
// Check the value of the priv and assign to grant or revoke query as appropriate; do this

0 comments on commit 56badea

Please sign in to comment.