From ec392f75e4277917363e73acc9cbfa9db7c7f6e8 Mon Sep 17 00:00:00 2001 From: Miltiadis Vasilakis Date: Fri, 22 Feb 2013 22:24:14 +0200 Subject: [PATCH] Use user catalog in sharing presentation and editing Provide separate input for sharing user and group. Fix bugs. --- pithos-apple-common | 2 +- pithos-macos.xcodeproj/project.pbxproj | 26 +- pithos-macos/PithosAccountNode.m | 69 +- pithos-macos/PithosObjectNode.h | 2 + pithos-macos/PithosObjectNode.m | 189 ++++- pithos-macos/PithosObjectNodeInfoController.h | 1 - pithos-macos/PithosObjectNodeInfoController.m | 4 +- pithos-macos/PithosObjectNodeInfoController.xib | 725 ++++++++------------ pithos-macos/PithosPreferencesController.xib | 192 +++++- pithos-macos/PithosSubdirNode.h | 2 + pithos-macos/PithosSubdirNode.m | 301 +++++++- pithos-macos/SharingDictionaryTransformer.m | 121 ---- pithos-macos/SharingNameFormatter.m | 71 -- ...former.h => SharingUserPermissionTransformer.h} | 6 +- ...matter.h => SharingUserPermissionTransformer.m} | 37 +- 15 files changed, 988 insertions(+), 760 deletions(-) delete mode 100644 pithos-macos/SharingDictionaryTransformer.m delete mode 100644 pithos-macos/SharingNameFormatter.m rename pithos-macos/{SharingDictionaryTransformer.h => SharingUserPermissionTransformer.h} (90%) rename pithos-macos/{SharingNameFormatter.h => SharingUserPermissionTransformer.m} (66%) diff --git a/pithos-apple-common b/pithos-apple-common index 0be02d2..ca7626d 160000 --- a/pithos-apple-common +++ b/pithos-apple-common @@ -1 +1 @@ -Subproject commit 0be02d23590cf90f1358d9c2029c07a3035edea6 +Subproject commit ca7626d763435ba5416f009de1f9a55dd20eacde diff --git a/pithos-macos.xcodeproj/project.pbxproj b/pithos-macos.xcodeproj/project.pbxproj index a2d02d9..c8bbe7d 100644 --- a/pithos-macos.xcodeproj/project.pbxproj +++ b/pithos-macos.xcodeproj/project.pbxproj @@ -7,6 +7,7 @@ objects = { /* Begin PBXBuildFile section */ + 6100FE8A16D7ED3C00D2351A /* SharingUserPermissionTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 6100FE8816D7ECAE00D2351A /* SharingUserPermissionTransformer.m */; }; 610DD2F613E6BB2000ED982F /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 610DD2F513E6BB2000ED982F /* Cocoa.framework */; }; 610DD30013E6BB2000ED982F /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 610DD2FE13E6BB2000ED982F /* InfoPlist.strings */; }; 610DD30313E6BB2000ED982F /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 610DD30213E6BB2000ED982F /* main.m */; }; @@ -70,11 +71,8 @@ 619B85D513F8077800C9371F /* PithosPreferencesController.m in Sources */ = {isa = PBXBuildFile; fileRef = 619B85D313F8077100C9371F /* PithosPreferencesController.m */; }; 619B85D613F8077800C9371F /* PithosPreferencesController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 619B85D413F8077300C9371F /* PithosPreferencesController.xib */; }; 61C24BBB1410D350007004DC /* PublicURLTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C24BBA1410D350007004DC /* PublicURLTransformer.m */; }; - 61C24BBE1410E031007004DC /* SharingDictionaryTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C24BBD1410E031007004DC /* SharingDictionaryTransformer.m */; }; - 61C24BC114110BDB007004DC /* SharingNameFormatter.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C24BC014110BDB007004DC /* SharingNameFormatter.m */; }; 61C24BEC14161EC7007004DC /* PithosUtilities.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C24BEB14161EC3007004DC /* PithosUtilities.m */; }; 61C65ADF1428C578002597C2 /* CountTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C65ADE1428C578002597C2 /* CountTransformer.m */; }; - 61C65AE31428D41C002597C2 /* PolicyVersioningTransformer.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C65AE21428D41C002597C2 /* PolicyVersioningTransformer.m */; }; 61C65AE6142918DD002597C2 /* PithosObjectNodeInfoController.m in Sources */ = {isa = PBXBuildFile; fileRef = 61C65AE5142918DD002597C2 /* PithosObjectNodeInfoController.m */; }; 61D83D9F16D03B1900A1F059 /* NSObject+SBJson.m in Sources */ = {isa = PBXBuildFile; fileRef = 61D83D8716D03B1900A1F059 /* NSObject+SBJson.m */; }; 61D83DA016D03B1900A1F059 /* SBJsonParser.m in Sources */ = {isa = PBXBuildFile; fileRef = 61D83D8A16D03B1900A1F059 /* SBJsonParser.m */; }; @@ -88,6 +86,7 @@ 61D83DA816D03B1900A1F059 /* SBJsonTokeniser.m in Sources */ = {isa = PBXBuildFile; fileRef = 61D83D9A16D03B1900A1F059 /* SBJsonTokeniser.m */; }; 61D83DA916D03B1900A1F059 /* SBJsonUTF8Stream.m in Sources */ = {isa = PBXBuildFile; fileRef = 61D83D9C16D03B1900A1F059 /* SBJsonUTF8Stream.m */; }; 61D83DAA16D03B1900A1F059 /* SBJsonWriter.m in Sources */ = {isa = PBXBuildFile; fileRef = 61D83D9E16D03B1900A1F059 /* SBJsonWriter.m */; }; + 61EF84AB16D6A142002B7B88 /* ASIPithosSharingUser.m in Sources */ = {isa = PBXBuildFile; fileRef = 613F5E9916D5979500343069 /* ASIPithosSharingUser.m */; }; 61F040F31448547000A0C788 /* FileMD5Hash.c in Sources */ = {isa = PBXBuildFile; fileRef = 61F040F11448547000A0C788 /* FileMD5Hash.c */; }; 61F04132144DB97200A0C788 /* PithosLocalObjectState.m in Sources */ = {isa = PBXBuildFile; fileRef = 61F040EE144757B500A0C788 /* PithosLocalObjectState.m */; }; 61F04133144DB97600A0C788 /* PithosSyncDaemon.m in Sources */ = {isa = PBXBuildFile; fileRef = 61F040EA144724F500A0C788 /* PithosSyncDaemon.m */; }; @@ -101,6 +100,8 @@ /* End PBXBuildFile section */ /* Begin PBXFileReference section */ + 6100FE8716D7ECAE00D2351A /* SharingUserPermissionTransformer.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = SharingUserPermissionTransformer.h; path = "pithos-macos/SharingUserPermissionTransformer.h"; sourceTree = ""; }; + 6100FE8816D7ECAE00D2351A /* SharingUserPermissionTransformer.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = SharingUserPermissionTransformer.m; path = "pithos-macos/SharingUserPermissionTransformer.m"; sourceTree = ""; }; 610DD2F113E6BB2000ED982F /* Pithos+.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Pithos+.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 610DD2F513E6BB2000ED982F /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; }; 610DD2F813E6BB2000ED982F /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; }; @@ -176,6 +177,8 @@ 6139837013EFEECC004CE444 /* FileSystemBrowserCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = FileSystemBrowserCell.m; path = "pithos-macos/FileSystemBrowserCell.m"; sourceTree = ""; }; 613BA8611461520E00FACAA5 /* NonEmptyStringFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NonEmptyStringFormatter.h; path = "pithos-macos/NonEmptyStringFormatter.h"; sourceTree = ""; }; 613BA8621461520E00FACAA5 /* NonEmptyStringFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NonEmptyStringFormatter.m; path = "pithos-macos/NonEmptyStringFormatter.m"; sourceTree = ""; }; + 613F5E9816D5979500343069 /* ASIPithosSharingUser.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ASIPithosSharingUser.h; sourceTree = ""; }; + 613F5E9916D5979500343069 /* ASIPithosSharingUser.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ASIPithosSharingUser.m; sourceTree = ""; }; 614299A714CEF0E7008D973A /* ASIPithos.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASIPithos.h; sourceTree = ""; }; 614299A814CEF0E7008D973A /* ASIPithos.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ASIPithos.m; sourceTree = ""; }; 61433BC7141BA1CE00CD978D /* HashMapHash.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = HashMapHash.h; path = "pithos-macos/HashMapHash.h"; sourceTree = ""; }; @@ -222,10 +225,6 @@ 619B85D413F8077300C9371F /* PithosPreferencesController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = PithosPreferencesController.xib; sourceTree = ""; }; 61C24BB91410D350007004DC /* PublicURLTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PublicURLTransformer.h; path = "pithos-macos/PublicURLTransformer.h"; sourceTree = ""; }; 61C24BBA1410D350007004DC /* PublicURLTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PublicURLTransformer.m; path = "pithos-macos/PublicURLTransformer.m"; sourceTree = ""; }; - 61C24BBC1410E031007004DC /* SharingDictionaryTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharingDictionaryTransformer.h; path = "pithos-macos/SharingDictionaryTransformer.h"; sourceTree = ""; }; - 61C24BBD1410E031007004DC /* SharingDictionaryTransformer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SharingDictionaryTransformer.m; path = "pithos-macos/SharingDictionaryTransformer.m"; sourceTree = ""; }; - 61C24BBF14110BDB007004DC /* SharingNameFormatter.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SharingNameFormatter.h; path = "pithos-macos/SharingNameFormatter.h"; sourceTree = ""; }; - 61C24BC014110BDB007004DC /* SharingNameFormatter.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = SharingNameFormatter.m; path = "pithos-macos/SharingNameFormatter.m"; sourceTree = ""; }; 61C24BEA14161EC0007004DC /* PithosUtilities.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PithosUtilities.h; sourceTree = ""; }; 61C24BEB14161EC3007004DC /* PithosUtilities.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PithosUtilities.m; sourceTree = ""; }; 61C65ADD1428C578002597C2 /* CountTransformer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CountTransformer.h; path = "pithos-macos/CountTransformer.h"; sourceTree = ""; }; @@ -419,6 +418,8 @@ 610DD33413E6BD8B00ED982F /* ASIPithosContainer.m */, 610DD33713E6BD8B00ED982F /* ASIPithosObject.h */, 610DD33813E6BD8B00ED982F /* ASIPithosObject.m */, + 613F5E9816D5979500343069 /* ASIPithosSharingUser.h */, + 613F5E9916D5979500343069 /* ASIPithosSharingUser.m */, ); name = Pithos; path = "pithos-apple-common/asi-http-request-with-pithos/Classes/Pithos"; @@ -450,8 +451,6 @@ children = ( 615A444F140F8A7F00308614 /* MetadataKeyFormatter.h */, 615A4450140F8A7F00308614 /* MetadataKeyFormatter.m */, - 61C24BBF14110BDB007004DC /* SharingNameFormatter.h */, - 61C24BC014110BDB007004DC /* SharingNameFormatter.m */, 613629B7143E51E000363787 /* GroupAndGroupMemberFormatter.h */, 613629B8143E51E000363787 /* GroupAndGroupMemberFormatter.m */, 613BA8611461520E00FACAA5 /* NonEmptyStringFormatter.h */, @@ -484,8 +483,8 @@ 615A444D140F8A5700308614 /* MetadataKeyTransformer.m */, 61C24BB91410D350007004DC /* PublicURLTransformer.h */, 61C24BBA1410D350007004DC /* PublicURLTransformer.m */, - 61C24BBC1410E031007004DC /* SharingDictionaryTransformer.h */, - 61C24BBD1410E031007004DC /* SharingDictionaryTransformer.m */, + 6100FE8716D7ECAE00D2351A /* SharingUserPermissionTransformer.h */, + 6100FE8816D7ECAE00D2351A /* SharingUserPermissionTransformer.m */, 61C65ADD1428C578002597C2 /* CountTransformer.h */, 61C65ADE1428C578002597C2 /* CountTransformer.m */, 61C65AE11428D41C002597C2 /* PolicyVersioningTransformer.h */, @@ -752,14 +751,11 @@ 615A444E140F8A5700308614 /* MetadataKeyTransformer.m in Sources */, 615A4451140F8A7F00308614 /* MetadataKeyFormatter.m in Sources */, 61C24BBB1410D350007004DC /* PublicURLTransformer.m in Sources */, - 61C24BBE1410E031007004DC /* SharingDictionaryTransformer.m in Sources */, - 61C24BC114110BDB007004DC /* SharingNameFormatter.m in Sources */, 61C24BEC14161EC7007004DC /* PithosUtilities.m in Sources */, 614592BC1417CE70002E7A8C /* ASIPithosAccount.m in Sources */, 61433BC9141BA1CE00CD978D /* HashMapHash.m in Sources */, 611405D01428BEC000637170 /* PithosContainerNodeInfoController.m in Sources */, 61C65ADF1428C578002597C2 /* CountTransformer.m in Sources */, - 61C65AE31428D41C002597C2 /* PolicyVersioningTransformer.m in Sources */, 61C65AE6142918DD002597C2 /* PithosObjectNodeInfoController.m in Sources */, 6152D08C143200CC00803874 /* PithosSharingAccountsNode.m in Sources */, 6152D092143334CC00803874 /* AllowedToBoolTransformer.m in Sources */, @@ -795,6 +791,8 @@ 61D83DA816D03B1900A1F059 /* SBJsonTokeniser.m in Sources */, 61D83DA916D03B1900A1F059 /* SBJsonUTF8Stream.m in Sources */, 61D83DAA16D03B1900A1F059 /* SBJsonWriter.m in Sources */, + 61EF84AB16D6A142002B7B88 /* ASIPithosSharingUser.m in Sources */, + 6100FE8A16D7ED3C00D2351A /* SharingUserPermissionTransformer.m in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/pithos-macos/PithosAccountNode.m b/pithos-macos/PithosAccountNode.m index ee1ded1..f5768d4 100644 --- a/pithos-macos/PithosAccountNode.m +++ b/pithos-macos/PithosAccountNode.m @@ -73,6 +73,37 @@ static NSImage *sharedIcon = nil; } #pragma mark - +#pragma mark Internal + +- (void)updateGroups { + if (!pithosAccount) { + self.translatedGroups = [NSMutableDictionary dictionary]; + } else if (pithosAccountManager) { + NSMutableSet *UUIDs = [NSMutableSet set]; + for (NSString *groupName in pithosAccount.groups) { + [UUIDs addObjectsFromArray:[pithosAccount.groups objectForKey:groupName]]; + } + [UUIDs removeObject:@""]; + [UUIDs removeObject:@"*"]; + if (UUIDs.count) { + [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:[UUIDs allObjects]]; + } + + NSMutableDictionary *newTranslatedGroups = [NSMutableDictionary dictionaryWithCapacity:pithosAccount.groups.count]; + for (NSString *groupName in pithosAccount.groups) { + NSMutableArray *groupUsers = [NSMutableArray array]; + for (NSString *UUID in [pithosAccount.groups objectForKey:groupName]) { + [groupUsers addObject:[pithosAccountManager displaynameForUUID:UUID safe:YES]]; + } + [newTranslatedGroups setObject:groupUsers forKey:groupName]; + } + self.translatedGroups = newTranslatedGroups; + } else { + self.translatedGroups = [pithosAccount.groups copy]; + } +} + +#pragma mark - #pragma mark Properties - (void)setPithos:(ASIPithos *)aPithos { @@ -90,32 +121,9 @@ static NSImage *sharedIcon = nil; } - (void)setPithosAccount:(ASIPithosAccount *)aPithosAccount { - if (!aPithosAccount) { + if (![pithosAccount isEqualTo:aPithosAccount]) { pithosAccount = aPithosAccount; - self.translatedGroups = [NSMutableDictionary dictionary]; - } else if (![aPithosAccount isEqualTo:pithosAccount]) { - pithosAccount = aPithosAccount; - if (pithosAccountManager) { - NSMutableArray *UUIDs = [NSMutableArray array]; - for (NSString *groupName in pithosAccount.groups) { - [UUIDs addObjectsFromArray:[pithosAccount.groups objectForKey:groupName]]; - } - if (UUIDs.count) { - [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:UUIDs]; - } - - NSMutableDictionary *newTranslatedGroups = [NSMutableDictionary dictionaryWithCapacity:pithosAccount.groups.count]; - for (NSString *groupName in pithosAccount.groups) { - NSMutableArray *groupUsers = [NSMutableArray array]; - for (NSString *UUID in [pithosAccount.groups objectForKey:groupName]) { - [groupUsers addObject:[pithosAccountManager displaynameForUUID:UUID safe:YES]]; - } - [newTranslatedGroups setObject:groupUsers forKey:groupName]; - } - self.translatedGroups = newTranslatedGroups; - } else { - self.translatedGroups = [pithosAccount.groups copy]; - } + [self updateGroups]; } } @@ -418,7 +426,7 @@ static NSImage *sharedIcon = nil; } } if (!inexistentGroupUsers.count) { - // create groups + // Create groups. for (NSString *groupName in translatedGroups) { NSMutableArray *groupUsers = [NSMutableArray array]; for (NSString *groupUser in [translatedGroups objectForKey:groupName]) { @@ -461,7 +469,14 @@ static NSImage *sharedIcon = nil; } } } else { - [groups setObject:[NSArray arrayWithObject:@""] forKey:@"group"]; + for (NSString *groupName in translatedGroups) { + if ([[translatedGroups objectForKey:groupName] containsObject:@"*"]) { + [groups setObject:[NSMutableArray arrayWithObject:@"*"] forKey:groupName]; + } + } + if (!groups.count) { + [groups setObject:[NSArray arrayWithObject:@""] forKey:@"group"]; + } } } else { [groups addEntriesFromDictionary:translatedGroups]; diff --git a/pithos-macos/PithosObjectNode.h b/pithos-macos/PithosObjectNode.h index f19321e..024b0ca 100644 --- a/pithos-macos/PithosObjectNode.h +++ b/pithos-macos/PithosObjectNode.h @@ -53,6 +53,7 @@ BOOL isPublic; NSString *translatedModifiedBy; + NSMutableArray *translatedPermissions; } - (id)initWithPithos:(ASIPithos *)aPithos @@ -65,6 +66,7 @@ @property (nonatomic, strong) NSArray *versions; @property (nonatomic, assign) BOOL isPublic; @property (nonatomic, strong) NSString *translatedModifiedBy; +@property (nonatomic, strong) NSMutableArray *translatedPermissions; - (void)applyInfo; - (void)refreshInfo; diff --git a/pithos-macos/PithosObjectNode.m b/pithos-macos/PithosObjectNode.m index 5407694..a0d0d97 100644 --- a/pithos-macos/PithosObjectNode.m +++ b/pithos-macos/PithosObjectNode.m @@ -41,6 +41,7 @@ #import "ASIPithosObjectRequest.h" #import "ASIPithosContainer.h" #import "ASIPithosObject.h" +#import "ASIPithosSharingUser.h" #import "ASIDownloadCache.h" #import "PithosAccount.h" #import "PithosUtilities.h" @@ -48,7 +49,7 @@ @implementation PithosObjectNode @synthesize pithos, pithosContainer, pithosObject, versions; -@synthesize isPublic, translatedModifiedBy; +@synthesize isPublic, translatedModifiedBy, translatedPermissions; #pragma mark - #pragma mark Object Lifecycle @@ -77,18 +78,42 @@ - (void)updateModifiedBy { if (!pithosObject.modifiedBy) { self.translatedModifiedBy = nil; - } else { - if (pithosAccountManager) { - NSString *displayname = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:NO]; - if (displayname) { - self.translatedModifiedBy = displayname; - } else { - [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:[NSArray arrayWithObject:pithosObject.modifiedBy]]; - self.translatedModifiedBy = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:YES]; - } + } else if (pithosAccountManager) { + NSString *displayname = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:NO]; + if (displayname) { + self.translatedModifiedBy = displayname; } else { - self.translatedModifiedBy = [pithosObject.modifiedBy copy]; + [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:[NSArray arrayWithObject:pithosObject.modifiedBy]]; + self.translatedModifiedBy = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:YES]; } + } else { + self.translatedModifiedBy = [pithosObject.modifiedBy copy]; + } +} + +- (void)updatePermissions { + if (!pithosObject) { + self.translatedPermissions = [NSMutableArray array]; + } else if (pithosAccountManager) { + NSMutableSet *UUIDs = [NSMutableSet set]; + for (ASIPithosSharingUser *sharingUser in pithosObject.permissions) { + [UUIDs addObject:sharingUser.name]; + } + [UUIDs removeObject:@""]; + [UUIDs removeObject:@"*"]; + if (UUIDs.count) { + [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:[UUIDs allObjects]]; + } + + NSMutableArray *newTranslatedPermissions = [NSMutableArray arrayWithCapacity:pithosObject.permissions.count]; + for (ASIPithosSharingUser *sharingUser in pithosObject.permissions) { + ASIPithosSharingUser *translatedSharingUser = [sharingUser copy]; + translatedSharingUser.name = [pithosAccountManager displaynameForUUID:translatedSharingUser.name safe:YES]; + [newTranslatedPermissions addObject:translatedSharingUser]; + } + self.translatedPermissions = newTranslatedPermissions; + } else { + self.translatedPermissions = [NSMutableArray arrayWithArray:[pithosObject.permissions copy]]; } } @@ -137,8 +162,9 @@ - (void)setPithosObject:(ASIPithosObject *)aPithosObject { if (![pithosObject isEqualTo:aPithosObject]) { pithosObject = aPithosObject; + [self updateModifiedBy]; + [self updatePermissions]; } - [self updateModifiedBy]; self.isPublic = (pithosObject.publicURI != nil); // Refresh browser if the object is in my shared and is no longer shared if (shared && !pithosObject.sharing) @@ -164,6 +190,7 @@ self.pithosObject.sharing = aPithosObject.sharing; self.pithosObject.publicURI = aPithosObject.publicURI; self.pithosObject = pithosObject; + [self updatePermissions]; } else { [self updateModifiedBy]; } @@ -252,18 +279,136 @@ if (applyMetadataObjectRequest == nil) { [[pithosNodeInfoController window] makeFirstResponder:nil]; if (sharingAccount) { - applyMetadataObjectRequest = [ASIPithosObjectRequest updateObjectMetadataRequestWithPithos:pithos - containerName:pithosContainer.name - objectName:pithosObject.name - contentEncoding:nil - contentDisposition:nil - manifest:nil - sharing:nil - isPublic:(isPublic ? ASIPithosObjectRequestPublicTrue : ASIPithosObjectRequestPublicFalse) - metadata:pithosObject.metadata - update:NO]; + applyMetadataObjectRequest = [ASIPithosObjectRequest updateObjectMetadataRequestWithPithos:pithos + containerName:pithosContainer.name + objectName:pithosObject.name + contentEncoding:nil + contentDisposition:nil + manifest:nil + sharing:nil + isPublic:(isPublic ? ASIPithosObjectRequestPublicTrue : ASIPithosObjectRequestPublicFalse) + metadata:pithosObject.metadata + update:NO]; [applyMetadataObjectRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithos]; } else { + NSMutableArray *permissions = [NSMutableArray array]; + if (translatedPermissions.count) { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.group.length && + [translatedsSharingUser.group rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@" -_~,;"]].location != NSNotFound) { + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:@"Invalid Input"]; + [alert setInformativeText:@"Group names cannot contain ' ', '-', '_', '~', ',' or ';'."]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + } + if (pithosAccountManager) { + NSMutableSet *allUsers = [NSMutableSet set]; + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + [allUsers addObject:translatedsSharingUser.name]; + } + } + [allUsers removeObject:@""]; + [allUsers removeObject:@"*"]; + if (allUsers.count) { + ASIPithosRequest *userCatalogRequest = [pithosAccountManager updateUserCatalogForForDisplaynames:[allUsers allObjects] + UUIDs:nil]; + if (userCatalogRequest.error || ((userCatalogRequest.responseStatusCode != 200) && (userCatalogRequest.responseStatusCode != 404))) { + return; + } else if (userCatalogRequest.responseStatusCode == 200) { + // Check if all users exist. + NSDictionary *displaynameCatalog = [userCatalogRequest displaynameCatalog]; + NSMutableArray *inexistentUsers = [NSMutableArray array]; + for (NSString *user in allUsers) { + if (![displaynameCatalog objectForKey:user]) { + [inexistentUsers addObject:user]; + } + } + if (!inexistentUsers.count) { + // Create permissions. + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (![sharingUser.name isEqualToString:@"*"]) { + sharingUser.name = [displaynameCatalog objectForKey:sharingUser.name]; + } + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } else { + NSAlert *alert = [[NSAlert alloc] init]; + if (inexistentUsers.count == 1) { + [alert setMessageText:@"Invalid User"]; + [alert setInformativeText:[NSString stringWithFormat:@"User '%@' doesn't exist.", [inexistentUsers objectAtIndex:0]]]; + } else { + [alert setMessageText:@"Invalid Users"]; + [alert setInformativeText:[NSString stringWithFormat:@"Users '%@' don't exist.", [inexistentUsers componentsJoinedByString:@"', '"]]]; + } + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + } else { + // 404. Since we don't translate to UUIDs, check for invalid chars. + BOOL valid = YES; + // Create permissions. + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length && + ([translatedsSharingUser.name rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@" ~,;:"]].location != NSNotFound)) { + valid = NO; + break; + } + } + if (valid) { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } else { + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:@"Invalid Input"]; + [alert setInformativeText:@"Users cannot contain ' ', '~', ',', ';' or ':'."]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + } + } else { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if ([translatedsSharingUser.name isEqualToString:@"*"]) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } + } else { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } + } + pithosObject.permissions = permissions; + applyMetadataObjectRequest = [ASIPithosObjectRequest updateObjectMetadataRequestWithPithos:pithos containerName:pithosContainer.name objectName:pithosObject.name diff --git a/pithos-macos/PithosObjectNodeInfoController.h b/pithos-macos/PithosObjectNodeInfoController.h index 2979dd3..a87f8d7 100644 --- a/pithos-macos/PithosObjectNodeInfoController.h +++ b/pithos-macos/PithosObjectNodeInfoController.h @@ -42,7 +42,6 @@ @interface PithosObjectNodeInfoController : PithosNodeInfoController { IBOutlet NSDictionaryController *metadataDictionaryController; - IBOutlet NSDictionaryController *sharingDictionaryController; IBOutlet NSArrayController *versionsArrayController; IBOutlet InspectorPane *versionsInspectorPane; diff --git a/pithos-macos/PithosObjectNodeInfoController.m b/pithos-macos/PithosObjectNodeInfoController.m index b9e11bc..959247f 100644 --- a/pithos-macos/PithosObjectNodeInfoController.m +++ b/pithos-macos/PithosObjectNodeInfoController.m @@ -64,9 +64,7 @@ [metadataDictionaryController setInitialKey:@"key"]; [metadataDictionaryController setInitialValue:@"value"]; - [sharingDictionaryController setInitialKey:@"user or user:group"]; - [sharingDictionaryController setInitialValue:@"read only"]; - + [[self window] setDelegate:self]; [versionsInspectorPane toggleCollapsedWithAnimation:NO]; diff --git a/pithos-macos/PithosObjectNodeInfoController.xib b/pithos-macos/PithosObjectNodeInfoController.xib index a11ba35..f475f7c 100755 --- a/pithos-macos/PithosObjectNodeInfoController.xib +++ b/pithos-macos/PithosObjectNodeInfoController.xib @@ -82,7 +82,6 @@ {{10, 768}, {32, 32}} - YES @@ -104,7 +103,6 @@ 270 {{47, 785}, {148, 17}} - YES @@ -142,7 +140,6 @@ 265 {{190, 785}, {68, 17}} - YES @@ -167,7 +164,6 @@ 268 {{47, 765}, {60, 17}} - YES @@ -189,7 +185,6 @@ 268 {{107, 768}, {151, 14}} - YES @@ -217,7 +212,6 @@ 289 {{193, 9}, {62, 17}} - YES @@ -244,7 +238,6 @@ 292 {{10, 9}, {62, 17}} - YES @@ -264,7 +257,6 @@ {265, 34} - _NS:9 NSView @@ -284,7 +276,6 @@ 270 {{128, 9}, {124, 19}} - YES @@ -316,7 +307,6 @@ 268 {{9, 10}, {114, 14}} - YES @@ -335,7 +325,6 @@ 270 {{128, 29}, {124, 19}} - YES @@ -354,7 +343,6 @@ 268 {{9, 31}, {114, 14}} - YES @@ -373,7 +361,6 @@ 270 {{128, 50}, {124, 19}} - YES @@ -392,7 +379,6 @@ 268 {{9, 52}, {114, 14}} - YES @@ -409,7 +395,6 @@ {265, 78} - InspectorPaneBody @@ -423,7 +408,6 @@ 268 {{3, 2}, {13, 13}} - YES @@ -445,7 +429,6 @@ 266 {{16, 1}, {242, 14}} - YES @@ -461,14 +444,12 @@ {{0, 78}, {265, 17}} - InspectorPaneHead {{0, 34}, {265, 95}} - InspectorPane @@ -487,7 +468,6 @@ 268 {{27, 8}, {18, 18}} - YES @@ -513,7 +493,6 @@ 268 {{10, 8}, {18, 18}} - YES @@ -549,7 +528,6 @@ 4352 {243, 78} - YES @@ -557,7 +535,6 @@ 256 {243, 17} - @@ -569,13 +546,13 @@ YES - 101 + 80 40 1000 75628096 2048 - Name + User 3 @@ -607,14 +584,45 @@ YES + + 74 + 10 + 3.4028234663852886e+38 + + 75628096 + 2048 + Group + + + 6 + System + headerColor + + + + + + 337772096 + 2048 + Text Cell + + + + + + 3 + YES + YES + + - 136 + 80 40 1000 75628096 2048 - Privilege + Permission @@ -631,8 +639,8 @@ YES YES - read only - read/write + Read Only + Read/Write @@ -728,7 +736,6 @@ {{1, 17}, {243, 78}} - @@ -739,7 +746,6 @@ -2147483392 {{224, 17}, {15, 102}} - _doScroller: @@ -750,12 +756,11 @@ -2147483392 {{1, 80}, {243, 15}} - 1 _doScroller: - 0.94921875 + 0.99183673469387756 @@ -766,7 +771,6 @@ {{1, 0}, {243, 17}} - @@ -775,7 +779,6 @@ {{10, 28}, {245, 96}} - 133682 @@ -789,7 +792,6 @@ 268 {{83, 130}, {61, 18}} - YES @@ -818,7 +820,6 @@ 270 {{84, 149}, {174, 14}} - YES @@ -836,7 +837,6 @@ 268 {{12, 149}, {72, 14}} - YES @@ -853,7 +853,6 @@ {265, 171} - InspectorPaneBody @@ -867,7 +866,6 @@ 268 {{3, 2}, {13, 13}} - YES @@ -889,7 +887,6 @@ 266 {{16, 1}, {242, 14}} - YES @@ -905,14 +902,12 @@ {{0, 171}, {265, 17}} - InspectorPaneHead {{0, 129}, {265, 188}} - InspectorPane @@ -931,7 +926,6 @@ 268 {{27, 8}, {18, 18}} - YES @@ -954,7 +948,6 @@ 268 {{10, 8}, {18, 18}} - YES @@ -987,7 +980,6 @@ 4352 {243, 78} - YES @@ -995,7 +987,6 @@ 256 {243, 17} - @@ -1081,7 +1072,6 @@ {{1, 17}, {243, 78}} - @@ -1092,7 +1082,6 @@ -2147483392 {{224, 17}, {15, 102}} - _doScroller: @@ -1104,7 +1093,6 @@ -2147483392 {{1, 119}, {223, 15}} - 1 @@ -1120,7 +1108,6 @@ {{1, 0}, {243, 17}} - @@ -1129,7 +1116,6 @@ {{10, 28}, {245, 96}} - 133682 @@ -1141,7 +1127,6 @@ {265, 134} - InspectorPaneBody @@ -1155,7 +1140,6 @@ 268 {{3, 2}, {13, 13}} - YES @@ -1177,7 +1161,6 @@ 266 {{16, 1}, {242, 14}} - YES @@ -1193,14 +1176,12 @@ {{0, 134}, {265, 17}} - InspectorPaneHead {{0, 317}, {265, 151}} - InspectorPane @@ -1219,7 +1200,6 @@ 289 {{183, 8}, {72, 17}} - YES @@ -1242,7 +1222,6 @@ 289 {{10, 8}, {72, 17}} - YES @@ -1275,7 +1254,6 @@ 4352 {243, 78} - YES @@ -1283,7 +1261,6 @@ 256 {243, 17} - @@ -1367,7 +1344,6 @@ {{1, 17}, {243, 78}} - @@ -1378,7 +1354,6 @@ -2147483392 {{224, 17}, {15, 102}} - _doScroller: @@ -1390,7 +1365,6 @@ -2147483392 {{1, 80}, {243, 15}} - 1 @@ -1406,7 +1380,6 @@ {{1, 0}, {243, 17}} - @@ -1415,7 +1388,6 @@ {{10, 29}, {245, 96}} - 133682 @@ -1427,7 +1399,6 @@ {265, 135} - InspectorPaneBody @@ -1441,7 +1412,6 @@ 268 {{3, 2}, {13, 13}} - YES @@ -1463,7 +1433,6 @@ 266 {{16, 1}, {242, 14}} - YES @@ -1479,14 +1448,12 @@ {{0, 135}, {265, 17}} - InspectorPaneHead {{0, 468}, {265, 152}} - InspectorPane @@ -1505,7 +1472,6 @@ 270 {{81, 8}, {174, 14}} - YES @@ -1523,7 +1489,6 @@ 268 {{9, 8}, {72, 14}} - YES @@ -1542,7 +1507,6 @@ 270 {{81, 23}, {174, 14}} - YES @@ -1560,7 +1524,6 @@ 268 {{9, 23}, {72, 14}} - YES @@ -1579,7 +1542,6 @@ 270 {{81, 38}, {174, 14}} - YES @@ -1597,7 +1559,6 @@ 268 {{9, 38}, {72, 14}} - YES @@ -1616,7 +1577,6 @@ 270 {{81, 53}, {174, 14}} - YES @@ -1634,7 +1594,6 @@ 268 {{9, 53}, {72, 14}} - YES @@ -1653,7 +1612,6 @@ 270 {{81, 68}, {174, 14}} - YES @@ -1671,7 +1629,6 @@ 268 {{9, 68}, {72, 14}} - YES @@ -1690,7 +1647,6 @@ 270 {{81, 83}, {174, 14}} - YES @@ -1708,7 +1664,6 @@ 268 {{9, 83}, {72, 14}} - YES @@ -1727,7 +1682,6 @@ 270 {{81, 98}, {174, 14}} - YES @@ -1745,7 +1699,6 @@ 268 {{9, 98}, {72, 14}} - YES @@ -1762,7 +1715,6 @@ {265, 120} - InspectorPaneBody @@ -1776,7 +1728,6 @@ 268 {{3, 2}, {13, 13}} - YES @@ -1798,7 +1749,6 @@ 266 {{16, 1}, {242, 14}} - YES @@ -1814,21 +1764,18 @@ {{0, 120}, {265, 17}} - InspectorPaneHead {{0, 620}, {265, 137}} - InspectorPane {265, 757} - _NS:9 InspectorPaneContainer @@ -1836,7 +1783,6 @@ {265, 810} - {{0, 0}, {1280, 778}} @@ -1861,22 +1807,21 @@ key value - + + + YES + name + group + permission + + ASIPithosSharingUser + YES + YES YES YES YES - - YES - - key - YES - compare: - - YES - key - value YES @@ -1888,9 +1833,6 @@ NonEmptyStringFormatter - - SharingNameFormatter - @@ -1913,14 +1855,6 @@ - sharingDictionaryController - - - - 320 - - - versionsInspectorPane @@ -1960,6 +1894,14 @@ 1500 + + sharingArrayController + + + + 1522 + + displayPatternTitle1: self.node.displayName @@ -2089,42 +2031,6 @@ 1249 - - contentDictionary: node.pithosObject.sharing - - - - - - contentDictionary: node.pithosObject.sharing - contentDictionary - node.pithosObject.sharing - - NSValueTransformerName - SharingDictionaryTransformer - - 2 - - - 298 - - - - add: - - - - 1331 - - - - remove: - - - - 1330 - - paneHead @@ -2717,14 +2623,14 @@ - enabled2: node.sharingAccount + enabled: node.sharingAccount - + - enabled2: node.sharingAccount - enabled2 + enabled: node.sharingAccount + enabled node.sharingAccount YES @@ -2734,7 +2640,6 @@ NSNoSelectionPlaceholder NSNotApplicablePlaceholder NSNullPlaceholder - NSValueTransformerName YES @@ -2742,166 +2647,194 @@ - SharingAccountBoolTransformer - 2 - 1319 + 1557 - enabled: canRemove + enabled2: canRemove - - + + - - enabled: canRemove - enabled + + enabled2: canRemove + enabled2 canRemove + + YES + + YES + NSMultipleValuesPlaceholder + NSNoSelectionPlaceholder + NSNotApplicablePlaceholder + NSNullPlaceholder + + + YES + + + + + + + 2 - 1318 - - - - sortDescriptors: sortDescriptors - - - - - - sortDescriptors: sortDescriptors - sortDescriptors - sortDescriptors - - 2 - - - 1327 + 1589 content: arrangedObjects - + - + content: arrangedObjects content arrangedObjects 2 - 1325 + 1590 - enabled: node.sharingAccount + selectionIndexes: selectionIndexes - - + + - - enabled: node.sharingAccount - enabled - node.sharingAccount - - NSValueTransformerName - SharingAccountBoolTransformer - + + selectionIndexes: selectionIndexes + selectionIndexes + selectionIndexes + 2 - 1329 + 1592 - selectionIndexes: selectionIndexes + sortDescriptors: sortDescriptors - - + + - - selectionIndexes: selectionIndexes - selectionIndexes - selectionIndexes - + + sortDescriptors: sortDescriptors + sortDescriptors + sortDescriptors + 2 - 1326 + 1593 - value: arrangedObjects.key + value: arrangedObjects.name - + - - value: arrangedObjects.key + + value: arrangedObjects.name value - arrangedObjects.key + arrangedObjects.name YES YES - NSConditionallySetsEditable + NSNullPlaceholder NSValidatesImmediately YES - + user 2 - 1321 + 1597 - value: arrangedObjects.value + enabled: node.sharingAccount + + + + + + enabled: node.sharingAccount + enabled + node.sharingAccount + + NSValueTransformerName + SharingAccountBoolTransformer + + 2 + + + 1615 + + + + value: arrangedObjects.permission - + - - value: arrangedObjects.value + + value: arrangedObjects.permission value - arrangedObjects.value + arrangedObjects.permission YES YES - NSConditionallySetsEnabled NSValidatesImmediately + NSValueTransformerName YES - + SharingUserPermissionTransformer 2 - 1320 + 1610 - - formatter - - + + enabled: node.sharingAccount + + + + + + enabled: node.sharingAccount + enabled + node.sharingAccount + + NSValueTransformerName + SharingAccountBoolTransformer + + 2 + - 1332 + 1623 @@ -3412,6 +3345,91 @@ 1489 + + + value: arrangedObjects.group + + + + + + value: arrangedObjects.group + value + arrangedObjects.group + + YES + + YES + NSNullPlaceholder + NSValidatesImmediately + + + YES + group + + + + 2 + + + 1601 + + + + enabled: node.sharingAccount + + + + + + enabled: node.sharingAccount + enabled + node.sharingAccount + + NSValueTransformerName + SharingAccountBoolTransformer + + 2 + + + 1619 + + + + add: + + + + 1585 + + + + remove: + + + + 1586 + + + + contentArray: node.translatedPermissions + + + + + + contentArray: node.translatedPermissions + contentArray + node.translatedPermissions + + NSValidatesImmediately + + + 2 + + + 1609 + @@ -3477,17 +3495,6 @@ - 295 - - - Dictionary Controller (Sharing) - - - 321 - - - - 5 @@ -4129,6 +4136,7 @@ YES + @@ -4562,6 +4570,26 @@ + + 1502 + + + YES + + + + + + 1503 + + + + + 1516 + + + Array Controller (Sharing) + @@ -4705,11 +4733,12 @@ 1457.IBPluginDependency 1483.IBPluginDependency 1484.IBPluginDependency + 1502.IBPluginDependency + 1503.IBPluginDependency + 1516.IBPluginDependency 2.IBPluginDependency 257.IBPluginDependency - 295.IBPluginDependency 3.IBPluginDependency - 321.IBPluginDependency 4.IBPluginDependency 5.IBPluginDependency 6.IBPluginDependency @@ -4808,8 +4837,8 @@ com.apple.InterfaceBuilder.CocoaPlugin YES - read only - read/write + Read Only + Read/Write com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -4873,6 +4902,7 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin @@ -4887,216 +4917,9 @@ - 1501 - - - - YES - - InspectorPane - NSView - - toggleCollapsed: - id - - - toggleCollapsed: - - toggleCollapsed: - id - - - - YES - - YES - collapseButton - paneBody - paneHead - titleTextField - - - YES - NSButton - InspectorPaneBody - InspectorPaneHead - NSTextField - - - - YES - - YES - collapseButton - paneBody - paneHead - titleTextField - - - YES - - collapseButton - NSButton - - - paneBody - InspectorPaneBody - - - paneHead - InspectorPaneHead - - - titleTextField - NSTextField - - - - - IBProjectSource - ./Classes/InspectorPane.h - - - - InspectorPaneBody - NSView - - IBProjectSource - ./Classes/InspectorPaneBody.h - - - - InspectorPaneContainer - NSView - - IBProjectSource - ./Classes/InspectorPaneContainer.h - - - - InspectorPaneHead - NSView - - pane - InspectorPane - - - pane - - pane - InspectorPane - - - - IBProjectSource - ./Classes/InspectorPaneHead.h - - - - NonEmptyStringFormatter - NSFormatter - - IBProjectSource - ./Classes/NonEmptyStringFormatter.h - - - - PithosNodeInfoController - NSWindowController - - IBProjectSource - ./Classes/PithosNodeInfoController.h - - - - PithosObjectNodeInfoController - PithosNodeInfoController - - downloadVersion: - id - - - downloadVersion: - - downloadVersion: - id - - - - YES - - YES - metadataDictionaryController - metadataInspectorPane - otherMetadataInspectorPane - sharingDictionaryController - versionsArrayController - versionsInspectorPane - - - YES - NSDictionaryController - InspectorPane - InspectorPane - NSDictionaryController - NSArrayController - InspectorPane - - - - YES - - YES - metadataDictionaryController - metadataInspectorPane - otherMetadataInspectorPane - sharingDictionaryController - versionsArrayController - versionsInspectorPane - - - YES - - metadataDictionaryController - NSDictionaryController - - - metadataInspectorPane - InspectorPane - - - otherMetadataInspectorPane - InspectorPane - - - sharingDictionaryController - NSDictionaryController - - - versionsArrayController - NSArrayController - - - versionsInspectorPane - InspectorPane - - - - - IBProjectSource - ./Classes/PithosObjectNodeInfoController.h - - - - SharingNameFormatter - NSFormatter - - IBProjectSource - ./Classes/SharingNameFormatter.h - - - + 1623 + 0 IBCocoaFramework diff --git a/pithos-macos/PithosPreferencesController.xib b/pithos-macos/PithosPreferencesController.xib index 49a80df..a00c1e6 100644 --- a/pithos-macos/PithosPreferencesController.xib +++ b/pithos-macos/PithosPreferencesController.xib @@ -82,6 +82,7 @@ 256 {118, 215} + _NS:1828 YES @@ -90,6 +91,7 @@ 256 {118, 17} + _NS:1830 @@ -190,6 +192,7 @@ {{1, 17}, {118, 215}} + _NS:1826 @@ -201,6 +204,7 @@ -2147483392 {{224, 17}, {15, 102}} + _NS:1845 @@ -213,6 +217,7 @@ -2147483392 {{1, 48.325627356767654}, {82.028970718383789, 15}} + _NS:1847 1 @@ -229,6 +234,7 @@ {{1, 0}, {118, 17}} + _NS:1831 @@ -238,6 +244,7 @@ {{20, 47}, {120, 233}} + _NS:1824 133682 @@ -252,6 +259,7 @@ 18 {{147, 37}, {265, 249}} + _NS:608 @@ -268,6 +276,7 @@ 268 {{14, 183}, {41, 14}} + YES @@ -291,6 +300,7 @@ 266 {{60, 181}, {168, 19}} + YES @@ -319,6 +329,7 @@ 266 {{60, 123}, {168, 19}} + YES @@ -337,6 +348,7 @@ 266 {{60, 96}, {168, 19}} + YES @@ -355,6 +367,7 @@ 266 {{60, 69}, {168, 19}} + YES @@ -373,6 +386,7 @@ 268 {{14, 125}, {41, 14}} + YES @@ -391,6 +405,7 @@ 268 {{14, 71}, {41, 14}} + YES @@ -409,6 +424,7 @@ 268 {{14, 98}, {41, 14}} + YES @@ -427,6 +443,7 @@ 268 {{14, 150}, {86, 14}} + YES @@ -445,6 +462,7 @@ -2147483634 {{-3, 170}, {251, 5}} + {0, 0} @@ -468,6 +486,7 @@ 268 {{57, 45}, {63, 18}} + YES @@ -496,6 +515,7 @@ 289 {{161, 4}, {72, 28}} + YES @@ -522,6 +542,7 @@ 289 {{91, 4}, {72, 28}} + YES @@ -542,6 +563,7 @@ {{10, 33}, {245, 203}} + _NS:610 @@ -638,7 +660,6 @@ 289 {{161, 4}, {72, 28}} - YES -2080244224 @@ -760,7 +781,7 @@ 256 {209, 95} - + _NS:13 YES @@ -912,7 +933,7 @@ {{17, 40}, {211, 113}} - + _NS:9 133682 @@ -952,7 +973,7 @@ 4352 {103, 116} - + YES @@ -1062,7 +1083,7 @@ {{17, 66}, {105, 134}} - + 133682 @@ -1085,7 +1106,7 @@ 4352 {103, 116} - + YES @@ -1195,7 +1216,7 @@ {{123, 66}, {105, 134}} - + 133682 @@ -1302,7 +1323,6 @@ 289 {{161, 4}, {72, 28}} - YES -2080244224 @@ -1365,6 +1385,7 @@ 292 {{20, 19}, {20, 20}} + _NS:2510 YES @@ -1389,6 +1410,8 @@ 292 {{39, 19}, {20, 20}} + + _NS:2510 YES @@ -1410,6 +1433,7 @@ {425, 300} + {{0, 0}, {1280, 778}} @@ -1463,9 +1487,6 @@ key value - - NonEmptyStringFormatter - @@ -2533,12 +2554,6 @@ - 484 - - - Non Empty String Formatter - - 505 @@ -3271,7 +3286,6 @@ 338.IBPluginDependency 396.IBPluginDependency 433.IBPluginDependency - 484.IBPluginDependency 5.IBPluginDependency 505.IBPluginDependency 506.IBPluginDependency @@ -3414,7 +3428,6 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -3484,7 +3497,146 @@ 909 - + + + YES + + PithosPreferencesController + NSWindowController + + YES + + YES + addAccount: + groupsApply: + groupsRevert: + login: + loginCancel: + removeAccount: + syncApply: + syncCancel: + syncRefresh: + + + YES + id + id + id + id + id + id + id + id + id + + + + YES + + YES + addAccount: + groupsApply: + groupsRevert: + login: + loginCancel: + removeAccount: + syncApply: + syncCancel: + syncRefresh: + + + YES + + addAccount: + id + + + groupsApply: + id + + + groupsRevert: + id + + + login: + id + + + loginCancel: + id + + + removeAccount: + id + + + syncApply: + id + + + syncCancel: + id + + + syncRefresh: + id + + + + + YES + + YES + accountsArrayController + groupsDictionaryController + selectedGroupMembersDictionaryController + syncAccountsOutlineView + + + YES + NSArrayController + NSDictionaryController + NSDictionaryController + NSOutlineView + + + + YES + + YES + accountsArrayController + groupsDictionaryController + selectedGroupMembersDictionaryController + syncAccountsOutlineView + + + YES + + accountsArrayController + NSArrayController + + + groupsDictionaryController + NSDictionaryController + + + selectedGroupMembersDictionaryController + NSDictionaryController + + + syncAccountsOutlineView + NSOutlineView + + + + + IBProjectSource + ./Classes/PithosPreferencesController.h + + + + 0 IBCocoaFramework diff --git a/pithos-macos/PithosSubdirNode.h b/pithos-macos/PithosSubdirNode.h index c48dd89..6b0199b 100644 --- a/pithos-macos/PithosSubdirNode.h +++ b/pithos-macos/PithosSubdirNode.h @@ -49,6 +49,7 @@ BOOL isPublic; NSString *translatedModifiedBy; + NSMutableArray *translatedPermissions; BOOL refreshParent; } @@ -61,6 +62,7 @@ @property (nonatomic, strong) NSArray *versions; @property (nonatomic, assign) BOOL isPublic; @property (nonatomic, strong) NSString *translatedModifiedBy; +@property (nonatomic, strong) NSMutableArray *translatedPermissions; - (void)applyInfo; - (void)refreshInfo; diff --git a/pithos-macos/PithosSubdirNode.m b/pithos-macos/PithosSubdirNode.m index 46e52ce..993d627 100644 --- a/pithos-macos/PithosSubdirNode.m +++ b/pithos-macos/PithosSubdirNode.m @@ -41,6 +41,7 @@ #import "ASIPithosObjectRequest.h" #import "ASIPithosContainer.h" #import "ASIPithosObject.h" +#import "ASIPithosSharingUser.h" #import "ASINetworkQueue.h" #import "ASIDownloadCache.h" #import "PithosAccount.h" @@ -51,7 +52,7 @@ static NSImage *sharedIcon = nil; @implementation PithosSubdirNode @synthesize pithosObject, versions; -@synthesize isPublic, translatedModifiedBy; +@synthesize isPublic, translatedModifiedBy, translatedPermissions; + (void)initialize { if (self == [PithosSubdirNode class]) @@ -85,18 +86,42 @@ static NSImage *sharedIcon = nil; - (void)updateModifiedBy { if (!pithosObject.modifiedBy) { self.translatedModifiedBy = nil; - } else { - if (pithosAccountManager) { - NSString *displayname = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:NO]; - if (displayname) { - self.translatedModifiedBy = displayname; - } else { - [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:[NSArray arrayWithObject:pithosObject.modifiedBy]]; - self.translatedModifiedBy = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:YES]; - } + } else if (pithosAccountManager) { + NSString *displayname = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:NO]; + if (displayname) { + self.translatedModifiedBy = displayname; } else { - self.translatedModifiedBy = [pithosObject.modifiedBy copy]; + [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:[NSArray arrayWithObject:pithosObject.modifiedBy]]; + self.translatedModifiedBy = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:YES]; } + } else { + self.translatedModifiedBy = [pithosObject.modifiedBy copy]; + } +} + +- (void)updatePermissions { + if (!pithosObject) { + self.translatedPermissions = [NSMutableArray array]; + } else if (pithosAccountManager) { + NSMutableSet *UUIDs = [NSMutableSet set]; + for (ASIPithosSharingUser *sharingUser in pithosObject.permissions) { + [UUIDs addObject:sharingUser.name]; + } + [UUIDs removeObject:@""]; + [UUIDs removeObject:@"*"]; + if (UUIDs.count) { + [pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:[UUIDs allObjects]]; + } + + NSMutableArray *newTranslatedPermissions = [NSMutableArray arrayWithCapacity:pithosObject.permissions.count]; + for (ASIPithosSharingUser *sharingUser in pithosObject.permissions) { + ASIPithosSharingUser *translatedSharingUser = [sharingUser copy]; + translatedSharingUser.name = [pithosAccountManager displaynameForUUID:translatedSharingUser.name safe:YES]; + [newTranslatedPermissions addObject:translatedSharingUser]; + } + self.translatedPermissions = newTranslatedPermissions; + } else { + self.translatedPermissions = [NSMutableArray arrayWithArray:[pithosObject.permissions copy]]; } } @@ -141,13 +166,14 @@ static NSImage *sharedIcon = nil; - (void)setPithosObject:(ASIPithosObject *)aPithosObject { if (![pithosObject isEqualTo:aPithosObject]) { pithosObject = aPithosObject; + [self updateModifiedBy]; + [self updatePermissions]; } if (pithosObject.subdir) { self.prefix = [pithosObject.name substringToIndex:([pithosObject.name length] - 1)]; } else { self.prefix = [NSString stringWithString:pithosObject.name]; } - [self updateModifiedBy]; self.isPublic = (pithosObject.publicURI != nil); // Refresh browser if the object is in my shared and is no longer shared if (shared && !pithosObject.subdir && !pithosObject.sharing) { @@ -174,6 +200,7 @@ static NSImage *sharedIcon = nil; self.pithosObject.sharing = aPithosObject.sharing; self.pithosObject.publicURI = aPithosObject.publicURI; self.pithosObject = pithosObject; + [self updatePermissions]; } else { [self updateModifiedBy]; } @@ -274,11 +301,7 @@ static NSImage *sharedIcon = nil; objectName:prefix]; [PithosUtilities startAndWaitForRequest:request]; if ([request error]) { - alert = [[NSAlert alloc] init]; - [alert setMessageText:@"HTTP Request Error"]; - [alert setInformativeText:[NSString stringWithFormat:@"An error occured: %@", [[request error] localizedDescription]]]; - [alert addButtonWithTitle:@"OK"]; - [alert runModal]; + [PithosUtilities httpRequestErrorAlertWithRequest:request]; return; } else if (request.responseStatusCode == 200) { alert = [[NSAlert alloc] init]; @@ -293,11 +316,7 @@ static NSImage *sharedIcon = nil; objectName:prefix]; [PithosUtilities startAndWaitForRequest:request]; if ([request error]) { - alert = [[NSAlert alloc] init]; - [alert setMessageText:@"HTTP Request Error"]; - [alert setInformativeText:[NSString stringWithFormat:@"An error occured: %@", [[request error] localizedDescription]]]; - [alert addButtonWithTitle:@"OK"]; - [alert runModal]; + [PithosUtilities httpRequestErrorAlertWithRequest:request]; return; } else if (request.responseStatusCode != 204) { [PithosUtilities unexpectedResponseStatusAlertWithRequest:request]; @@ -316,6 +335,124 @@ static NSImage *sharedIcon = nil; } if (createObject) { [[pithosNodeInfoController window] makeFirstResponder:nil]; + NSMutableArray *permissions = [NSMutableArray array]; + if (translatedPermissions.count) { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.group.length && + [translatedsSharingUser.group rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@" -_~,;"]].location != NSNotFound) { + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:@"Invalid Input"]; + [alert setInformativeText:@"Group names cannot contain ' ', '-', '_', '~', ',' or ';'."]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + } + if (pithosAccountManager) { + NSMutableSet *allUsers = [NSMutableSet set]; + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + [allUsers addObject:translatedsSharingUser.name]; + } + } + [allUsers removeObject:@""]; + [allUsers removeObject:@"*"]; + if (allUsers.count) { + ASIPithosRequest *userCatalogRequest = [pithosAccountManager updateUserCatalogForForDisplaynames:[allUsers allObjects] + UUIDs:nil]; + if (userCatalogRequest.error || ((userCatalogRequest.responseStatusCode != 200) && (userCatalogRequest.responseStatusCode != 404))) { + return; + } else if (userCatalogRequest.responseStatusCode == 200) { + // Check if all users exist. + NSDictionary *displaynameCatalog = [userCatalogRequest displaynameCatalog]; + NSMutableArray *inexistentUsers = [NSMutableArray array]; + for (NSString *user in allUsers) { + if (![displaynameCatalog objectForKey:user]) { + [inexistentUsers addObject:user]; + } + } + if (!inexistentUsers.count) { + // Create permissions. + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (![sharingUser.name isEqualToString:@"*"]) { + sharingUser.name = [displaynameCatalog objectForKey:sharingUser.name]; + } + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } else { + NSAlert *alert = [[NSAlert alloc] init]; + if (inexistentUsers.count == 1) { + [alert setMessageText:@"Invalid User"]; + [alert setInformativeText:[NSString stringWithFormat:@"User '%@' doesn't exist.", [inexistentUsers objectAtIndex:0]]]; + } else { + [alert setMessageText:@"Invalid Users"]; + [alert setInformativeText:[NSString stringWithFormat:@"Users '%@' don't exist.", [inexistentUsers componentsJoinedByString:@"', '"]]]; + } + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + } else { + // 404. Since we don't translate to UUIDs, check for invalid chars. + BOOL valid = YES; + // Create permissions. + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length && + ([translatedsSharingUser.name rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@" ~,;:"]].location != NSNotFound)) { + valid = NO; + break; + } + } + if (valid) { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } else { + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:@"Invalid Input"]; + [alert setInformativeText:@"Users cannot contain ' ', '~', ',', ';' or ':'."]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + } + } else { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if ([translatedsSharingUser.name isEqualToString:@"*"]) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } + } else { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } + } + pithosObject.permissions = permissions; + applyMetadataObjectRequest = [ASIPithosObjectRequest writeObjectDataRequestWithPithos:pithos containerName:pithosContainer.name objectName:prefix @@ -324,7 +461,7 @@ static NSImage *sharedIcon = nil; contentEncoding:pithosObject.contentEncoding contentDisposition:pithosObject.contentDisposition manifest:pithosObject.manifest - sharing:pithosObject.sharing + sharing:(pithosObject.sharing ? pithosObject.sharing : @"") isPublic:(isPublic ? ASIPithosObjectRequestPublicTrue : ASIPithosObjectRequestPublicFalse) metadata:pithosObject.metadata data:[NSData data]]; @@ -355,6 +492,124 @@ static NSImage *sharedIcon = nil; update:NO]; [applyMetadataObjectRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithos]; } else { + NSMutableArray *permissions = [NSMutableArray array]; + if (translatedPermissions.count) { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.group.length && + [translatedsSharingUser.group rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@" -_~,;"]].location != NSNotFound) { + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:@"Invalid Input"]; + [alert setInformativeText:@"Group names cannot contain ' ', '-', '_', '~', ',' or ';'."]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + } + if (pithosAccountManager) { + NSMutableSet *allUsers = [NSMutableSet set]; + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + [allUsers addObject:translatedsSharingUser.name]; + } + } + [allUsers removeObject:@""]; + [allUsers removeObject:@"*"]; + if (allUsers.count) { + ASIPithosRequest *userCatalogRequest = [pithosAccountManager updateUserCatalogForForDisplaynames:[allUsers allObjects] + UUIDs:nil]; + if (userCatalogRequest.error || ((userCatalogRequest.responseStatusCode != 200) && (userCatalogRequest.responseStatusCode != 404))) { + return; + } else if (userCatalogRequest.responseStatusCode == 200) { + // Check if all users exist. + NSDictionary *displaynameCatalog = [userCatalogRequest displaynameCatalog]; + NSMutableArray *inexistentUsers = [NSMutableArray array]; + for (NSString *user in allUsers) { + if (![displaynameCatalog objectForKey:user]) { + [inexistentUsers addObject:user]; + } + } + if (!inexistentUsers.count) { + // Create permissions. + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (![sharingUser.name isEqualToString:@"*"]) { + sharingUser.name = [displaynameCatalog objectForKey:sharingUser.name]; + } + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } else { + NSAlert *alert = [[NSAlert alloc] init]; + if (inexistentUsers.count == 1) { + [alert setMessageText:@"Invalid User"]; + [alert setInformativeText:[NSString stringWithFormat:@"User '%@' doesn't exist.", [inexistentUsers objectAtIndex:0]]]; + } else { + [alert setMessageText:@"Invalid Users"]; + [alert setInformativeText:[NSString stringWithFormat:@"Users '%@' don't exist.", [inexistentUsers componentsJoinedByString:@"', '"]]]; + } + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + } else { + // 404. Since we don't translate to UUIDs, check for invalid chars. + BOOL valid = YES; + // Create permissions. + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length && + ([translatedsSharingUser.name rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@" ~,;:"]].location != NSNotFound)) { + valid = NO; + break; + } + } + if (valid) { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } else { + NSAlert *alert = [[NSAlert alloc] init]; + [alert setMessageText:@"Invalid Input"]; + [alert setInformativeText:@"Users cannot contain ' ', '~', ',', ';' or ':'."]; + [alert addButtonWithTitle:@"OK"]; + [alert runModal]; + return; + } + } + } else { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if ([translatedsSharingUser.name isEqualToString:@"*"]) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } + } else { + for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { + if (translatedsSharingUser.name.length) { + ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; + if (!sharingUser.permission) { + sharingUser.permission = @"read"; + } + [permissions addObject:sharingUser]; + } + } + } + } + pithosObject.permissions = permissions; + applyMetadataObjectRequest = [ASIPithosObjectRequest updateObjectMetadataRequestWithPithos:pithos containerName:pithosContainer.name objectName:pithosObject.name diff --git a/pithos-macos/SharingDictionaryTransformer.m b/pithos-macos/SharingDictionaryTransformer.m deleted file mode 100644 index 3f84de3..0000000 --- a/pithos-macos/SharingDictionaryTransformer.m +++ /dev/null @@ -1,121 +0,0 @@ -// -// SharingDictionaryTransformer.m -// pithos-macos -// -// Copyright 2011 GRNET S.A. All rights reserved. -// -// Redistribution and use in source and binary forms, with or -// without modification, are permitted provided that the following -// conditions are met: -// -// 1. Redistributions of source code must retain the above -// copyright notice, this list of conditions and the following -// disclaimer. -// -// 2. Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials -// provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS -// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// The views and conclusions contained in the software and -// documentation are those of the authors and should not be -// interpreted as representing official policies, either expressed -// or implied, of GRNET S.A. - -#import "SharingDictionaryTransformer.h" - -@implementation SharingDictionaryTransformer - -+ (Class)transformedValueClass { - return [NSMutableDictionary class]; -} - -+ (BOOL)allowsReverseTransformation { - return YES; -} - -- (id)transformedValue:(id)value { - NSMutableDictionary *sharingDictionary = [NSMutableDictionary dictionary]; - - if (value == nil) - return sharingDictionary; - - NSRange readRange = [(NSString *)value rangeOfString:@"read=" options:NSCaseInsensitiveSearch]; - NSUInteger readStart = readRange.location + readRange.length; - NSRange writeRange = [(NSString *)value rangeOfString:@"write=" options:NSCaseInsensitiveSearch]; - NSUInteger writeStart = writeRange.location + writeRange.length; - if (writeRange.length == 0) { - if (readRange.length == 0) { - return sharingDictionary; - } - for (NSString *readUser in [[(NSString *)value substringFromIndex:readStart] componentsSeparatedByString:@","]) { - [sharingDictionary setValue:@"read only" forKey:readUser]; - } - } else if (readRange.length == 0) { - for (NSString *writeUser in [[(NSString *)value substringFromIndex:writeStart] componentsSeparatedByString:@","]) { - [sharingDictionary setValue:@"read/write" forKey:writeUser]; - } - } else if (readRange.location < writeRange.location) { - NSRange semicolonRange = [(NSString *)value rangeOfString:@";"]; - for (NSString *readUser in [[(NSString *)value substringWithRange:NSMakeRange(readStart, semicolonRange.location - readStart)] componentsSeparatedByString:@","]) { - [sharingDictionary setValue:@"read only" forKey:readUser]; - } - for (NSString *writeUser in [[(NSString *)value substringFromIndex:writeStart] componentsSeparatedByString:@","]) { - [sharingDictionary setValue:@"read/write" forKey:writeUser]; - } - } else { - NSRange semicolonRange = [(NSString *)value rangeOfString:@";"]; - for (NSString *readUser in [[(NSString *)value substringFromIndex:readStart] componentsSeparatedByString:@","]) { - [sharingDictionary setValue:@"read only" forKey:readUser]; - } - for (NSString *writeUser in [[(NSString *)value substringWithRange:NSMakeRange(writeStart, semicolonRange.location - writeStart)] componentsSeparatedByString:@","]) { - [sharingDictionary setValue:@"read/write" forKey:writeUser]; - } - } - - return sharingDictionary; -} - -- (id)reverseTransformedValue:(id)value { - if ((value == nil) || ([(NSMutableDictionary *)value count] == 0)) - return nil; - - NSString *readSharingString = nil; - NSArray *readUsers = [(NSMutableDictionary *)value allKeysForObject:@"read only"]; - if ([readUsers count]) - readSharingString = [NSString stringWithFormat:@"read=%@", [readUsers componentsJoinedByString:@","]]; - NSString *writeSharingString = nil; - - NSArray *writeUsers = [(NSMutableDictionary *)value allKeysForObject:@"read/write"]; - if ([writeUsers count]) - writeSharingString = [NSString stringWithFormat:@"write=%@", [writeUsers componentsJoinedByString:@","]]; - - - if (readSharingString) { - if (writeSharingString) { - return [NSString stringWithFormat:@"%@;%@", readSharingString, writeSharingString]; - } - return readSharingString; - } else { - return writeSharingString; - } -} - -+ (void)initialize { - [[self class] setValueTransformer:[self new] forName:@"SharingDictionaryTransformer"]; -} - -@end diff --git a/pithos-macos/SharingNameFormatter.m b/pithos-macos/SharingNameFormatter.m deleted file mode 100644 index ed1636e..0000000 --- a/pithos-macos/SharingNameFormatter.m +++ /dev/null @@ -1,71 +0,0 @@ -// -// SharingNameFormatter.m -// pithos-macos -// -// Copyright 2011 GRNET S.A. All rights reserved. -// -// Redistribution and use in source and binary forms, with or -// without modification, are permitted provided that the following -// conditions are met: -// -// 1. Redistributions of source code must retain the above -// copyright notice, this list of conditions and the following -// disclaimer. -// -// 2. Redistributions in binary form must reproduce the above -// copyright notice, this list of conditions and the following -// disclaimer in the documentation and/or other materials -// provided with the distribution. -// -// THIS SOFTWARE IS PROVIDED BY GRNET S.A. ``AS IS'' AND ANY EXPRESS -// OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR -// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GRNET S.A OR -// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF -// USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED -// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE -// POSSIBILITY OF SUCH DAMAGE. -// -// The views and conclusions contained in the software and -// documentation are those of the authors and should not be -// interpreted as representing official policies, either expressed -// or implied, of GRNET S.A. - -#import "SharingNameFormatter.h" - -@implementation SharingNameFormatter - -- (NSString *)stringForObjectValue:(id)anObject { - if (anObject != nil) - return [NSString stringWithString:anObject]; - return nil; -} - -- (BOOL)getObjectValue:(id *)anObject forString:(NSString *)string errorDescription:(NSString **)error { - *anObject = [NSString stringWithString:string]; - return YES; -} - -- (BOOL)isPartialStringValid:(NSString *)partialString newEditingString:(NSString **)newString errorDescription:(NSString **)error { - if ([partialString length] == 0) { - *newString = nil; - return NO; - } - - unichar aChar; - for (int i = 0; i < [partialString length]; i++) { - aChar = [partialString characterAtIndex:i]; - if ((aChar == ' ') || (aChar == '=') || (aChar == ',') || (aChar == ';')) { - *newString = nil; - return NO; - } - } - - return YES; -} - -@end diff --git a/pithos-macos/SharingDictionaryTransformer.h b/pithos-macos/SharingUserPermissionTransformer.h similarity index 90% rename from pithos-macos/SharingDictionaryTransformer.h rename to pithos-macos/SharingUserPermissionTransformer.h index 39ee3f4..7626764 100644 --- a/pithos-macos/SharingDictionaryTransformer.h +++ b/pithos-macos/SharingUserPermissionTransformer.h @@ -1,8 +1,8 @@ // -// SharingDictionaryTransformer.h +// SharingUserPermissionTransformer.h // pithos-macos // -// Copyright 2011 GRNET S.A. All rights reserved. +// Copyright 2013 GRNET S.A. All rights reserved. // // Redistribution and use in source and binary forms, with or // without modification, are permitted provided that the following @@ -35,5 +35,5 @@ // interpreted as representing official policies, either expressed // or implied, of GRNET S.A. -@interface SharingDictionaryTransformer : NSValueTransformer +@interface SharingUserPermissionTransformer : NSValueTransformer @end diff --git a/pithos-macos/SharingNameFormatter.h b/pithos-macos/SharingUserPermissionTransformer.m similarity index 66% rename from pithos-macos/SharingNameFormatter.h rename to pithos-macos/SharingUserPermissionTransformer.m index 80f025b..1d5a1a7 100644 --- a/pithos-macos/SharingNameFormatter.h +++ b/pithos-macos/SharingUserPermissionTransformer.m @@ -1,8 +1,8 @@ // -// SharingNameFormatter.h +// SharingUserPermissionTransformer.m // pithos-macos // -// Copyright 2011 GRNET S.A. All rights reserved. +// Copyright 2013 GRNET S.A. All rights reserved. // // Redistribution and use in source and binary forms, with or // without modification, are permitted provided that the following @@ -35,5 +35,36 @@ // interpreted as representing official policies, either expressed // or implied, of GRNET S.A. -@interface SharingNameFormatter : NSFormatter +#import "SharingUserPermissionTransformer.h" + +@implementation SharingUserPermissionTransformer + ++ (Class)transformedValueClass { + return [NSString class]; +} + ++ (BOOL)allowsReverseTransformation { + return YES; +} + +- (id)transformedValue:(id)value { + if (value && [(NSString *)value isEqualToString:@"write"]) { + return @"Read/Write"; + } else { + return @"Read Only"; + } +} + +- (id)reverseTransformedValue:(id)value { + if (value && [(NSString *)value isEqualToString:@"Read/Write"]) { + return @"write"; + } else { + return @"read"; + } +} + ++ (void)initialize { + [[self class] setValueTransformer:[self new] forName:@"SharingUserPermissionTransformer"]; +} + @end -- 1.7.10.4