]> err.no Git - scalable-opengroupware.org/blobdiff - UI/SOGoUI/UIxComponent.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1287 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / UI / SOGoUI / UIxComponent.m
index 59ab845d6144ef34ea6d9a7f9dc5b684cbd34445..50e6bf253c28cc32521870927b9aae8003c7bafd 100644 (file)
   02111-1307, USA.
 */
 
-#import "SOGoJSStringFormatter.h"
-#import "common.h"
+#import <Foundation/NSDictionary.h>
+#import <Foundation/NSException.h>
+#import <Foundation/NSUserDefaults.h>
+#import <Foundation/NSKeyValueCoding.h>
+#import <Foundation/NSPathUtilities.h>
 
 #import <NGObjWeb/SoHTTPAuthenticator.h>
+#import <NGObjWeb/SoObjects.h>
 #import <NGObjWeb/WOResourceManager.h>
-
-#import <SOGo/NSString+Utilities.h>
-
-#import <SOGo/SOGoUser.h>
-#import <SOGo/SOGoObject.h>
-#import <SOGo/SOGoCustomGroupFolder.h>
-#import <SOGo/NSCalendarDate+SOGo.h>
-
-#import "../Common/UIxJSClose.h"
+#import <NGObjWeb/WORequest.h>
+#import <NGObjWeb/WOResponse.h>
+#import <NGObjWeb/WOContext+SoObjects.h>
+#import <NGExtensions/NSObject+Logs.h>
+#import <NGExtensions/NSString+misc.h>
+#import <NGExtensions/NSURL+misc.h>
+
+#import <SoObjects/SOGo/NSCalendarDate+SOGo.h>
+#import <SoObjects/SOGo/NSString+Utilities.h>
+#import <SoObjects/SOGo/SOGoUser.h>
+#import <SoObjects/SOGo/SOGoObject.h>
+#import <SoObjects/SOGo/SOGoContentObject.h>
+#import <SoObjects/SOGo/SOGoCustomGroupFolder.h>
+#import <SoObjects/SOGo/SOGoPermissions.h>
+
+#import "UIxJSClose.h"
 
 #import "UIxComponent.h"
 
@@ -124,9 +135,8 @@ static BOOL uixDebugEnabled = NO;
 
 - (void) dealloc
 {
-  [self->queryParameters release];
-  if (_selectedDate)
-    [_selectedDate release];
+  [queryParameters release];
+  [_selectedDate release];
   [super dealloc];
 }
 
@@ -156,7 +166,7 @@ static BOOL uixDebugEnabled = NO;
           value = [[part substringFromIndex:(r.location + r.length)] 
                     stringByUnescapingURL];
         }
-      [self->queryParameters setObject:value forKey:key];
+      [queryParameters setObject:value forKey:key];
       part = [e nextObject];
     }
 }
@@ -190,12 +200,12 @@ static BOOL uixDebugEnabled = NO;
   NSRange   r;
   NSString *qs;
   
-  if (self->queryParameters)
-    return self->queryParameters;
+  if (queryParameters)
+    return queryParameters;
 
-  self->queryParameters = [[NSMutableDictionary alloc] initWithCapacity:8];
+  queryParameters = [[NSMutableDictionary alloc] initWithCapacity:8];
 
-  req = [[self context] request];
+  req = [context request];
   uri = [req uri];
   r   = [uri rangeOfString:@"?" options:NSBackwardsSearch];
   if (r.length > 0)
@@ -207,7 +217,7 @@ static BOOL uixDebugEnabled = NO;
   /* add form values */
   [self addKeepAliveFormValuesToQueryParameters];
 
-  return self->queryParameters;
+  return queryParameters;
 }
 
 - (NSDictionary *) queryParameters
