Revision ec392f75 pithos-macos/PithosObjectNode.m
b/pithos-macos/PithosObjectNode.m | ||
---|---|---|
41 | 41 |
#import "ASIPithosObjectRequest.h" |
42 | 42 |
#import "ASIPithosContainer.h" |
43 | 43 |
#import "ASIPithosObject.h" |
44 |
#import "ASIPithosSharingUser.h" |
|
44 | 45 |
#import "ASIDownloadCache.h" |
45 | 46 |
#import "PithosAccount.h" |
46 | 47 |
#import "PithosUtilities.h" |
... | ... | |
48 | 49 |
|
49 | 50 |
@implementation PithosObjectNode |
50 | 51 |
@synthesize pithos, pithosContainer, pithosObject, versions; |
51 |
@synthesize isPublic, translatedModifiedBy; |
|
52 |
@synthesize isPublic, translatedModifiedBy, translatedPermissions;
|
|
52 | 53 |
|
53 | 54 |
#pragma mark - |
54 | 55 |
#pragma mark Object Lifecycle |
... | ... | |
77 | 78 |
- (void)updateModifiedBy { |
78 | 79 |
if (!pithosObject.modifiedBy) { |
79 | 80 |
self.translatedModifiedBy = nil; |
80 |
} else { |
|
81 |
if (pithosAccountManager) { |
|
82 |
NSString *displayname = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:NO]; |
|
83 |
if (displayname) { |
|
84 |
self.translatedModifiedBy = displayname; |
|
85 |
} else { |
|
86 |
[pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:[NSArray arrayWithObject:pithosObject.modifiedBy]]; |
|
87 |
self.translatedModifiedBy = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:YES]; |
|
88 |
} |
|
81 |
} else if (pithosAccountManager) { |
|
82 |
NSString *displayname = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:NO]; |
|
83 |
if (displayname) { |
|
84 |
self.translatedModifiedBy = displayname; |
|
89 | 85 |
} else { |
90 |
self.translatedModifiedBy = [pithosObject.modifiedBy copy]; |
|
86 |
[pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:[NSArray arrayWithObject:pithosObject.modifiedBy]]; |
|
87 |
self.translatedModifiedBy = [pithosAccountManager displaynameForUUID:pithosObject.modifiedBy safe:YES]; |
|
91 | 88 |
} |
89 |
} else { |
|
90 |
self.translatedModifiedBy = [pithosObject.modifiedBy copy]; |
|
91 |
} |
|
92 |
} |
|
93 |
|
|
94 |
- (void)updatePermissions { |
|
95 |
if (!pithosObject) { |
|
96 |
self.translatedPermissions = [NSMutableArray array]; |
|
97 |
} else if (pithosAccountManager) { |
|
98 |
NSMutableSet *UUIDs = [NSMutableSet set]; |
|
99 |
for (ASIPithosSharingUser *sharingUser in pithosObject.permissions) { |
|
100 |
[UUIDs addObject:sharingUser.name]; |
|
101 |
} |
|
102 |
[UUIDs removeObject:@""]; |
|
103 |
[UUIDs removeObject:@"*"]; |
|
104 |
if (UUIDs.count) { |
|
105 |
[pithosAccountManager updateUserCatalogForForDisplaynames:nil UUIDs:[UUIDs allObjects]]; |
|
106 |
} |
|
107 |
|
|
108 |
NSMutableArray *newTranslatedPermissions = [NSMutableArray arrayWithCapacity:pithosObject.permissions.count]; |
|
109 |
for (ASIPithosSharingUser *sharingUser in pithosObject.permissions) { |
|
110 |
ASIPithosSharingUser *translatedSharingUser = [sharingUser copy]; |
|
111 |
translatedSharingUser.name = [pithosAccountManager displaynameForUUID:translatedSharingUser.name safe:YES]; |
|
112 |
[newTranslatedPermissions addObject:translatedSharingUser]; |
|
113 |
} |
|
114 |
self.translatedPermissions = newTranslatedPermissions; |
|
115 |
} else { |
|
116 |
self.translatedPermissions = [NSMutableArray arrayWithArray:[pithosObject.permissions copy]]; |
|
92 | 117 |
} |
93 | 118 |
} |
94 | 119 |
|
... | ... | |
137 | 162 |
- (void)setPithosObject:(ASIPithosObject *)aPithosObject { |
138 | 163 |
if (![pithosObject isEqualTo:aPithosObject]) { |
139 | 164 |
pithosObject = aPithosObject; |
165 |
[self updateModifiedBy]; |
|
166 |
[self updatePermissions]; |
|
140 | 167 |
} |
141 |
[self updateModifiedBy]; |
|
142 | 168 |
self.isPublic = (pithosObject.publicURI != nil); |
143 | 169 |
// Refresh browser if the object is in my shared and is no longer shared |
144 | 170 |
if (shared && !pithosObject.sharing) |
... | ... | |
164 | 190 |
self.pithosObject.sharing = aPithosObject.sharing; |
165 | 191 |
self.pithosObject.publicURI = aPithosObject.publicURI; |
166 | 192 |
self.pithosObject = pithosObject; |
193 |
[self updatePermissions]; |
|
167 | 194 |
} else { |
168 | 195 |
[self updateModifiedBy]; |
169 | 196 |
} |
... | ... | |
252 | 279 |
if (applyMetadataObjectRequest == nil) { |
253 | 280 |
[[pithosNodeInfoController window] makeFirstResponder:nil]; |
254 | 281 |
if (sharingAccount) { |
255 |
applyMetadataObjectRequest = [ASIPithosObjectRequest updateObjectMetadataRequestWithPithos:pithos
|
|
256 |
containerName:pithosContainer.name
|
|
257 |
objectName:pithosObject.name
|
|
258 |
contentEncoding:nil
|
|
259 |
contentDisposition:nil
|
|
260 |
manifest:nil
|
|
261 |
sharing:nil
|
|
262 |
isPublic:(isPublic ? ASIPithosObjectRequestPublicTrue : ASIPithosObjectRequestPublicFalse)
|
|
263 |
metadata:pithosObject.metadata
|
|
264 |
update:NO];
|
|
282 |
applyMetadataObjectRequest = [ASIPithosObjectRequest updateObjectMetadataRequestWithPithos:pithos |
|
283 |
containerName:pithosContainer.name
|
|
284 |
objectName:pithosObject.name
|
|
285 |
contentEncoding:nil
|
|
286 |
contentDisposition:nil
|
|
287 |
manifest:nil
|
|
288 |
sharing:nil |
|
289 |
isPublic:(isPublic ? ASIPithosObjectRequestPublicTrue : ASIPithosObjectRequestPublicFalse)
|
|
290 |
metadata:pithosObject.metadata |
|
291 |
update:NO]; |
|
265 | 292 |
[applyMetadataObjectRequest setRequestUserFromDefaultTo:sharingAccount withPithos:pithos]; |
266 | 293 |
} else { |
294 |
NSMutableArray *permissions = [NSMutableArray array]; |
|
295 |
if (translatedPermissions.count) { |
|
296 |
for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { |
|
297 |
if (translatedsSharingUser.group.length && |
|
298 |
[translatedsSharingUser.group rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@" -_~,;"]].location != NSNotFound) { |
|
299 |
NSAlert *alert = [[NSAlert alloc] init]; |
|
300 |
[alert setMessageText:@"Invalid Input"]; |
|
301 |
[alert setInformativeText:@"Group names cannot contain ' ', '-', '_', '~', ',' or ';'."]; |
|
302 |
[alert addButtonWithTitle:@"OK"]; |
|
303 |
[alert runModal]; |
|
304 |
return; |
|
305 |
} |
|
306 |
} |
|
307 |
if (pithosAccountManager) { |
|
308 |
NSMutableSet *allUsers = [NSMutableSet set]; |
|
309 |
for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { |
|
310 |
if (translatedsSharingUser.name.length) { |
|
311 |
[allUsers addObject:translatedsSharingUser.name]; |
|
312 |
} |
|
313 |
} |
|
314 |
[allUsers removeObject:@""]; |
|
315 |
[allUsers removeObject:@"*"]; |
|
316 |
if (allUsers.count) { |
|
317 |
ASIPithosRequest *userCatalogRequest = [pithosAccountManager updateUserCatalogForForDisplaynames:[allUsers allObjects] |
|
318 |
UUIDs:nil]; |
|
319 |
if (userCatalogRequest.error || ((userCatalogRequest.responseStatusCode != 200) && (userCatalogRequest.responseStatusCode != 404))) { |
|
320 |
return; |
|
321 |
} else if (userCatalogRequest.responseStatusCode == 200) { |
|
322 |
// Check if all users exist. |
|
323 |
NSDictionary *displaynameCatalog = [userCatalogRequest displaynameCatalog]; |
|
324 |
NSMutableArray *inexistentUsers = [NSMutableArray array]; |
|
325 |
for (NSString *user in allUsers) { |
|
326 |
if (![displaynameCatalog objectForKey:user]) { |
|
327 |
[inexistentUsers addObject:user]; |
|
328 |
} |
|
329 |
} |
|
330 |
if (!inexistentUsers.count) { |
|
331 |
// Create permissions. |
|
332 |
for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { |
|
333 |
if (translatedsSharingUser.name.length) { |
|
334 |
ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; |
|
335 |
if (![sharingUser.name isEqualToString:@"*"]) { |
|
336 |
sharingUser.name = [displaynameCatalog objectForKey:sharingUser.name]; |
|
337 |
} |
|
338 |
if (!sharingUser.permission) { |
|
339 |
sharingUser.permission = @"read"; |
|
340 |
} |
|
341 |
[permissions addObject:sharingUser]; |
|
342 |
} |
|
343 |
} |
|
344 |
} else { |
|
345 |
NSAlert *alert = [[NSAlert alloc] init]; |
|
346 |
if (inexistentUsers.count == 1) { |
|
347 |
[alert setMessageText:@"Invalid User"]; |
|
348 |
[alert setInformativeText:[NSString stringWithFormat:@"User '%@' doesn't exist.", [inexistentUsers objectAtIndex:0]]]; |
|
349 |
} else { |
|
350 |
[alert setMessageText:@"Invalid Users"]; |
|
351 |
[alert setInformativeText:[NSString stringWithFormat:@"Users '%@' don't exist.", [inexistentUsers componentsJoinedByString:@"', '"]]]; |
|
352 |
} |
|
353 |
[alert addButtonWithTitle:@"OK"]; |
|
354 |
[alert runModal]; |
|
355 |
return; |
|
356 |
} |
|
357 |
} else { |
|
358 |
// 404. Since we don't translate to UUIDs, check for invalid chars. |
|
359 |
BOOL valid = YES; |
|
360 |
// Create permissions. |
|
361 |
for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { |
|
362 |
if (translatedsSharingUser.name.length && |
|
363 |
([translatedsSharingUser.name rangeOfCharacterFromSet:[NSCharacterSet characterSetWithCharactersInString:@" ~,;:"]].location != NSNotFound)) { |
|
364 |
valid = NO; |
|
365 |
break; |
|
366 |
} |
|
367 |
} |
|
368 |
if (valid) { |
|
369 |
for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { |
|
370 |
if (translatedsSharingUser.name.length) { |
|
371 |
ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; |
|
372 |
if (!sharingUser.permission) { |
|
373 |
sharingUser.permission = @"read"; |
|
374 |
} |
|
375 |
[permissions addObject:sharingUser]; |
|
376 |
} |
|
377 |
} |
|
378 |
} else { |
|
379 |
NSAlert *alert = [[NSAlert alloc] init]; |
|
380 |
[alert setMessageText:@"Invalid Input"]; |
|
381 |
[alert setInformativeText:@"Users cannot contain ' ', '~', ',', ';' or ':'."]; |
|
382 |
[alert addButtonWithTitle:@"OK"]; |
|
383 |
[alert runModal]; |
|
384 |
return; |
|
385 |
} |
|
386 |
} |
|
387 |
} else { |
|
388 |
for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { |
|
389 |
if ([translatedsSharingUser.name isEqualToString:@"*"]) { |
|
390 |
ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; |
|
391 |
if (!sharingUser.permission) { |
|
392 |
sharingUser.permission = @"read"; |
|
393 |
} |
|
394 |
[permissions addObject:sharingUser]; |
|
395 |
} |
|
396 |
} |
|
397 |
} |
|
398 |
} else { |
|
399 |
for (ASIPithosSharingUser *translatedsSharingUser in translatedPermissions) { |
|
400 |
if (translatedsSharingUser.name.length) { |
|
401 |
ASIPithosSharingUser *sharingUser = [translatedsSharingUser copy]; |
|
402 |
if (!sharingUser.permission) { |
|
403 |
sharingUser.permission = @"read"; |
|
404 |
} |
|
405 |
[permissions addObject:sharingUser]; |
|
406 |
} |
|
407 |
} |
|
408 |
} |
|
409 |
} |
|
410 |
pithosObject.permissions = permissions; |
|
411 |
|
|
267 | 412 |
applyMetadataObjectRequest = [ASIPithosObjectRequest updateObjectMetadataRequestWithPithos:pithos |
268 | 413 |
containerName:pithosContainer.name |
269 | 414 |
objectName:pithosObject.name |
Also available in: Unified diff