@@ -242,7 +252,7 @@ static BOOL uixDebugEnabled = NO;
   qp = [self queryParameters];
   if ([qp count] > 0)
     {
-      ctx = [self context];
+      ctx = context;
       qps = [ctx queryPathSeparator];
       [ctx setQueryPathSeparator: @"&"];
       qs = [ctx queryStringFromDictionary: qp];
@@ -260,7 +270,7 @@ static BOOL uixDebugEnabled = NO;
   NSString *uri;
   NSRange  r;
     
-  uri = [[[self context] request] uri];
+  uri = [[context request] uri];
     
   /* first: cut off query parameters */
     
@@ -269,7 +279,7 @@ static BOOL uixDebugEnabled = NO;
     uri = [uri substringToIndex:r.location];
     
   /* next: strip trailing slash */
-    
+
   if ([uri hasSuffix: @"/"])
     uri = [uri substringToIndex: ([uri length] - 1)];
   r = [uri rangeOfString:@"/" options: NSBackwardsSearch];
@@ -285,12 +295,11 @@ static BOOL uixDebugEnabled = NO;
 - (NSString *) userFolderPath
 {
   WOContext *ctx;
-  NSString  *url, *path;
   NSEnumerator *objects;
   SOGoObject *currentObject;
   BOOL found;
 
-  ctx = [self context];
+  ctx = context;
   objects = [[ctx objectTraversalStack] objectEnumerator];
   currentObject = [objects nextObject];
   found = NO;
@@ -301,41 +310,39 @@ static BOOL uixDebugEnabled = NO;
     else
       currentObject = [objects nextObject];
 
-  url = [currentObject baseURLInContext:ctx];
-  path = [[NSURL URLWithString:url] path];
-
-  return path;
+  return [[currentObject baseURLInContext:ctx] hostlessURL];
 }
 
 - (NSString *) applicationPath
 {
   SOGoObject *currentClient, *parent;
-  NSString *url;
   BOOL found;
   Class objectClass, groupFolderClass, userFolderClass;
-  WOContext *ctx;
-
-  groupFolderClass = [SOGoCustomGroupFolder class];
-  userFolderClass = [SOGoUserFolder class];
 
   currentClient = [self clientObject];
-  objectClass = [currentClient class];
-  found = (objectClass == groupFolderClass || objectClass == userFolderClass);
-  while (!found && currentClient)
+  if (currentClient
+      && [currentClient isKindOfClass: [SOGoObject class]])
     {
-      parent = [currentClient container];
-      objectClass = [parent class];
-      if (objectClass == groupFolderClass
-          || objectClass == userFolderClass)
-        found = YES;
-      else
-        currentClient = parent;
+      groupFolderClass = [SOGoCustomGroupFolder class];
+      userFolderClass = [SOGoUserFolder class];
+
+      objectClass = [currentClient class];
+      found = (objectClass == groupFolderClass || objectClass == userFolderClass);
+      while (!found && currentClient)
+       {
+         parent = [currentClient container];
+         objectClass = [parent class];
+         if (objectClass == groupFolderClass
+             || objectClass == userFolderClass)
+           found = YES;
+         else
+           currentClient = parent;
+       }
     }
+  else
+    currentClient = [WOApplication application];
 
-  ctx = [self context];
-  url = [currentClient baseURLInContext: ctx];
-
-  return [[NSURL URLWithString: url] path];
+  return [[currentClient baseURLInContext: context] hostlessURL];
 }
 
 - (NSString *) resourcesPath
@@ -353,7 +360,7 @@ static BOOL uixDebugEnabled = NO;
   NSString *uri;
   NSRange  r;
   
-  uri = [[[self context] request] uri];
+  uri = [[context request] uri];
   
   /* first: cut off query parameters */
   
@@ -368,7 +375,7 @@ static BOOL uixDebugEnabled = NO;
 {
   NSString *dst, *rel;
 
-  dst = [[self userFolderPath] stringByAppendingPathComponent:_sub];
+  dst = [[self userFolderPath] stringByAppendingPathComponent: _sub];
   rel = [dst urlPathRelativeToPath:[self ownPath]];
 
   return rel;
@@ -376,13 +383,16 @@ static BOOL uixDebugEnabled = NO;
 
 - (NSCalendarDate *) selectedDate
 {
+  NSTimeZone *userTimeZone;
+
   if (!_selectedDate)
     {
+      userTimeZone = [[context activeUser] timeZone];
       _selectedDate
         = [NSCalendarDate
             dateFromShortDateString: [self queryParameterForKey: @"day"]
             andShortTimeString: [self queryParameterForKey: @"hm"]
-            inTimeZone: [[self clientObject] userTimeZone]];
+            inTimeZone: userTimeZone];
       [_selectedDate retain];
     }
 
@@ -391,9 +401,12 @@ static BOOL uixDebugEnabled = NO;
 
 - (NSString *) dateStringForDate: (NSCalendarDate *) _date
 {
-  [_date setTimeZone: [[self clientObject] userTimeZone]];
+  NSTimeZone *userTimeZone;
+
+  userTimeZone = [[context activeUser] timeZone];
+  [_date setTimeZone: userTimeZone];
 
-  return [_date descriptionWithCalendarFormat:@"%Y%m%d"];
+  return [_date descriptionWithCalendarFormat: @"%Y%m%d"];
 }
 
 - (BOOL) hideFrame
@@ -412,37 +425,26 @@ static BOOL uixDebugEnabled = NO;
   return jsClose;
 }
 
-/* SoUser */
-
-- (SoUser *) user
+/* common conditions */
+- (BOOL) canCreateOrModify
 {
-  WOContext *ctx;
-  
-  ctx = [self context];
+  SoSecurityManager *sm;
 
-  return [[[self clientObject] authenticatorInContext: ctx] userInContext: ctx];
+  sm = [SoSecurityManager sharedSecurityManager];
+
+  return (![sm validatePermission: SoPerm_ChangeImagesAndFiles
+              onObject: [self clientObject]
+              inContext: context]);
 }
 
+/* SoUser */
+
 - (NSString *) shortUserNameForDisplay
 {
-  // TODO: better use a SoUser formatter?
-  // TODO: who calls that?
-  NSString *s;
-  NSRange  r;
-  
-  // TODO: USE USER MANAGER INSTEAD!
-  
-  s = [[self user] login];
-  if ([s length] < 10)
-    return s;
-    
-  // TODO: algorithm might be inappropriate, depends on the actual UID
-    
-  r = [s rangeOfString:@"."];
-  if (r.length == 0)
-    return s;
-    
-  return [s substringToIndex:r.location];
+  if ([context activeUser] == nil)
+    return @"wrongusernamepassword";
+
+  return [[context activeUser] login];
 }
 
 /* labels */
@@ -459,7 +461,7 @@ static BOOL uixDebugEnabled = NO;
   
   /* lookup languages */
     
-  languages = [[self context] resourceLookupLanguages];
+  languages = [context resourceLookupLanguages];
     
   /* find resource manager */
     
@@ -487,12 +489,6 @@ static BOOL uixDebugEnabled = NO;
   if ([lTable hasPrefix:@"$"])
     lTable = [self valueForKeyPath:[lTable substringFromIndex:1]];
   
-#if 0
-  if ([lVal hasPrefix:@"$"])
-    lVal = [self valueForKeyPath:[lVal substringFromIndex:1]];
-  
-#endif
-  
   /* lookup string */
   return [rm stringForKey: lKey
              inTableNamed: lTable
@@ -526,7 +522,7 @@ static BOOL uixDebugEnabled = NO;
   // TODO: move to WORequest?
   NSString *m;
   
-  m = [[[self context] request] method];
+  m = [[context request] method];
   if ([m isEqualToString:@"GET"])  return YES;
   if ([m isEqualToString:@"HEAD"]) return YES;
   return NO;
@@ -536,14 +532,14 @@ static BOOL uixDebugEnabled = NO;
 
 - (NSDictionary *)locale {
   /* we need no fallback here, as locale is guaranteed to be set by sogod */
-  return [[self context] valueForKey:@"locale"];
+  return [context valueForKey: @"locale"];
 }
 
 - (WOResourceManager *) pageResourceManager
 {
   WOResourceManager *rm;
   
-  if ((rm = [[[self context] page] resourceManager]) == nil)
+  if ((rm = [[context page] resourceManager]) == nil)
     rm = [[WOApplication application] resourceManager];
 
   return rm;
@@ -566,12 +562,12 @@ static BOOL uixDebugEnabled = NO;
       if (!url)
         {
           rm = [self pageResourceManager];
-          page = [[self context] page];
+          page = [context page];
           pageBundle = [NSBundle bundleForClass: [page class]];
           url = [rm urlForResourceNamed: filename
                     inFramework: [pageBundle bundlePath]
                     languages: nil
-                    request: [[self context] request]];
+                    request: [context request]];
           if (!url)
             url = @"";
           else
@@ -588,6 +584,16 @@ static BOOL uixDebugEnabled = NO;
   return url;
 }
 
+- (WOResponse *) responseWith204
+{
+  WOResponse *response;
+
+  response = [context response];
+  [response setStatus: 204];
+
+  return response;
+}
+
 /* debugging */
 
 - (BOOL)isUIxDebugEnabled {